src/sql/drivers/mysql/qsql_mysql.cpp
changeset 7 f7bc934e204c
parent 3 41300fa6a67c
--- a/src/sql/drivers/mysql/qsql_mysql.cpp	Tue Feb 02 00:43:10 2010 +0200
+++ b/src/sql/drivers/mysql/qsql_mysql.cpp	Wed Mar 31 11:06:36 2010 +0300
@@ -1,6 +1,6 @@
 /****************************************************************************
 **
-** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
 ** All rights reserved.
 ** Contact: Nokia Corporation (qt-info@nokia.com)
 **
@@ -320,6 +320,16 @@
            || t == MYSQL_TYPE_LONG_BLOB;
 }
 
+static bool qIsInteger(int t)
+{
+    return t == MYSQL_TYPE_TINY
+           || t == MYSQL_TYPE_SHORT
+           || t == MYSQL_TYPE_LONG
+           || t == MYSQL_TYPE_LONGLONG
+           || t == MYSQL_TYPE_INT24;
+}
+
+
 void QMYSQLResultPrivate::bindBlobs()
 {
     int i;
@@ -368,6 +378,13 @@
             fieldInfo->length = 0;
             hasBlobs = true;
         } else {
+            // fieldInfo->length specifies the display width, which may be too
+            // small to hold valid integer values (see
+            // http://dev.mysql.com/doc/refman/5.0/en/numeric-types.html ), so
+            // always use the MAX_BIGINT_WIDTH for integer types
+            if (qIsInteger(fieldInfo->type)) {
+                fieldInfo->length = MAX_BIGINT_WIDTH;
+            }
             fieldInfo->type = MYSQL_TYPE_STRING;
         }
         bind = &inBinds[i];