Results 1 to 2 of 2

Thread: QSqlQuery::value() incorrectly returns "0" for large id numbers

  1. #1
    Join Date
    Oct 2006
    Posts
    3
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Question QSqlQuery::value() incorrectly returns "0" for large id numbers

    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:
    Qt Code:
    1. QSqlQuery q(db);
    2. p.prepare("select id from mytable where col1=? and col2=?");
    3. p.addBindValue(var1);
    4. p.addBindValue(var2);
    5. q.exec();
    6. while (q.next()){
    7. QVariant v = q.value(0);
    8. // this incorrectly reports "0" for records with id numbers over 1 million
    9. qDebug() << v.typeName(); // reports 'uint'
    10. qDebug() << v.toString();
    11. }
    To copy to clipboard, switch view to plain text mode 

    Anyone know what the heck is going on?

    Thanks,
    Peter

  2. #2
    Join Date
    Oct 2006
    Posts
    3
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QSqlQuery::value() incorrectly returns "0" for large id numbers

    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...

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.