src/sql/drivers/mysql/qsql_mysql.cpp
changeset 19 fcece45ef507
parent 18 2f34d5167611
--- a/src/sql/drivers/mysql/qsql_mysql.cpp	Fri Apr 16 15:50:13 2010 +0300
+++ b/src/sql/drivers/mysql/qsql_mysql.cpp	Mon May 03 13:17:34 2010 +0300
@@ -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];