darcs patch: * Implementing bigint support for odbc + mssql
[clsql.git] / db-odbc / odbc-api.lisp
index 50ef4432d3485df1f6792b2cb01041c8a4e39106..49a6e1f6fc7a03da30960a203875639f815ae46f 100644 (file)
@@ -240,7 +240,7 @@ as possible second argument) to the desired representation of date/time/timestam
     (SQLTransact
      henv hdbc $SQL_ROLLBACK)))
 
-; col-nr is zero-based in Lisp
+; col-nr is zero-based in Lisp but 1 based in sql
 ; col-nr = :bookmark retrieves a bookmark.
 (defun %bind-column (hstmt column-nr c-type data-ptr precision out-len-ptr)
   (with-error-handling
@@ -493,6 +493,7 @@ as possible second argument) to the desired representation of date/time/timestam
            (deref-pointer column-scale-ptr :short)
            (deref-pointer column-nullable-p-ptr :short)))))))
 
+;; this function isn't used, which is good because FreeTDS dosn't support it.
 ;; parameter counting is 1-based
 (defun %describe-parameter (hstmt parameter-nr)
   (with-foreign-objects ((column-sql-type-ptr :short)
@@ -584,9 +585,10 @@ as possible second argument) to the desired representation of date/time/timestam
 (defun sql-to-c-type (sql-type)
   (ecase sql-type
     ((#.$SQL_CHAR #.$SQL_VARCHAR #.$SQL_LONGVARCHAR
-      #.$SQL_NUMERIC #.$SQL_DECIMAL #.$SQL_BIGINT -8 -9 -10) $SQL_C_CHAR) ;; Added -10 for MSSQL ntext type
+      #.$SQL_NUMERIC #.$SQL_DECIMAL -8 -9 -10) $SQL_C_CHAR) ;; Added -10 for MSSQL ntext type
     (#.$SQL_INTEGER $SQL_C_SLONG)
     (#.$SQL_SMALLINT $SQL_C_SSHORT)
+    (#.$SQL_BIGINT $SQL_C_SBIGINT)
     (#.$SQL_DOUBLE $SQL_C_DOUBLE)
     (#.$SQL_FLOAT $SQL_C_DOUBLE)
     (#.$SQL_REAL $SQL_C_FLOAT)
@@ -604,6 +606,7 @@ as possible second argument) to the desired representation of date/time/timestam
 (def-type short-pointer-type (* :short))
 (def-type int-pointer-type (* :int))
 (def-type long-pointer-type (* #.$ODBC-LONG-TYPE))
+(def-type big-pointer-type (* #.$ODBC-BIG-TYPE))
 (def-type float-pointer-type (* :float))
 (def-type double-pointer-type (* :double))
 (def-type string-pointer-type (* :unsigned-char))
@@ -624,6 +627,10 @@ as possible second argument) to the desired representation of date/time/timestam
   (locally (declare (type long-pointer-type ptr))
     (deref-pointer ptr #.$ODBC-LONG-TYPE)))
 
+(defun get-cast-big (ptr)
+  (locally (declare (type big-pointer-type ptr))
+    (deref-pointer ptr #.$ODBC-BIG-TYPE)))
+
 (defun get-cast-single-float (ptr)
   (locally (declare (type float-pointer-type ptr))
     (deref-pointer ptr :float)))
@@ -670,8 +677,7 @@ as possible second argument) to the desired representation of date/time/timestam
                    (#.$SQL_C_SSHORT (get-cast-short data-ptr)) ;; ?
                    (#.$SQL_SMALLINT (get-cast-short data-ptr)) ;; ??
                    (#.$SQL_INTEGER (get-cast-int data-ptr))
-                   (#.$SQL_BIGINT (read-from-string
-                                   (get-cast-foreign-string data-ptr)))
+                   (#.$SQL_BIGINT (get-cast-big data-ptr))
                    (#.$SQL_DECIMAL
                     (let ((*read-base* 10))
                       (read-from-string (get-cast-foreign-string data-ptr))))
@@ -741,6 +747,7 @@ as possible second argument) to the desired representation of date/time/timestam
             (#.$SQL_C_BIT (uffi:allocate-foreign-object :byte))
             (#.$SQL_C_STINYINT (uffi:allocate-foreign-object :byte))
             (#.$SQL_C_SSHORT (uffi:allocate-foreign-object :short))
+           (#.$SQL_C_SBIGINT (uffi:allocate-foreign-object #.$ODBC-BIG-TYPE))
             (#.$SQL_C_CHAR (uffi:allocate-foreign-string (1+ size)))
             (#.$SQL_C_BINARY (uffi:allocate-foreign-string (1+ (* 2 size))))
             (t
@@ -913,10 +920,7 @@ as possible second argument) to the desired representation of date/time/timestam
                                  (error 'clsql:sql-database-error :message "wrong type. preliminary."))
                             while
                             (and (= res $SQL_SUCCESS_WITH_INFO)
-                                 #+ingore(eq (sql-state +null-handle-ptr+ +null-handle-ptr+ hstmt)
-                                             $sql-data-truncated)
-                                 (equal (sql-state +null-handle-ptr+ +null-handle-ptr+ hstmt)
-                                        "01004"))
+                                 (> out-len +max-precision+))
                             do (setf res (%sql-get-data hstmt column-nr c-type data-ptr
                                                         +max-precision+ out-len-ptr)
                                      out-len (deref-pointer out-len-ptr #.$ODBC-LONG-TYPE)))