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.cl,v 1.5 2002/04/01 05:27:55 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-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-initialize-database-type (database-type)
36 "The internal generic implementation of initialize-database-type."))
38 (defgeneric database-name-from-spec (connection-spec database-type)
40 "Returns the name of the database that would be created if connect
41 was called with the connection-spec."))
43 (defgeneric database-connect (connection-spec database-type)
44 (:documentation "Internal generic implementation of connect."))
46 (defgeneric database-disconnect (database)
47 (:method ((database closed-database))
48 (signal-closed-database-error database))
49 (:method ((database t))
50 (signal-nodb-error database))
51 (:documentation "Internal generic implementation of disconnect."))
53 (defgeneric database-query (query-expression database types)
54 (:method (query-expression (database closed-database) types)
55 (declare (ignore query-expression types))
56 (signal-closed-database-error database))
57 (:method (query-expression (database t) types)
58 (declare (ignore query-expression types))
59 (signal-nodb-error database))
60 (:documentation "Internal generic implementation of query."))
63 (defgeneric database-execute-command (sql-expression database)
64 (:method (sql-expression (database closed-database))
65 (declare (ignore sql-expression))
66 (signal-closed-database-error database))
67 (:method (sql-expression (database t))
68 (declare (ignore sql-expression))
69 (signal-nodb-error database))
70 (:documentation "Internal generic implementation of execute-command."))
72 ;;; Mapping and iteration
73 (defgeneric database-query-result-set
74 (query-expression database &key full-set types)
75 (:method (query-expression (database closed-database) &key full-set types)
76 (declare (ignore query-expression full-set types))
77 (signal-closed-database-error database)
79 (:method (query-expression (database t) &key full-set types)
80 (declare (ignore query-expression full-set types))
81 (signal-nodb-error database)
84 "Internal generic implementation of query mapping. Starts the
85 query specified by query-expression on the given database and returns
86 a result-set to be used with database-store-next-row and
87 database-dump-result-set to access the returned data. The second
88 value is the number of columns in the result-set, if there are any.
89 If full-set is true, the number of rows in the result-set is returned
90 as a third value, if this is possible (otherwise nil is returned for
91 the third value). This might have memory and resource usage
92 implications, since many databases will require the query to be
93 executed in full to answer this question. If the query produced no
94 results then nil is returned for all values that would have been
95 returned otherwise. If an error occurs during query execution, the
96 function should signal a clsql-sql-error."))
98 (defgeneric database-dump-result-set (result-set database)
99 (:method (result-set (database closed-database))
100 (declare (ignore result-set))
101 (signal-closed-database-error database))
102 (:method (result-set (database t))
103 (declare (ignore result-set))
104 (signal-nodb-error database))
105 (:documentation "Dumps the received result-set."))
107 (defgeneric database-store-next-row (result-set database list)
108 (:method (result-set (database closed-database) list)
109 (declare (ignore result-set list))
110 (signal-closed-database-error database))
111 (:method (result-set (database t) list)
112 (declare (ignore result-set list))
113 (signal-nodb-error database))
115 "Returns t and stores the next row in the result set in list or
116 returns nil when result-set is finished."))
119 ;; Interfaces to support UncommonSQL
121 (defgeneric database-create-sequence (name database)
122 (:documentation "Create a sequence in DATABASE."))
124 (defgeneric database-drop-sequence (name database)
125 (:documentation "Drop a sequence from DATABASE."))
127 (defgeneric database-sequence-next (name database)
128 (:documentation "Increment a sequence in DATABASE."))
130 (defgeneric database-start-transaction (database)
131 (:documentation "Start a transaction in DATABASE."))
133 (defgeneric database-commit-transaction (database)
134 (:documentation "Commit current transaction in DATABASE."))
136 (defgeneric database-abort-transaction (database)
137 (:documentation "Abort current transaction in DATABASE."))
139 (defgeneric database-get-type-specifier (type args database)
140 (:documentation "Return the type SQL type specifier as a string, for
141 the given lisp type and parameters."))
143 (defgeneric database-list-tables (database &key (system-tables nil))
144 (:documentation "List all tables in the given database"))
146 (defgeneric database-list-attributes (table database)
147 (:documentation "List all attributes in TABLE."))
149 (defgeneric database-attribute-type (attribute table database)
150 (:documentation "Return the type of ATTRIBUTE in TABLE."))
152 (defgeneric database-add-attribute (table attribute database)
153 (:documentation "Add the attribute to the table."))
155 (defgeneric database-rename-attribute (table oldatt newname database)
156 (:documentation "Rename the attribute in the table to NEWNAME."))
158 (defgeneric oid (object)
159 (:documentation "Return the unique ID of a database object."))