1 ;;;; -*- Mode: LISP; Syntax: ANSI-Common-Lisp; Base: 10 -*-
2 ;;;; *************************************************************************
3 ;;;; FILE IDENTIFICATION
5 ;;;; Name: functional.lisp
6 ;;;; Purpose: Functional interface
7 ;;;; Programmer: Pierre R. Mai
9 ;;;; Copyright (c) 1999-2001 Pierre R. Mai
13 ;;;; This file is part of CLSQL.
15 ;;;; CLSQL is free software; you can redistribute it and/or modify
16 ;;;; it under the terms of the GNU General Public License (version 2) as
17 ;;;; published by the Free Software Foundation.
19 ;;;; CLSQL is distributed in the hope that it will be useful,
20 ;;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
21 ;;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 ;;;; GNU General Public License for more details.
24 ;;;; You should have received a copy of the GNU General Public License
25 ;;;; along with CLSQL; if not, write to the Free Software Foundation, Inc.,
26 ;;;; 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
27 ;;;; *************************************************************************
29 (in-package #:clsql-sys)
32 ;;; This file implements the more advanced functions of the
33 ;;; functional SQL interface, which are just nicer layers above the
34 ;;; basic SQL interface.
36 ;;; With the integration of CLSQL-USQL, these functions are no
37 ;;; longer exported by the CLSQL package since they conflict with names
38 ;;; exported by CLSQL-USQL
41 (&key into attributes values av-pairs query (database *default-database*))
42 "Insert records into the given table according to the given options."
44 ((and av-pairs (or attributes values))
45 (error "Supply either av-pairs or values (and possibly attributes) to call of insert-records."))
46 ((and (or av-pairs values) query)
48 "Supply either query or values/av-pairs to call of insert-records."))
49 ((and attributes (not query)
50 (or (not (listp values)) (/= (length attributes) (length values))))
51 (error "You must supply a matching values list when using attributes in call of insert-records."))
54 (format nil "insert into ~A ~@[(~{~A~^,~}) ~]~A" into attributes query)
58 (multiple-value-bind (attributes values)
60 (values (mapcar #'first av-pairs) (mapcar #'second av-pairs))
61 (values attributes values))
62 (format nil "insert into ~A ~@[(~{~A~^,~}) ~]values (~{'~A'~^,~})"
63 into attributes values))
64 :database database))))
66 (defun delete-records (&key from where (database *default-database*))
67 "Delete the indicated records from the given database."
68 (execute-command (format nil "delete from ~A ~@[where ~A ~]" from where)
71 (defun update-records (table &key attributes values av-pairs where (database *default-database*))
72 "Update the specified records in the given database."
74 ((and av-pairs (or attributes values))
75 (error "Supply either av-pairs or values (and possibly attributes) to call of update-records."))
77 (or (not (listp values)) (/= (length attributes) (length values))))
78 (error "You must supply a matching values list when using attributes in call of update-records."))
79 ((or (and attributes (not values)) (and values (not attributes)))
80 (error "You must supply both values and attributes in call of update-records."))
83 (format nil "update ~A set ~:{~A = '~A'~:^, ~}~@[ where ~A~]"
86 (mapcar #'list attributes values))
88 :database database))))