PDA

View Full Version : QSqlQuery: value(0) return wrong value compared to running command in database



codemonkey
16th January 2010, 20:52
Hi.
I just tried to execute a prepared statement



username="what";
password="ever";

QSqlQuery* qptr = new QSqlQuery( myQSqlDatabase );
qptr->prepare("SELECT * FROM MyFunction(?,?)");

qptr->bindValue(0,username);
qptr->bindValue(1,password);

qptr->exec();

QSqlError e = qptr->lastError();
qDebug()<<"Last error:"<<e.text();

qDebug()<<"is active:"<<qptr->isActive();
qDebug()<<"size:"<<qptr->size();
qptr->first();
qDebug()<<"value 0: "<<qptr->value(0);
qDebug()<<"record:"<<qptr->record().fieldName(0);
qDebug()<<"record count:"<<qptr->record().count();
qDebug()<<"exe:"<<qptr->executedQuery();


The result is: no error, size =1, value is 0, record shows "myfunction" and record count shows 1.
The problem is that the value should be 1! This is the expected value, and I get the correct value when running the query in the database by hand.

The last exe command shows SELECT * FROM MyFunction(?,?) (so I guess the values are hidden somewhere else.

Any ideas on how to solve this or find the bug?



I run the QPSQL driver (Postgresql 8.4)
In the database logs I see the two commands:
PREPARE qpsqlpstmt_1 AS SELECT * FROM MyFunction($1,$2)
EXECUTE qpsqlpstmt_1 ('what', 'ever')
and they also work and give the correct result.

codemonkey
17th January 2010, 08:36
I think I've solved it. It was a rights problem in the database.