r8826: allegro improvement
[clsql.git] / usql / 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        
197        ;; recording.lisp -- SQL I/O Recording 
198        #:record-sql-comand
199        #:record-sql-result
200        #:add-sql-stream                 ; recording  xx
201        #:delete-sql-stream                ; recording  xx
202        #:list-sql-streams                 ; recording  xx
203        #:sql-recording-p                  ; recording  xx
204        #:sql-stream                       ; recording  xx
205        #:start-sql-recording              ; recording  xx
206        #:stop-sql-recording               ; recording  xx
207        
208        ;; Transactions
209        #:with-transaction
210        #:commit-transaction
211        #:rollback-transaction
212        #:add-transaction-commit-hook
213        #:add-transaction-rollback-hook
214        #:commit                            ; transact   xx
215        #:rollback                         ; transact   xx
216        #:with-transaction                 ; transact   xx               .
217        #:start-transaction                 ; transact   xx
218        #:in-transaction-p                  ; transact   xx
219        #:database-start-transaction
220        #:database-abort-transaction
221        #:database-commit-transaction
222        #:transaction-level
223        #:transaction
224        ))
225    (:export
226     ;; "Private" exports for use by interface packages
227     :check-connection-spec
228     :database-initialize-database-type
229     :database-type-load-foreign
230     :database-name-from-spec
231     :database-connect
232    :database-query
233    :database-execute-command
234    :database-create-sequence
235    :database-drop-sequence
236    :database-sequence-next
237    :database-set-sequence-position
238    :database-query-result-set
239    :database-dump-result-set
240    :database-store-next-row
241    :database-get-type-specifier
242    :database-list-tables
243    :database-table-exists-p
244    :database-list-views
245    :database-view-exists-p
246    :database-list-indexes
247    :database-index-exists-p
248    :database-list-sequences
249    :database-sequence-exists-p
250    :database-list-attributes
251    :database-attribute-type
252
253    .
254    ;; Shared exports for re-export by USQL. 
255    ;; I = Implemented, D = Documented
256    ;;  name                                 file       ID
257    ;;====================================================
258    #2=(;;------------------------------------------------
259        ;; CommonSQL API 
260        ;;------------------------------------------------
261       ;;FDML 
262        :select                            ; objects    xx
263        :cache-table-queries               ; 
264        :*cache-table-queries-default*     ; 
265        :delete-records                    ; sql        xx
266        :insert-records                    ; sql        xx
267        :update-records                    ; sql        xx
268        :execute-command                   ; sql        xx
269        :query                             ; sql        xx
270        :print-query                       ; sql        xx
271        :do-query                          ; sql        xx
272        :map-query                         ; sql        xx
273        :loop                              ; loop-ext   x
274        ;;FDDL
275        :create-table                      ; table      xx
276        :drop-table                        ; table      xx
277        :list-tables                       ; table      xx
278        :table-exists-p                    ; table      xx 
279        :list-attributes                   ; table      xx
280        :attribute-type                    ; table      xx
281        :list-attribute-types              ; table      xx
282        :create-view                       ; table      xx
283        :drop-view                         ; table      xx
284        :create-index                      ; table      xx               
285        :drop-index                        ; table      xx               
286        ;;OODDL
287        :standard-db-object                ; objects    xx
288        :def-view-class                    ; objects    xx
289        :create-view-from-class            ; objects    xx
290        :drop-view-from-class              ; objects    xx
291        ;;OODML
292        :instance-refreshed                ;
293        :update-object-joins               ;
294        :*default-update-objects-max-len*  ; 
295        :update-slot-from-record           ; objects    xx
296        :update-instance-from-records      ; objects    xx
297        :update-records-from-instance      ; objects    xx
298        :update-record-from-slot           ; objects    xx
299        :update-record-from-slots          ; objects    xx
300        :list-classes                      ; objects    xx
301        :delete-instance-records           ; objects    xx
302        ;;Symbolic SQL Syntax 
303        :sql                               ; syntax     xx
304        :sql-expression                    ; syntax     xx
305        :sql-operation                     ; syntax     xx
306        :sql-operator                      ; syntax     xx       
307        :disable-sql-reader-syntax         ; syntax     xx
308        :enable-sql-reader-syntax          ; syntax     xx
309        :locally-disable-sql-reader-syntax ; syntax     xx
310        :locally-enable-sql-reader-syntax  ; syntax     xx
311        :restore-sql-reader-syntax-state   ; syntax     xx
312
313        ;;------------------------------------------------
314        ;; Miscellaneous Extensions
315        ;;------------------------------------------------
316        ;;Initialization
317        :*loaded-database-types*           ; clsql-base xx
318        :reload-database-types             ; clsql-base xx
319        :closed-database                   ; database   xx
320        :database-type                     ; database   x
321        :in-schema                         ; classes    x
322        ;;FDDL 
323        :list-views                        ; table      xx
324        :view-exists-p                     ; table      xx
325        :list-indexes                      ; table      xx
326        :index-exists-p                    ; table      xx
327        :create-sequence                   ; table      xx
328        :drop-sequence                     ; table      xx
329        :list-sequences                    ; table      xx
330        :sequence-exists-p                 ; table      xx
331        :sequence-next                     ; table      xx
332        :sequence-last                     ; table      xx
333        :set-sequence-position             ; table      xx
334        ;;OODDL
335        :view-table                        ; metaclass  x
336        :create-sequence-from-class        ; objects    x
337        :drop-sequence-from-class          ; objects    x        
338        ;;OODML
339        :add-to-relation                   ; objects    x
340        :remove-from-relation              ; objects    x
341        :read-sql-value                    ; objects    x
342        :database-output-sql-as-type       ; objects    x
343        :database-get-type-specifier       ; objects    x
344        :database-output-sql               ; sql/class  xx
345
346        ;;-----------------------------------------------
347        ;; Symbolic Sql Syntax 
348        ;;-----------------------------------------------
349        :sql-and-qualifier
350        :sql-escape
351        :sql-query
352        :sql-any
353        :sql-all
354        :sql-not
355        :sql-union
356        :sql-intersection
357        :sql-minus
358        :sql-group-by
359        :sql-having
360        :sql-null
361        :sql-not-null
362        :sql-exists
363        :sql-*
364        :sql-+
365        :sql-/
366        :sql-like
367        :sql-uplike
368        :sql-and
369        :sql-or
370        :sql-in
371        :sql-||
372        :sql-is
373        :sql-=
374        :sql-==
375        :sql-<
376        :sql->
377        :sql->=
378        :sql-<=
379        :sql-count
380        :sql-max
381        :sql-min
382        :sql-avg
383        :sql-sum
384        :sql-view-class
385        :sql_slot-value
386
387        . 
388        #1#
389        ))
390   (:documentation "This is the INTERNAL SQL-Interface package of USQL."))
391
392
393 ;; see http://thread.gmane.org/gmane.lisp.lispworks.general/681
394 #+lispworks
395 (setf *packages-for-warn-on-redefinition* 
396       (delete "SQL" *packages-for-warn-on-redefinition* :test 'string=))
397
398 (defpackage #:clsql-usql
399   (:nicknames #:usql #:sql)
400   (:use :common-lisp)
401   (:import-from :clsql-usql-sys . #2#)
402   (:export . #2#)
403   (:documentation "This is the SQL-Interface package of USQL."))
404
405   ;; This is from USQL's pcl-patch  
406   #+(or usql-sbcl-pcl usql-cmucl-pcl)
407   (progn
408     ;; Note that this will no longer required for cmucl as of version 19a. 
409     (in-package #+cmu :pcl #+sbcl :sb-pcl)
410     (defmacro pv-binding1 ((pv calls pv-table-symbol pv-parameters slot-vars) 
411                            &body body)
412       `(pv-env (,pv ,calls ,pv-table-symbol ,pv-parameters)
413         (let (,@(mapcar #'(lambda (slot-var p) `(,slot-var (get-slots-or-nil ,p)))
414                         slot-vars pv-parameters))
415           ,@(mapcar #'(lambda (slot-var) `(declare (ignorable ,slot-var))) slot-vars)
416           ,@body))))
417   
418   
419   #+sbcl
420   (if (find-package 'sb-mop)
421       (setq cl:*features* (delete :usql-sbcl-mop cl:*features*))
422       (setq cl:*features* (delete :usql-sbcl-pcl cl:*features*)))
423   
424   #+cmu
425   (if (find-package 'mop)
426       (setq cl:*features* (delete :usql-cmucl-mop cl:*features*))
427       (setq cl:*features* (delete :usql-cmucl-pcl cl:*features*)))
428   
429 );eval-when                                      
430
431