Changeset error-handling,5


Ignore:
Timestamp:
01/18/2008 12:58:17 AM (18 years ago)
Author:
David Owen <dsowen@…>
branch-nick:
error-handling
revision id:
dsowen@fugue88.ws-20080118005817-3jz82tlxi9e09uk4
Message:
  • Made it very easy to define new ODBC errors.
  • Added several ODBC errors.
Location:
error-handling
Files:
2 added
3 edited

Legend:

Unmodified
Added
Removed
  • error-handling/plain-odbc.asd

    r1 r5  
    1111                         (:file "cffi-support")
    1212                         (:file "odbc-ff-interface")
     13                         (:file "error-base")
     14                         (:file "error-defs")
    1315                         (:file "odbc-functions")
    1416                         (:file "parameter")
  • error-handling/src/odbc/odbc-functions.lisp

    r4 r5  
    111111
    112112
    113 (defun print-odbc-error (condition stream)
    114   (with-slots (message code) condition
    115     (format stream "[ODBC error] ~a; state: ~a" message code)))
    116 
    117 (define-condition odbc-error (error)
    118   ((message :initarg :message :reader error-message)
    119    (code :initarg :code :reader error-code))
    120   (:report print-odbc-error))
    121 
    122 (define-condition odbc-not-null-violation (odbc-error) ())
    123 
    124 (define-condition odbc-foreign-key-error (odbc-error) ())
    125 
    126 (define-condition odbc-unique-violation (odbc-error) ())
    127 
    128 (define-condition odbc-check-violation (odbc-error) ())
    129 
    130 (define-condition odbc-insufficient-privilege (odbc-error) ())
    131 
    132 (define-condition odbc-undefined-object (odbc-error) ())
    133 
    134 (defun read-and-throw-error (henv hdbc hstmt)
    135   (multiple-value-bind (error-message sql-state)
    136       (handle-error (or henv (cffi:null-pointer))
    137                     (or hdbc (cffi:null-pointer))
    138                     (or hstmt (cffi:null-pointer)))
    139     (let ((type (cdr (assoc sql-state '(("23502" . odbc-not-null-violation)
    140                                         ("23503" . odbc-foreign-key-error)
    141                                         ("23505" . odbc-unique-violation)
    142                                         ("23514" . odbc-check-violation)
    143                                         ("42501" . odbc-insufficient-privilege)
    144                                         ("42704" . odbc-undefined-object))
    145                             :test #'string=))))
    146       (error (if type type 'odbc-error)
    147              :message error-message
    148              :code sql-state))))
    149113
    150114;;; rav:
  • error-handling/src/odbc/plain-odbc-package.lisp

    r4 r5  
    1212   "COMMON-LISP" #+mcl "CCL" #+cormanlisp "WIN32" "CFFI")
    1313  (:export
     14   "PRINT-ODBC-ERROR"
    1415   "ODBC-ERROR"
    1516   "ERROR-MESSAGE"
    1617   "ERROR-CODE"
    17    "ODBC-NOT-NULL-VIOLATION"
    18    "ODBC-FOREIGN-KEY-VIOLATION"
    19    "ODBC-UNIQUE-VIOLATION"
    20    "ODBC-CHECK-VIOLATION"
    21    "ODBC-INSUFFICIENT-PRIVILEGE"
    22    "ODBC-UNDEFINED-OBJECT"
    2318
    2419   "EXEC-QUERY"
Note: See TracChangeset for help on using the changeset viewer.