lundi 3 avril 2023

How do I properly use sqlite3_bind_text in C++?

I have been playing around with mysqlite3 in C++ but I seem to be getting some strange errors.

I have limited this to just the purtenent code:

the following runs when the class is built to pre prepare the statement I will be using a lot of times

//statement to find a flag value
const char *sql1="SELECT value FROM flags WHERE key LIKE ?;";
sqlite3_prepare_v2(db, sql1,strlen(sql1),&_stmtCheckFlag, nullptr);
cout << "\n>>>>" << sqlite3_errmsg(db) << "<<<<<\n";   //this returns "Not an error"

and during testing I execute this code with flag set to a key I know exists

//get result
cout << "\n\n\nSELECT value FROM flags WHERE key LIKE \""<<flag<<"\" LIMIT 1;";  //if I run the code printed here manually on database it returns 1 column with expected value(1);
cout << "\n\n\n";


int rc;
sqlite3_reset(_stmtCheckFlag);
sqlite3_bind_text(_stmtCheckFlag, 0, flag, strlen(flag), SQLITE_STATIC);
rc = sqlite3_step(_stmtCheckFlag);
cout << "\n" << rc << "\n";    //prints 101 no more rows

when I run the code it says there are no more rows but I can run the sql command on the database and it returns a row. I have tried wrapping the ? in the prepared statement with double quotes but this makes no difference.

Aucun commentaire:

Enregistrer un commentaire