1 ;;;; -*- Mode: LISP; Syntax: ANSI-Common-Lisp; Base: 10 -*-
2 ;;;; *************************************************************************
3 ;;;; FILE IDENTIFICATION
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
12 ;;;; $Id: db-interface.lisp,v 1.1 2002/09/30 10:19:01 kevin Exp $
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
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 (declaim (optimize (debug 3) (speed 3) (safety 1) (compilation-speed 0)))
23 (in-package :clsql-base-sys)
25 (defgeneric database-type-load-foreign (database-type)
27 "The internal generic implementation of reload-database-types."))
29 (defgeneric database-type-library-loaded (database-type)
31 "The internal generic implementation for checking if
32 database type library loaded successfully."))
34 (defgeneric database-type (database)
36 "Returns database type")
38 (signal-nodb-error database)))
41 (defgeneric database-initialize-database-type (database-type)
43 "The internal generic implementation of initialize-database-type."))
45 (defgeneric database-name-from-spec (connection-spec database-type)
47 "Returns the name of the database that would be created if connect
48 was called with the connection-spec."))
50 (defgeneric database-connect (connection-spec database-type)
51 (:documentation "Internal generic implementation of connect."))
53 (defgeneric database-disconnect (database)
54 (:method ((database closed-database))
55 (signal-closed-database-error database))
56 (:method ((database t))
57 (signal-nodb-error database))
58 (:documentation "Internal generic implementation of disconnect."))
60 (defgeneric database-query (query-expression database types)
61 (:method (query-expression (database closed-database) types)
62 (declare (ignore query-expression types))
63 (signal-closed-database-error database))
64 (:method (query-expression (database t) types)
65 (declare (ignore query-expression types))
66 (signal-nodb-error database))
67 (:documentation "Internal generic implementation of query."))
70 (defgeneric database-execute-command (sql-expression database)
71 (:method (sql-expression (database closed-database))
72 (declare (ignore sql-expression))
73 (signal-closed-database-error database))
74 (:method (sql-expression (database t))
75 (declare (ignore sql-expression))
76 (signal-nodb-error database))
77 (:documentation "Internal generic implementation of execute-command."))
79 ;;; Mapping and iteration
80 (defgeneric database-query-result-set
81 (query-expression database &key full-set types)
82 (:method (query-expression (database closed-database) &key full-set types)
83 (declare (ignore query-expression full-set types))
84 (signal-closed-database-error database)
86 (:method (query-expression (database t) &key full-set types)
87 (declare (ignore query-expression full-set types))
88 (signal-nodb-error database)
91 "Internal generic implementation of query mapping. Starts the
92 query specified by query-expression on the given database and returns
93 a result-set to be used with database-store-next-row and
94 database-dump-result-set to access the returned data. The second
95 value is the number of columns in the result-set, if there are any.
96 If full-set is true, the number of rows in the result-set is returned
97 as a third value, if this is possible (otherwise nil is returned for
98 the third value). This might have memory and resource usage
99 implications, since many databases will require the query to be
100 executed in full to answer this question. If the query produced no
101 results then nil is returned for all values that would have been
102 returned otherwise. If an error occurs during query execution, the
103 function should signal a clsql-sql-error."))
105 (defgeneric database-dump-result-set (result-set database)
106 (:method (result-set (database closed-database))
107 (declare (ignore result-set))
108 (signal-closed-database-error database))
109 (:method (result-set (database t))
110 (declare (ignore result-set))
111 (signal-nodb-error database))
112 (:documentation "Dumps the received result-set."))
114 (defgeneric database-store-next-row (result-set database list)
115 (:method (result-set (database closed-database) list)
116 (declare (ignore result-set list))
117 (signal-closed-database-error database))
118 (:method (result-set (database t) list)
119 (declare (ignore result-set list))
120 (signal-nodb-error database))
122 "Returns t and stores the next row in the result set in list or
123 returns nil when result-set is finished."))
126 ;; Interfaces to support UncommonSQL
128 (defgeneric database-create-sequence (name database)
129 (:documentation "Create a sequence in DATABASE."))
131 (defgeneric database-drop-sequence (name database)
132 (:documentation "Drop a sequence from DATABASE."))
134 (defgeneric database-sequence-next (name database)
135 (:documentation "Increment a sequence in DATABASE."))
137 (defgeneric database-start-transaction (database)
138 (:documentation "Start a transaction in DATABASE."))
140 (defgeneric database-commit-transaction (database)
141 (:documentation "Commit current transaction in DATABASE."))
143 (defgeneric database-abort-transaction (database)
144 (:documentation "Abort current transaction in DATABASE."))
146 (defgeneric database-get-type-specifier (type args database)
147 (:documentation "Return the type SQL type specifier as a string, for
148 the given lisp type and parameters."))
150 (defgeneric database-list-tables (database &key system-tables)
151 (:documentation "List all tables in the given database"))
153 (defgeneric database-list-attributes (table database)
154 (:documentation "List all attributes in TABLE."))
156 (defgeneric database-attribute-type (attribute table database)
157 (:documentation "Return the type of ATTRIBUTE in TABLE."))
159 (defgeneric database-add-attribute (table attribute database)
160 (:documentation "Add the attribute to the table."))
162 (defgeneric database-rename-attribute (table oldatt newname database)
163 (:documentation "Rename the attribute in the table to NEWNAME."))
165 (defgeneric oid (object)
166 (:documentation "Return the unique ID of a database object."))
169 ;;; Large objects support (Marc Battyani)
171 (defgeneric database-create-large-object (database)
172 (:documentation "Creates a new large object in the database and returns the object identifier"))
174 (defgeneric database-write-large-object (object-id data database)
175 (:documentation "Writes data to the large object"))
177 (defgeneric database-read-large-object (object-id database)
178 (:documentation "Reads the large object content"))
180 (defgeneric database-delete-large-object (object-id database)
181 (:documentation "Deletes the large object in the database"))