ODBC BIGINT hacking
BIGINTs on ODBC didn't work for me. I hacked for a while and now it
does, but you probably won't like it. With this it actually reads
bigints as 8 byte signed integers instead of trying to read them in as a
string (which left me with the first half of the number). I think this
has something to do with the way freetds or sqlserver structures that
column. It looks like bignum on odbc->postgres did work, it still works
in this patch.
The downside: I didn't figure out how to make it work with uffi. This
uses :long-long out of the cffi-uffi-compat library. If someone can
figure out a comparable item in uffi, or can teach uffi then this might
be more useful, as is I'm posting it for reference as much as anything.
I also included a patch for switch from uffi to the cffi-uffi-compat
library if anyone with this problem (I have a feeling there aren't many
of us
is interested in trying that.
Nathan Bird
PS: and with that, all the local patches i have are submitted! Cheers,
and thanks for the great library.
Thu Jun 14 16:28:20 EDT 2007 Nathan Bird <nathan@...>
* switiching to use cffi-uffi-compat instead of uffi
diff -rN -u old-clsql/clsql-mysql.asd new-clsql/clsql-mysql.asd
--- old-clsql/clsql-mysql.asd 2007-06-15 18:35:51.000000000 -0400
+++ new-clsql/clsql-mysql.asd 2007-06-15 18:35:51.000000000 -0400
<at> <at> -80,7 +80,7 <at> <at>
:description "Common Lisp SQL MySQL Driver"
:long-description "cl-sql-mysql package provides a database driver to the MySQL database system."
- :depends-on (uffi clsql clsql-uffi)
+ :depends-on (cffi-uffi-compat clsql clsql-uffi)
:components
((:module :db-mysql
:components
diff -rN -u old-clsql/clsql-odbc.asd new-clsql/clsql-odbc.asd
--- old-clsql/clsql-odbc.asd 2007-06-15 18:35:51.000000000 -0400
+++ new-clsql/clsql-odbc.asd 2007-06-15 18:35:51.000000000 -0400
<at> <at> -27,7 +27,7 <at> <at>
:description "Common Lisp SQL ODBC Driver"
:long-description "cl-sql-odbc package provides a database driver to the ODBC database system."
- :depends-on (uffi clsql clsql-uffi)
+ :depends-on (cffi-uffi-compat clsql clsql-uffi)
:components
((:module :db-odbc
:components
diff -rN -u old-clsql/clsql-postgresql-socket.asd new-clsql/clsql-postgresql-socket.asd
--- old-clsql/clsql-postgresql-socket.asd 2007-06-15 18:35:51.000000000 -0400
+++ new-clsql/clsql-postgresql-socket.asd 2007-06-15 18:35:51.000000000 -0400
<at> <at> -29,7 +29,7 <at> <at>
:description "Common Lisp SQL PostgreSQL Socket Driver"
:long-description "cl-sql-postgresql-socket package provides a database driver to the PostgreSQL
database via a socket interface."
- :depends-on (clsql uffi md5 #+sbcl sb-bsd-sockets)
+ :depends-on (clsql cffi-uffi-compat md5 #+sbcl sb-bsd-sockets)
:components
((:module :db-postgresql-socket
:components
diff -rN -u old-clsql/clsql-postgresql.asd new-clsql/clsql-postgresql.asd
--- old-clsql/clsql-postgresql.asd 2007-06-15 18:35:51.000000000 -0400
+++ new-clsql/clsql-postgresql.asd 2007-06-15 18:35:51.000000000 -0400
<at> <at> -29,7 +29,7 <at> <at>
:description "Common Lisp PostgreSQL API Driver"
:long-description "cl-sql-postgresql package provides a the database driver for the PostgreSQL API."
- :depends-on (uffi clsql clsql-uffi)
+ :depends-on (cffi-uffi-compat clsql clsql-uffi)
:components
((:module :db-postgresql
:components
diff -rN -u old-clsql/clsql-uffi.asd new-clsql/clsql-uffi.asd
--- old-clsql/clsql-uffi.asd 2007-06-15 18:35:51.000000000 -0400
+++ new-clsql/clsql-uffi.asd 2007-06-15 18:35:51.000000000 -0400
<at> <at> -79,7 +79,7 <at> <at>
:description "Common UFFI Helper functions for Common Lisp SQL Interface Library"
:long-description "cl-sql-uffi package provides common helper functions using the UFFI for the CLSQL package."
- :depends-on (uffi clsql)
+ :depends-on (cffi-uffi-compat clsql)
:components
((:module :uffi
diff -rN -u old-clsql/clsql.asd new-clsql/clsql.asd
--- old-clsql/clsql.asd 2007-06-15 18:35:51.000000000 -0400
+++ new-clsql/clsql.asd 2007-06-15 18:35:51.000000000 -0400
<at> <at> -27,7 +27,7 <at> <at>
;; need to load uffi for below perform :after method
(eval-when (:compile-toplevel :load-toplevel :execute)
(unless (find-package 'uffi)
- (asdf:operate 'asdf:load-op 'uffi)))
+ (asdf:operate 'asdf:load-op 'cffi-uffi-compat)))
(defsystem clsql
:name "CLSQL"
Thu Jun 14 15:25:43 EDT 2007 Nathan Bird <nathan@...>
* Implementing bigint support for odbc + mssql
diff -rN -u old-clsql/db-odbc/odbc-api.lisp new-clsql/db-odbc/odbc-api.lisp
--- old-clsql/db-odbc/odbc-api.lisp 2007-06-15 17:57:28.000000000 -0400
+++ new-clsql/db-odbc/odbc-api.lisp 2007-06-15 17:57:28.000000000 -0400
<at> <at> -240,7 +240,7 <at> <at>
(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
<at> <at> -494,6 +494,7 <at> <at>
(deref-pointer column-nullable-p-ptr :short)))))))
;; parameter counting is 1-based
+;; this function isn't used, which is good because FreeTDS dosn't support it.
(defun %describe-parameter (hstmt parameter-nr)
(with-foreign-objects ((column-sql-type-ptr :short)
(column-precision-ptr #.$ODBC-ULONG-TYPE)
<at> <at> -584,9 +585,10 <at> <at>
(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)
<at> <at> -604,6 +606,7 <at> <at>
(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))
<at> <at> -624,6 +627,10 <at> <at>
(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)))
<at> <at> -670,8 +677,7 <at> <at>
(#.$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))))
<at> <at> -741,6 +747,7 <at> <at>
(#.$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
diff -rN -u old-clsql/db-odbc/odbc-constants.lisp new-clsql/db-odbc/odbc-constants.lisp
--- old-clsql/db-odbc/odbc-constants.lisp 2007-06-15 17:57:28.000000000 -0400
+++ new-clsql/db-odbc/odbc-constants.lisp 2007-06-15 17:57:28.000000000 -0400
<at> <at> -21,6 +21,7 <at> <at>
;; on SuSE AMD64 9.0, unixODBC is compiled with with SQLLEN being 4 bytes long
(defconstant $ODBC-LONG-TYPE :int)
(defconstant $ODBC-ULONG-TYPE :unsigned-int)
+(defconstant $ODBC-BIG-TYPE :long-long)
;; (defconstant $ODBCVER #x0210)
<at> <at> -934,6 +935,7 <at> <at>
(defconstant $SQL_C_BINARY $SQL_BINARY)
(defconstant $SQL_C_BIT $SQL_BIT)
(defconstant $SQL_C_TINYINT $SQL_TINYINT)
+(defconstant $SQL_C_SBIGINT (+ $SQL_BIGINT $SQL_SIGNED_OFFSET))
(defconstant $SQL_C_SLONG (+ $SQL_C_LONG $SQL_SIGNED_OFFSET)) ;; SIGNED INTEGER
(defconstant $SQL_C_SSHORT (+ $SQL_C_SHORT $SQL_SIGNED_OFFSET)) ;; SIGNED SMALLINT
(defconstant $SQL_C_STINYINT (+ $SQL_TINYINT $SQL_SIGNED_OFFSET)) ;; SIGNED TINYINT
diff -rN -u old-clsql/db-odbc/odbc-dbi.lisp new-clsql/db-odbc/odbc-dbi.lisp
--- old-clsql/db-odbc/odbc-dbi.lisp 2007-06-15 17:57:28.000000000 -0400
+++ new-clsql/db-odbc/odbc-dbi.lisp 2007-06-15 17:57:28.000000000 -0400
<at> <at> -454,22 +454,19 <at> <at>
(setf computed-result-types (make-array column-count))
(dotimes (i column-count)
(setf (aref computed-result-types i)
- (cond
- ((consp result-types)
- (nth i result-types))
- ((eq result-types :auto)
- (if (eq (aref column-sql-types i) odbc::$SQL_BIGINT)
- :number
- (case (aref column-c-types i)
- (#.odbc::$SQL_C_SLONG :int)
- (#.odbc::$SQL_C_DOUBLE :double)
- (#.odbc::$SQL_C_FLOAT :float)
- (#.odbc::$SQL_C_SSHORT :short)
- (#.odbc::$SQL_C_STINYINT :short)
- (#.odbc::$SQL_BIGINT :short)
- (t t))))
- (t
- t)))))
+ (cond
+ ((consp result-types)
+ (nth i result-types))
+ ((eq result-types :auto)
+ (case (aref column-c-types i)
+ (#.odbc::$SQL_C_SLONG :int)
+ (#.odbc::$SQL_C_DOUBLE :double)
+ (#.odbc::$SQL_C_FLOAT :float)
+ (#.odbc::$SQL_C_SSHORT :short)
+ (#.odbc::$SQL_C_STINYINT :short)
+ (#.odbc::$SQL_C_SBIGINT #.odbc::$ODBC-BIG-TYPE)
+ (t t)))
+ (t t)))))
query)
(defun db-close-query (query &key drop-p)
<at> <at> -564,7 +561,8 <at> <at>
(defun sql-to-lisp-type (sql-type)
(ecase sql-type
((#.odbc::$SQL_CHAR #.odbc::$SQL_VARCHAR #.odbc::$SQL_LONGVARCHAR) :string)
- ((#.odbc::$SQL_NUMERIC #.odbc::$SQL_DECIMAL #.odbc::$SQL_BIGINT) :string) ; ??
+ ((#.odbc::$SQL_NUMERIC #.odbc::$SQL_DECIMAL ) :string) ; ??
+ (#.odbc::$SQL_BIGINT #.odbc::$ODBC-BIG-TYPE)
(#.odbc::$SQL_INTEGER #.odbc::$ODBC-LONG-TYPE)
(#.odbc::$SQL_SMALLINT :short)
((#.odbc::$SQL_FLOAT #.odbc::$SQL_DOUBLE) #.odbc::$ODBC-LONG-TYPE)
_______________________________________________
CLSQL-Devel mailing list
CLSQL-Devel@...
http://lists.b9.com/mailman/listinfo/clsql-devel