PDA

View Full Version : QSqlQuery::value() incorrectly returns "0" for large id numbers



peter
13th March 2007, 17:16
Hi,

I'm using QT 4.2, to access some tables in a MySQL database.
Everything was working OK until my (autoincrement) ID field for one of my tables reached 1,000,000.

Now, when I use QSqlQuery to read rows in that table... the id fields always come back as "0", instead of something like "1000085"


The offending code goes something like this:


QSqlQuery q(db);
p.prepare("select id from mytable where col1=? and col2=?");
p.addBindValue(var1);
p.addBindValue(var2);
q.exec();
while (q.next()){
QVariant v = q.value(0);
// this incorrectly reports "0" for records with id numbers over 1 million
qDebug() << v.typeName(); // reports 'uint'
qDebug() << v.toString();
}


Anyone know what the heck is going on? :confused:

Thanks,
Peter

peter
13th March 2007, 17:33
Doh! I figured it out. The id field in my table was defined as "INT(6) UNSIGNED".

It seems that the 6 was preventing QT from reading values longer than 6 digits. (Even though they are perfectly legal in my table.) I changed the column to INT UNSIGNED, and things are working again. Seems like a bug to me... :eek: