PDA

View Full Version : QMYSQL3: Unable to fetch data



crystlrain
11th November 2009, 07:56
I have been trying to SELECT records from a mysql database. The QMYSQL driver works fine for INSERT, CREATE TABLE and other query statements except SELECT statements. Anytime I run my code, I get an error which says:

QMYSQL3: Unable to fetch data

Another confusing thing this is that I have three database drivers:
QMYSQL3, QMYSQL and QSQLITE.
When I use QMYSQL in my code, the application runs with QMYSQL3. Could this be the source of my problems?

Here's mycode:



QSqlDatabase db;
db = QSqlDatabase::addDatabase("QMYSQL");
db.setHostName("dbhost");
db.setDatabaseName("dbname");
db.setUserName("dbuser");
db.setPassword("dbpasswd");
db.setPort(3306);
if (db.open()){
cerr<<"Connected!";
QSqlQuery query;
query.exec("SELECT now()");
while (query.next()){
cerr<<"-- "<<qPrintable(query.value(0).toString());
}
cerr<<"\nExec: "<< query.executedQuery().toStdString();
QSqlError err = query.lastError();
qDebug()<<"\nError: "<< query.lastError().text();
}
else
{
cerr<<"\n\nNot Connected!";
}


What am I doing wrong? :confused:

I am using the 2009.04 version of QT4 and mysql 5.0.45

yogeshgokul
11th November 2009, 08:19
Can you please try with a simple select statement. And tell us the result.
Kinda "SELECT * from table;"

crystlrain
11th November 2009, 08:24
I did, and still get the same error. I tried and insert statement like:


query.exec("INSERT INTO person(id,firstname,lastname) VALUES(2,'John','Smith')");

and it works fine.

But when I try:


query.exec("SELECT id,firstname,lastname FROM person");


I still get the error:

QMYSQL3: Unable to fetch data
I really need help on this.:confused::(