PDA

View Full Version : QOCI..query selection...



KillGabio
11th February 2012, 07:08
//----------------------SOLVED
OK so I was just trying different things and deleting the ";" at the end of the line solves it *-*. Maybe it can help other people
//---------------------END SOLVED



Hi guys im having a real problem with the OCI driver

i execute this line

SELECT rn, frase, autor FROM (SELECT rownum AS rn, t.frase, t.autor FROM TABLE_frases t) where rn =4;

in the SQL Developer with no problems, I receive the line I want.

but when I do this in my app


if (db.open ()){
query = new QSqlQuery (db);
query->exec ("SELECT COUNT (*) FROM TABLE_FRASES");
query->next ();
int random_row = this->random_number (query->value (0).toInt ());
query->exec ("SELECT rn, frase, autor FROM (SELECT rownum AS rn, t.frase, t.autor FROM TABLE_FRASES t) WHERE rn = 4;");//+ random_row);
query->next ();
QStringList frase_autor;
qDebug () << query->value (0).toString ()<< query->value (1).toString ();


executing the same line gives the following result:


QSqlQuery::value: not positioned on a valid record
QSqlQuery::value: not positioned on a valid record
"" ""

Anyone knows what the problem might be?

ChrisW67
11th February 2012, 07:25
QSqlQuery::exec() returns a bool indicating success: you should check that. When it is false you should look at QSqlQuery::lastError() for information on the problem.

KillGabio
11th February 2012, 07:41
yes sorry i did that, as the debugging part is not going to be part of the app I started deleting the lines involving printf, qDebug , cout, etc...

the inverted commas quoted are the result of lastError().text () information.. ;)

thanks chris!