What does QSqlError(-1, "", "") mean?
Hi again,
I keep getting the QSqlError(-1, "", "") return from lastError() after I try to select a row from a SQLite table. I checked the query buy using it directly in the SQLite table via the FireFox plugin. The connection to the database is also okay. The code I am using to get the line I have been using over and over and it always worked as intended. I just cannot figure out what the difference is here. Does anyone know what this error message means?
Here is the code that is not working:
Code:
if(conOpen()){ // here I open the connection to the db and get an output connected, so the connection is okay
query->prepare("SELECT * FROM chars WHERE type='steel' AND class='V2A'");
if(query->exec() && query->size() > 0){ // if I don't use the size() the next lines provides an error telling me that there is no value(1)
qDebug() << query->value(1).toString();
}else{
qDebug() << query->lastError(); // -> here I get the error QSqlError(-1, "", "")
}
conClose();
}else{
ui->log->append("No connection");
}
Re: What does QSqlError(-1, "", "") mean?
This is most likely the default constructed QSqlError instance, i.e. no error.
Cheers,
_
Re: What does QSqlError(-1, "", "") mean?
This is "no error" because query->exec() == true but query->size() == 0. Perhaps query->size() == 0 is an error in the logic of your program but it is not a SQL error.
P.S.
Using construction
Code:
query.exec("SELECT * FROM ....");
query.value(1);
is bad because no database does not guarantee the order of the columns in such queries.
Re: What does QSqlError(-1, "", "") mean?
Hi!
Thanks for the hints. If I had configured my profile right I would have gotten a info that there were replies and would not have wasted the entire day...
Your are absolutely right. QSqlError(-1, "", "") is no error. I added an query->next() and then I had all my data.
Re: What does QSqlError(-1, "", "") mean?
Only some database drivers support returning the result set size. See QSqlDriver::hasFeature()