1 ;;;; -*- Mode: LISP; Syntax: ANSI-Common-Lisp; Base: 10 -*-
2 ;;;; *************************************************************************
6 ;;;; Base SQL functions
8 ;;;; This file is part of CLSQL.
10 ;;;; CLSQL users are granted the rights to distribute and use this software
11 ;;;; as governed by the terms of the Lisp Lesser GNU Public License
12 ;;;; (http://opensource.franz.com/preamble.html), also known as the LLGPL.
13 ;;;; *************************************************************************
15 (in-package #:clsql-sys)
19 (defgeneric query (query-expression &key database result-types flatp field-names)
21 "Executes the SQL query expression QUERY-EXPRESSION, which may
22 be an SQL expression or a string, on the supplied DATABASE which
23 defaults to *DEFAULT-DATABASE*. RESULT-TYPES is a list of symbols
24 which specifies the lisp type for each field returned by
25 QUERY-EXPRESSION. If RESULT-TYPES is nil all results are returned
26 as strings whereas the default value of :auto means that the lisp
27 types are automatically computed for each field. FIELD-NAMES is t
28 by default which means that the second value returned is a list
29 of strings representing the columns selected by
30 QUERY-EXPRESSION. If FIELD-NAMES is nil, the list of column names
31 is not returned as a second value. FLATP has a default value of
32 nil which means that the results are returned as a list of
33 lists. If FLATP is t and only one result is returned for each
34 record selected by QUERY-EXPRESSION, the results are returned as
35 elements of a list."))
37 (defmethod query ((query-expression string) &key (database *default-database*)
38 (result-types :auto) (flatp nil) (field-names t))
39 (record-sql-command query-expression database)
40 (multiple-value-bind (rows names)
41 (database-query query-expression database result-types field-names)
42 (let ((result (if (and flatp (= 1 (length (car rows))))
45 (record-sql-result result database)
52 (defgeneric execute-command (expression &key database)
54 "Executes the SQL command EXPRESSION, which may be an SQL
55 expression or a string representing any SQL statement apart from
56 a query, on the supplied DATABASE which defaults to
57 *DEFAULT-DATABASE*."))
59 (defmethod execute-command ((sql-expression string)
60 &key (database *default-database*))
61 (record-sql-command sql-expression database)
62 (let ((res (database-execute-command sql-expression database)))
63 (record-sql-result res database))
66 ;;; Large objects support
68 (defun create-large-object (&key (database *default-database*))
69 "Creates a new large object in the database and returns the object identifier"
70 (database-create-large-object database))
72 (defun write-large-object (object-id data &key (database *default-database*))
73 "Writes data to the large object"
74 (database-write-large-object object-id data database))
76 (defun read-large-object (object-id &key (database *default-database*))
77 "Reads the large object content"
78 (database-read-large-object object-id database))
80 (defun delete-large-object (object-id &key (database *default-database*))
81 "Deletes the large object in the database"
82 (database-delete-large-object object-id database))