(defun handle-error (henv hdbc hstmt)
(let ((sql-state (allocate-foreign-string 256))
- (error-message (allocate-foreign-string $SQL_MAX_MESSAGE_LENGTH)))
+ (error-message (allocate-foreign-string #.$SQL_MAX_MESSAGE_LENGTH)))
(with-foreign-objects ((error-code :long)
(msg-length :short))
(SQLError henv hdbc hstmt sql-state
error-code error-message
- $SQL_MAX_MESSAGE_LENGTH msg-length)
- (values
- (prog1
- (convert-from-foreign-string error-message)
- (free-foreign-object error-message))
- (prog1
- (convert-from-foreign-string sql-state)
- (free-foreign-object error-message))
- (deref-pointer msg-length :short)
- (deref-pointer error-code :long)))))
+ #.$SQL_MAX_MESSAGE_LENGTH msg-length)
+ (let ((err (convert-from-foreign-string error-message))
+ (state (convert-from-foreign-string sql-state)))
+
+ (free-foreign-object error-message)
+ (free-foreign-object sql-state)
+ (values
+ err
+ state
+ (deref-pointer msg-length :short)
+ (deref-pointer error-code :long))))))
(defun sql-state (henv hdbc hstmt)
(let ((sql-state (allocate-foreign-string 256))
- (error-message (allocate-foreign-string $SQL_MAX_MESSAGE_LENGTH)))
+ (error-message (allocate-foreign-string #.$SQL_MAX_MESSAGE_LENGTH)))
(with-foreign-objects ((error-code :long)
(msg-length :short))
(SQLError henv hdbc hstmt sql-state error-code
- error-message $SQL_MAX_MESSAGE_LENGTH msg-length)
- (free-foreign-object error-message)
- (prog1
- (convert-from-foreign-string sql-state)
- (free-foreign-object sql-state)))
- ;; test this: return a keyword for efficiency
- ;;(%cstring-to-keyword sql-state)
- ))
+ error-message #.$SQL_MAX_MESSAGE_LENGTH msg-length)
+ (let ((state (convert-from-foreign-string sql-state)))
+ (free-foreign-object error-message)
+ (free-foreign-object sql-state)
+ state
+ ;; test this: return a keyword for efficiency
+ ;;(%cstring-to-keyword state)
+ ))))
(defmacro with-error-handling ((&key henv hdbc hstmt (print-info t))
odbc-call &body body)
(with-error-handling
(:hdbc hdbc)
(SQLGetInfo hdbc info-type info-ptr 1023 info-length-ptr)
- (prog1
- (convert-from-foreign-string info-ptr)
- (free-foreign-object info-ptr))))))
+ (let ((info (convert-from-foreign-string info-ptr)))
+ (free-foreign-object info-ptr)
+ info)))))
;; those returning a word
((#.$SQL_ACTIVE_CONNECTIONS
#.$SQL_ACTIVE_STATEMENTS
(let ((column-name-ptr (allocate-foreign-string 256)))
(with-foreign-objects ((column-name-length-ptr :short)
(column-sql-type-ptr :short)
- (column-precision-ptr :long)
+ (column-precision-ptr :unsigned-long)
(column-scale-ptr :short)
(column-nullable-p-ptr :short))
(with-error-handling (:hstmt hstmt)
(values
column-name
(deref-pointer column-sql-type-ptr :short)
- (deref-pointer column-precision-ptr :long)
+ (deref-pointer column-precision-ptr :unsigned-long)
(deref-pointer column-scale-ptr :short)
(deref-pointer column-nullable-p-ptr :short)))))))
;; parameter counting is 1-based
(defun %describe-parameter (hstmt parameter-nr)
(with-foreign-objects ((column-sql-type-ptr :short)
- (column-precision-ptr :long)
+ (column-precision-ptr :unsigned-long)
(column-scale-ptr :short)
(column-nullable-p-ptr :short))
(with-error-handling
column-nullable-p-ptr)
(values
(deref-pointer column-sql-type-ptr :short)
- (deref-pointer column-precision-ptr :long)
+ (deref-pointer column-precision-ptr :unsigned-long)
(deref-pointer column-scale-ptr :short)
(deref-pointer column-nullable-p-ptr :short)))))
(SQLColAttributes hstmt column-nr descriptor-type descriptor-info-ptr
256 descriptor-length-ptr
numeric-descriptor-ptr)
- (values
- (prog1
- (convert-from-foreign-string descriptor-info-ptr)
- (free-foreign-object descriptor-info-ptr))
- (deref-pointer numeric-descriptor-ptr :long))))))
+ (let ((desc (convert-from-foreign-string descriptor-info-ptr)))
+ (free-foreign-object descriptor-info-ptr)
+ (values
+ desc
+ (deref-pointer numeric-descriptor-ptr :long)))))))
(defun %prepare-describe-columns (hstmt table-qualifier table-owner
table-name column-name)
description-ptr
1024
description-length-ptr))))
- (unless (= res $SQL_NO_DATA_FOUND)
- (values
- (prog1
- (convert-from-foreign-string name-ptr)
- (free-foreign-object name-ptr))
- (prog1
- (convert-from-foreign-string description-ptr)
- (free-foreign-object description-ptr))))))))
+ (cond
+ ((= res $SQL_NO_DATA_FOUND)
+ (let ((name (convert-from-foreign-string name-ptr))
+ (desc (convert-from-foreign-string description-ptr)))
+ (free-foreign-object name-ptr)
+ (free-foreign-object description-ptr)
+ (values
+ name
+ desc)))
+ (t
+ (free-foreign-object name-ptr)
+ (free-foreign-object description-ptr)
+ nil))))))
+
+
(defun sql-to-c-type (sql-type)
(ecase sql-type
(hdbc sql-handle) ; HDBC hdbc
(hstmt sql-handle) ; HSTMT hstmt
(*szSqlState string-ptr) ; UCHAR FAR *szSqlState
- (*pfNativeError :pointer-void) ; SDWORD FAR *pfNativeError
+ (*pfNativeError (* :long)) ; SDWORD FAR *pfNativeError
(*szErrorMsg string-ptr) ; UCHAR FAR *szErrorMsg
(cbErrorMsgMax :short) ; SWORD cbErrorMsgMax
- (*pcbErrorMsg :pointer-void) ; SWORD FAR *pcbErrorMsg
+ (*pcbErrorMsg (* :short)) ; SWORD FAR *pcbErrorMsg
)
:module "odbc"
:returning :short) ; RETCODE_SQL_API
(def-function "SQLNumResultCols"
((hstmt sql-handle) ; HSTMT hstmt
- (*pccol :pointer-void) ; SWORD FAR *pccol
+ (*pccol (* :short)) ; SWORD FAR *pccol
)
:module "odbc"
:returning :short) ; RETCODE_SQL_API
(def-function "SQLRowCount"
((hstmt sql-handle) ; HSTMT hstmt
- (*pcrow :pointer-void) ; SDWORD FAR *pcrow
+ (*pcrow (* :long)) ; SDWORD FAR *pcrow
)
:module "odbc"
:returning :short) ; RETCODE_SQL_API
(icol :short) ; UWORD icol
(*szColName string-ptr) ; UCHAR FAR *szColName
(cbColNameMax :short) ; SWORD cbColNameMax
- (*pcbColName :pointer-void) ; SWORD FAR *pcbColName
- (*pfSqlType :pointer-void) ; SWORD FAR *pfSqlType
- (*pcbColDef :pointer-void) ; UDWORD FAR *pcbColDef
- (*pibScale :pointer-void) ; SWORD FAR *pibScale
- (*pfNullable :pointer-void) ; SWORD FAR *pfNullable
+ (*pcbColName (* :short)) ; SWORD FAR *pcbColName
+ (*pfSqlType (* :short)) ; SWORD FAR *pfSqlType
+ (*pcbColDef (* :unsigned-long)) ; UDWORD FAR *pcbColDef
+ (*pibScale (* :short)) ; SWORD FAR *pibScale
+ (*pfNullable (* :short)) ; SWORD FAR *pfNullable
)
:module "odbc"
:returning :short) ; RETCODE_SQL_API
((hstmt sql-handle) ; HSTMT hstmt
(icol :short) ; UWORD icol
(fDescType :short) ; UWORD fDescType
- (rgbDesc :cstring) ; PTR rgbDesc
+ (rgbDesc string-ptr) ; PTR rgbDesc
(cbDescMax :short) ; SWORD cbDescMax
- (*pcbDesc :cstring) ; SWORD FAR *pcbDesc
- (*pfDesc :pointer-void) ; SDWORD FAR *pfDesc
+ (*pcbDesc (* :short)) ; SWORD FAR *pcbDesc
+ (*pfDesc (* :long)) ; SDWORD FAR *pfDesc
)
:module "odbc"
:returning :short) ; RETCODE_SQL_API
(fCType :short) ; SWORD fCType
(rgbValue :pointer-void) ; PTR rgbValue
(cbValueMax :long) ; SDWORD cbValueMax
- (*pcbValue :pointer-void) ; SDWORD FAR *pcbValue
+ (*pcbValue (* :long)) ; SDWORD FAR *pcbValue
)
:module "odbc"
:returning :short) ; RETCODE_SQL_API
(def-function "SQLDescribeParam"
((hstmt sql-handle) ; HSTMT hstmt
(ipar :short) ; UWORD ipar
- (*pfSqlType :pointer-void) ; SWORD FAR *pfSqlType
- (*pcbColDef :pointer-void) ; UDWORD FAR *pcbColDef
- (*pibScale :pointer-void) ; SWORD FAR *pibScale
- (*pfNullable :pointer-void) ; SWORD FAR *pfNullable
+ (*pfSqlType (* :short)) ; SWORD FAR *pfSqlType
+ (*pcbColDef (* :unsigned-long)) ; UDWORD FAR *pcbColDef
+ (*pibScale (* :short)) ; SWORD FAR *pibScale
+ (*pfNullable (* :short)) ; SWORD FAR *pfNullable
)
:module "odbc"
:returning :short) ; RETCODE_SQL_API