X-Git-Url: http://git.kpe.io/?a=blobdiff_plain;f=db-oracle%2Foracle-sql.lisp;h=dc2c98bd51c7836ec6bc812e7858571851977079;hb=a33175f8396cc948094ba4a2ea3a54fec3e11066;hp=d59665de16c8815b5fc572004b4c6827ac62e75c;hpb=d27220b2eb7a769fe8ec1f8b674c9422dde014c9;p=clsql.git diff --git a/db-oracle/oracle-sql.lisp b/db-oracle/oracle-sql.lisp index d59665d..dc2c98b 100644 --- a/db-oracle/oracle-sql.lisp +++ b/db-oracle/oracle-sql.lisp @@ -64,7 +64,7 @@ likely that we'll have to worry about the CMUCL limit.")) ;;; database. Thus, there's no obstacle to having any number of DB ;;; objects referring to the same database. -(uffi:def-type pointer-pointer-void '(* :pointer-void)) +(uffi:def-type pointer-pointer-void (* :pointer-void)) (defclass oracle-database (database) ; was struct db ((envhp @@ -126,36 +126,37 @@ the length of that format.") ;;; NULLS-OK are as in the OERR function. (defun handle-oci-error (&key database nulls-ok) - (cond (database - (with-slots (errhp) database - (uffi:with-foreign-objects ((errbuf '(:array :unsigned-char - #.+errbuf-len+)) - (errcode :long)) - ;; ensure errbuf empty string - (setf (uffi:deref-array errbuf '(:array :unsigned-char) 0) - (uffi:ensure-char-storable (code-char 0))) - (setf (uffi:deref-pointer errcode :long) 0) - - (uffi:with-cstring (sqlstate nil) - (oci-error-get (deref-vp errhp) 1 - sqlstate - errcode - (uffi:char-array-to-pointer errbuf) - +errbuf-len+ +oci-htype-error+)) - (let ((subcode (uffi:deref-pointer errcode :long))) - (unless (and nulls-ok (= subcode +null-value-returned+)) - (error 'sql-database-error - :database database - :error-id subcode - :message (uffi:convert-from-foreign-string errbuf))))))) - (nulls-ok - (error 'sql-database-error - :database database - :message "can't handle NULLS-OK without ERRHP")) - (t - (error 'sql-database-error - :database database - :message "OCI Error (and no ERRHP available to find subcode)")))) + (cond + (database + (with-slots (errhp) database + (uffi:with-foreign-object (errcode :long) + (let ((errbuf (uffi:allocate-foreign-string #.+errbuf-len+))) + ;; ensure errbuf empty string + (setf (uffi:deref-array errbuf '(:array :unsigned-char) 0) + (uffi:ensure-char-storable (code-char 0))) + (setf (uffi:deref-pointer errcode :long) 0) + + (uffi:with-cstring (sqlstate nil) + (oci-error-get (deref-vp errhp) 1 + sqlstate + errcode + (uffi:char-array-to-pointer errbuf) + +errbuf-len+ +oci-htype-error+)) + (let ((subcode (uffi:deref-pointer errcode :long))) + (unless (and nulls-ok (= subcode +null-value-returned+)) + (error 'sql-database-error + :database database + :error-id subcode + :message (uffi:convert-from-foreign-string errbuf)))) + (uffi:free-foreign-object errbuf))))) + (nulls-ok + (error 'sql-database-error + :database database + :message "can't handle NULLS-OK without ERRHP")) + (t + (error 'sql-database-error + :database database + :message "OCI Error (and no ERRHP available to find subcode)")))) ;;; Require an OCI success code. ;;; @@ -338,9 +339,9 @@ the length of that format.") ;; STREAM which has no more data, and QC is not a STREAM, we signal ;; DBI-ERROR instead. -(uffi:def-type short-array '(:array :short)) -(uffi:def-type int-pointer '(* :int)) -(uffi:def-type double-pointer '(* :double)) +(uffi:def-type short-array (:array :short)) +(uffi:def-type int-pointer (* :int)) +(uffi:def-type double-pointer (* :double)) ;;; the result of a database query: a cursor through a table (defstruct (oracle-result-set (:print-function print-query-cursor)