r9403: Rework conditions to be CommonSQL backward compatible
[clsql.git] / sql / package.lisp
1 ;;;; -*- Mode: LISP; Syntax: ANSI-Common-Lisp; Base: 10 -*-
2 ;;;; *************************************************************************
3 ;;;; FILE IDENTIFICATION
4 ;;;;
5 ;;;; Name:          package.lisp
6 ;;;; Purpose:       Package definition for SQL interface
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 ;;;; This file makes the required package definitions for CLSQL's
18 ;;;; core packages.
19
20 (eval-when (:compile-toplevel :load-toplevel :execute)
21   #+sbcl
22   (if (find-package 'sb-mop)
23       (pushnew :clsql-sbcl-mop cl:*features*)
24       (pushnew :clsql-sbcl-pcl cl:*features*))
25   
26   #+cmu
27   (if (eq (symbol-package 'pcl:find-class)
28           (find-package 'common-lisp))
29       (pushnew :clsql-cmucl-mop cl:*features*)
30       (pushnew :clsql-cmucl-pcl cl:*features*)))
31
32
33 (eval-when (:compile-toplevel :load-toplevel :execute)
34   (defpackage #:clsql-sys
35     (:use #:common-lisp
36           #+clsql-sbcl-mop #:sb-mop
37           #+clsql-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     #+clsql-sbcl-mop 
50     (:shadowing-import-from 
51      #:sb-pcl
52      #:generic-function-lambda-list)
53     #+clsql-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      #:compute-class-precedence-list)
72     #+clsql-cmucl-mop 
73     (:shadowing-import-from 
74      #:pcl
75      #:generic-function-lambda-list)
76     #+clsql-cmucl-pcl
77     (:shadowing-import-from 
78      #:pcl
79      #:class-direct-slots
80      #:name
81      #:class-of  #:class-name #:class-slots #:find-class #:standard-class
82      #:slot-boundp
83      #:slot-definition-name #:finalize-inheritance
84      #:standard-direct-slot-definition #:standard-effective-slot-definition
85      #:validate-superclass #:direct-slot-definition-class
86      #:effective-slot-definition-class
87      #:compute-effective-slot-definition
88      #:slot-value-using-class
89      #:class-prototype #:generic-function-method-class #:intern-eql-specializer
90      #:make-method-lambda #:generic-function-lambda-list
91      #:class-precedence-list #:slot-definition-type
92      #:class-direct-superclasses
93      #:compute-class-precedence-list)
94     #+scl
95     (:shadowing-import-from 
96      #:clos
97      #:class-prototype  ;; note: make-method-lambda is not fbound
98      )
99     
100     (:export
101      ;; "Private" exports for use by interface packages
102      #:check-connection-spec
103      #:database-initialize-database-type
104      #:database-type-load-foreign
105      #:database-name-from-spec
106      #:database-connect
107      #:database-disconnect
108      #:database-query
109      #:database-execute-command
110      #:database-create-sequence
111      #:database-drop-sequence
112      #:database-sequence-next
113      #:database-set-sequence-position
114      #:database-query-result-set
115      #:database-dump-result-set
116      #:database-store-next-row
117      #:database-get-type-specifier
118      #:database-list-tables
119      #:database-table-exists-p
120      #:database-list-views
121      #:database-view-exists-p
122      #:database-list-indexes
123      #:database-list-table-indexes
124      #:database-index-exists-p
125      #:database-list-sequences
126      #:database-sequence-last
127      #:database-sequence-exists-p
128      #:database-list-attributes
129      #:database-attribute-type
130      #:database-describe-table
131      #:database-type-library-loaded
132      #:database-create
133      #:database-destroy
134      #:database-probe
135      #:database-list
136      
137      #:db-backend-has-create/destroy-db?
138      #:db-type-has-views?
139      #:db-type-has-bigint?
140      #:db-type-has-union?
141      #:db-type-has-subqueries?
142      #:db-type-has-boolean-where?
143      #:db-type-transaction-capable?
144      #:db-type-has-fancy-math?
145      #:db-type-default-case
146      #:db-type-use-column-on-drop-index? 
147      #:database-underlying-type
148
149      ;; Large objects 
150      #:database-create-large-object
151      #:database-write-large-object
152      #:database-read-large-object
153      #:database-delete-large-object
154      #:create-large-object
155      #:write-large-object
156      #:read-large-object
157      #:delete-large-object
158
159      ;; accessors for database class
160      #:name
161      #:connection-spec
162      #:transaction
163      #:transaction-level
164      #:conn-pool
165      #:command-recording-stream
166      #:result-recording-stream
167      #:record-caches
168      #:view-classes
169      #:database-type
170      #:database-state
171      #:attribute-cache
172      
173
174      ;; utils.lisp
175      #:without-interrupts
176      #:make-process-lock
177      #:with-process-lock
178      #:command-output
179      #:symbol-name-default-case
180      #:convert-to-db-default-case
181      #:ensure-keyword
182
183      #:*loaded-database-types*
184      #:reload-database-types
185      #:*connect-if-exists*
186      #:connected-databases
187      #:database
188      #:find-database
189      #:is-database-open
190      #:database-type                     ; database   x
191
192      ;; utils.lisp
193      #:number-to-sql-string
194      #:float-to-sql-string
195      #:sql-escape-quotes
196      #:in
197      
198      .
199      ;; Shared exports for re-export by CLSQL package. 
200      ;; I = Implemented, D = Documented
201      ;;  name                                 file       ID
202      ;;====================================================
203      #1=(;;------------------------------------------------
204          ;; CommonSQL API 
205          ;;------------------------------------------------
206          ;;FDML 
207          #:select                            ; objects    xx
208          #:cache-table-queries               ; 
209          #:*cache-table-queries-default*     ; 
210          #:delete-records                    ; sql        xx
211          #:insert-records                    ; sql        xx
212          #:update-records                    ; sql        xx
213          #:execute-command                   ; sql        xx
214          #:query                             ; sql        xx
215          #:print-query                       ; sql        xx
216          #:do-query                          ; sql        xx
217          #:map-query                         ; sql        xx
218          #:for-each-row
219          #:loop
220
221          ;; conditions
222          #:sql-user-error
223          #:sql-database-error
224          #:sql-database-data-error
225          #:sql-connection-error
226          #:sql-temporary-error
227          #:sql-error-error-id
228          #:sql-error-secondary-error-id
229          #:sql-error-database-message
230
231          ;; CLSQL Extensions
232          #:sql-error-database
233          #:sql-database-warning
234          #:sql-warning
235          #:sql-condition
236
237          ;;FDDL
238          #:create-table                      ; table      xx
239          #:drop-table                        ; table      xx
240          #:list-tables                       ; table      xx
241          #:table-exists-p                    ; table      xx 
242          #:list-attributes                   ; table      xx
243          #:attribute-type                    ; table      xx
244          #:list-attribute-types            ; table      xx
245          #:*cache-table-queries-default*
246          #:create-view                       ; table      xx
247          #:drop-view                         ; table      xx
248          #:create-index                      ; table      xx            
249          #:drop-index                        ; table      xx            
250          #:truncate-database
251          ;;OODDL
252          #:standard-db-object                ; objects    xx
253          #:def-view-class                    ; objects    xx
254          #:create-view-from-class            ; objects    xx
255          #:drop-view-from-class              ; objects    xx
256          ;;OODML
257          #:instance-refreshed                ; objects    xx 
258          #:update-object-joins               ;
259          #:*default-update-objects-max-len*  ; 
260          #:update-slot-from-record         ; objects    xx
261          #:update-instance-from-records      ; objects    xx
262          #:update-records-from-instance      ; objects    xx
263          #:update-record-from-slot           ; objects    xx
264          #:update-record-from-slots          ; objects    xx
265          #:list-classes                      ; objects    xx
266          #:delete-instance-records           ; objects    xx
267          ;;Symbolic SQL Syntax 
268          #:sql                               ; syntax     xx
269          #:sql-expression                    ; syntax     xx
270          #:sql-operation                     ; syntax     xx
271          #:sql-operator                      ; syntax     xx    
272          #:disable-sql-reader-syntax         ; syntax     xx
273          #:enable-sql-reader-syntax          ; syntax     xx
274          #:locally-disable-sql-reader-syntax ; syntax     xx
275          #:locally-enable-sql-reader-syntax  ; syntax     xx
276          #:restore-sql-reader-syntax-state   ; syntax     xx
277          
278          ;;FDDL 
279          #:list-views                        ; table      xx
280          #:view-exists-p                     ; table      xx
281          #:list-indexes                      ; table      xx
282          #:list-table-indexes                ; table      xx
283          #:index-exists-p                    ; table      xx
284          #:create-sequence                   ; table      xx
285          #:drop-sequence                     ; table      xx
286          #:list-sequences                    ; table      xx
287          #:sequence-exists-p                 ; table      xx
288          #:sequence-next                     ; table      xx
289          #:sequence-last                     ; table      xx
290          #:set-sequence-position             ; table      xx
291          ;;OODDL
292          #:view-table                        ; metaclass  x
293          #:universal-time                  ; objects    xx 
294          #:bigint
295          ;;OODML
296          #:*db-auto-sync*                    ; objects    xx              
297          #:add-to-relation                   ; objects    x
298          #:remove-from-relation              ; objects    x
299          #:read-sql-value                    ; objects    x
300          #:database-output-sql-as-type       ; objects    x
301          #:database-get-type-specifier       ; objects    x
302          #:database-output-sql               ; sql/class  xx
303          
304          ;; conditions
305          #:clsql-condition
306          #:clsql-error
307          #:clsql-simple-error
308          #:clsql-simple-warning
309          
310          ;;-----------------------------------------------
311          ;; Symbolic Sql Syntax 
312          ;;-----------------------------------------------
313          #:sql-and-qualifier
314          #:sql-escape
315          #:sql-query
316          #:sql-object-query
317          #:sql-any
318          #:sql-all
319          #:sql-not
320          #:sql-union
321          #:sql-intersection
322          #:sql-minus
323          #:sql-group-by
324          #:sql-having
325          #:sql-null
326          #:sql-not-null
327          #:sql-exists
328          #:sql-*
329          #:sql-+
330          #:sql-/
331          #:sql-like
332          #:sql-uplike
333          #:sql-and
334          #:sql-or
335          #:sql-in
336          #:sql-||
337          #:sql-is
338          #:sql-=
339          #:sql-==
340          #:sql-<
341        #:sql->
342        #:sql->=
343        #:sql-<=
344        #:sql-count
345        #:sql-max
346        #:sql-min
347        #:sql-avg
348        #:sql-sum
349        #:sql-view-class
350        #:sql_slot-value
351
352
353
354        ;; time.lisp
355        #:bad-component
356        #:current-day
357      #:current-month
358      #:current-year
359      #:day-duration
360      #:db-timestring
361      #:decode-duration
362      #:decode-time
363      #:duration
364      #:duration+
365      #:duration<
366      #:duration<=
367      #:duration=
368      #:duration>
369      #:duration>=
370      #:duration-day
371      #:duration-hour
372      #:duration-minute
373      #:duration-month
374      #:duration-second
375      #:duration-year
376      #:duration-reduce 
377      #:duration-timestring
378      #:extract-roman 
379      #:format-duration
380      #:format-time
381      #:get-time
382      #:utime->time
383      #:interval-clear
384      #:interval-contained
385      #:interval-data
386      #:interval-edit
387      #:interval-end
388      #:interval-match
389      #:interval-push
390      #:interval-relation
391      #:interval-start
392      #:interval-type
393      #:make-duration
394      #:make-interval
395      #:make-time
396      #:merged-time
397      #:midnight
398      #:month-name
399      #:parse-date-time
400      #:parse-timestring
401      #:parse-yearstring
402      #:print-date
403      #:roll
404      #:roll-to
405      #:time
406      #:time+
407      #:time-
408      #:time-by-adding-duration
409      #:time-compare
410      #:time-difference
411      #:time-dow
412      #:time-element
413      #:time-max
414      #:time-min
415      #:time-mjd
416      #:time-msec
417      #:time-p
418      #:time-sec
419      #:time-well-formed
420      #:time-ymd
421      #:time<
422      #:time<=
423      #:time=
424      #:time>
425      #:time>=
426      #:timezone
427      #:universal-time
428      #:wall-time
429      #:wall-timestring
430      #:week-containing
431      #:gregorian-to-mjd
432      #:mjd-to-gregorian
433
434      ;; recording.lisp -- SQL I/O Recording 
435      #:record-sql-command
436      #:record-sql-result
437      #:add-sql-stream                 ; recording  xx
438      #:delete-sql-stream                  ; recording  xx
439      #:list-sql-streams           ; recording  xx
440      #:sql-recording-p            ; recording  xx
441      #:sql-stream                         ; recording  xx
442      #:start-sql-recording                ; recording  xx
443      #:stop-sql-recording                 ; recording  xx
444
445      ;; database.lisp -- Connection
446      #:*default-database-type*            ; clsql-base xx
447      #:*default-database*                 ; classes    xx
448      #:*initialized-database-types*
449      #:initialize-database-type
450      #:connect                            ; database   xx
451      #:disconnect                         ; database   xx
452      #:*connect-if-exists*                ; database   xx
453      #:connected-databases                ; database   xx
454      #:database                   ; database   xx
455      #:database-name                     ; database   xx
456      #:reconnect                         ; database
457      #:find-database                     ; database   xx
458      #:status                            ; database   xx
459      #:with-database
460      #:with-default-database
461      #:disconnect-pooled
462      #:create-database
463      #:destroy-database
464      #:probe-database
465      #:list-databases
466      
467      #:describe-table
468      #:*backend-warning-behavior*
469      
470      ;; Transactions
471      #:with-transaction
472      #:commit-transaction
473      #:rollback-transaction
474      #:add-transaction-commit-hook
475      #:add-transaction-rollback-hook
476      #:commit                            ; transact   xx
477      #:rollback                   ; transact   xx
478      #:with-transaction           ; transact   xx               .
479      #:start-transaction                 ; transact   xx
480      #:in-transaction-p                  ; transact   xx
481      #:database-start-transaction
482      #:database-abort-transaction
483      #:database-commit-transaction
484      #:transaction-level
485      #:transaction
486        ))
487   (:documentation "This is the INTERNAL SQL-Interface package of CLSQL."))
488
489
490 (defpackage #:clsql
491   (:use #:common-lisp)
492   (:import-from #:clsql-sys . #1#)
493   (:export . #1#)
494   (:documentation "This is the user package with CLSQL symbols."))
495
496 (defpackage #:clsql-user
497   (:use #:common-lisp)
498   (:import-from #:clsql-sys . #1#)
499   (:export . #1#)
500   (:documentation "This is the user package with CLSQL symbols."))
501
502   ;; This is from USQL's pcl-patch  
503   #+(or clsql-sbcl-pcl clsql-cmucl-pcl)
504   (progn
505     ;; Note that this will no longer required for cmucl as of version 19a. 
506     (in-package #+cmu :pcl #+sbcl :sb-pcl)
507     (defmacro pv-binding1 ((pv calls pv-table-symbol pv-parameters slot-vars) 
508                            &body body)
509       `(pv-env (,pv ,calls ,pv-table-symbol ,pv-parameters)
510         (let (,@(mapcar #'(lambda (slot-var p) `(,slot-var (get-slots-or-nil ,p)))
511                         slot-vars pv-parameters))
512           ,@(mapcar #'(lambda (slot-var) `(declare (ignorable ,slot-var))) slot-vars)
513           ,@body))))
514
515 ;; see http://thread.gmane.org/gmane.lisp.lispworks.general/681
516 #+lispworks
517 (setf *packages-for-warn-on-redefinition* 
518       (delete "SQL" *packages-for-warn-on-redefinition* :test 'string=))
519
520   #+sbcl
521   (if (find-package 'sb-mop)
522       (setq cl:*features* (delete :clsql-sbcl-mop cl:*features*))
523       (setq cl:*features* (delete :clsql-sbcl-pcl cl:*features*)))
524   
525   #+cmu
526   (if (find-package 'mop)
527       (setq cl:*features* (delete :clsql-cmucl-mop cl:*features*))
528       (setq cl:*features* (delete :clsql-cmucl-pcl cl:*features*)))
529
530 ) ;eval-when                                      
531