Skip to content

Commit 8c6c643

Browse files
r9403: Rework conditions to be CommonSQL backward compatible
1 parent 5be3156 commit 8c6c643

25 files changed

Lines changed: 456 additions & 531 deletions

ChangeLog

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,11 @@
77
19 May 2004 Kevin Rosenberg (kevin@rosenberg.net)
88
* sql/package.lisp: Export initialize-database-type and
99
*initialize-database-types* from CLSQL package.
10-
10+
* sql/conditions.lisp: Add new CommonSQL compatible conditions,
11+
remove old CLSQL conditions.
12+
* sql/loop-extensions.lisp: Make errors of type sql-user-error
13+
* */*.lisp: Convert to from old to new conditions
14+
1115
18 May 2004 Kevin Rosenberg (kevin@rosenberg.net)
1216
* sql/table.lisp: Add PURGE to drop command for oracle 10g backend.
1317
To handle this difference, will need to add a new database-drop-table

TODO

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ TESTS TO ADD
1111

1212
COMMONSQL INCOMPATIBILITY
1313

14-
o Condition names/accessors
1514
o userenv (Oracle specific but deprecated in Oracle 9)
1615

1716
VARIANCES FROM COMMONSQL

db-aodbc/aodbc-sql.lisp

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -59,11 +59,10 @@
5959
(clsql-error (e)
6060
(error e))
6161
(error () ;; Init or Connect failed
62-
(error 'clsql-connect-error
62+
(error 'sql-connection-error
6363
:database-type database-type
6464
:connection-spec connection-spec
65-
:errno nil
66-
:error "Connection failed")))))
65+
:message "Connection failed")))))
6766

6867
(defmethod database-disconnect ((database aodbc-database))
6968
#+aodbc-v2
@@ -80,11 +79,10 @@
8079
(clsql-error (e)
8180
(error e))
8281
(error ()
83-
(error 'clsql-sql-error
82+
(error 'sql-database-data-error
8483
:database database
8584
:expression query-expression
86-
:errno nil
87-
:error "Query failed"))))
85+
:message "Query failed."))))
8886

8987
(defmethod database-execute-command (sql-expression
9088
(database aodbc-database))
@@ -94,11 +92,10 @@
9492
(clsql-error (e)
9593
(error e))
9694
(error ()
97-
(error 'clsql-sql-error
95+
(error 'sql-database-data-error
9896
:database database
9997
:expression sql-expression
100-
:errno nil
101-
:error "Execute command failed"))))
98+
:error "Execute command failed."))))
10299

103100
(defstruct aodbc-result-set
104101
(query nil)
@@ -127,11 +124,10 @@
127124
(clsql-error (e)
128125
(error e))
129126
(error ()
130-
(error 'clsql-sql-error
127+
(error 'sql-database-data-error
131128
:database database
132129
:expression query-expression
133-
:errno nil
134-
:error "Query result set failed"))))
130+
:error "Query result set failed."))))
135131

136132
(defmethod database-dump-result-set (result-set (database aodbc-database))
137133
#+aodbc-v2

db-mysql/mysql-sql.lisp

Lines changed: 30 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -99,11 +99,11 @@
9999
(let ((mysql-ptr (mysql-init (uffi:make-null-pointer 'mysql-mysql)))
100100
(socket nil))
101101
(if (uffi:null-pointer-p mysql-ptr)
102-
(error 'clsql-connect-error
102+
(error 'sql-connection-error
103103
:database-type database-type
104104
:connection-spec connection-spec
105-
:errno (mysql-errno mysql-ptr)
106-
:error (mysql-error-string mysql-ptr))
105+
:error-id (mysql-errno mysql-ptr)
106+
:message (mysql-error-string mysql-ptr))
107107
(uffi:with-cstrings ((host-native host)
108108
(user-native user)
109109
(password-native password)
@@ -117,11 +117,11 @@
117117
db-native 0 socket-native 0))
118118
(progn
119119
(setq error-occurred t)
120-
(error 'clsql-connect-error
120+
(error 'sql-connect-error
121121
:database-type database-type
122122
:connection-spec connection-spec
123-
:errno (mysql-errno mysql-ptr)
124-
:error (mysql-error-string mysql-ptr)))
123+
:error-id (mysql-errno mysql-ptr)
124+
:message (mysql-error-string mysql-ptr)))
125125
(make-instance 'mysql-database
126126
:name (database-name-from-spec connection-spec
127127
database-type)
@@ -173,16 +173,16 @@
173173
(when field-names
174174
(result-field-names num-fields res-ptr))))
175175
(mysql-free-result res-ptr))
176-
(error 'clsql-sql-error
176+
(error 'sql-database-data-error
177177
:database database
178178
:expression query-expression
179-
:errno (mysql-errno mysql-ptr)
180-
:error (mysql-error-string mysql-ptr))))
181-
(error 'clsql-sql-error
179+
:error-id (mysql-errno mysql-ptr)
180+
:message (mysql-error-string mysql-ptr))))
181+
(error 'sql-database-data-error
182182
:database database
183183
:expression query-expression
184-
:errno (mysql-errno mysql-ptr)
185-
:error (mysql-error-string mysql-ptr))))))
184+
:error-id (mysql-errno mysql-ptr)
185+
:message (mysql-error-string mysql-ptr))))))
186186

187187
(defmethod database-execute-command (sql-expression (database mysql-database))
188188
(uffi:with-cstring (sql-native sql-expression)
@@ -191,11 +191,11 @@
191191
(if (zerop (mysql-real-query mysql-ptr sql-native
192192
(length sql-expression)))
193193
t
194-
(error 'clsql-sql-error
194+
(error 'sql-database-data-error
195195
:database database
196196
:expression sql-expression
197-
:errno (mysql-errno mysql-ptr)
198-
:error (mysql-error-string mysql-ptr))))))
197+
:error-id (mysql-errno mysql-ptr)
198+
:message (mysql-error-string mysql-ptr))))))
199199

200200

201201
(defstruct mysql-result-set
@@ -233,16 +233,16 @@
233233
(mysql-num-rows res-ptr))
234234
(values result-set
235235
num-fields)))
236-
(error 'clsql-sql-error
236+
(error 'sql-database-data-error
237237
:database database
238238
:expression query-expression
239-
:errno (mysql-errno mysql-ptr)
240-
:error (mysql-error-string mysql-ptr))))
241-
(error 'clsql-sql-error
239+
:error-id (mysql-errno mysql-ptr)
240+
:message (mysql-error-string mysql-ptr))))
241+
(error 'sql-database-data-error
242242
:database database
243243
:expression query-expression
244-
:errno (mysql-errno mysql-ptr)
245-
:error (mysql-error-string mysql-ptr))))))
244+
:error-id (mysql-errno mysql-ptr)
245+
:message (mysql-error-string mysql-ptr))))))
246246

247247
(defmethod database-dump-result-set (result-set (database mysql-database))
248248
(mysql-free-result (mysql-result-set-res-ptr result-set))
@@ -398,12 +398,11 @@
398398
name)
399399
(if (or (not (eql 0 status))
400400
(and (search "failed" output) (search "error" output)))
401-
(error 'clsql-access-error
402-
:connection-spec connection-spec
403-
:database-type type
404-
:error
405-
(format nil "database-create failed: ~A" output))
406-
t))))
401+
(error 'sql-database-error
402+
:message
403+
(format nil "mysql database creation failed with connection-spec ~A."
404+
connection-spec))
405+
t))))
407406

408407
(defmethod database-destroy (connection-spec (type (eql :mysql)))
409408
(destructuring-bind (host name user password) connection-spec
@@ -414,11 +413,10 @@
414413
name)
415414
(if (or (not (eql 0 status))
416415
(and (search "failed" output) (search "error" output)))
417-
(error 'clsql-access-error
418-
:connection-spec connection-spec
419-
:database-type type
420-
:error
421-
(format nil "database-destroy failed: ~A" output))
416+
(error 'sql-database-error
417+
:message
418+
(format nil "mysql database deletion failed with connection-spec ~A."
419+
connection-spec))
422420
t))))
423421

424422
(defmethod database-probe (connection-spec (type (eql :mysql)))

db-odbc/odbc-api.lisp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -113,20 +113,20 @@ as possible second argument) to the desired representation of date/time/timestam
113113
(progn ,result-code ,@body))
114114
(#.$SQL_INVALID_HANDLE
115115
(error
116-
'clsql-sys:clsql-odbc-error
117-
:odbc-message "Invalid handle"))
116+
'clsql-sys:sql-database-error
117+
:message "ODBC: Invalid handle"))
118118
(#.$SQL_STILL_EXECUTING
119119
(error
120-
'clsql-sys:clsql-odbc-error
121-
:odbc-message "Still executing"))
120+
'clsql-sys:sql-temporary-error
121+
:message "ODBC: Still executing"))
122122
(#.$SQL_ERROR
123123
(multiple-value-bind (error-message sql-state)
124124
(handle-error (or ,henv +null-handle-ptr+)
125125
(or ,hdbc +null-handle-ptr+)
126126
(or ,hstmt +null-handle-ptr+))
127127
(error
128-
'clsql-sys:clsql-odbc-error
129-
:odbc-message error-message
128+
'clsql-sys:sql-database-error
129+
:message error-message
130130
:sql-state sql-state)))
131131
(#.$SQL_NO_DATA_FOUND
132132
(progn ,result-code ,@body))
@@ -138,9 +138,9 @@ as possible second argument) to the desired representation of date/time/timestam
138138
(or ,hdbc +null-handle-ptr+)
139139
(or ,hstmt +null-handle-ptr+))
140140
(error
141-
'clsql-sys:clsql-odbc-error
142-
:odbc-message error-message
143-
:sql-state sql-state))
141+
'clsql-sys:sql-database-error
142+
:message error-message
143+
:secondary-error-id sql-state))
144144
#+ignore
145145
(progn ,result-code ,@body))))))
146146

db-odbc/odbc-dbi.lisp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,8 @@ the query against." ))
176176
((zerop count)
177177
(close-query query)
178178
(when eof-errorp
179-
(error 'clsql-odbc-error :odbc-message "Ran out of data in fetch-row"))
179+
(error 'sql-database-data-error
180+
:message "ODBC: Ran out of data in fetch-row"))
180181
eof-value)
181182
(t
182183
(car row)))))

db-odbc/odbc-sql.lisp

Lines changed: 18 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -50,15 +50,14 @@
5050
:data-source-name dsn))))
5151
(store-type-of-connected-database db)
5252
db)
53-
(clsql-error (e)
54-
(error e))
55-
#+ignore
56-
(error () ;; Init or Connect failed
57-
(error 'clsql-connect-error
58-
:database-type database-type
59-
:connection-spec connection-spec
60-
:errno nil
61-
:error "Connection failed")))))
53+
#+ignore
54+
(sql-condition (e)
55+
(error e))
56+
(error () ;; Init or Connect failed
57+
(error 'sql-connection-error
58+
:database-type database-type
59+
:connection-spec connection-spec
60+
:message "Connection failed")))))
6261

6362
(defmethod database-underlying-type ((database odbc-database))
6463
(database-odbc-db-type database))
@@ -92,29 +91,27 @@
9291
(odbc-dbi:sql query-expression :db (database-odbc-conn database)
9392
:result-types result-types
9493
:column-names field-names)
95-
(clsql-error (e)
96-
(error e))
9794
#+ignore
95+
(sql-error (e)
96+
(error e))
9897
(error ()
99-
(error 'clsql-sql-error
98+
(error 'sql-database-data-error
10099
:database database
101100
:expression query-expression
102-
:errno nil
103-
:error "Query failed"))))
101+
:message "Query failed"))))
104102

105103
(defmethod database-execute-command (sql-expression
106104
(database odbc-database))
107105
(handler-case
108106
(odbc-dbi:sql sql-expression :db (database-odbc-conn database))
109-
(clsql-error (e)
110-
(error e))
111107
#+ignore
108+
(sql-error (e)
109+
(error e))
112110
(error ()
113-
(error 'clsql-sql-error
111+
(error 'sql-database-data-error
114112
:database database
115113
:expression sql-expression
116-
:errno nil
117-
:error "Execute command failed"))))
114+
:message "Execute command failed"))))
118115

119116
(defstruct odbc-result-set
120117
(query nil)
@@ -138,13 +135,11 @@
138135
(length column-names)
139136
nil ;; not able to return number of rows with odbc
140137
))
141-
#+ignore
142138
(error ()
143-
(error 'clsql-sql-error
139+
(error 'sql-database-data-error
144140
:database database
145141
:expression query-expression
146-
:errno nil
147-
:error "Query result set failed"))))
142+
:message "Query result set failed"))))
148143

149144
(defmethod database-dump-result-set (result-set (database odbc-database))
150145
(odbc-dbi:close-query (odbc-result-set-query result-set))

db-oracle/oracle-sql.lisp

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -140,17 +140,16 @@ the length of that format.")
140140
errcode errbuf +errbuf-len+ +oci-htype-error+)
141141
(let ((subcode (uffi:deref-pointer errcode :long)))
142142
(unless (and nulls-ok (= subcode +null-value-returned+))
143-
(error 'clsql-sql-error
143+
(error 'sql-database-error
144144
:database database
145-
:errno subcode
146-
:expression nil
147-
:error (uffi:convert-from-foreign-string errbuf)))))))
145+
:error-id subcode
146+
:message (uffi:convert-from-foreign-string errbuf)))))))
148147
(nulls-ok
149-
(error 'clsql-sql-error
148+
(error 'sql-database-error
150149
:database database
151150
:message "can't handle NULLS-OK without ERRHP"))
152151
(t
153-
(error 'clsql-sql-error
152+
(error 'sql-database-error
154153
:database database
155154
:message "OCI Error (and no ERRHP available to find subcode)"))))
156155

@@ -309,7 +308,7 @@ the length of that format.")
309308
(format nil
310309
"select user_tab_columns,column_name from user_tab_columns where user_tab_columns.table_name='~A'"
311310
table)
312-
database nil nil))))
311+
database nil nil)))
313312

314313

315314
;; Return one row of the table referred to by QC, represented as a

0 commit comments

Comments
 (0)