;;;; -*- Mode: LISP; Syntax: ANSI-Common-Lisp; Base: 10 -*-
-;;;; ======================================================================
-;;;; File: sql.lisp
-;;;; Updated: <04/04/2004 12:05:32 marcusp>
-;;;; ======================================================================
+;;;; *************************************************************************
;;;;
-;;;; Description ==========================================================
-;;;; ======================================================================
+;;;; $Id$
;;;;
;;;; The CLSQL Functional Data Manipulation Language (FDML).
;;;;
-;;;; ======================================================================
+;;;; This file is part of CLSQL.
+;;;;
+;;;; CLSQL users are granted the rights to distribute and use this software
+;;;; as governed by the terms of the Lisp Lesser GNU Public License
+;;;; (http://opensource.franz.com/preamble.html), also known as the LLGPL.
+;;;; *************************************************************************
(in-package #:clsql-sys)
-
;;; Basic operations on databases
(defmethod database-query-result-set ((expr %sql-expression) database
- &key full-set types)
+ &key full-set result-types)
(database-query-result-set (sql-output expr database) database
- :full-set full-set :types types))
+ :full-set full-set :result-types result-types))
(defmethod execute-command ((expr %sql-expression)
&key (database *default-database*))
(values))
-
(defmethod query ((expr %sql-expression) &key (database *default-database*)
(result-types nil) (flatp nil))
(query (sql-output expr database) :database database :flatp flatp
:result-types result-types))
+(defun truncate-database (database)
+ (unless (typep database 'database)
+ (clsql-base-sys::signal-no-database-error database))
+ (unless (is-database-open database)
+ (database-reconnect database))
+ (dolist (table (list-tables :database database))
+ (drop-table table :database database))
+ (dolist (index (list-indexes :database database))
+ (drop-index index :database database))
+ (dolist (seq (list-sequences :database database))
+ (drop-sequence seq :database database)))
+
(defun print-query (query-exp &key titles (formats t) (sizes t) (stream t)
(database *default-database*))
"The PRINT-QUERY function takes a symbolic SQL query expression and
(vals nil)
(av-pairs nil)
(subquery nil))
- (if (null into)
+ (unless into
(error 'clsql-sql-syntax-error :reason ":into keyword not supplied"))
- (let ((ins (make-instance 'sql-insert :into into)))
+ (let ((insert (make-instance 'sql-insert :into into)))
(with-slots (attributes values query)
- ins
+ insert
(cond ((and vals (not attrs) (not query) (not av-pairs))
(setf values vals))
((and vals attrs (not subquery) (not av-pairs))
(t
(error 'clsql-sql-syntax-error
:reason "bad or ambiguous keyword combination.")))
- ins)))
+ insert)))
(defun delete-records (&key (from nil)
(where nil)
(let ((stmt (make-instance 'sql-delete :from from :where where)))
(execute-command stmt :database database)))
-(defun update-records (table &key
- (attributes nil)
- (values nil)
- (av-pairs nil)
- (where nil)
- (database *default-database*))
+(defun update-records (table &key (attributes nil)
+ (values nil)
+ (av-pairs nil)
+ (where nil)
+ (database *default-database*))
"Changes the values of existing fields in TABLE with columns
specified by ATTRIBUTES and VALUES (or AV-PAIRS) where the WHERE
condition is true."
(declare (ignore database))
(db-timestring self))
+(defmethod database-output-sql ((self duration) database)
+ (declare (ignore database))
+ (format nil "'~a'" (duration-timestring self)))
+
(defmethod database-output-sql (thing database)
(if (or (null thing)
(eq 'null thing))
"No type conversion to SQL for ~A is defined for DB ~A."
:format-arguments (list (type-of thing) (type-of database)))))
+
(defmethod output-sql-hash-key ((arg vector) &optional database)
(list 'vector (map 'list (lambda (arg)
(or (output-sql-hash-key arg database)
(defmethod output-sql (expr &optional (database *default-database*))
(write-string (database-output-sql expr database) *sql-stream*)
- t)
+ (values))
(defmethod output-sql ((expr list) &optional (database *default-database*))
(if (null expr)
(write-char #\) *sql-stream*)))
t)
+(defmethod describe-table ((table sql-create-table)
+ &key (database *default-database*))
+ (database-describe-table
+ database
+ (string-downcase (symbol-name (slot-value table 'name)))))
+#+nil
+(defmethod add-storage-class ((self database) (class symbol) &key (sequence t))
+ (let ((tablename (view-table (find-class class))))
+ (unless (tablep tablename)
+ (create-view-from-class class)
+ (when sequence
+ (create-sequence-from-class class)))))
+