PDA

View Full Version : SQLite What am i doing wrong?



Malisha100ka
18th January 2015, 11:50
int row;
open conn...
QSqlQuery qry;
qry.prepare("select rowid from my_table");
qry.exec();
while(qry.next()){
if(something==something2)
row=qry.value(0).toInt();
}
close conn...
QString some;
open conn...
qry.prepare("UPDATE my_table"
"SET some=:some"
"WHERE rowid=:row");

qry.bindValue(":some", some);
qry.bindValue(":row",row);

if(qry.exec()){

...
close conn...
}

else{
QMessageBox::critical(this,tr("error::"),qry.lastError().text());
close conn...
}



i rly don't understand what am i doing wrong...
note that my sql connections are working fine, ...

i keep getting error "no query unable to fetch row"

Thanks

ChrisW67
18th January 2015, 19:46
When reporting errors it is generally useful to specify where you get the error.

I guess line 13 or maybe 20. The qry object is associated withthe default database connection at the time the query was constructed. You close that connection at 'line' 10 so the qry object is no longer associated with a connection and you get the error when you try to use the connection.

d_stranz
18th January 2015, 19:56
I am curious how you got the lines "open conn..." and "close conn..." to compile. If you're going to post code and ask us questions about it, at least post real code.

Here's a hint: How does the QSqlQuery you have created know what database to use when executing the query? Where have you told it anything about the database?