r1696: *** 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.1 2002/03/29 07:42:10 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
25 (defgeneric database-type-load-foreign (database-type)
26   (:documentation
27    "The internal generic implementation of reload-database-types.")
28   (:method :after (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   (:documentation "Internal generic implementation of disconnect."))
52
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   (:documentation "Internal generic implementation of query."))
58
59
60 (defgeneric database-execute-command (sql-expression database)
61   (:method (sql-expression (database closed-database))
62            (declare (ignore sql-expression))
63            (signal-closed-database-error database))
64   (:documentation "Internal generic implementation of execute-command."))
65
66 ;;; Mapping and iteration
67 (defgeneric database-query-result-set
68     (query-expression database &key full-set types)
69   (:method (query-expression (database closed-database) &key full-set types)
70            (declare (ignore query-expression full-set types))
71            (signal-closed-database-error database)
72            (values nil nil nil))
73   (:documentation
74    "Internal generic implementation of query mapping.  Starts the
75 query specified by query-expression on the given database and returns
76 a result-set to be used with database-store-next-row and
77 database-dump-result-set to access the returned data.  The second
78 value is the number of columns in the result-set, if there are any.
79 If full-set is true, the number of rows in the result-set is returned
80 as a third value, if this is possible (otherwise nil is returned for
81 the third value).  This might have memory and resource usage
82 implications, since many databases will require the query to be
83 executed in full to answer this question.  If the query produced no
84 results then nil is returned for all values that would have been
85 returned otherwise.  If an error occurs during query execution, the
86 function should signal a clsql-sql-error."))
87
88 (defgeneric database-dump-result-set (result-set database)
89   (:method (result-set (database closed-database))
90            (declare (ignore result-set))
91            (signal-closed-database-error database))
92   (:documentation "Dumps the received result-set."))
93
94 (defgeneric database-store-next-row (result-set database list)
95   (:method (result-set (database closed-database) list)
96            (declare (ignore result-set list))
97            (signal-closed-database-error database))
98   (:documentation
99    "Returns t and stores the next row in the result set in list or
100 returns nil when result-set is finished."))