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