In my c++ page, i have a preparement statement
sqlite3_stmt *sqlstmt;
which returns SQLITE_OK when it is passed data through the int
string query;
query = "select * from A;"
int rc = sqlite3_prepare_v2(db,query.c_str(),0,&stmt,0);
if (SQLITE_OK != rc ){ return; }
function.
Then start the next line.
int rc;
rc = sqlite3_step(sqlstmt);
//rc = 21 here.
An except from the SQLITE3 documentation. My current version is 3.07.14.01 i believe.
http://www.sqlite.org/c3ref/step.html
SQLITE_MISUSE means that the this routine was called inappropriately. Perhaps it was called on a prepared statement that has already been finalized or on one that had previously returned SQLITE_ERROR or SQLITE_DONE. Or it could be the case that the same database connection is being used by two or more threads at the same moment in time.
For all versions of SQLite up to and including 3.6.23.1, a call to sqlite3_reset() was required after sqlite3_step() returned anything other than SQLITE_ROW before any subsequent invocation of sqlite3_step(). Failure to reset the prepared statement using sqlite3_reset() would result in an SQLITE_MISUSE return from sqlite3_step(). But after version 3.6.23.1, sqlite3_step() began calling sqlite3_reset() automatically in this circumstance rather than returning SQLITE_MISUSE. This is not considered a compatibility break because any application that ever receives an SQLITE_MISUSE error is broken by definition. The SQLITE_OMIT_AUTORESET compile-time option can be used to restore the legacy behavior.
actual code function
vector cDataInterpretor::getWorkingSet(int userID){
vector t_val;
vector retVal;
sqlite3 *db;
int rc;
rc = sqlite3_open(databasePath.c_str(), &db);
if(rc != SQLITE_OK){
sqlite3_close(db);
return t_val;
}
string query = “select * from insp_Assets;”;
char* errorMessage;
sqlite3_stmt *sqlstmt;
//rc = sqlite3_exec(db, query.c_str(), 0, 0, &errorMessage);
cout << "preparing statement"<<endl;
rc = sqlite3_prepare_v2(db, query.c_str(), 0, &sqlstmt, 0);
cout << "prepare code: "<<rc << endl;
if(rc != SQLITE_OK){
sqlite3_close(db);
return t_val;
}
cout << "Resetting call." <<endl;
rc = sqlite3_reset(sqlstmt);
cout << "about to start while"<<endl;
rc =sqlite3_step(sqlstmt);
cout << rc<<"|" << SQLITE_ROW <<"|" << SQLITE_OK <<"|"<<SQLITE_DONE<< endl;
while(rc == SQLITE_ROW){
//sset retVal (id,name,code,typeId,reportTypeId,parentAsset);
int id,typeID, reportTypeId;
id = sqlite3_column_int(sqlstmt, 0);
string name(reinterpret_cast<char const *>(sqlite3_column_text(sqlstmt, 1)));
string code(reinterpret_cast<char const *>(sqlite3_column_text(sqlstmt, 2)));
typeID = sqlite3_column_int(sqlstmt, 3);
reportTypeId = sqlite3_column_int(sqlstmt, 4);
string parentAsset(reinterpret_cast<const char *>(sqlite3_column_text(sqlstmt, 5)));
cout <<"Fetched Asset Data: "<< id <<"|"<<name<<"|"<<code<<"|"<<typeID<<"|"<<reportTypeId<<"|"<<parentAsset << endl;
Asset a (id, name, code, typeID, reportTypeId, parentAsset);
retVal.push_back(a);
rc = sqlite3_step(sqlstmt);
}
cout << "while ended, about to return."<<endl;
sqlite3_close(db);
return retVal;
}
You are incorrectly calling
sqlite3_prepare_v2(). From the documentation:So, your prepare statement should look like this (easiest change, at least):