r1698: *** empty log message ***
[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 
9 ;;;; Date Started:  Feb 2002
10 ;;;;
11 ;;;; $Id: db-interface.cl,v 1.3 2002/03/29 08:23:38 kevin Exp $
12 ;;;;
13 ;;;; This file, part of CLSQL, is Copyright (c) 2002 by Kevin M. Rosenberg
14 ;;;; and Copyright (c) 1999-2001 by Pierre R. Mai
15 ;;;;
16 ;;;; CLSQL users are granted the rights to distribute and use this software
17 ;;;; as governed by the terms of the Lisp Lesser GNU Public License
18 ;;;; (http://opensource.franz.com/preamble.html), also known as the LLGPL.
19 ;;;; *************************************************************************
20
21 (declaim (optimize (debug 3) (speed 3) (safety 1) (compilation-speed 0)))
22 (in-package :clsql-sys)
23
24 (defgeneric database-type-load-foreign (database-type)
25   (:documentation
26    "The internal generic implementation of reload-database-types.")
27   (:method :after (database-type)
28            (when (database-type-library-loaded database-type)
29              (pushnew database-type *loaded-database-types*))))
30
31 (defgeneric database-type-library-loaded (database-type)
32   (:documentation
33    "The internal generic implementation for checking if
34 database type library loaded successfully."))
35
36 (defgeneric database-initialize-database-type (database-type)
37   (:documentation
38    "The internal generic implementation of initialize-database-type."))
39
40 (defgeneric database-name-from-spec (connection-spec database-type)
41   (:documentation
42    "Returns the name of the database that would be created if connect
43 was called with the connection-spec."))
44
45 (defgeneric database-connect (connection-spec database-type)
46   (:documentation "Internal generic implementation of connect."))
47
48 (defgeneric database-disconnect (database)
49   (:method ((database closed-database))
50            (signal-closed-database-error database))
51   (:method ((database t))
52            (signal-nodb-error database))
53   (:documentation "Internal generic implementation of disconnect."))
54
55 (defgeneric database-query (query-expression database types)
56   (:method (query-expression (database closed-database) types)
57            (declare (ignore query-expression types))
58            (signal-closed-database-error database))  
59   (:method (query-expression (database t) types)
60            (declare (ignore query-expression types))
61            (signal-nodb-error database))
62   (:documentation "Internal generic implementation of query."))
63
64
65 (defgeneric database-execute-command (sql-expression database)
66   (:method (sql-expression (database closed-database))
67            (declare (ignore sql-expression))
68            (signal-closed-database-error database))
69   (:method (sql-expression (database t))
70            (declare (ignore sql-expression))
71            (signal-nodb-error database))
72   (:documentation "Internal generic implementation of execute-command."))
73
74 ;;; Mapping and iteration
75 (defgeneric database-query-result-set
76     (query-expression database &key full-set types)
77   (:method (query-expression (database closed-database) &key full-set types)
78            (declare (ignore query-expression full-set types))
79            (signal-closed-database-error database)
80            (values nil nil nil))
81   (:method (query-expression (database t) &key full-set types)
82            (declare (ignore query-expression full-set types))
83            (signal-nodb-error database)
84            (values nil nil nil))
85   (:documentation
86    "Internal generic implementation of query mapping.  Starts the
87 query specified by query-expression on the given database and returns
88 a result-set to be used with database-store-next-row and
89 database-dump-result-set to access the returned data.  The second
90 value is the number of columns in the result-set, if there are any.
91 If full-set is true, the number of rows in the result-set is returned
92 as a third value, if this is possible (otherwise nil is returned for
93 the third value).  This might have memory and resource usage
94 implications, since many databases will require the query to be
95 executed in full to answer this question.  If the query produced no
96 results then nil is returned for all values that would have been
97 returned otherwise.  If an error occurs during query execution, the
98 function should signal a clsql-sql-error."))
99
100 (defgeneric database-dump-result-set (result-set database)
101   (:method (result-set (database closed-database))
102            (declare (ignore result-set))
103            (signal-closed-database-error database))
104   (:method (result-set (database t))
105            (declare (ignore result-set))
106            (signal-nodb-error database))
107   (:documentation "Dumps the received result-set."))
108
109 (defgeneric database-store-next-row (result-set database list)
110   (:method (result-set (database closed-database) list)
111            (declare (ignore result-set list))
112            (signal-closed-database-error database))
113   (:method (result-set (database t) list)
114            (declare (ignore result-set list))
115            (signal-nodb-error database))
116   (:documentation
117    "Returns t and stores the next row in the result set in list or
118 returns nil when result-set is finished."))