The following code is part of a class member function that loads data
from an existing database. The database has been opened and there IS
data in the target table.  I have had it working with callbacks, but
using the prepare/step/finalise approach below I consistently get the
log message:

Step : ERROR - not an error

i.e. the 'sqlite3_step' loop returns only once indicating an error but
the error message says 'not an error'. Can anyone spot my silly error?

--------------------------------------------------------------------
string sql = "SELECT name,value FROM setting;" ;
sqlite3_stmt *pStmt ;

LOGLN("SQL: "+sql) ;
if( sqlite3_prepare( db, sql.c_str(), -1, &pStmt, 0 ) != SQLITE_OK )
{
    LOGLN(string("Prepare: ERROR -")+sqlite3_errmsg(db)) ;
}
else
{
    int rc ;
    while( rc=sqlite3_step(pStmt) != SQLITE_DONE )
    {
        if( rc == SQLITE_ROW )
        {
            string name = (const char*)(sqlite3_column_text(pStmt,0)) ;
            string value = (const char*)(sqlite3_column_text(pStmt,1)) ;
            settings[name] = value.c_str() ? value : "" ;
            LOGLN(name+"="+value) ;
        }
        else if( rc == SQLITE_BUSY )
        {
            LOGLN("Step: BUSY") ;
            continue ;
        }
        else if( rc == SQLITE_ERROR )
        {
            LOGLN(string("Step : ERROR - ")+sqlite3_errmsg(db)) ;
            break ;
        }
        else if( rc == SQLITE_MISUSE )
        {
            LOGLN("Step: MISUSE") ;
            break ;
        }
    }
}
sqlite3_finalize(pStmt) ;


Reply via email to