r9119: Automated commit for Debian build of clsql upstream-version-2.9.2
[clsql.git] / sql / table.lisp
index 1a225de5d76a48a31a063dc1eda332b55811c2c4..d51960e3e06f617536bd167693d4ea9b3c5e4707 100644 (file)
@@ -1,18 +1,19 @@
 ;;;; -*- Mode: LISP; Syntax: ANSI-Common-Lisp; Base: 10 -*-
-;;;; ======================================================================
-;;;; File:    table.lisp
-;;;; Updated: <04/04/2004 12:05:03 marcusp>
-;;;; ======================================================================
+;;;; *************************************************************************
 ;;;;
-;;;; Description ==========================================================
-;;;; ======================================================================
+;;;; $Id$
 ;;;;
-;;;; The CLSQL-USQL Functional Data Definition Language (FDDL)
+;;;; The CLSQL Functional Data Definition Language (FDDL)
 ;;;; including functions for schema manipulation. Currently supported
 ;;;; SQL objects include tables, views, indexes, attributes and
 ;;;; sequences.
 ;;;;
-;;;; ======================================================================
+;;;; 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)
 
 
 ;; Tables 
 
-(defvar *table-schemas* (make-hash-table :test #'equal)
-  "Hash of schema name to table lists.")
-
 (defun create-table (name description &key (database *default-database*)
-                          (constraints nil))
+                          (constraints nil) (transactions t))
   "Create a table called NAME, in DATABASE which defaults to
 *DEFAULT-DATABASE*, containing the attributes in DESCRIPTION which is
 a list containing lists of attribute-name and type information pairs."
@@ -46,9 +44,8 @@ a list containing lists of attribute-name and type information pairs."
          (stmt (make-instance 'sql-create-table
                               :name table-name
                               :columns description
-                              :modifiers constraints)))
-    (pushnew table-name (gethash *default-schema* *table-schemas*)
-             :test #'equal)
+                              :modifiers constraints
+                             :transactions transactions)))
     (execute-command stmt :database database)))
 
 (defun drop-table (name &key (if-does-not-exist :error)
@@ -91,9 +88,6 @@ returned as a list of strings."
 
 ;; Views 
 
-(defvar *view-schemas* (make-hash-table :test #'equal)
-  "Hash of schema name to view lists.")
-
 (defun create-view (name &key as column-list (with-check-option nil)
                          (database *default-database*))
   "Creates a view called NAME using the AS query and the optional
@@ -110,7 +104,6 @@ is NIL. The default value of DATABASE is *DEFAULT-DATABASE*."
                               :column-list column-list
                               :query as
                               :with-check-option with-check-option)))
-    (pushnew view-name (gethash *default-schema* *view-schemas*) :test #'equal)
     (execute-command stmt :database database)))
 
 (defun drop-view (name &key (if-does-not-exist :error)
@@ -152,9 +145,6 @@ of strings."
 
 ;; Indexes 
 
-(defvar *index-schemas* (make-hash-table :test #'equal)
-  "Hash of schema name to index lists.")
-
 (defun create-index (name &key on (unique nil) attributes
                           (database *default-database*))
   "Creates an index called NAME on the table specified by ON. The
@@ -168,7 +158,6 @@ UNIQUE is nil. The default value of DATABASE is *DEFAULT-DATABASE*."
          (stmt (format nil "CREATE ~A INDEX ~A ON ~A (~{~A~^, ~})"
                        (if unique "UNIQUE" "")
                        index-name table-name attributes)))
-    (pushnew index-name (gethash *default-schema* *index-schemas*))
     (execute-command stmt :database database)))
 
 (defun drop-index (name &key (if-does-not-exist :error)
@@ -185,6 +174,8 @@ specification of a table to drop the index from."
        (unless (index-exists-p index-name :database database)
          (return-from drop-index)))
       (:error t))
+    (unless (db-type-use-column-on-drop-index? (database-underlying-type database))
+      (setq on nil))
     (execute-command (format nil "DROP INDEX ~A~A" index-name
                              (if (null on) ""
                                  (concatenate 'string " ON "
@@ -197,6 +188,15 @@ specification of a table to drop the index from."
 OWNER is a string, this denotes a username and only indexs owned by
 OWNER are considered. Index names are returned as a list of strings."
   (database-list-indexes database :owner owner))
+
+(defun list-table-indexes (table &key (owner nil)
+                                     (database *default-database*))
+  "List all indexes in DATABASE for a TABLE, which defaults to
+*default-database*. If OWNER is :all , all indexs are considered. If
+OWNER is a string, this denotes a username and only indexs owned by
+OWNER are considered. Index names are returned as a list of strings."
+  (database-list-table-indexes (database-identifier table)
+                              database :owner owner))
   
 (defun index-exists-p (name &key (owner nil) (database *default-database*))
   "Test for existence of an index called NAME in DATABASE which
@@ -261,16 +261,11 @@ is the vendor-specific type returned by ATTRIBUTE-TYPE."
 
 ;; Sequences 
 
-(defvar *sequence-schemas* (make-hash-table :test #'equal)
-  "Hash of schema name to sequence lists.")
-
 (defun create-sequence (name &key (database *default-database*))
   "Create a sequence called NAME in DATABASE which defaults to
 *DEFAULT-DATABASE*."
   (let ((sequence-name (database-identifier name)))
-    (database-create-sequence sequence-name database)
-    (pushnew sequence-name (gethash *default-schema* *sequence-schemas*)
-             :test #'equal))
+    (database-create-sequence sequence-name database))
   (values))
 
 (defun drop-sequence (name &key (if-does-not-exist :error)