r8848: more usql to clsql renaming
[clsql.git] / sql / package.lisp
1 ;;;; -*- Mode: LISP; Syntax: ANSI-Common-Lisp; Base: 10 -*-
2 ;;;; ======================================================================
3 ;;;; File:    package.lisp
4 ;;;; Author:  Marcus Pearce <m.t.pearce@city.ac.uk>, Kevin Rosenberg
5 ;;;; Created: 30/03/2004
6 ;;;; Updated: <04/04/2004 12:21:50 marcusp>
7 ;;;; ======================================================================
8 ;;;;
9 ;;;; Description ==========================================================
10 ;;;; ======================================================================
11 ;;;;
12 ;;;; Package definitions for CLSQL-USQL. 
13 ;;;;
14 ;;;; ======================================================================
15
16 (in-package #:cl-user)
17
18 (eval-when (:compile-toplevel :load-toplevel :execute)
19
20 #+sbcl
21   (if (find-package 'sb-mop)
22       (pushnew :usql-sbcl-mop cl:*features*)
23       (pushnew :usql-sbcl-pcl cl:*features*))
24
25   #+cmu
26   (if (eq (symbol-package 'pcl:find-class)
27           (find-package 'common-lisp))
28       (pushnew :usql-cmucl-mop cl:*features*)
29       (pushnew :usql-cmucl-pcl cl:*features*)))
30
31
32 (eval-when (:compile-toplevel :load-toplevel :execute)
33   (defpackage #:clsql-usql-sys
34     (:nicknames #:usql-sys)
35     (:use #:common-lisp #:clsql-base-sys
36           #+usql-sbcl-mop #:sb-mop
37           #+usql-cmucl-mop #:mop
38           #+allegro #:mop
39           #+lispworks #:clos
40           #+scl #:clos
41           #+openmcl #:openmcl-mop)
42     
43     #+allegro
44     (:shadowing-import-from 
45      #:excl)
46    #+lispworks
47    (:shadowing-import-from 
48     #:clos)
49    #+usql-sbcl-mop 
50    (:shadowing-import-from 
51     #:sb-pcl
52     #:generic-function-lambda-list)
53    #+usql-sbcl-pcl
54    (:shadowing-import-from 
55     #:sb-pcl
56     #:name
57     #:class-direct-slots
58     #:class-of #:class-name #:class-slots #:find-class
59     #:slot-boundp
60     #:standard-class
61     #:slot-definition-name #:finalize-inheritance
62     #:standard-direct-slot-definition
63     #:standard-effective-slot-definition #:validate-superclass
64     #:direct-slot-definition-class #:compute-effective-slot-definition
65     #:effective-slot-definition-class
66     #:slot-value-using-class
67     #:class-prototype #:generic-function-method-class #:intern-eql-specializer
68     #:make-method-lambda #:generic-function-lambda-list
69     #:class-precedence-list #:slot-definition-type
70     #:class-direct-superclasses)
71    #+usql-cmucl-mop 
72    (:shadowing-import-from 
73     #:pcl
74     #:generic-function-lambda-list)
75    #+usql-cmucl-pcl
76    (:shadowing-import-from 
77     #:pcl
78     #:class-direct-slots
79     #:name
80     #:class-of  #:class-name #:class-slots #:find-class #:standard-class
81     #:slot-boundp
82     #:slot-definition-name #:finalize-inheritance
83     #:standard-direct-slot-definition #:standard-effective-slot-definition
84     #:validate-superclass #:direct-slot-definition-class
85     #:effective-slot-definition-class
86     #:compute-effective-slot-definition
87     #:slot-value-using-class
88     #:class-prototype #:generic-function-method-class #:intern-eql-specializer
89     #:make-method-lambda #:generic-function-lambda-list
90     #:class-precedence-list #:slot-definition-type
91     #:class-direct-superclasses)
92    #+scl
93    (:shadowing-import-from 
94     #:clos
95     #:class-prototype  ;; note: make-method-lambda is not fbound
96     )
97    
98    (:import-from 
99     #:clsql-base-sys
100     .
101     #1=(
102        ;; conditions 
103        :clsql-condition
104        :clsql-error
105        :clsql-simple-error
106        :clsql-warning
107        :clsql-simple-warning
108        :clsql-invalid-spec-error
109        :clsql-invalid-spec-error-connection-spec
110        :clsql-invalid-spec-error-database-type
111        :clsql-invalid-spec-error-template
112        :clsql-connect-error
113        :clsql-connect-error-database-type
114        :clsql-connect-error-connection-spec
115        :clsql-connect-error-errno
116        :clsql-connect-error-error
117        :clsql-sql-error
118        :clsql-sql-error-database
119        :clsql-sql-error-expression
120        :clsql-sql-error-errno
121        :clsql-sql-error-error
122        :clsql-database-warning
123        :clsql-database-warning-database
124        :clsql-database-warning-message
125        :clsql-exists-condition
126        :clsql-exists-condition-new-db
127        :clsql-exists-condition-old-db
128        :clsql-exists-warning
129        :clsql-exists-error
130        :clsql-closed-error
131        :clsql-closed-error-database
132        :clsql-type-error
133        :clsql-sql-syntax-error
134
135        ;; db-interface
136        :check-connection-spec
137        :database-initialize-database-type
138        :database-type-load-foreign
139        :database-name-from-spec
140        :database-create-sequence
141        :database-drop-sequence
142        :database-sequence-next
143        :database-set-sequence-position
144        :database-query-result-set
145        :database-dump-result-set
146        :database-store-next-row
147        :database-get-type-specifier
148        :database-list-tables
149        :database-list-views
150        :database-list-indexes
151        :database-list-sequences
152        :database-list-attributes
153        :database-attribute-type
154        :database-add-attribute
155        :database-type 
156        ;; initialize
157        :*loaded-database-types*
158        :reload-database-types
159        :*default-database-type*
160        :*initialized-database-types*
161        :initialize-database-type
162        ;; classes
163        :database
164        :closed-database
165        :database-name
166        :command-recording-stream
167        :result-recording-stream
168        :database-view-classes
169        :database-schema
170        :conn-pool
171        :print-object 
172        ;; utils
173        :sql-escape
174
175        ;; database.lisp -- Connection
176        #:*default-database-type*                  ; clsql-base xx
177        #:*default-database*               ; classes    xx
178        #:connect                                  ; database   xx
179        #:*connect-if-exists*              ; database   xx
180        #:connected-databases              ; database   xx
181        #:database                         ; database   xx
182        #:database-name                     ; database   xx
183        #:disconnect                       ; database   xx
184        #:reconnect                         ; database
185        #:find-database                     ; database   xx
186        #:status                            ; database   xx
187        #:with-database
188        #:with-default-database
189        
190        ;; basic-sql.lisp
191        #:query
192        #:execute-command
193        #:write-large-object
194        #:read-large-object
195        #:delete-large-object
196        #:do-query
197        #:map-query
198
199        ;; recording.lisp -- SQL I/O Recording 
200        #:record-sql-comand
201        #:record-sql-result
202        #:add-sql-stream                 ; recording  xx
203        #:delete-sql-stream                ; recording  xx
204        #:list-sql-streams                 ; recording  xx
205        #:sql-recording-p                  ; recording  xx
206        #:sql-stream                       ; recording  xx
207        #:start-sql-recording              ; recording  xx
208        #:stop-sql-recording               ; recording  xx
209        
210        ;; Transactions
211        #:with-transaction
212        #:commit-transaction
213        #:rollback-transaction
214        #:add-transaction-commit-hook
215        #:add-transaction-rollback-hook
216        #:commit                            ; transact   xx
217        #:rollback                         ; transact   xx
218        #:with-transaction                 ; transact   xx               .
219        #:start-transaction                 ; transact   xx
220        #:in-transaction-p                  ; transact   xx
221        #:database-start-transaction
222        #:database-abort-transaction
223        #:database-commit-transaction
224        #:transaction-level
225        #:transaction
226        ))
227    (:export
228     ;; "Private" exports for use by interface packages
229     :check-connection-spec
230     :database-initialize-database-type
231     :database-type-load-foreign
232     :database-name-from-spec
233     :database-connect
234    :database-query
235    :database-execute-command
236    :database-create-sequence
237    :database-drop-sequence
238    :database-sequence-next
239    :database-set-sequence-position
240    :database-query-result-set
241    :database-dump-result-set
242    :database-store-next-row
243    :database-get-type-specifier
244    :database-list-tables
245    :database-table-exists-p
246    :database-list-views
247    :database-view-exists-p
248    :database-list-indexes
249    :database-index-exists-p
250    :database-list-sequences
251    :database-sequence-exists-p
252    :database-list-attributes
253    :database-attribute-type
254
255    .
256    ;; Shared exports for re-export by USQL. 
257    ;; I = Implemented, D = Documented
258    ;;  name                                 file       ID
259    ;;====================================================
260    #2=(;;------------------------------------------------
261        ;; CommonSQL API 
262        ;;------------------------------------------------
263       ;;FDML 
264        :select                            ; objects    xx
265        :cache-table-queries               ; 
266        :*cache-table-queries-default*     ; 
267        :delete-records                    ; sql        xx
268        :insert-records                    ; sql        xx
269        :update-records                    ; sql        xx
270        :execute-command                   ; sql        xx
271        :query                             ; sql        xx
272        :print-query                       ; sql        xx
273        :do-query                          ; sql        xx
274        :map-query                         ; sql        xx
275        :loop                              ; loop-ext   x
276        ;;FDDL
277        :create-table                      ; table      xx
278        :drop-table                        ; table      xx
279        :list-tables                       ; table      xx
280        :table-exists-p                    ; table      xx 
281        :list-attributes                   ; table      xx
282        :attribute-type                    ; table      xx
283        :list-attribute-types              ; table      xx
284        :create-view                       ; table      xx
285        :drop-view                         ; table      xx
286        :create-index                      ; table      xx               
287        :drop-index                        ; table      xx               
288        ;;OODDL
289        :standard-db-object                ; objects    xx
290        :def-view-class                    ; objects    xx
291        :create-view-from-class            ; objects    xx
292        :drop-view-from-class              ; objects    xx
293        ;;OODML
294        :instance-refreshed                ;
295        :update-object-joins               ;
296        :*default-update-objects-max-len*  ; 
297        :update-slot-from-record           ; objects    xx
298        :update-instance-from-records      ; objects    xx
299        :update-records-from-instance      ; objects    xx
300        :update-record-from-slot           ; objects    xx
301        :update-record-from-slots          ; objects    xx
302        :list-classes                      ; objects    xx
303        :delete-instance-records           ; objects    xx
304        ;;Symbolic SQL Syntax 
305        :sql                               ; syntax     xx
306        :sql-expression                    ; syntax     xx
307        :sql-operation                     ; syntax     xx
308        :sql-operator                      ; syntax     xx       
309        :disable-sql-reader-syntax         ; syntax     xx
310        :enable-sql-reader-syntax          ; syntax     xx
311        :locally-disable-sql-reader-syntax ; syntax     xx
312        :locally-enable-sql-reader-syntax  ; syntax     xx
313        :restore-sql-reader-syntax-state   ; syntax     xx
314
315        ;;------------------------------------------------
316        ;; Miscellaneous Extensions
317        ;;------------------------------------------------
318        ;;Initialization
319        :*loaded-database-types*           ; clsql-base xx
320        :reload-database-types             ; clsql-base xx
321        :closed-database                   ; database   xx
322        :database-type                     ; database   x
323        :in-schema                         ; classes    x
324        ;;FDDL 
325        :list-views                        ; table      xx
326        :view-exists-p                     ; table      xx
327        :list-indexes                      ; table      xx
328        :index-exists-p                    ; table      xx
329        :create-sequence                   ; table      xx
330        :drop-sequence                     ; table      xx
331        :list-sequences                    ; table      xx
332        :sequence-exists-p                 ; table      xx
333        :sequence-next                     ; table      xx
334        :sequence-last                     ; table      xx
335        :set-sequence-position             ; table      xx
336        ;;OODDL
337        :view-table                        ; metaclass  x
338        :create-sequence-from-class        ; objects    x
339        :drop-sequence-from-class          ; objects    x        
340        ;;OODML
341        :add-to-relation                   ; objects    x
342        :remove-from-relation              ; objects    x
343        :read-sql-value                    ; objects    x
344        :database-output-sql-as-type       ; objects    x
345        :database-get-type-specifier       ; objects    x
346        :database-output-sql               ; sql/class  xx
347
348        ;;-----------------------------------------------
349        ;; Symbolic Sql Syntax 
350        ;;-----------------------------------------------
351        :sql-and-qualifier
352        :sql-escape
353        :sql-query
354        :sql-any
355        :sql-all
356        :sql-not
357        :sql-union
358        :sql-intersection
359        :sql-minus
360        :sql-group-by
361        :sql-having
362        :sql-null
363        :sql-not-null
364        :sql-exists
365        :sql-*
366        :sql-+
367        :sql-/
368        :sql-like
369        :sql-uplike
370        :sql-and
371        :sql-or
372        :sql-in
373        :sql-||
374        :sql-is
375        :sql-=
376        :sql-==
377        :sql-<
378        :sql->
379        :sql->=
380        :sql-<=
381        :sql-count
382        :sql-max
383        :sql-min
384        :sql-avg
385        :sql-sum
386        :sql-view-class
387        :sql_slot-value
388
389        . 
390        #1#
391        ))
392   (:documentation "This is the INTERNAL SQL-Interface package of USQL."))
393
394
395 ;; see http://thread.gmane.org/gmane.lisp.lispworks.general/681
396 #+lispworks
397 (setf *packages-for-warn-on-redefinition* 
398       (delete "SQL" *packages-for-warn-on-redefinition* :test 'string=))
399
400 (defpackage #:clsql-usql
401   (:nicknames #:usql #:sql)
402   (:use :common-lisp)
403   (:import-from :clsql-usql-sys . #2#)
404   (:export . #2#)
405   (:documentation "This is the SQL-Interface package of USQL."))
406
407   ;; This is from USQL's pcl-patch  
408   #+(or usql-sbcl-pcl usql-cmucl-pcl)
409   (progn
410     ;; Note that this will no longer required for cmucl as of version 19a. 
411     (in-package #+cmu :pcl #+sbcl :sb-pcl)
412     (defmacro pv-binding1 ((pv calls pv-table-symbol pv-parameters slot-vars) 
413                            &body body)
414       `(pv-env (,pv ,calls ,pv-table-symbol ,pv-parameters)
415         (let (,@(mapcar #'(lambda (slot-var p) `(,slot-var (get-slots-or-nil ,p)))
416                         slot-vars pv-parameters))
417           ,@(mapcar #'(lambda (slot-var) `(declare (ignorable ,slot-var))) slot-vars)
418           ,@body))))
419   
420   
421   #+sbcl
422   (if (find-package 'sb-mop)
423       (setq cl:*features* (delete :usql-sbcl-mop cl:*features*))
424       (setq cl:*features* (delete :usql-sbcl-pcl cl:*features*)))
425   
426   #+cmu
427   (if (find-package 'mop)
428       (setq cl:*features* (delete :usql-cmucl-mop cl:*features*))
429       (setq cl:*features* (delete :usql-cmucl-pcl cl:*features*)))
430   
431 );eval-when                                      
432
433