1 ;;;; -*- Mode: LISP; Syntax: ANSI-Common-Lisp; Base: 10 -*-
2 ;;;; *************************************************************************
3 ;;;; FILE IDENTIFICATION
5 ;;;; Name: functional.lisp
6 ;;;; Purpose: Functional interface
8 ;;;; Copyright (c) 1999-2001 Pierre R. Mai
12 ;;;; This file is part of CLSQL.
14 ;;;; CLSQL users are granted the rights to distribute and use this software
15 ;;;; as governed by the terms of the Lisp Lesser GNU Public License
16 ;;;; (http://opensource.franz.com/preamble.html), also known as the LLGPL.
17 ;;;; *************************************************************************
19 (in-package #:clsql-classic-sys)
22 ;;; This file implements the more advanced functions of the
23 ;;; functional SQL interface, which are just nicer layers above the
24 ;;; basic SQL interface.
26 ;;; With the integration of CLSQL-USQL, these functions are no
27 ;;; longer exported by the CLSQL package since they conflict with names
28 ;;; exported by CLSQL-USQL
31 (&key into attributes values av-pairs query (database *default-database*))
32 "Insert records into the given table according to the given options."
34 ((and av-pairs (or attributes values))
35 (error "Supply either av-pairs or values (and possibly attributes) to call of insert-records."))
36 ((and (or av-pairs values) query)
38 "Supply either query or values/av-pairs to call of insert-records."))
39 ((and attributes (not query)
40 (or (not (listp values)) (/= (length attributes) (length values))))
41 (error "You must supply a matching values list when using attributes in call of insert-records."))
44 (format nil "insert into ~A ~@[(~{~A~^,~}) ~]~A" into attributes query)
48 (multiple-value-bind (attributes values)
50 (values (mapcar #'first av-pairs) (mapcar #'second av-pairs))
51 (values attributes values))
52 (format nil "insert into ~A ~@[(~{~A~^,~}) ~]values (~{'~A'~^,~})"
53 into attributes values))
54 :database database))))
56 (defun delete-records (&key from where (database *default-database*))
57 "Delete the indicated records from the given database."
58 (execute-command (format nil "delete from ~A ~@[where ~A ~]" from where)
61 (defun update-records (table &key attributes values av-pairs where (database *default-database*))
62 "Update the specified records in the given database."
64 ((and av-pairs (or attributes values))
65 (error "Supply either av-pairs or values (and possibly attributes) to call of update-records."))
67 (or (not (listp values)) (/= (length attributes) (length values))))
68 (error "You must supply a matching values list when using attributes in call of update-records."))
69 ((or (and attributes (not values)) (and values (not attributes)))
70 (error "You must supply both values and attributes in call of update-records."))
73 (format nil "update ~A set ~:{~A = '~A'~:^, ~}~@[ where ~A~]"
76 (mapcar #'list attributes values))
78 :database database))))