I have what I think is a very simple case, but I don't understand why it fails.
Database used is sqlite3, linux platform. Qt 5.3.
I have this table: CREATE TABLE db_info (name TEXT, value TEXT);
Containing this data (output from sqlite3 client):
version|1
created|2015-01-16 11:06:12
Yes, it's very simple.
The purpose is to check if the DB is created with another version of the application. So I compare the version in the DB with a compiled constant in the code.
Thus, during startup, I do this (trimmed for brevity):
_db = new QSqlDatabase(QSqlDatabase::addDatabase("QSQLITE", "mydb"));
_db->setDatabaseName(dbFile);
_db->open();
QSqlQuery query(*_db);
query.prepare("SELECT value FROM db_info WHERE name = 'version' AND value = :version");
query.bindValue(":version", DB_VERSION);
query.exec();
if(query.first())
// same version
else
// some other version
Not very complicated stuff... Now to the specific problem:
_db->open()
returnstrue
query.prepare()
returnstrue
query.isSelect()
returnstrue
query.exec()
returnstrue
After exec()
:
query.isActive()
returnstrue
query.size()
returns-1
query.first()
orquery.next()
returnsfalse
What could be the problem?
According to the dox (http://doc.qt.io/qt-5/qsqlquery.html#first), first()
returns false if the query is not active or it's not a select, so that can't be it.
But I guess, since size()
returns -1 there definitely is something amiss somewhere...
I've tried adding some calls to lastError()
but it's always empty. Both from query
and from _db
. It there some other means of getting some mesages from the database, or driver or some such?
I've also tried removing the WHERE
clause. No difference.
Running the exact same query in the sqlite3
client works fine.