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