PDA

View Full Version : database problem



rogerholmes
7th November 2009, 07:57
I do not have the mySql driver so i am trying to connect to mySql using odbc. It seems to connect and open but i can not query the database. can someone please help me out?



{
QSqlDatabase Db = QSqlDatabase::addDatabase("QODBC", "Calendar");

Db.setHostName("localhost");
Db.setDatabaseName("mySql");
Db.setUserName("root");

bool goodQuery;
bool validrec;
int x;
x=1;

if(Db.open()) // database is open
{
QSqlQuery query(Db);
query.exec("SELECT * from artist" );
goodQuery=query.isActive(); // this returns true
query.first();
validrec=query.isValid(); // this returns false
x=query.size(); // this returns -1

while(query.next()){
new QListWidgetItem(tr("Hazel"), ui->listWidget); //this never executes
}
}
Db.close();
}

rogerholmes
8th November 2009, 02:31
i have further tracked this down

query.lasterror() returns :
QSqlError(0, "QODBC3: Unable to fetch first", " [iODBC][Driver Manager]Optional feature not implemented")

what does this mean? :(

ChrisW67
8th November 2009, 08:09
The query cursor is probably opened in a forward-only mode and cannot 'reverse' to the first record (or the ODBC driver does not support doing this). Comment out line 18 and see how you get on.

rogerholmes
8th November 2009, 22:23
thank you for your response, i did as you suggested :

now the error is :QSqlError(-1, "", "") , looks like progress :o