No query Unable to fetch row when ERROR , when trying to do a simple query
I have a sqlite 3 database where I have some fake data just for testing, but it seems that every time I try to do a simple query it gives me the error that I mentioned in the title.
here's the code:
Code:
db.setDatabaseName("adtDB.sql");
db.open();
if(db.isOpen())
{
if(q.exec())
{
qDebug()<<"works!";
while(q.next())
{
qDebug()<<q.value(8).toString();
}
}
qDebug()<<"---db failed to open! , error: "<<q.lastError().text();
db.close();
return true;
}
qDebug()<<"db failed to open! , error: "<<db.lastError().text();
return false;
The database opens fine but this is the error that I get including the debug statement:
---db failed to open! , error: "No query Unable to fetch row"
the red text is the error the rest is in the debug statement that I included.
Re: No query Unable to fetch row when ERROR , when trying to do a simple query
You are doing 2 times exec(). Code should looks like :
Code:
if(!q.lastError().isValid())
{
qDebug()<<"works!";
while(q.next())
{
qDebug()<<q.value(8).toString();
}
}
else
{
qDebug()<<"---db failed to open! , error: "<<q.lastError().text();
}
db.close();
return true;
Re: No query Unable to fetch row when ERROR , when trying to do a simple query
Quote:
Originally Posted by
Lesiok
You are doing 2 times exec(). Code should looks like :
Code:
if(!q.lastError().isValid())
{
qDebug()<<"works!";
while(q.next())
{
qDebug()<<q.value(8).toString();
}
}
else
{
qDebug()<<"---db failed to open! , error: "<<q.lastError().text();
}
db.close();
return true;
Thanks for your answer but this gives me another error:
file is encrypted or is not a database Unable to execute statement
new code:
Code:
db.setDatabaseName("adtDB.sql");
db.open();
if(db.isOpen())
{
if(!q.lastError().isValid())
{
qDebug()<<"works!";
while(q.next())
{
qDebug()<<q.value(8).toString();
}
}
qDebug()<<"---db failed to open! , error: "<<q.lastError().text();
db.close();
return true;
}
qDebug()<<"db failed to open! , error: "<<db.lastError().text();
return false;
Re: No query Unable to fetch row when ERROR , when trying to do a simple query
Sorry for commenting so the post will go to the top, but this problem is pretty annoying and I really need a fix since I need to finish this in two days to submit it.
Re: No query Unable to fetch row when ERROR , when trying to do a simple query
From which line is this error : 15 or 19 ? Description of error is clear. The database is encrypted or damaged.
Re: No query Unable to fetch row when ERROR , when trying to do a simple query
Re: No query Unable to fetch row when ERROR , when trying to do a simple query
Line 15 is pointless. Compare my code and Your.
Re: No query Unable to fetch row when ERROR , when trying to do a simple query
Can you access this database using the sqlite3 command line program and execute your query successfully? If not, then your Qt program certainly won't be able to either.
Since you are specifying a relative file name for your database, you may be creating an empty file inadvertently by opening your database in a different working directory than you think.
Try hard coding the fully qualified file path and see if that works and/or search your drive for your file name and see if you have another file created somewhere you did not intend, etc.