r8903: fixes for AllegroCL/Lispworks/OpenMCL
[clsql.git] / sql / package.lisp
1 ;;;; -*- Mode: LISP; Syntax: ANSI-Common-Lisp; Base: 10 -*-
2 ;;;; *************************************************************************
3 ;;;;
4 ;;;; $Id$
5 ;;;;
6 ;;;; Package definitions for CLSQL. 
7 ;;;;
8 ;;;; This file is part of CLSQL.
9 ;;;;
10 ;;;; CLSQL users are granted the rights to distribute and use this software
11 ;;;; as governed by the terms of the Lisp Lesser GNU Public License
12 ;;;; (http://opensource.franz.com/preamble.html), also known as the LLGPL.
13 ;;;; *************************************************************************
14
15 (in-package #:cl-user)
16
17 (eval-when (:compile-toplevel :load-toplevel :execute)
18
19 #+sbcl
20   (if (find-package 'sb-mop)
21       (pushnew :clsql-sbcl-mop cl:*features*)
22       (pushnew :clsql-sbcl-pcl cl:*features*))
23
24   #+cmu
25   (if (eq (symbol-package 'pcl:find-class)
26           (find-package 'common-lisp))
27       (pushnew :clsql-cmucl-mop cl:*features*)
28       (pushnew :clsql-cmucl-pcl cl:*features*)))
29
30
31 (eval-when (:compile-toplevel :load-toplevel :execute)
32   (defpackage #:clsql-sys
33     (:use #:common-lisp #:clsql-base-sys
34           #+clsql-sbcl-mop #:sb-mop
35           #+clsql-cmucl-mop #:mop
36           #+allegro #:mop
37           #+lispworks #:clos
38           #+scl #:clos
39           #+openmcl #:openmcl-mop)
40     
41     #+allegro
42     (:shadowing-import-from 
43      #:excl)
44    #+lispworks
45    (:shadowing-import-from 
46     #:clos)
47    #+clsql-sbcl-mop 
48    (:shadowing-import-from 
49     #:sb-pcl
50     #:generic-function-lambda-list)
51    #+clsql-sbcl-pcl
52    (:shadowing-import-from 
53     #:sb-pcl
54     #:name
55     #:class-direct-slots
56     #:class-of #:class-name #:class-slots #:find-class
57     #:slot-boundp
58     #:standard-class
59     #:slot-definition-name #:finalize-inheritance
60     #:standard-direct-slot-definition
61     #:standard-effective-slot-definition #:validate-superclass
62     #:direct-slot-definition-class #:compute-effective-slot-definition
63     #:effective-slot-definition-class
64     #:slot-value-using-class
65     #:class-prototype #:generic-function-method-class #:intern-eql-specializer
66     #:make-method-lambda #:generic-function-lambda-list
67     #:class-precedence-list #:slot-definition-type
68     #:class-direct-superclasses
69     #:compute-class-precedence-list)
70    #+clsql-cmucl-mop 
71    (:shadowing-import-from 
72     #:pcl
73     #:generic-function-lambda-list)
74    #+clsql-cmucl-pcl
75    (:shadowing-import-from 
76     #:pcl
77     #:class-direct-slots
78     #:name
79     #:class-of  #:class-name #:class-slots #:find-class #:standard-class
80     #:slot-boundp
81     #:slot-definition-name #:finalize-inheritance
82     #:standard-direct-slot-definition #:standard-effective-slot-definition
83     #:validate-superclass #:direct-slot-definition-class
84     #:effective-slot-definition-class
85     #:compute-effective-slot-definition
86     #:slot-value-using-class
87     #:class-prototype #:generic-function-method-class #:intern-eql-specializer
88     #:make-method-lambda #:generic-function-lambda-list
89     #:class-precedence-list #:slot-definition-type
90     #:class-direct-superclasses
91     #:compute-class-precedence-list)
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        ;; pool.lisp
191        #:disconnect-pooled
192
193        ;; basic-sql.lisp
194        #:query
195        #:execute-command
196        #:write-large-object
197        #:read-large-object
198        #:delete-large-object
199        #:do-query
200        #:map-query
201
202        ;; recording.lisp -- SQL I/O Recording 
203        #:record-sql-comand
204        #:record-sql-result
205        #:add-sql-stream                 ; recording  xx
206        #:delete-sql-stream                ; recording  xx
207        #:list-sql-streams                 ; recording  xx
208        #:sql-recording-p                  ; recording  xx
209        #:sql-stream                       ; recording  xx
210        #:start-sql-recording              ; recording  xx
211        #:stop-sql-recording               ; recording  xx
212        
213        ;; Transactions
214        #:with-transaction
215        #:commit-transaction
216        #:rollback-transaction
217        #:add-transaction-commit-hook
218        #:add-transaction-rollback-hook
219        #:commit                            ; transact   xx
220        #:rollback                         ; transact   xx
221        #:with-transaction                 ; transact   xx               .
222        #:start-transaction                 ; transact   xx
223        #:in-transaction-p                  ; transact   xx
224        #:database-start-transaction
225        #:database-abort-transaction
226        #:database-commit-transaction
227        #:transaction-level
228        #:transaction
229        ))
230    (:export
231     ;; "Private" exports for use by interface packages
232     #:check-connection-spec
233     #:database-initialize-database-type
234     #:database-type-load-foreign
235     #:database-name-from-spec
236     #:database-connect
237    #:database-query
238    #:database-execute-command
239    #:database-create-sequence
240    #:database-drop-sequence
241    #:database-sequence-next
242    #:database-set-sequence-position
243    #:database-query-result-set
244    #:database-dump-result-set
245    #:database-store-next-row
246    #:database-get-type-specifier
247    #:database-list-tables
248    #:database-table-exists-p
249    #:database-list-views
250    #:database-view-exists-p
251    #:database-list-indexes
252    #:database-index-exists-p
253    #:database-list-sequences
254    #:database-sequence-exists-p
255    #:database-list-attributes
256    #:database-attribute-type
257
258    .
259    ;; Shared exports for re-export by CLSQL. 
260    ;; I = Implemented, D = Documented
261    ;;  name                                 file       ID
262    ;;====================================================
263    #2=(;;------------------------------------------------
264        ;; CommonSQL API 
265        ;;------------------------------------------------
266       ;;FDML 
267        #:select                            ; objects    xx
268        #:cache-table-queries               ; 
269        #:*cache-table-queries-default*     ; 
270        #:delete-records                    ; sql               xx
271        #:insert-records                    ; sql        xx
272        #:update-records                    ; sql               xx
273        #:execute-command                          ; sql        xx
274        #:query                             ; sql        xx
275        #:print-query                      ; sql        xx
276        #:do-query                         ; sql        xx
277        #:map-query                        ; sql        xx
278        #:loop                             ; loop-ext   x
279        ;;FDDL
280        #:create-table                     ; table      xx
281        #:drop-table                       ; table      xx
282        #:list-tables                      ; table      xx
283        #:table-exists-p                    ; table      xx 
284        #:list-attributes                          ; table      xx
285        #:attribute-type                    ; table      xx
286        #:list-attribute-types              ; table      xx
287        #:create-view                      ; table      xx
288        #:drop-view                        ; table      xx
289        #:create-index                     ; table      xx               
290        #:drop-index                       ; table      xx               
291        ;;OODDL
292        #:standard-db-object               ; objects    xx
293        #:def-view-class                    ; objects    xx
294        #:create-view-from-class            ; objects    xx
295        #:drop-view-from-class             ; objects    xx
296        ;;OODML
297        #:instance-refreshed                ;
298        #:update-object-joins               ;
299        #:*default-update-objects-max-len*  ; 
300        #:update-slot-from-record           ; objects    xx
301        #:update-instance-from-records      ; objects    xx
302        #:update-records-from-instance     ; objects    xx
303        #:update-record-from-slot                  ; objects    xx
304        #:update-record-from-slots         ; objects    xx
305        #:list-classes                     ; objects    xx
306        #:delete-instance-records                  ; objects    xx
307        ;;Symbolic SQL Syntax 
308        #:sql                              ; syntax     xx
309        #:sql-expression                    ; syntax     xx
310        #:sql-operation                     ; syntax     xx
311        #:sql-operator                     ; syntax     xx       
312        #:disable-sql-reader-syntax         ; syntax     xx
313        #:enable-sql-reader-syntax          ; syntax     xx
314        #:locally-disable-sql-reader-syntax ; syntax     xx
315        #:locally-enable-sql-reader-syntax  ; syntax     xx
316        #:restore-sql-reader-syntax-state   ; syntax     xx
317
318        ;;------------------------------------------------
319        ;; Miscellaneous Extensions
320        ;;------------------------------------------------
321        ;;Initialization
322        #:*loaded-database-types*           ; clsql-base xx
323        #:reload-database-types             ; clsql-base xx
324        #:closed-database                  ; database   xx
325        #:database-type                     ; database   x
326        #:in-schema                         ; classes    x
327        ;;FDDL 
328        #:list-views                        ; table      xx
329        #:view-exists-p                     ; table      xx
330        #:list-indexes                      ; table      xx
331        #:index-exists-p                    ; table      xx
332        #:create-sequence                   ; table      xx
333        #:drop-sequence                     ; table      xx
334        #:list-sequences                    ; table      xx
335        #:sequence-exists-p                 ; table      xx
336        #:sequence-next                     ; table      xx
337        #:sequence-last                     ; table      xx
338        #:set-sequence-position             ; table      xx
339        ;;OODDL
340        #:view-table                        ; metaclass  x
341        #:create-sequence-from-class        ; objects    x
342        #:drop-sequence-from-class          ; objects    x       
343        ;;OODML
344        #:add-to-relation                   ; objects    x
345        #:remove-from-relation              ; objects    x
346        #:read-sql-value                    ; objects    x
347        #:database-output-sql-as-type       ; objects    x
348        #:database-get-type-specifier       ; objects    x
349        #:database-output-sql               ; sql/class  xx
350
351        ;;-----------------------------------------------
352        ;; Symbolic Sql Syntax 
353        ;;-----------------------------------------------
354        #:sql-and-qualifier
355        #:sql-escape
356        #:sql-query
357        #:sql-any
358        #:sql-all
359        #:sql-not
360        #:sql-union
361        #:sql-intersection
362        #:sql-minus
363        #:sql-group-by
364        #:sql-having
365        #:sql-null
366        #:sql-not-null
367        #:sql-exists
368        #:sql-*
369        #:sql-+
370        #:sql-/
371        #:sql-like
372        #:sql-uplike
373        #:sql-and
374        #:sql-or
375        #:sql-in
376        #:sql-||
377        #:sql-is
378        #:sql-=
379        #:sql-==
380        #:sql-<
381        #:sql->
382        #:sql->=
383        #:sql-<=
384        #:sql-count
385        #:sql-max
386        #:sql-min
387        #:sql-avg
388        #:sql-sum
389        #:sql-view-class
390        #:sql_slot-value
391
392        . 
393        #1#
394        ))
395   (:documentation "This is the INTERNAL SQL-Interface package of CLSQL."))
396
397
398 ;; see http://thread.gmane.org/gmane.lisp.lispworks.general/681
399 #+lispworks
400 (setf *packages-for-warn-on-redefinition* 
401       (delete "SQL" *packages-for-warn-on-redefinition* :test 'string=))
402
403 (defpackage #:clsql
404   (:use #:common-lisp)
405   (:import-from #:clsql-sys . #2#)
406   (:export . #2#)
407   (:documentation "This is the SQL-Interface package of CLSQL."))
408
409 (defpackage #:clsql-user
410   (:use #:common-lisp)
411   (:import-from #:clsql-sys . #2#)
412   (:export . #2#)
413   (:documentation "This is the user package with CLSQL symbols."))
414
415   ;; This is from USQL's pcl-patch  
416   #+(or clsql-sbcl-pcl clsql-cmucl-pcl)
417   (progn
418     ;; Note that this will no longer required for cmucl as of version 19a. 
419     (in-package #+cmu :pcl #+sbcl :sb-pcl)
420     (defmacro pv-binding1 ((pv calls pv-table-symbol pv-parameters slot-vars) 
421                            &body body)
422       `(pv-env (,pv ,calls ,pv-table-symbol ,pv-parameters)
423         (let (,@(mapcar #'(lambda (slot-var p) `(,slot-var (get-slots-or-nil ,p)))
424                         slot-vars pv-parameters))
425           ,@(mapcar #'(lambda (slot-var) `(declare (ignorable ,slot-var))) slot-vars)
426           ,@body))))
427   
428   
429   #+sbcl
430   (if (find-package 'sb-mop)
431       (setq cl:*features* (delete :clsql-sbcl-mop cl:*features*))
432       (setq cl:*features* (delete :clsql-sbcl-pcl cl:*features*)))
433   
434   #+cmu
435   (if (find-package 'mop)
436       (setq cl:*features* (delete :clsql-cmucl-mop cl:*features*))
437       (setq cl:*features* (delete :clsql-cmucl-pcl cl:*features*)))
438   
439 );eval-when                                      
440
441