1 ;;;; -*- Mode: LISP; Syntax: ANSI-Common-Lisp; Base: 10 -*-
2 ;;;; *************************************************************************
3 ;;;; FILE IDENTIFICATION
5 ;;;; Name: db-interface.lisp
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
14 ;;;; This file, part of CLSQL, is Copyright (c) 2002-2004 by Kevin M. Rosenberg
15 ;;;; and Copyright (c) 1999-2001 by Pierre R. Mai, and onShoreD
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 ;;;; *************************************************************************
22 (in-package #:clsql-base-sys)
24 (defgeneric database-type-load-foreign (database-type)
26 "The internal generic implementation of reload-database-types."))
28 (defgeneric database-type-library-loaded (database-type)
30 "The internal generic implementation for checking if
31 database type library loaded successfully."))
33 (defgeneric database-type (database)
35 "Returns database type")
37 (signal-nodb-error database)))
40 (defgeneric database-initialize-database-type (database-type)
42 "The internal generic implementation of initialize-database-type."))
44 (defgeneric database-name-from-spec (connection-spec database-type)
46 "Returns the name of the database that would be created if connect
47 was called with the connection-spec."))
49 (defgeneric database-connect (connection-spec database-type)
50 (:documentation "Internal generic implementation of connect."))
52 (defgeneric database-disconnect (database)
53 (:method ((database closed-database))
54 (signal-closed-database-error database))
55 (:method ((database t))
56 (signal-nodb-error database))
57 (:documentation "Internal generic implementation of disconnect."))
59 (defgeneric database-query (query-expression database types)
60 (:method (query-expression (database closed-database) types)
61 (declare (ignore query-expression types))
62 (signal-closed-database-error database))
63 (:method (query-expression (database t) types)
64 (declare (ignore query-expression types))
65 (signal-nodb-error database))
66 (:documentation "Internal generic implementation of query."))
69 (defgeneric database-execute-command (sql-expression database)
70 (:method (sql-expression (database closed-database))
71 (declare (ignore sql-expression))
72 (signal-closed-database-error database))
73 (:method (sql-expression (database t))
74 (declare (ignore sql-expression))
75 (signal-nodb-error database))
76 (:documentation "Internal generic implementation of execute-command."))
78 ;;; Mapping and iteration
79 (defgeneric database-query-result-set
80 (query-expression database &key full-set types)
81 (:method (query-expression (database closed-database) &key full-set types)
82 (declare (ignore query-expression full-set types))
83 (signal-closed-database-error database)
85 (:method (query-expression (database t) &key full-set types)
86 (declare (ignore query-expression full-set types))
87 (signal-nodb-error database)
90 "Internal generic implementation of query mapping. Starts the
91 query specified by query-expression on the given database and returns
92 a result-set to be used with database-store-next-row and
93 database-dump-result-set to access the returned data. The second
94 value is the number of columns in the result-set, if there are any.
95 If full-set is true, the number of rows in the result-set is returned
96 as a third value, if this is possible (otherwise nil is returned for
97 the third value). This might have memory and resource usage
98 implications, since many databases will require the query to be
99 executed in full to answer this question. If the query produced no
100 results then nil is returned for all values that would have been
101 returned otherwise. If an error occurs during query execution, the
102 function should signal a clsql-sql-error."))
104 (defgeneric database-dump-result-set (result-set database)
105 (:method (result-set (database closed-database))
106 (declare (ignore result-set))
107 (signal-closed-database-error database))
108 (:method (result-set (database t))
109 (declare (ignore result-set))
110 (signal-nodb-error database))
111 (:documentation "Dumps the received result-set."))
113 (defgeneric database-store-next-row (result-set database list)
114 (:method (result-set (database closed-database) list)
115 (declare (ignore result-set list))
116 (signal-closed-database-error database))
117 (:method (result-set (database t) list)
118 (declare (ignore result-set list))
119 (signal-nodb-error database))
121 "Returns t and stores the next row in the result set in list or
122 returns nil when result-set is finished."))
125 ;; Interfaces to support UncommonSQL
127 (defgeneric database-create-sequence (name database)
128 (:documentation "Create a sequence in DATABASE."))
130 (defgeneric database-drop-sequence (name database)
131 (:documentation "Drop a sequence from DATABASE."))
133 (defgeneric database-sequence-next (name database)
134 (:documentation "Increment a sequence in DATABASE."))
136 (defgeneric database-list-sequences (database &key owner)
137 (:documentation "List all sequences in DATABASE."))
139 (defgeneric database-set-sequence-position (name position database)
140 (:documentation "Set the position of the sequence called NAME in DATABASE."))
142 (defgeneric database-sequence-last (name database)
143 (:documentation "Select the last value in sequence NAME in DATABASE."))
145 (defgeneric database-start-transaction (database)
146 (:documentation "Start a transaction in DATABASE."))
148 (defgeneric database-commit-transaction (database)
149 (:documentation "Commit current transaction in DATABASE."))
151 (defgeneric database-abort-transaction (database)
152 (:documentation "Abort current transaction in DATABASE."))
154 (defgeneric database-get-type-specifier (type args database)
155 (:documentation "Return the type SQL type specifier as a string, for
156 the given lisp type and parameters."))
158 (defgeneric database-list-tables (database &key owner)
159 (:documentation "List all tables in the given database"))
161 (defgeneric database-list-views (database &key owner)
162 (:documentation "List all views in the DATABASE."))
164 (defgeneric database-list-indexes (database &key owner)
165 (:documentation "List all indexes in the DATABASE."))
167 (defgeneric database-list-attributes (table database &key owner)
168 (:documentation "List all attributes in TABLE."))
170 (defgeneric database-attribute-type (attribute table database &key owner)
171 (:documentation "Return the type of ATTRIBUTE in TABLE."))
173 (defgeneric database-add-attribute (table attribute database)
174 (:documentation "Add the attribute to the table."))
176 (defgeneric database-rename-attribute (table oldatt newname database)
177 (:documentation "Rename the attribute in the table to NEWNAME."))
179 (defgeneric oid (object)
180 (:documentation "Return the unique ID of a database object."))
183 ;;; Large objects support (Marc Battyani)
185 (defgeneric database-create-large-object (database)
186 (:documentation "Creates a new large object in the database and returns the object identifier"))
188 (defgeneric database-write-large-object (object-id data database)
189 (:documentation "Writes data to the large object"))
191 (defgeneric database-read-large-object (object-id database)
192 (:documentation "Reads the large object content"))
194 (defgeneric database-delete-large-object (object-id database)
195 (:documentation "Deletes the large object in the database"))