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