Changeset 64-bit,2.1.3 for 64-bit/src/odbc/odbc-functions.lisp
- Timestamp:
- 02/03/2008 08:14:49 PM (18 years ago)
- revision id:
- svn-v3-trunk1:1c22b0a8-4d0b-0410-a296-af6a2e6f35e3:plain-odbc%2Ftrunk:10
- File:
-
- 1 edited
-
64-bit/src/odbc/odbc-functions.lisp (modified) (10 diffs)
Legend:
- Unmodified
- Added
- Removed
-
64-bit/src/odbc/odbc-functions.lisp
r2.1.1 r2.1.3 47 47 ;; TODO: Why doesn't this use with-temporary-allocations? -dso 48 48 (defun handle-error (henv hdbc hstmt) 49 ( let49 (with-temporary-allocations 50 50 ((sql-state (alloc-chars 256)) 51 51 (error-message (alloc-chars #.$SQL_MAX_MESSAGE_LENGTH)) … … 63 63 (cffi:mem-ref error-code 'sql-integer)))) 64 64 65 66 ; test this: return a keyword for efficiency67 ;; rav,68 ;; problem: calling SQLError clears the error state69 ;#+ignore70 65 (defun sql-state (henv hdbc hstmt) 71 66 (with-temporary-allocations … … 83 78 84 79 (defun error-handling-fun (result-code henv hdbc hstmt) 85 ;; *** is this a bug in allegro or in my code??86 ;#+allegro (setf result-code (short-to-signed-short result-code))87 88 80 (case result-code 89 ( #.$SQL_SUCCESS(values result-code nil))81 ((#.$SQL_SUCCESS #.$SQL_NO_DATA_FOUND) (values result-code nil)) 90 82 ((#.$SQL_SUCCESS_WITH_INFO #.$SQL_ERROR) 91 83 (multiple-value-bind (error-message sql-state msg-length error-code) … … 102 94 :sql-state sql-state 103 95 :error-code error-code)))) 104 96 ; this can happen, using a wrong handle 105 97 (#.$SQL_INVALID_HANDLE 106 98 (values result-code 107 99 (make-condition 'sql-error :error-message "[ODBC error] Invalid handle"))) 100 ;; maybe this should raise an error immediately 108 101 (#.$SQL_STILL_EXECUTING 109 102 (values result-code 110 103 (make-condition 'sql-error :error-message"[ODBC error] Still executing"))) 111 (otherwise (values result-code nil)) 104 (#.$SQL_NEED_DATA 105 (values result-code nil)) 106 107 ;; rav: hope above are all result codes I know 108 (otherwise (error "unknown result of odbc execution: ~A" result-code)) 112 109 )) 113 110 … … 115 112 ;;; rav: 116 113 ;;; but the remaining macro is still large 117 #+ignore 118 (defmacro with-error-handling ((&key henv hdbc hstmt (print-info t))114 115 (defmacro with-error-handling ((&key henv hdbc hstmt) 119 116 odbc-call &body body) 120 (declare (ignore print-info))121 117 (let ((condition-var (gensym)) 122 118 (result-code (gensym))) … … 129 125 130 126 131 ;;; rav:132 ;; the original macro133 #-ignore134 (defmacro with-error-handling ((&key henv hdbc hstmt (print-info t))135 odbc-call &body body)136 (let ((result-code (gensym)))137 `(let ((,result-code ,odbc-call))138 ;; *** is this a bug in allegro or in my code??139 ;#+allegro (setf ,result-code (short-to-signed-short ,result-code))140 (case ,result-code141 (#.$SQL_SUCCESS142 (progn ,result-code ,@body))143 (#.$SQL_SUCCESS_WITH_INFO144 (when ,print-info145 (multiple-value-bind (error-message sql-state)146 (handle-error (or ,henv (cffi:null-pointer))147 (or ,hdbc (cffi:null-pointer))148 (or ,hstmt (cffi:null-pointer)))149 (warn "[ODBC info] ~a state: ~a"150 ,result-code error-message151 sql-state)))152 (progn ,result-code ,@body))153 (#.$SQL_INVALID_HANDLE154 (error "[ODBC error] Invalid handle"))155 (#.$SQL_STILL_EXECUTING156 (error "[ODBC error] Still executing"))157 (#.$SQL_ERROR158 (multiple-value-bind (error-message sql-state)159 (handle-error (or ,henv (cffi:null-pointer))160 (or ,hdbc (cffi:null-pointer))161 (or ,hstmt (cffi:null-pointer)))162 (error "[ODBC error] ~a; state: ~a" error-message sql-state)))163 (otherwise164 (progn ,result-code ,@body))165 ))))166 167 168 127 (defun %new-environment-handle () 169 128 (cffi:with-foreign-object (phenv 'sql-h-env) … … 196 155 (progn ,@body) 197 156 (%free-statement ,hstmt :drop)))) 198 199 ;;; rav: ignored200 #+ignore201 (defmacro %with-transaction ((henv hdbc) &body body)202 (let ((successp (gensym)))203 `(let ((,successp nil))204 (unwind-protect205 (prog1206 (progn ,@body)207 (setf ,successp t))208 (with-error-handling (:henv ,henv :hdbc ,hdbc)209 (SQLTransact210 ,henv ,hdbc211 (if ,successp $SQL_COMMIT $SQL_ROLLBACK)))))))212 157 213 158 ;; functional interface … … 595 540 (declare (type (integer 0) column-nr)) 596 541 (with-error-handling 597 (:hstmt hstmt :print-info nil)542 (:hstmt hstmt) 598 543 (SQLGetData hstmt (if (eq column-nr :bookmark) 0 (1+ column-nr)) 599 544 c-type data-ptr precision out-len-ptr))) … … 606 551 607 552 (defun %sql-param-data (hstmt param-ptr) 608 (with-error-handling (:hstmt hstmt :print-info t) ;; nil553 (with-error-handling (:hstmt hstmt) 609 554 (SQLParamData hstmt param-ptr))) 610 555 … … 612 557 (defun %sql-put-data (hstmt data-ptr size) 613 558 (with-error-handling 614 (:hstmt hstmt :print-info t) ;; nil559 (:hstmt hstmt ) 615 560 (SQLPutData hstmt data-ptr size))) 616 561
Note: See TracChangeset
for help on using the changeset viewer.
