Patch for clsql-odbc

Francisco Vides Fernández <fvides-u/fcxpuwxnlHddKoEH+GZlaTQe2KTcn/@public.gmane.org> Mon, 28 Nov 2011 22:25:06 +0100
Newsgroups gmane.lisp.clsql.general
Organization Dédalo Ingenieros S.L.
Message-ID <[email protected]>
Dear list

I've found a problem at the odbc driver of clsql, in the last version
installed from quicklisp, 6.0.1-1 acording to debian/changelog in
reading dates before 1900-01-01, because clsql-odbc uses universal-time
which can't represent dates before that.

I've developed the attached patch (which Works For Me (tm)), that
converts directly from a pointer to the odbc value to clsql-sys:time,
which in fact overcomes the universal-time limits.

HTH.

Many thanks

-- 
+-----------------
| Francisco Vides Fernández <fvides-u/fcxpuwxnlHddKoEH+GZlaTQe2KTcn/@public.gmane.org>
| Gerente
| Teléfono fijo:   952 60 29 59
| Fax:             952 60 29 59
| Dédalo Ingenieros http://www.dedaloingenieros.com/
| PGP: http://pgp.rediris.es:11371/pks/lookup?op=index&search=0xB1299C15
+------

_______________________________________________
CLSQL mailing list
[email protected]
http://lists.b9.com/cgi-bin/mailman/listinfo/clsql
clsql-20111001-replace-universal-time.patch (text/x-diff, 4.7 KB)
diff -u -r clsql-20111001-git.a/db-odbc/odbc-api.lisp clsql-20111001-git.b/db-odbc/odbc-api.lisp
--- clsql-20111001-git.a/db-odbc/odbc-api.lisp	2011-11-15 21:11:39.000000000 +0100
+++ clsql-20111001-git.b/db-odbc/odbc-api.lisp	2011-11-28 20:58:14.000000000 +0100
@@ -22,13 +22,9 @@
 
 
 (defvar *binary-format* :unsigned-byte-vector)
-(defvar *time-conversion-function*
-    (lambda (universal-time &optional fraction)
-       (let ((time (clsql-sys:utime->time universal-time)))
-	 (setf time (clsql-sys:time+
-		     time
-		     (clsql-sys:make-duration :usec (/ fraction 1000))))
-	 (clsql-sys:format-time nil time :format :iso))
+(defvar *time-format*
+  (lambda (time)
+    (clsql-sys:format-time nil time :format :iso)
       #+ignore
       universal-time)
    "Bound to a function that converts from a Lisp universal time fixnum (and a fractional
@@ -689,13 +685,11 @@
                    (t
                     (case c-type
                       ((#.$SQL_C_DATE #.$SQL_C_TYPE_DATE)
-                       (funcall *time-conversion-function* (date-to-universal-time data-ptr)))
+                       (funcall *time-format* (date-to-clsql-time data-ptr)))
                       ((#.$SQL_C_TIME #.$SQL_C_TYPE_TIME)
-                       (multiple-value-bind (universal-time frac) (time-to-universal-time data-ptr)
-                         (funcall *time-conversion-function* universal-time frac)))
+		       (funcall *time-format* (time-to-clsql-time data-ptr)))
                       ((#.$SQL_C_TIMESTAMP #.$SQL_C_TYPE_TIMESTAMP)
-                       (multiple-value-bind (universal-time frac) (timestamp-to-universal-time data-ptr)
-                         (funcall *time-conversion-function* universal-time frac)))
+		       (funcall *time-format* (timestamp-to-clsql-time data-ptr)))
                       (#.$SQL_INTEGER
                        (get-cast-int data-ptr))
                       (#.$SQL_C_FLOAT
@@ -946,17 +940,17 @@
 (def-type c-time-ptr-type (* (:struct sql-c-time)))
 (def-type c-date-ptr-type (* (:struct sql-c-date)))
 
-(defun timestamp-to-universal-time (ptr)
+(defun timestamp-to-clsql-time (ptr)
   (declare (type c-timestamp-ptr-type ptr))
-  (values
-   (encode-universal-time
-    (get-slot-value ptr 'sql-c-timestamp 'second)
-    (get-slot-value ptr 'sql-c-timestamp 'minute)
-    (get-slot-value ptr 'sql-c-timestamp 'hour)
-    (get-slot-value ptr 'sql-c-timestamp 'day)
-    (get-slot-value ptr 'sql-c-timestamp 'month)
-    (get-slot-value ptr 'sql-c-timestamp 'year))
-   (get-slot-value ptr 'sql-c-timestamp 'fraction)))
+  (clsql-sys:make-time
+   :second (get-slot-value ptr 'sql-c-timestamp 'second)
+   :minute (get-slot-value ptr 'sql-c-timestamp 'minute)
+   :hour (get-slot-value ptr 'sql-c-timestamp 'hour)
+   :day (get-slot-value ptr 'sql-c-timestamp 'day)
+   :month (get-slot-value ptr 'sql-c-timestamp 'month)
+   :year (get-slot-value ptr 'sql-c-timestamp 'year)
+   :usec (let ((frac (get-slot-value ptr 'sql-c-timestamp 'fraction)))
+	   (if frac (/ frac 1000) 0))))
 
 (defun universal-time-to-timestamp (time &optional (fraction 0))
   "TODO: Dead function?"
@@ -986,21 +980,20 @@
           (get-slot-value ptr 'sql-c-timestamp 'fraction) fraction)
       ptr))
 
-(defun date-to-universal-time (ptr)
+(defun date-to-clsql-time (ptr)
   (declare (type c-date-ptr-type ptr))
-  (encode-universal-time
-   0 0 0
-   (get-slot-value ptr 'sql-c-timestamp 'day)
-   (get-slot-value ptr 'sql-c-timestamp 'month)
-   (get-slot-value ptr 'sql-c-timestamp 'year)))
+  (clsql-sys:make-time
+   :second 0 :minute 0 :hour 0
+   :day (get-slot-value ptr 'sql-c-timestamp 'day)
+   :month (get-slot-value ptr 'sql-c-timestamp 'month)
+   :year (get-slot-value ptr 'sql-c-timestamp 'year)))
 
-(defun time-to-universal-time (ptr)
+(defun time-to-clsql-time (ptr)
   (declare (type c-time-ptr-type ptr))
-  (encode-universal-time
-   (get-slot-value ptr 'sql-c-timestamp 'second)
-   (get-slot-value ptr 'sql-c-timestamp 'minute)
-   (get-slot-value ptr 'sql-c-timestamp 'hour)
-   1 1 0))
+  (clsql-sys:make-time
+   :second (get-slot-value ptr 'sql-c-timestamp 'second)
+   :minute (get-slot-value ptr 'sql-c-timestamp 'minute)
+   :hour (get-slot-value ptr 'sql-c-timestamp 'hour)))
 
 
 ;;; Added by KMR
Sólo en clsql-20111001-git.b/db-odbc: odbc-api.lisp.orig
diff -u -r clsql-20111001-git.a/db-odbc/odbc-package.lisp clsql-20111001-git.b/db-odbc/odbc-package.lisp
--- clsql-20111001-git.a/db-odbc/odbc-package.lisp	2011-11-15 21:11:39.000000000 +0100
+++ clsql-20111001-git.b/db-odbc/odbc-package.lisp	2011-11-28 20:09:51.000000000 +0100
@@ -17,7 +17,7 @@
 (in-package #:cl-user)
 
 (defpackage #:odbc
-  (:use #:cl #:uffi)
+  (:use #:cl #:uffi #:local-time)
   (:export
      #:database-library-loaded
 
Sólo en clsql-20111001-git.b/db-odbc: odbc-package.lisp.orig