Ignore:
Timestamp:
02/03/2008 08:14:49 PM (18 years ago)
Author:
raverkamp
revision id:
svn-v3-trunk1:1c22b0a8-4d0b-0410-a296-af6a2e6f35e3:plain-odbc%2Ftrunk:10
Message:

adding exec-sql, changes to documentation, more tests

File:
1 edited

Legend:

Unmodified
Added
Removed
  • unicode/src/odbc/odbc-functions.lisp

    r3 r5  
    4747;; TODO: Why doesn't this use with-temporary-allocations? -dso
    4848(defun handle-error (henv hdbc hstmt)
    49   (let
     49  (with-temporary-allocations
    5050      ((sql-state (alloc-chars 256))
    5151       (error-message (alloc-chars #.$SQL_MAX_MESSAGE_LENGTH))
     
    6363     (cffi:mem-ref error-code 'sql-integer))))
    6464
    65 
    66 ; test this: return a keyword for efficiency
    67 ;; rav,
    68 ;; problem: calling SQLError clears the error state
    69 ;#+ignore
    7065(defun sql-state (henv hdbc hstmt)
    7166  (with-temporary-allocations
     
    8378
    8479(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 
    8880  (case result-code
    89     (#.$SQL_SUCCESS (values result-code nil))
     81    ((#.$SQL_SUCCESS #.$SQL_NO_DATA_FOUND) (values result-code nil))
    9082    ((#.$SQL_SUCCESS_WITH_INFO #.$SQL_ERROR)
    9183      (multiple-value-bind (error-message sql-state msg-length error-code)
     
    10294                 :sql-state sql-state
    10395                 :error-code error-code))))
    104    
     96    ; this can happen, using  a wrong handle
    10597    (#.$SQL_INVALID_HANDLE
    10698      (values result-code
    10799              (make-condition 'sql-error :error-message "[ODBC error] Invalid handle")))
     100    ;; maybe this should raise an error immediately
    108101    (#.$SQL_STILL_EXECUTING
    109102      (values result-code
    110103              (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))
    112109    ))
    113110
     
    115112;;; rav:
    116113;;; 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)
    119116                                   odbc-call &body body)
    120   (declare (ignore print-info))
    121117  (let ((condition-var (gensym))
    122118        (result-code (gensym)))
     
    129125
    130126
    131 ;;; rav:
    132 ;; the original macro
    133 #-ignore
    134 (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-code
    141          (#.$SQL_SUCCESS
    142           (progn ,result-code ,@body))
    143          (#.$SQL_SUCCESS_WITH_INFO
    144           (when ,print-info
    145             (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-message
    151                     sql-state)))
    152           (progn ,result-code ,@body))
    153          (#.$SQL_INVALID_HANDLE
    154           (error "[ODBC error] Invalid handle"))
    155          (#.$SQL_STILL_EXECUTING
    156           (error "[ODBC error] Still executing"))
    157          (#.$SQL_ERROR
    158           (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          (otherwise
    164            (progn ,result-code ,@body))
    165          ))))
    166 
    167 
    168127(defun %new-environment-handle ()
    169128  (cffi:with-foreign-object (phenv 'sql-h-env)
     
    196155       (progn ,@body)
    197156       (%free-statement ,hstmt :drop))))
    198 
    199 ;;; rav: ignored
    200 #+ignore
    201 (defmacro %with-transaction ((henv hdbc) &body body)
    202   (let ((successp (gensym)))
    203     `(let ((,successp nil))
    204        (unwind-protect
    205          (prog1
    206            (progn ,@body)
    207            (setf ,successp t))
    208          (with-error-handling (:henv ,henv :hdbc ,hdbc)
    209            (SQLTransact
    210             ,henv ,hdbc
    211             (if ,successp $SQL_COMMIT $SQL_ROLLBACK)))))))
    212157
    213158;; functional interface
     
    595540  (declare (type (integer 0) column-nr))
    596541  (with-error-handling
    597       (:hstmt hstmt :print-info nil)
     542      (:hstmt hstmt)
    598543      (SQLGetData hstmt (if (eq column-nr :bookmark) 0 (1+ column-nr))
    599544                  c-type data-ptr precision out-len-ptr)))
     
    606551
    607552(defun %sql-param-data (hstmt param-ptr)
    608   (with-error-handling (:hstmt hstmt :print-info t) ;; nil
     553  (with-error-handling (:hstmt hstmt)
    609554      (SQLParamData hstmt param-ptr)))
    610555
     
    612557(defun %sql-put-data (hstmt data-ptr size)
    613558  (with-error-handling
    614       (:hstmt hstmt :print-info t) ;; nil
     559      (:hstmt hstmt )
    615560      (SQLPutData hstmt data-ptr size)))
    616561
Note: See TracChangeset for help on using the changeset viewer.