Rewind TSQLResult?

Hallo,

by calling the next() method of a TSQLResult i receive one row of the result table. I can do this for every row inside the table. Is it possible to do this twice? I didn’t found a function to rewind the result table.

...
TSQLRow *row;

while( (row = tsqlResult->Next()) ) {
    if(row->GetField(0)==123) {
       ...
    }
    delete row;
}

while( (row = tsqlResult->Next()) ) {
    if(row->GetField(2)==0815) {
       ...
    }
    delete row;
}
...

I do only one mysql query in my program and I have to use the result table several times. I want make a search trough this table.

cheers,
Rico

Hi Rico,

Unfortunately, there is no possibility to rewind data in TSQLResult object in way you would like. Main reason for this - most sql APIs do not support such feature.

For you two solutions are possible:

  1. Recreate TSQLResult object (via TSQLServer::Query() call) every time you want look through table rows. It is not efficient and you must be sure, that table does not changed in between.
  2. Copy row values in any intermediate object - TTree, for example.

Important remark - it is not allowed to create list of TSQLRow objects - after TSQLResult::Next() call data of previous row may became invalid (the only exception - Oracle).

To optimize your performance, I recommend to use TSQLStatement class - it supports most of basic data types (int, double, …) and much more efficient in memory usage and speed.

Regards,
Sergey

Think I try it with your second suggestion and use something to store the table.

Thank you for your help :smiley: