QSqlQuery different value() type
-
Hi, have two tables(mysql)
first: id(unsigned int, primary_key, auto_increment), name(varchar(250)).
second: id(unsigned int, primary_key, auto_increment), name(varchar(250)), status(tinyint(1))...etc.
difference only in column count. But result of "SELECT id FROM..." :
first table: QVariant(uint, 1);
second table: QVariant(uchar, 1);QSqlQuery query(*db); query.prepare("SELECT test.test1.id FROM test.test1;"); if(query.exec()) { while(query.next()) { qDebug() << query.value(0); } }
before 5.6 have no problems
what could be the problem, any ideas? -
Hi,
What database driver are you using ?
Can you share the code you use to connect to the database ?
What version were you using before 5.6 ?
-
Hi, previous version 5.5.1
main connection:
db = new QSqlDatabase(); *db = QSqlDatabase::addDatabase("QMYSQL"); db->setHostName("127.0.0.1"); db->setPort(3306); db->setDatabaseName("testDB"); db->setUserName("root"); db->setPassword("1234567890"); if (db->open()) doSomething(); else qDebug() << db->lastError();
inside taskThread:
void TaskThread::run() { db = new QSqlDatabase(); *db = QSqlDatabase::cloneDatabase(QSqlDatabase::database(), QString::number((qintptr)QThread::currentThread())); if (db->open()) emit result(doSomething()); else return; } QString TaskThread::doSomething() { QSqlQuery query(*db); query.prepare("SELECT test.test1.id FROM test.test1" " WHERE test.test1.name=:name;"); query.bindValue(":name", "name"); if(query.exec() && query.first()) return query.value(0).toString(); else return 0; }
driver - QMYSQL plugin from source
MySql server version 5.7.11 -
One unrelated note, you're not using QSqlDatabase correctly. There's no need to use new on it.
What OS and MySQL version are you using ?
-
Did you only change Qt version or also MySQL ?
Did you rebuild the MySQL plugin ?
-
What size are both tables ?
-
I meant number of rows of each tables.
-
The plugin hasn't changed anything related to that between 5.5 and 5.6 so I wonder if it's a change in QVariant.
By the way, why do you need that information ? You should be able to just convert to int without any problem.