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