- (sizeof nil))
- (do ((icolumn 0 (1+ icolumn))
- (cds-as-reversed-list nil))
- ((not (eql (oci-param-get (deref-vp stmthp)
- +oci-htype-stmt+
- (deref-vp errhp)
- parmdp
- (1+ icolumn) :database database)
- +oci-success+))
- (coerce (reverse cds-as-reversed-list) 'simple-vector))
- ;; Decode type of ICOLUMNth column into a type we're prepared to
- ;; handle in Lisp.
- (oci-attr-get (deref-vp parmdp)
- +oci-dtype-param+
- dtype-foreign
- +unsigned-int-null-pointer+
- +oci-attr-data-type+
- (deref-vp errhp))
- (let ((dtype (uffi:deref-pointer dtype-foreign :unsigned-short)))
- (declare (fixnum dtype))
- (case dtype
- (#.SQLT-DATE
- (setf buffer (acquire-foreign-resource :unsigned-char
- (* 32 +n-buf-rows+)))
- (setf sizeof 32 dtype #.SQLT-STR))
- (#.SQLT-NUMBER
- (oci-attr-get (deref-vp parmdp)
- +oci-dtype-param+
- precision
- +unsigned-int-null-pointer+
- +oci-attr-precision+
- (deref-vp errhp))
- (oci-attr-get (deref-vp parmdp)
- +oci-dtype-param+
- scale
- +unsigned-int-null-pointer+
- +oci-attr-scale+
- (deref-vp errhp))
- (let ((*scale (uffi:deref-pointer scale :byte))
- (*precision (uffi:deref-pointer precision :short)))
-
- ;;(format t "scale=~d, precision=~d~%" *scale *precision)
- (cond
- ((or (and (minusp *scale) (zerop *precision))
- (and (zerop *scale) (plusp *precision)))
- (setf buffer (acquire-foreign-resource :int +n-buf-rows+)
- sizeof 4 ;; sizeof(int)
- dtype #.SQLT-INT))
- (t
- (setf buffer (acquire-foreign-resource :double +n-buf-rows+)
- sizeof 8 ;; sizeof(double)
- dtype #.SQLT-FLT)))))
- ;; Default to SQL-STR
- (t
- (setf (uffi:deref-pointer colsize :unsigned-short) 0)
- (setf dtype #.SQLT-STR)
- (oci-attr-get (deref-vp parmdp)
- +oci-dtype-param+
- colsize
- +unsigned-int-null-pointer+
- +oci-attr-data-size+
- (deref-vp errhp))
- (let ((colsize-including-null (1+ (uffi:deref-pointer colsize :unsigned-short))))
- (setf buffer (acquire-foreign-resource
- :unsigned-char (* +n-buf-rows+ colsize-including-null)))
- (setf sizeof colsize-including-null))))
- (let ((retcodes (acquire-foreign-resource :unsigned-short +n-buf-rows+))
- (indicators (acquire-foreign-resource :short +n-buf-rows+))
- (colname-string ""))
- (when field-names
- (oci-attr-get (deref-vp parmdp)
- +oci-dtype-param+
- colname
- colnamelen
- +oci-attr-name+
- (deref-vp errhp))
- (setq colname-string (uffi:convert-from-foreign-string
- (uffi:deref-pointer colname '(* :unsigned-char))
- :length (uffi:deref-pointer colnamelen 'ub4))))
- (push (make-cd :name colname-string
- :sizeof sizeof
- :buffer buffer
- :oci-data-type dtype
- :retcodes retcodes
- :indicators indicators
- :result-type (cond
- ((consp result-types)
- (nth icolumn result-types))
- ((null result-types)
- :string)
- (t
- result-types)))
- cds-as-reversed-list)
- (oci-define-by-pos (deref-vp stmthp)
- defnp
- (deref-vp errhp)
- (1+ icolumn) ; OCI 1-based indexing again
- (foreign-resource-buffer buffer)
- sizeof
- dtype
- (foreign-resource-buffer indicators)
- +unsigned-short-null-pointer+
- (foreign-resource-buffer retcodes)
- +oci-default+))))))))
+ (sizeof nil))
+ (do ((icolumn 0 (1+ icolumn))
+ (cds-as-reversed-list nil))
+ ((not (eql (oci-param-get (deref-vp stmthp)
+ +oci-htype-stmt+
+ (deref-vp errhp)
+ parmdp
+ (1+ icolumn) :database database)
+ +oci-success+))
+ (coerce (reverse cds-as-reversed-list) 'simple-vector))
+ ;; Decode type of ICOLUMNth column into a type we're prepared to
+ ;; handle in Lisp.
+ (oci-attr-get (deref-vp parmdp)
+ +oci-dtype-param+
+ dtype-foreign
+ +unsigned-int-null-pointer+
+ +oci-attr-data-type+
+ (deref-vp errhp))
+ (let ((dtype (uffi:deref-pointer dtype-foreign :unsigned-short)))
+ (declare (fixnum dtype))
+ (case dtype
+ (#.SQLT-DATE
+ (setf buffer (acquire-foreign-resource :unsigned-char
+ (* 32 +n-buf-rows+)))
+ (setf sizeof 32 dtype #.SQLT-STR))
+ (#.SQLT-NUMBER
+ (oci-attr-get (deref-vp parmdp)
+ +oci-dtype-param+
+ precision
+ +unsigned-int-null-pointer+
+ +oci-attr-precision+
+ (deref-vp errhp))
+ (oci-attr-get (deref-vp parmdp)
+ +oci-dtype-param+
+ scale
+ +unsigned-int-null-pointer+
+ +oci-attr-scale+
+ (deref-vp errhp))
+ (let ((*scale (uffi:deref-pointer scale :byte))
+ (*precision (uffi:deref-pointer precision :short)))
+
+ ;;(format t "scale=~d, precision=~d~%" *scale *precision)
+ (cond
+ ((or (and (minusp *scale) (zerop *precision))
+ (and (zerop *scale) (plusp *precision)))
+ (setf buffer (acquire-foreign-resource :int +n-buf-rows+)
+ sizeof 4 ;; sizeof(int)
+ dtype #.SQLT-INT))
+ (t
+ (setf buffer (acquire-foreign-resource :double +n-buf-rows+)
+ sizeof 8 ;; sizeof(double)
+ dtype #.SQLT-FLT)))))
+ ;; Default to SQL-STR
+ (t
+ (setf (uffi:deref-pointer colsize :unsigned-short) 0)
+ (setf dtype #.SQLT-STR)
+ (oci-attr-get (deref-vp parmdp)
+ +oci-dtype-param+
+ colsize
+ +unsigned-int-null-pointer+
+ +oci-attr-data-size+
+ (deref-vp errhp))
+ (let ((colsize-including-null (1+ (uffi:deref-pointer colsize :unsigned-short))))
+ (setf buffer (acquire-foreign-resource
+ :unsigned-char (* +n-buf-rows+ colsize-including-null)))
+ (setf sizeof colsize-including-null))))
+ (let ((retcodes (acquire-foreign-resource :unsigned-short +n-buf-rows+))
+ (indicators (acquire-foreign-resource :short +n-buf-rows+))
+ (colname-string ""))
+ (when field-names
+ (oci-attr-get (deref-vp parmdp)
+ +oci-dtype-param+
+ colname
+ colnamelen
+ +oci-attr-name+
+ (deref-vp errhp))
+ (setq colname-string (uffi:convert-from-foreign-string
+ (uffi:deref-pointer colname '(* :unsigned-char))
+ :length (uffi:deref-pointer colnamelen 'ub4)
+ :encoding (encoding database))))
+ (push (make-cd :name colname-string
+ :sizeof sizeof
+ :buffer buffer
+ :oci-data-type dtype
+ :retcodes retcodes
+ :indicators indicators
+ :result-type (cond
+ ((consp result-types)
+ (nth icolumn result-types))
+ ((null result-types)
+ :string)
+ (t
+ result-types)))
+ cds-as-reversed-list)
+ (oci-define-by-pos (deref-vp stmthp)
+ defnp
+ (deref-vp errhp)
+ (1+ icolumn) ; OCI 1-based indexing again
+ (foreign-resource-buffer buffer)
+ sizeof
+ dtype
+ (foreign-resource-buffer indicators)
+ +unsigned-short-null-pointer+
+ (foreign-resource-buffer retcodes)
+ +oci-default+))))))))