mardi 3 février 2015

Qt sqlite can't perform Select querys

I know many questions were asked around the issue I have, I spent along time trying to implement all kinds of solutions but didn't help.


I am trying to read a .db file using Qt sqlite platform. windows 8 Qt 5.3.2


Opening the db file in DB browser for sqlite and executing my simple query succeeds:



SELECT Name FROM Person ORDER BY Name


and there is a list of 10 rows at the output.


I would like to do it throw Qt. my code:



QSqlDatabase db = QSqlDatabase::addDatabase("QSQLITE");
db.setDatabaseName("C:\mydb.db");
if(db.open())
{
QSqlQuery qry(db);
if(qry.exec("SELECT Name FROM Person ORDER BY Name"))
{
while(qry.next())
{
//some code
}
}

QSqlError e;
QString s,d;
e = qry.lastError();
s = e.databaseText();
d = e.driverText();
}


this code falls, the qry.exec command returns false, and last error is "no such table; person"


Running the command: QStringList tables = db.tables(QSql::AllTables); after the Data Base is open shows that there is one table in Data Base called: sqlite_master. trying to replace the query within the exec command with the query: "SELECT tbl_name FROM sqlite_master WHERE type = 'table'" as says at: http://ift.tt/1kGQwal causes the exec command to return true but qry.next() returns false already from the first iteration, although I have 5 tables in my data base.


I would be great full to how ever can me with my problem!


thanks!!!


Aucun commentaire:

Enregistrer un commentaire