views:

844

answers:

2

Im getting an error "not an error" on iPhone SDK, I spent a whole day trying to resolve it. SQLite version 3.4.0

sqlite3_step(compiledStatement)

The table I'm using in the query has only one row. It returns 100..?

sqlite3_errmsg( database )

This line gives me the above error.

I've created a database and tables in it with terminal commands, and placed in the application resources folder as well as in the documents path, which is done dynamically.

while(sqlite3_step(compiledStatement) == SQLITE_ROW)

This loops never executes in my code, inside which i get all the values.

I think this info is enough, let me know. Anyone know where i'm having the problems..?

thanks in advance

+3  A: 

It's quite simple actually. Have a look at the documentation of sqlite3_step. Basically, SQLITE_ROW tells you that it finished successfully and that another row can be retrieved by calling sqlite3_step again. For the final row, all you get is SQLITE_DONE, which will translate to "not an error".

Bluehorn
+1  A: 

The issue I think you are having is you expect sqlite3_step to return the value from the compiled statement. It doesn't do that, it returns an error code, in this case 100 (SQLITE_ROW), which means the query was successful and there may be more data so you should call the sqlite3_step once you are done getting the data from this step of the query.

If you want to see the actual returned data of that query step you need to use the various sqlite3_column APIs to extract the data from the step.

Louis Gerbarg
I had already used sqlite3_step() to find the return value of it( 100 ), as the while loop werent functioning with this method. All I had was only one row and while loop never executed, obvious now. An sqlite3_reset() inbetween the two lines got it working fine..thanks to both of you.. \m/Now the character encoding is something unreadable for sqlite3_column_text even when I used 'NSString stringWithUTF8String'. Thanks
pMan