Description: In *Binding, check size of object, not size of type.
Origin: vendor, http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=538643
Forwarded: http://sf.net/tracker/?func=detail&aid=1875874&group_id=23045&atid=377333
Reviewed-by: Stephen Leake <stephen_leake@stephe-leake.org>


Index: gnade-1.6.2/dbi/odbc/gnu-db-sqlcli.gpb
===================================================================
--- gnade-1.6.2.orig/dbi/odbc/gnu-db-sqlcli.gpb	2009-09-07 08:20:52.000000000 -0400
+++ gnade-1.6.2/dbi/odbc/gnu-db-sqlcli.gpb	2009-09-07 08:21:32.000000000 -0400
@@ -831,14 +831,15 @@
                           return SQLRETURN;
          pragma Import ($CALLCONVENTION, BindCol, "SQLBindCol");
          DT  : SQL_C_DATA_TYPE;
+         Size : constant Positive := TargetValue.all'Size;
       begin
-         if Int'Size = SQLTINYINT'Size then
+         if Size = SQLTINYINT'Size then
             DT := SQL_C_TINYINT;
-         elsif Int'Size = SQLSMALLINT'Size then
+         elsif Size = SQLSMALLINT'Size then
             DT := SQL_C_SHORT;
-         elsif Int'Size = SQLINTEGER'Size then
+         elsif Size = SQLINTEGER'Size then
             DT := SQL_C_LONG;
-         elsif Int'Size = SQLBIGINT'Size then
+         elsif Size = SQLBIGINT'Size then
             DT := SQL_C_SBIGINT;
          else
             raise Constraint_Error;
@@ -847,7 +848,7 @@
                          ColumnNumber,
                          DT,
                          TargetValue,
-                         SQLINTEGER (Int'Size / 8),
+                         SQLINTEGER (Size / 8),
                          IndPtr);
       end SQLBindCol;

@@ -877,20 +878,21 @@
          C_DataType   : SQL_C_DATA_TYPE;
          SQL_DataType : SQL_DATA_TYPE;
          ColumnSize   : SQLUINTEGER;
+         Size         : constant Positive := Value.all'Size;
       begin
-         if Int'Size = SQLTINYINT'Size then
+         if Size = SQLTINYINT'Size then
             C_DataType   := SQL_C_TINYINT;
             SQL_DataType := SQL_TINYINT;
             ColumnSize   := 3;
-         elsif Int'Size = SQLSMALLINT'Size then
+         elsif Size = SQLSMALLINT'Size then
             C_DataType   := SQL_C_SHORT;
             SQL_DataType := SQL_SMALLINT;
             ColumnSize   := 5;
-         elsif Int'Size = SQLINTEGER'Size then
+         elsif Size = SQLINTEGER'Size then
             C_DataType   := SQL_C_LONG;
             SQL_DataType := SQL_INTEGER;
             ColumnSize   := 10;
-         elsif Int'Size = SQLBIGINT'Size then
+         elsif Size = SQLBIGINT'Size then
             C_DataType   := SQL_C_SBIGINT;
             SQL_DataType := SQL_BIGINT;
             ColumnSize   := 19;
@@ -944,14 +946,15 @@
                           return SQLRETURN;
          pragma Import ($CALLCONVENTION, BindCol, "SQLBindCol");
          DT  : SQL_C_DATA_TYPE;
+         Size : constant Positive := TargetValue.all'Size;
       begin
-         if Unsigned'Size = SQLTINYINT'Size then
+         if Size = SQLTINYINT'Size then
             DT := SQL_C_UTINYINT;
-         elsif Unsigned'Size = SQLSMALLINT'Size then
+         elsif Size = SQLSMALLINT'Size then
             DT := SQL_C_USHORT;
-         elsif Unsigned'Size = SQLINTEGER'Size then
+         elsif Size = SQLINTEGER'Size then
             DT := SQL_C_ULONG;
-         elsif Unsigned'Size = SQLBIGINT'Size then
+         elsif Size = SQLBIGINT'Size then
             DT := SQL_C_UBIGINT;
          else
             raise Constraint_Error;
@@ -960,7 +963,7 @@
                          ColumnNumber,
                          DT,
                          TargetValue,
-                         SQLINTEGER (Unsigned'Size / 8),
+                         SQLINTEGER (Size / 8),
                          IndPtr);

       end SQLBindCol;
@@ -992,20 +995,21 @@
          C_DataType   : SQL_C_DATA_TYPE;
          SQL_DataType : SQL_DATA_TYPE;
          ColumnSize   : SQLUINTEGER;
+         Size         : constant Positive := Value.all'Size;
       begin
-         if Unsigned'Size = SQLTINYINT'Size then
+         if Size = SQLTINYINT'Size then
             C_DataType   := SQL_C_UTINYINT;
             SQL_DataType := SQL_TINYINT;
             ColumnSize   := 3;
-         elsif Unsigned'Size = SQLSMALLINT'Size then
+         elsif Size = SQLSMALLINT'Size then
             C_DataType   := SQL_C_USHORT;
             SQL_DataType := SQL_SMALLINT;
             ColumnSize   := 5;
-         elsif Unsigned'Size = SQLINTEGER'Size then
+         elsif Size = SQLINTEGER'Size then
             C_DataType   := SQL_C_ULONG;
             SQL_DataType := SQL_INTEGER;
             ColumnSize   := 10;
-         elsif Unsigned'Size = SQLBIGINT'Size then
+         elsif Size = SQLBIGINT'Size then
             C_DataType   := SQL_C_UBIGINT;
             SQL_DataType := SQL_BIGINT;
             ColumnSize   := 20;
@@ -1155,14 +1159,15 @@
                           return SQLRETURN;
          pragma Import ($CALLCONVENTION, BindCol, "SQLBindCol");
          DT  : SQL_C_DATA_TYPE;
+         Size : constant Positive := TargetValue.all'Size;
       begin
-         if Enum'Size = SQLTINYINT'Size then
+         if Size = SQLTINYINT'Size then
             DT := SQL_C_TINYINT;
-         elsif Enum'Size = SQLSMALLINT'Size then
+         elsif Size = SQLSMALLINT'Size then
             DT := SQL_C_SHORT;
-         elsif Enum'Size = SQLINTEGER'Size then
+         elsif Size = SQLINTEGER'Size then
             DT := SQL_C_LONG;
-         elsif Enum'Size = SQLBIGINT'Size then
+         elsif Size = SQLBIGINT'Size then
             DT := SQL_C_SBIGINT;
          else
             raise Constraint_Error;
@@ -1171,7 +1176,7 @@
                          ColumnNumber,
                          DT,
                          TargetValue,
-                         SQLINTEGER (Enum'Size / 8),
+                         SQLINTEGER (Size / 8),
                          IndPtr);
       end SQLBindCol;

@@ -1201,20 +1206,21 @@
          C_DataType   : SQL_C_DATA_TYPE;
          SQL_DataType : SQL_DATA_TYPE;
          ColumnSize   : SQLUINTEGER;
+         Size         : constant Positive := Value.all'Size;
       begin
-         if Enum'Size = SQLTINYINT'Size then
+         if Size = SQLTINYINT'Size then
             C_DataType   := SQL_C_UTINYINT;
             SQL_DataType := SQL_TINYINT;
             ColumnSize   := 3;
-         elsif Enum'Size = SQLSMALLINT'Size then
+         elsif Size = SQLSMALLINT'Size then
             C_DataType   := SQL_C_USHORT;
             SQL_DataType := SQL_SMALLINT;
             ColumnSize   := 5;
-         elsif Enum'Size = SQLINTEGER'Size then
+         elsif Size = SQLINTEGER'Size then
             C_DataType   := SQL_C_ULONG;
             SQL_DataType := SQL_INTEGER;
             ColumnSize   := 10;
-         elsif Enum'Size = SQLBIGINT'Size then
+         elsif Size = SQLBIGINT'Size then
             C_DataType   := SQL_C_UBIGINT;
             SQL_DataType := SQL_BIGINT;
             ColumnSize   := 20;
