Pymongo : skip line in cursor - cursor

How to skip a line in cursor. I used next() but I got an error.
Here is my code:
for row in cursor:
if(...):
move to next line
else :
...
Thank you

Try something like this:
for row in cursor:
if (...):
continue
standard logic here....

Related

Update with wildcard

in need to update all the rows that have sub string like this:
'forcestartpage=xx'and replace it with 'forcestartpage=18'
* there is lots of characters before and after the substring that shouldnt change
tried this, doesnt work:
update t_reminderscont
set body = REPLACE (body,'forcestartpage=__','forcestartpage=18')
thanks
You can get away with a STUFF function:
SELECT
T.body,
Replaced = STUFF(
T.Body, -- Insert in T.Body
CHARINDEX('forcestartpage=', T.Body), -- ... at the position where 'forcestartpage=' starts
LEN('forcestartpage=18'), -- ... while replacing 17 characters
'forcestartpage=18') -- ... the value forcestartpage=18
FROM
YourTable AS T
WHERE
T.body LIKE '%forcestartpage=__%' AND
T.body NOT LIKE '%forcestartpage=18%'
However this will only work for the first appearance of the forcestartpage= on each row.

stucking logical operator in WHILE statement

as you can see my picture above, i have problem with logical operators, so i need a looping program for searching data, my parameter can be filled with game_code or game_title, but there are some problem in the looping sequence.
so how to solve this problem, i tried this but not work
begin
write(#32'Enter Game Title or Code: '); readln(param);
i:=1;
while((data[i].game_title<>param) or (data[i].game_code<>param)) and (i<totaldata) do
i:=i+1;
if (data[i].game_title=param) or (data[i].game_code=param) then
You seem to be missing a parenthesis. try this and let me know:
while(((data[i].game_title=param) or (data[i].game_code=param)) and (i<totaldata)) do
begin
i:=i+1;
end;
You should go with and:
while (i < totaldata) and (data[i].game_title <> param) and (data[i].game_code <> param) do
i:=i+1;
The or expression (data[i].game_title <> param) or (data[i].game_code <> param) will always be true until game_title = game_data = param.
Note that i < totaldata check must be done first to avoid access to memory out of array bounds.

Nested loop conditional

Supposed I have this table:
TDID TDLINE
F04 04-AA
F04 04-BB <-- call a function
F05 05-AA
F05 05-BB <-- call a function
F06 06-AA <-- call a function
I would like to call a function while the TDID field is not the same as the previous one. I have the code below, it works but somehow it's not perfectly works (it missed the last row):
LOOP AT lines ASSIGNING <fs1>.
IF <fs2> IS INITIAL.
<fs2> = <fs1>.
ELSE.
li_line-tdline = <fs2>-tdline.
APPEND li_line.
IF <fs1>-tdid NE <fs2>-tdid.
li_thead-tdid = <fs2>-tdid.
CALL FUNCTION 'SAVE_TEXT'
EXPORTING
header = li_thead
savemode_direct = 'X'
TABLES
lines = li_line
CLEAR: li_thead,
li_line.
FREE: li_thead,
li_line.
ENDIF.
ENDIF.
ENDLOOP.
ANSWER
Thank you to vwegert for the answer:
LOOP AT lines ASSIGNING <fs1>.
AT NEW tdid.
REFRESH li_thead.
REFRESH li_line.
li_thead-tdid = <fs1>-tdid.
APPEND li_thead.
ENDAT.
li_line-tdline = <fs1>-tdline.
APPEND li_line.
AT END OF tdid.
CALL FUNCTION 'SAVE_TEXT'
EXPORTING
header = li_thead
savemode_direct = 'X'
TABLES
lines = li_line
ENDAT.
ENDLOOP.
Assuming that the table is sorted by TDID and no field left of TDID changes more frequently than TDID:
LOOP AT lines ASSIGNING <fs1>.
AT NEW tdid.
REFRESH some_other_tab.
ENDAT.
APPEND <fs1> TO some_other_tab.
AT END OF tdid.
CALL FUNCTION ...
ENDAT.
ENDLOOP.
The unpredictability as mentioned by vwegert comes because the characters fields next to the field on which Control statement is applied are converted to asterisks(*). If you want to use these values in the control statement make sure you copy the values in a temporary table and loop on it instead of the original internal table and use the values using READ on the original internal table. Also keep in mind that control statement considers all columns to the left of the column being used in the statement for it's condition.

Reading and processing file in Pascal won't work after first line

I'm having trouble reading more than one line from a data file in Pascal. It gives me an "Invalid numeric format" run-time error when I try to read in more than one line (I tested just the first line separately and it works fine). This makes me think that it has something to do with the carriage return at the end of a line.
Here is the code that should read in all of the lines from my .DAT file:
program commission;
var
moreRec:Boolean;
FileOut:Text;
FileIn:Text;
DRONE_ID:String[9];
DRONE_NAME:String[18];
SALES:Real;
COMM:Real;
procedure header;
begin
writeln(FileOut, Space(16),'SALES COMMISSION REPORT');
writeln(FileOut);
writeln(FileOut,' SSN',Space(10),'SALESPERSON',Space(9),'SALES COMMISSION');
writeln(FileOut);
end;
procedure readRec;
begin
if EOF(FileIn) THEN
moreRec:=false
else
read(FileIn, DRONE_ID);
read(FileIn, DRONE_NAME);
read(FileIn, SALES);
COMM:=SALES*0.03;
end; {readRec}
procedure initial;
begin
moreRec:=true;
Assign(FileIn, 'PRG2-150.DAT ');
Reset(FileIn);
Assign(FileOut,'output.txt');
Rewrite(FileOut);
readRec
end; {initial}
procedure process;
begin
write(FileOut, DRONE_ID);
write(FileOut, Space(2));
write(FileOut, DRONE_NAME);
write(FileOut, Space(5));
write(FileOut, SALES:9:2);
write(FileOut, Space(3));
writeln(FileOut, COMM:8:2);
readRec
end; {process}
procedure wrapup;
begin
Close(FileOut);
Close(FileIn);
end; {wrapup}
begin
initial;
header;
while moreRec = true do
process;
wrapup;
end.
And here is the .DAT file that I am reading from:
998874673Joe Smith 27.65
849773298Sue Williams 35.90
445861253Al Oop 54.90
584988754Diane Mindykowski 25.96
758423652Alicen Morse 53.35
485236845Burton Schuring 58.52
586974512Linda Gillam 69.35
I'm new to Pascal but I'd love to learn why my program won't read in more than one line.
Thanks
I think you'll need a
readln(FileIn);
towards the end of readRec to skip past the CR/LF delimiter to the next line.
Pascal wants the data fields in text files to be white-space delimited. The problem is that you have no space between the Drone_Id and Drone_Name fields.
998874673Joe Smith 27.65
_________^__ Insert space here.
You also should use a readln for the last field on the line (Sales).
EDIT: Sorry the space isn't needed there (I was thinking that the first field was numeric). But do make sure you use readln on the last field of the line.

To have conditional ANDing inside WHERE clause

Can we add null check over one of the parameter of procedure inside WHERE clause and avoid block of code getting repeated like
select aa=t1.aa,bb=t2.bb ,cc=t3.cc
from t1,t2,t3,t4,t5
where t1.p1=t2.p1
and t2.p2=t3.p2
IF(procParameter IS NOT NULL)
and t3.p2=procParameter
and t4.p2=t5.p2
and t5.p3=t1.p2
Look I want one of the AND to get executed conditionally and otherwise it should NOT GET EXECUTED AT ALL..!!!!
How should I go for this optimisation??
I dont want code repeatation like
IF(procParameter IS NOT NULL)
begin
select aa=t1.aa,bb=t2.bb ,cc=t3.cc
from t1,t2,t3,t4,t5
where t1.p1=t2.p1
and t2.p2=t3.p2
and t3.p2=procParameter
and t4.p2=t5.p2
and t5.p3=t1.p2
end
Else
begin
select aa=t1.aa,bb=t2.bb ,cc=t3.cc
from t1,t2,t3,t4,t5
where t1.p1=t2.p1
and t2.p2=t3.p2
and t4.p2=t5.p2
and t5.p3=t1.p2
end
Thanks,
This is one approach:
AND (procParameter IS NULL OR t3.p2=procParameter)

Resources