Hello,
 

I'm using two prepared statements in a block of cross platform C++ code
like this (very roughly):
 

{
    sqlite3_stmt * pstmt1 = NULL;
    sqlite3_stmt * pstmt2 = NULL;
 
    pstmt1 = PrepareAndBind(...); // Prepare and bind one statement
    pstmt2 = PrepareAndBind(...); // Prepare and bind a different
statement

    sqlite3_step(pstmt1); // Returns SQLITE_ROW (as expected)
    sqlite3_step(pstmt2); // Returns SQLITE_DONE on Mac OS X  but
returns SQLITE_ROW on Windows (same database. same queries)

    sqlite3_finalize(pstmt1);
    sqlite3_finalize(pstmt2);
 
}
 

The second step function call returns SQLITE_DONE on Mac OS X (when it
should have found records and returned SQLITE_ROW). On Windows, this
always works (both step function calls return SQLITE_ROW and I can
iterate through both sets of records using step until finished).
 
To work around this so it works on both platforms, I iterate through the
records using step for pstmt1 and call sqlite3_finalize before calling
sqlite3_step on pstmt2. This solution works on both platforms.
 
This could easily be a bug in my code (I have built some light wrappers
to accomplish most of this). But I have copied the same database from
Mac to Windows and ran the same queries to make sure the data is in the
db and the queries work fine. And I've commented out one prepared
statement or the other and both return results. But as soon as I
uncomment the other statement, it stops returning rows on the Mac as
I've described above.
 
Are there any known issues with using multiple prepared statements like
I have done? Am I doing something wrong (maybe I should be calling
sqlite3_reset somewhere along the way?)

Reply via email to