0

I'm using SQLite version 3 to run the following code.

//Run SQL SELCT query
sqlite3_prepare16_v2("SELECT * FROM table_name");
sqlite3_step();

//Need to review results in several iterations
for(int i = 0; i < n; i++)
{
    //Seek to beginning
    sqlite3_reset();

    do
    {
        //Get values
        sqlite3_column_int();
        ...
        sqlite3_column_text16();
    }
    while(sqlite3_step() == SQLITE_ROW);
}

But for some reason the first batch of data I get is all 0's. What am I not doing correct in the code above?

ahmd0
  • 16,633
  • 33
  • 137
  • 233

1 Answers1

1

Assuming what you are showing is pseudocode since you're missing many arguments to the sqlite3 funcitons...

You need a sqlite3_step after sqlite3_reset and before getting the first row of values.

You can change your do {...} while(sqlite3_step() == SQLITE_ROW) to a while(sqlite3_step() == SQLITE_ROW)...} to accomplish that.

This will also eliminate the need to step immediately after the sqlite3_prepare16_v2

Doug Currie
  • 40,708
  • 1
  • 95
  • 119
  • Yes, that was a pseudocode. And thanks. It works now. Although it sounds kinda weird to call _step_ after each operation, but we can't judge it from this point... – ahmd0 Apr 25 '11 at 20:10