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