r2006: debian
[clsql.git] / sql / db-interface.cl
1 ;;;; -*- Mode: LISP; Syntax: ANSI-Common-Lisp; Base: 10 -*-
2 ;;;; *************************************************************************
3 ;;;; FILE IDENTIFICATION
4 ;;;;
5 ;;;; Name:          db-interface.cl
6 ;;;; Purpose:       Generic function definitions for DB interfaces
7 ;;;; Programmers:   Kevin M. Rosenberg based on
8 ;;;;                Original code by Pierre R. Mai. Additions from
9 ;;;;                onShoreD to support UncommonSQL front-end 
10 ;;;; Date Started:  Feb 2002
11 ;;;;
12 ;;;; $Id: db-interface.cl,v 1.7 2002/04/27 20:58:11 kevin Exp $
13 ;;;;
14 ;;;; This file, part of CLSQL, is Copyright (c) 2002 by Kevin M. Rosenberg
15 ;;;; and Copyright (c) 1999-2001 by Pierre R. Mai, and onShoreD
16 ;;;;
17 ;;;; CLSQL users are granted the rights to distribute and use this software
18 ;;;; as governed by the terms of the Lisp Lesser GNU Public License
19 ;;;; (http://opensource.franz.com/preamble.html), also known as the LLGPL.
20 ;;;; *************************************************************************
21
22 (declaim (optimize (debug 3) (speed 3) (safety 1) (compilation-speed 0)))
23 (in-package :clsql-sys)
24
25 (defgeneric database-type-load-foreign (database-type)
26   (:documentation
27    "The internal generic implementation of reload-database-types."))
28
29 (defgeneric database-type-library-loaded (database-type)
30   (:documentation
31    "The internal generic implementation for checking if
32 database type library loaded successfully."))
33
34 (defgeneric database-type (database-type)
35   (:documentation
36    "Returns database type")
37   (:method (database-type)
38            (declare (ignore database-type))
39            (signal-nodb-error database)))
40
41
42 (defgeneric database-initialize-database-type (database-type)
43   (:documentation
44    "The internal generic implementation of initialize-database-type."))
45
46 (defgeneric database-name-from-spec (connection-spec database-type)
47   (:documentation
48    "Returns the name of the database that would be created if connect
49 was called with the connection-spec."))
50
51 (defgeneric database-connect (connection-spec database-type)
52   (:documentation "Internal generic implementation of connect."))
53
54 (defgeneric database-disconnect (database)
55   (:method ((database closed-database))
56            (signal-closed-database-error database))
57   (:method ((database t))
58            (signal-nodb-error database))
59   (:documentation "Internal generic implementation of disconnect."))
60
61 (defgeneric database-query (query-expression database types)
62   (:method (query-expression (database closed-database) types)
63            (declare (ignore query-expression types))
64            (signal-closed-database-error database))  
65   (:method (query-expression (database t) types)
66            (declare (ignore query-expression types))
67            (signal-nodb-error database))
68   (:documentation "Internal generic implementation of query."))
69
70
71 (defgeneric database-execute-command (sql-expression database)
72   (:method (sql-expression (database closed-database))
73            (declare (ignore sql-expression))
74            (signal-closed-database-error database))
75   (:method (sql-expression (database t))
76            (declare (ignore sql-expression))
77            (signal-nodb-error database))
78   (:documentation "Internal generic implementation of execute-command."))
79
80 ;;; Mapping and iteration
81 (defgeneric database-query-result-set
82     (query-expression database &key full-set types)
83   (:method (query-expression (database closed-database) &key full-set types)
84            (declare (ignore query-expression full-set types))
85            (signal-closed-database-error database)
86            (values nil nil nil))
87   (:method (query-expression (database t) &key full-set types)
88            (declare (ignore query-expression full-set types))
89            (signal-nodb-error database)
90            (values nil nil nil))
91   (:documentation
92    "Internal generic implementation of query mapping.  Starts the
93 query specified by query-expression on the given database and returns
94 a result-set to be used with database-store-next-row and
95 database-dump-result-set to access the returned data.  The second
96 value is the number of columns in the result-set, if there are any.
97 If full-set is true, the number of rows in the result-set is returned
98 as a third value, if this is possible (otherwise nil is returned for
99 the third value).  This might have memory and resource usage
100 implications, since many databases will require the query to be
101 executed in full to answer this question.  If the query produced no
102 results then nil is returned for all values that would have been
103 returned otherwise.  If an error occurs during query execution, the
104 function should signal a clsql-sql-error."))
105
106 (defgeneric database-dump-result-set (result-set database)
107   (:method (result-set (database closed-database))
108            (declare (ignore result-set))
109            (signal-closed-database-error database))
110   (:method (result-set (database t))
111            (declare (ignore result-set))
112            (signal-nodb-error database))
113   (:documentation "Dumps the received result-set."))
114
115 (defgeneric database-store-next-row (result-set database list)
116   (:method (result-set (database closed-database) list)
117            (declare (ignore result-set list))
118            (signal-closed-database-error database))
119   (:method (result-set (database t) list)
120            (declare (ignore result-set list))
121            (signal-nodb-error database))
122   (:documentation
123    "Returns t and stores the next row in the result set in list or
124 returns nil when result-set is finished."))
125
126
127 ;; Interfaces to support UncommonSQL
128
129 (defgeneric database-create-sequence (name database)
130   (:documentation "Create a sequence in DATABASE."))
131
132 (defgeneric database-drop-sequence (name database)
133   (:documentation "Drop a sequence from DATABASE."))
134
135 (defgeneric database-sequence-next (name database)
136   (:documentation "Increment a sequence in DATABASE."))
137
138 (defgeneric database-start-transaction (database)
139   (:documentation "Start a transaction in DATABASE."))
140
141 (defgeneric database-commit-transaction (database)
142   (:documentation "Commit current transaction in DATABASE."))
143
144 (defgeneric database-abort-transaction (database)
145   (:documentation "Abort current transaction in DATABASE."))
146
147 (defgeneric database-get-type-specifier (type args database)
148   (:documentation "Return the type SQL type specifier as a string, for
149 the given lisp type and parameters."))
150
151 (defgeneric database-list-tables (database &key (system-tables nil))
152   (:documentation "List all tables in the given database"))
153
154 (defgeneric database-list-attributes (table database)
155   (:documentation "List all attributes in TABLE."))
156
157 (defgeneric database-attribute-type (attribute table database)
158   (:documentation "Return the type of ATTRIBUTE in TABLE."))
159
160 (defgeneric database-add-attribute (table attribute database)
161   (:documentation "Add the attribute to the table."))
162
163 (defgeneric database-rename-attribute (table oldatt newname database)
164   (:documentation "Rename the attribute in the table to NEWNAME."))
165
166 (defgeneric oid (object)
167   (:documentation "Return the unique ID of a database object."))
168
169  
170 ;;; Large objects support (Marc Battyani)
171
172 (defgeneric database-create-large-object (database)
173   (:documentation "Creates a new large object in the database and returns the object identifier"))
174
175 (defgeneric database-write-large-object (object-id (data string) database)
176   (:documentation "Writes data to the large object"))
177
178 (defgeneric database-read-large-object (object-id database)
179   (:documentation "Reads the large object content"))
180
181 (defgeneric database-delete-large-object (object-id database)
182   (:documentation "Deletes the large object in the database"))