Hello linux brothers,
I'm having a weird problem with SQLite on linux...
The code is fine, it compiles and all but I can't read back the dummy value I've inserted into the table.
I'm warning you, this is wild code because I always try to get things to work first, I clean it up when that's done:
Code:
QSqlDatabase *db = QSqlDatabase::addDatabase("QSQLITE");
db->setDatabaseName("TeST.db");
bool ok = db->open();
qDebug( "Opening database = %i", ok );
db->exec( "CREATE TABLE Test(mytext text);");
QString str = db->lastError().text();
qDebug( "LastQuery CREATE= %s", str.ascii() );
db->exec( "INSERT INTO Test(mytext) VALUES('Dummy');");
str = db->lastError().text();
qDebug( "LastQuery INSERT= %s", str.ascii() );
QSqlQuery answer = db->exec( "SELECT * FROM Test;");
str = db->lastError().text();
qDebug( "LastQuery SELECT= %s", str.ascii() );
str = answer.value(0).toString();
qDebug( "LastQuery VALUE= %s", str.ascii() );
db->close();
The debug messages I get (note that no answer as for CREATE, INSERT and SELECT means "all good", otherwise I get long errors when I mess up):
Opening database = 1
LastQuery CREATE=
LastQuery INSERT=
LastQuery SELECT=
QSqlQuery::value: not positioned on a valid record
LastQuery VALUE= (null)
*** Exited normally ***
I tried to have a look into the database using the command line tool sqlite3 and I can open the database fine, but when I try the following:
/debug/src> sqlite3 TeST.db
SQLite version 3.3.8
Enter ".help" for instructions
sqlite> SELECT * FROM Test;
SQL error: file is encrypted or is not a database
sqlite> .quit
/debug/src>
Now, I didn't encrypt the database, I swear to God!!
Manu