- (out-len (deref-pointer out-len-ptr #.$ODBC-LONG-TYPE))
- (offset 0))
- (case out-len
- (#.$SQL_NULL_DATA
- (return-from read-data-in-chunks *null*))
- (#.$SQL_NO_TOTAL ;; don't know how long it is going to be
- (let ((str (make-array 0 :element-type 'character :adjustable t)))
- (loop do (if (= c-type #.$SQL_CHAR)
- (let ((data-length (foreign-string-length data-ptr)))
- (adjust-array str (+ offset data-length)
- :initial-element #\?)
- (setf offset (%cstring-into-vector
- data-ptr str
- offset
- data-length)))
- (error 'clsql:sql-database-error :message "wrong type. preliminary."))
- while (and (= res $SQL_SUCCESS_WITH_INFO)
- (equal (sql-state +null-handle-ptr+ +null-handle-ptr+ hstmt)
- "01004"))
- do (setf res (%sql-get-data hstmt column-nr c-type data-ptr
- +max-precision+ out-len-ptr)))
- (setf str (coerce str 'string))
- (if (= sql-type $SQL_DECIMAL)
- (let ((*read-base* 10))
- (read-from-string str))
- str)))
- (otherwise
- (let ((str (make-string out-len)))
- (loop do (if (= c-type #.$SQL_CHAR)
- (setf offset (%cstring-into-vector ;string
- data-ptr str
- offset
- (min out-len (1- +max-precision+))))
- (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"))
- 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)))
- (if (= sql-type $SQL_DECIMAL)
- (let ((*read-base* 10))
- (read-from-string str))
- str))))))
-
-(def-type c-timestamp-ptr-type '(* (:struct sql-c-timestamp)))
-(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)
+ (out-len (get-cast-long out-len-ptr))
+ (offset 0)
+ (result (case out-len
+ (#.$SQL_NULL_DATA
+ (return-from read-data-in-chunks *null*))
+ (#.$SQL_NO_TOTAL ;; don't know how long it is going to be
+ (let ((str (make-array 0 :element-type 'character :adjustable t)))
+ (loop do (if (= c-type #.$SQL_CHAR)
+ (let ((data-length (foreign-string-length data-ptr)))
+ (adjust-array str (+ offset data-length)
+ :initial-element #\?)
+ (setf offset (%cstring-into-vector
+ data-ptr str
+ offset
+ data-length)))
+ (error 'clsql:sql-database-error :message "wrong type. preliminary."))
+ while (and (= res $SQL_SUCCESS_WITH_INFO)
+ (equal (sql-state +null-handle-ptr+ +null-handle-ptr+ hstmt)
+ "01004"))
+ do (setf res (%sql-get-data hstmt column-nr c-type data-ptr
+ +max-precision+ out-len-ptr)))
+ (setf str (coerce str 'string))
+ (if (= sql-type $SQL_DECIMAL)
+ (let ((*read-base* 10))
+ (read-from-string str))
+ str)))
+ (otherwise
+ (let ((str (make-string out-len)))
+ (loop
+ do
+ (if (= c-type #.$SQL_CHAR)
+ (setf offset (%cstring-into-vector ;string
+ data-ptr str
+ offset
+ (min out-len (1- +max-precision+))))
+ (error 'clsql:sql-database-error :message "wrong type. preliminary."))
+ while
+ (and (= res $SQL_SUCCESS_WITH_INFO)
+ (>= out-len +max-precision+))
+ do (setf res (%sql-get-data hstmt column-nr c-type data-ptr
+ +max-precision+ out-len-ptr)
+ out-len (get-cast-long out-len-ptr)))
+ (if (= sql-type $SQL_DECIMAL)
+ (let ((*read-base* 10)
+ (*read-default-float-format* 'double-float))
+ (read-from-string str))
+ str))))))
+
+ (setf (deref-pointer out-len-ptr #.$ODBC-LONG-TYPE) #.$SQL_NO_TOTAL) ;; reset the out length for the next row
+ result))
+
+
+(def-type c-timestamp-ptr-type (* (:struct sql-c-timestamp)))
+(def-type c-time-ptr-type (* (:struct sql-c-time)))
+(def-type c-date-ptr-type (* (:struct sql-c-date)))
+
+(defun timestamp-to-clsql-time (ptr)