vendredi 19 juin 2015

sqlite get variable from select statement in C++

I'm trying to select a value from a database and store it into a c++ variable. Here is the code I'm using

sqlite3_open("learning.db", &db);

sqlite3_stmt *statement; 

char const *query = "select ID from games ORDER BY id ASC LIMIT 1";

sqlite3_prepare(db, query, -1, &statement, 0 );

cout << "FOO " << sqlite3_step(statement) << " BAR" << endl;

sqlite3_close(db);

When I run this code (in a loop) I get a few results, although they aren't correct and then a lot of "database is locked"

So how do I get a variable from the database to a c++ variable. I can do an insert or update fine so I know the connection to the database is fine. Thanks!

Aucun commentaire:

Enregistrer un commentaire