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 "Execute the SQL query expression QUERY-EXPRESSION on the given
22 DATABASE which defaults to *default-database*. RESULT-TYPES is a list
23 of symbols such as :string and :integer, one for each field in the
24 query, which are used to specify the types to return. The FLATP
25 argument, which has a default value of nil, specifies if full
26 bracketed results should be returned for each matched entry. If FLATP
27 is nil, the results are returned as a list of lists. If FLATP is t,
28 the results are returned as elements of a list, only if there is only
29 one result per row. Returns a list of lists of values of the result of
30 that expression and a list of field names selected in sql-exp."))
32 (defmethod query ((query-expression string) &key (database *default-database*)
33 (result-types :auto) (flatp nil) (field-names t))
34 (record-sql-command query-expression database)
35 (multiple-value-bind (rows names) (database-query query-expression database result-types
37 (let ((result (if (and flatp (= 1 (length (car rows))))
40 (record-sql-result result database)
47 (defgeneric execute-command (expression &key database)
49 "Executes the SQL command specified by EXPRESSION for the database
50 specified by DATABASE, which has a default value of
51 *DEFAULT-DATABASE*. The argument EXPRESSION may be any SQL statement
52 other than a query. To run a stored procedure, pass an appropriate
53 string. The call to the procedure needs to be wrapped in a BEGIN END
56 (defmethod execute-command ((sql-expression string)
57 &key (database *default-database*))
58 (record-sql-command sql-expression database)
59 (let ((res (database-execute-command sql-expression database)))
60 (record-sql-result res database))
63 ;;; Large objects support
65 (defun create-large-object (&key (database *default-database*))
66 "Creates a new large object in the database and returns the object identifier"
67 (database-create-large-object database))
69 (defun write-large-object (object-id data &key (database *default-database*))
70 "Writes data to the large object"
71 (database-write-large-object object-id data database))
73 (defun read-large-object (object-id &key (database *default-database*))
74 "Reads the large object content"
75 (database-read-large-object object-id database))
77 (defun delete-large-object (object-id &key (database *default-database*))
78 "Deletes the large object in the database"
79 (database-delete-large-object object-id database))