sql server - Eof not triggering -


i have function data db, test data set returns 6500 rows (i extracted formatted sql statement sqltext variable , ran test), when run following code eof never triggers , have seen on 100k rows imported.

adoquery := tadoquery.create(nil); adoquery.connectionstring := connect_string;  // build sql query  sqltext :=   format( 'select  temp.serial, temp.qcsample , temp.scrap , temp.stationid , temp.defect , temp.adddata , temp2.serial parent_serial ' +       'from tab_element temp ' +         'left join tab_element temp2 on  temp.parent_id = temp2.element_id ' +        'where temp.batch_id = %d    , temp.stationid = 0 ',[isearchid]);  adoquery.sql.clear;   // clear query of garbage values adoquery.sql.text := sqltext; // add query text query module adoquery.open;   // handle results iindexpos := 0;  tdataimport.beginupdate;    while not adoquery.eof begin     tdataimport.items[iindexpos].serial := adoquery.fieldbyname('serial').asstring;     tdataimport.items[iindexpos].qcstatus := adoquery.fieldbyname('qcsample').asboolean;     tdataimport.items[iindexpos].scrap := adoquery.fieldbyname('scrap').asinteger;     tdataimport.items[iindexpos].stationid := adoquery.fieldbyname('stationid').asinteger;     tdataimport.items[iindexpos].defect := adoquery.fieldbyname('defect').asboolean;     tdataimport.items[iindexpos].adddata := adoquery.fieldbyname('adddata').asstring;     tdataimport.items[iindexpos].parentserial := adoquery.fieldbyname('parent_serial').asstring;      inc(iindexpos); end; 

so in summery running query these parameters expect 6500 rows, when run never ends after 100k+ rows processed.

open() places cursor on first record , sets eof accordingly. not calling next() advance cursor next record , update eof, processing same record on , over:

adoquery.open;  while not adoquery.eof begin   //...   adoquery.next; // <-- add this! end; 

on side note, should using parameterized query instead of formatted sql query string. safer, faster, , more efficient on db:

adoquery := tadoquery.create(nil); adoquery.connectionstring := connect_string;  adoquery.sql.text := 'select  temp.serial, temp.qcsample , temp.scrap , temp.stationid , temp.defect , temp.adddata , temp2.serial parent_serial ' +   'from tab_element temp ' +    'left join tab_element temp2 on  temp.parent_id = temp2.element_id ' +    'where temp.batch_id = :isearchid , temp.stationid = 0 ';  adoquery.parameters.parambyname('isearchid') begin   datatype := ftinteger;   value := isearchid; end;  adoquery.open;  try   iindexpos := 0;    tdataimport.beginupdate;     try     while not adoquery.eof     begin       tdataimport.items[iindexpos].serial := adoquery.fieldbyname('serial').asstring;       tdataimport.items[iindexpos].qcstatus := adoquery.fieldbyname('qcsample').asboolean;       tdataimport.items[iindexpos].scrap := adoquery.fieldbyname('scrap').asinteger;       tdataimport.items[iindexpos].stationid := adoquery.fieldbyname('stationid').asinteger;       tdataimport.items[iindexpos].defect := adoquery.fieldbyname('defect').asboolean;       tdataimport.items[iindexpos].adddata := adoquery.fieldbyname('adddata').asstring;       tdataimport.items[iindexpos].parentserial := adoquery.fieldbyname('parent_serial').asstring;       inc(iindexpos);       adoquery.next;            tdataimport.endupdate;       end;   end;   adoquery.close;  end; 

Comments

Popular posts from this blog

sublimetext3 - what keyboard shortcut is to comment/uncomment for this script tag in sublime -

java - No use of nillable="0" in SOAP Webservice -

ubuntu - Laravel 5.2 quickstart guide gives Not Found Error -