Hi,

Most of the dbi drivers don't handle correctly the column types
unsigned int and unsigned long long.

I modified test_dbi.c to check unsigned types, and the ulong and
theulonglong tests failed:

the_char: in:-127 out:-127<<
the_uchar: in:255 out:255<<
the_short: in:-32768 out:-32768<<
the_ushort: in:65535 out:65535<<
the_long: in:-2147483648 out:-2147483648<<
-->> the_ulong: in:4294967295 out:2147483647<<
the_longlong: in:-9223372036854775807 out:-9223372036854775807<<
->>> the_ulonglong: in:18446744073709551615 out:9223372036854775807<<

Due to lack of time, i patched only mysql driver, and the mysql test in
test_dbi.c

[ I'm not on the list yet, Please keep me in CC ]
--- tests/test_dbi.c.orig       2005-09-28 21:55:17.000000000 +0200
+++ tests/test_dbi.c    2005-11-18 15:55:13.000000000 +0100
@@ -720,7 +720,7 @@
   dbi_result result;
 
   if (!strcmp(ptr_cinfo->drivername, "mysql")) {
-    snprintf(query, QUERY_LEN, "CREATE TABLE test_datatypes ( the_char 
TINYINT, the_uchar TINYINT, the_short SMALLINT, the_ushort SMALLINT, the_long 
INT, the_ulong INT, the_longlong BIGINT, the_ulonglong BIGINT, the_float 
FLOAT4, the_double FLOAT8, the_driver_string VARCHAR(255), the_conn_string 
VARCHAR(255), the_empty_string VARCHAR(255), the_null_string VARCHAR(255), 
the_binary_string BLOB, the_datetime DATETIME, the_date DATE, the_time TIME, id 
INT AUTO_INCREMENT, PRIMARY KEY (id))");
+    snprintf(query, QUERY_LEN, "CREATE TABLE test_datatypes ( the_char 
TINYINT, the_uchar TINYINT UNSIGNED, the_short SMALLINT, the_ushort SMALLINT 
UNSIGNED, the_long INT, the_ulong INT UNSIGNED, the_longlong BIGINT, 
the_ulonglong BIGINT UNSIGNED, the_float FLOAT4, the_double FLOAT8, 
the_driver_string VARCHAR(255), the_conn_string VARCHAR(255), the_empty_string 
VARCHAR(255), the_null_string VARCHAR(255), the_binary_string BLOB, 
the_datetime DATETIME, the_date DATE, the_time TIME, id INT AUTO_INCREMENT, 
PRIMARY KEY (id))");
   }
   else if (!strcmp(ptr_cinfo->drivername, "pgsql")) {
     /* PostgreSQL does not have a 1-byte integer, use smallint
@@ -751,7 +751,6 @@
      snprintf(query, QUERY_LEN, "CREATE TABLE test_datatypes ( the_char 
TINYINT, the_uchar TINYINT, the_short SMALLINT, the_ushort SMALLINT, the_long 
INT, the_ulong INT, the_longlong BIGINT, the_ulonglong BIGINT, the_float REAL, 
the_double FLOAT, the_driver_string VARCHAR(255), the_conn_string VARCHAR(255), 
the_empty_string VARCHAR(255), the_null_string VARCHAR(255), the_binary_string 
IMAGE, the_datetime DATETIME, the_date DATETIME, the_time DATETIME, id INT 
IDENTITY, CONSTRAINT tr_test_datatypes PRIMARY KEY (id))");
   } 
 
-
   if ((result = dbi_conn_query(conn, query)) == NULL) {
     dbi_conn_error(conn, &errmsg);
     printf("\tAAH! Can't create table! Error message: %s\n", errmsg);
@@ -826,7 +825,7 @@
             conn_quoted_string, quoted_binary);
   }
 else {
-    snprintf(query, QUERY_LEN, "INSERT INTO test_datatypes (the_char, 
the_uchar, the_short, the_ushort, the_long, the_ulong, the_longlong, 
the_ulonglong, the_float, the_double, the_driver_string, the_conn_string, 
the_empty_string, the_null_string, the_binary_string, the_datetime, the_date, 
the_time) VALUES (-127, 127, -32768, 32767, -2147483648, 2147483647, 
-9223372036854775807, 9223372036854775807, 3.402823466E+38, 
1.7976931348623157E+307, %s, %s, '', NULL, %s, '2001-12-31 23:59:59', 
'2001-12-31', '23:59:59')", driver_quoted_string, conn_quoted_string, 
quoted_binary);
+    snprintf(query, QUERY_LEN, "INSERT INTO test_datatypes (the_char, 
the_uchar, the_short, the_ushort, the_long, the_ulong, the_longlong, 
the_ulonglong, the_float, the_double, the_driver_string, the_conn_string, 
the_empty_string, the_null_string, the_binary_string, the_datetime, the_date, 
the_time) VALUES (-127, 255, -32768, 65535, -2147483648, 4294967295, 
-9223372036854775807, 18446744073709551615, 3.402823466E+38, 
1.7976931348623157E+307, %s, %s, '', NULL, %s, '2001-12-31 23:59:59', 
'2001-12-31', '23:59:59')", driver_quoted_string, conn_quoted_string, 
quoted_binary);
   }
 
   if (driver_quoted_string) {
@@ -1115,7 +1114,7 @@
               , the_short, the_ushort, the_long, the_ulong, the_float, 
the_double, string_to_quote, the_driver_string, string_to_quote, 
the_conn_string, the_empty_string, the_null_string, year_dt, mon_dt, day_dt, 
hour_dt, min_dt, sec_dt, year, mon, day, hour, min, sec);
       }
       else {
-       printf("the_char: in:-127 out:%d<<\nthe_uchar: in:127 
out:%u<<\nthe_short: in:-32768 out:%hd<<\nthe_ushort: in:32767 
out:%hu<<\nthe_long: in:-2147483648 out:%ld<<\nthe_ulong: in:2147483647 
out:%lu<<\nthe_longlong: in:-9223372036854775807 out:%lld<<\nthe_ulonglong: 
in:9223372036854775807 out:%llu<<\nthe_float: in:3.402823466E+38 
out:%e<<\nthe_double: in:1.7976931348623157E+307 out:%e\nthe_driver_string: 
in:\'%s\' out:\'%s\'<<\nthe_conn_string: in:\'%s\' 
out:\'%s\'<<\nthe_empty_string: out:\'%s\'<<\nthe_null_string: 
out:\'%s\'\nthe_datetime: in:\'2001-12-31 23:59:59\' out:%d-%d-%d 
%d:%d:%d\nthe_date: in:\'2001-12-31\' out:%d-%d-%d\nthe_time: in:\'23:59:59\' 
out:%d:%d:%d\n", (signed int)the_char, (unsigned int)the_uchar, the_short, 
the_ushort, the_long, the_ulong, the_longlong, the_ulonglong, the_float, 
the_double, string_to_quote, the_driver_string, string_to_quote, 
the_conn_string, the_empty_string, the_null_string, year_dt, mon_dt, day_dt, 
hour_dt, min_dt, sec_dt, year, mon, day, hour, min, sec);
+       printf("the_char: in:-127 out:%d<<\nthe_uchar: in:255 
out:%u<<\nthe_short: in:-32768 out:%hd<<\nthe_ushort: in:65535 
out:%hu<<\nthe_long: in:-2147483648 out:%ld<<\nthe_ulong: in:4294967295 
out:%lu<<\nthe_longlong: in:-9223372036854775807 out:%lld<<\nthe_ulonglong: 
in:18446744073709551615 out:%llu<<\nthe_float: in:3.402823466E+38 
out:%e<<\nthe_double: in:1.7976931348623157E+307 out:%e\nthe_driver_string: 
in:\'%s\' out:\'%s\'<<\nthe_conn_string: in:\'%s\' 
out:\'%s\'<<\nthe_empty_string: out:\'%s\'<<\nthe_null_string: 
out:\'%s\'\nthe_datetime: in:\'2001-12-31 23:59:59\' out:%d-%d-%d 
%d:%d:%d\nthe_date: in:\'2001-12-31\' out:%d-%d-%d\nthe_time: in:\'23:59:59\' 
out:%d:%d:%d\n", (signed int)the_char, (unsigned int)the_uchar, the_short, 
the_ushort, the_long, the_ulong, the_longlong, the_ulonglong, the_float, 
the_double, string_to_quote, the_driver_string, string_to_quote, 
the_conn_string, the_empty_string, the_null_string, year_dt, mon_dt, day_dt, 
hour_dt, min_dt, sec_dt, year, mon, day, hour, min, sec);
       }
     }
     
--- drivers/mysql/dbd_mysql.c.orig      2005-11-18 16:27:50.000000000 +0100
+++ drivers/mysql/dbd_mysql.c   2005-11-18 16:34:32.000000000 +0100
@@ -684,9 +684,13 @@
                                                data->d_short = (short) 
atol(raw); break;
                                        case DBI_INTEGER_SIZE3:
                                        case DBI_INTEGER_SIZE4:
-                                               data->d_long = (int) atol(raw); 
break;
+                                               data->d_long = strtoll(raw, 
NULL, 10);
+                                               break;
                                        case DBI_INTEGER_SIZE8:
-                                               data->d_longlong = (long long) 
atoll(raw); break;
+                                               if 
(result->field_types[curfield] & DBI_INTEGER_UNSIGNED)
+                                                       data->d_longlong = 
(long long)strtoull(raw, NULL, 10);
+                                               else
+                                                       data->d_longlong = 
strtoll(raw, NULL, 10);      
                                        default:
                                                break;
                                }

Reply via email to