X-Git-Url: http://git.kpe.io/?a=blobdiff_plain;f=sql%2Ffddl.lisp;h=2c28ab2bc212884195c2059cc141cbf6d89f3023;hb=b06efa829274786139a8d410f09a0c3751b359e7;hp=6363f2618f9b3822c767dcf856db65a76ff78adb;hpb=e567409d9fff3f7231c2a0bb69b345e19de2b246;p=clsql.git diff --git a/sql/fddl.lisp b/sql/fddl.lisp index 6363f26..2c28ab2 100644 --- a/sql/fddl.lisp +++ b/sql/fddl.lisp @@ -1,8 +1,6 @@ ;;;; -*- Mode: LISP; Syntax: ANSI-Common-Lisp; Base: 10 -*- ;;;; ************************************************************************* ;;;; -;;;; $Id$ -;;;; ;;;; The CLSQL Functional Data Definition Language (FDDL) ;;;; including functions for schema manipulation. Currently supported ;;;; SQL objects include tables, views, indexes, attributes and @@ -23,8 +21,7 @@ (defun database-identifier (name database) (sql-escape (etypecase name ;; honor case of strings - (string name - #+nil (convert-to-db-default-case name database)) + (string name) (sql-ident (sql-output name database)) (symbol (sql-output name database))))) @@ -67,16 +64,13 @@ the table. CONSTRAINTS is a string representing an SQL table constraint expression or a list of such strings. With MySQL databases, if TRANSACTIONS is t an InnoDB table is created which supports transactions." - (let* ((table-name (etypecase name - (symbol (sql-expression :attribute name)) - (string (sql-expression :attribute name)) - (sql-ident name))) - (stmt (make-instance 'sql-create-table - :name table-name - :columns description - :modifiers constraints - :transactions transactions))) - (execute-command stmt :database database))) + (execute-command + (make-instance 'sql-create-table + :name name + :columns description + :modifiers constraints + :transactions transactions) + :database database)) (defun drop-table (name &key (if-does-not-exist :error) (database *default-database*) @@ -94,8 +88,12 @@ an error is signalled if IF-DOES-NOT-EXIST is :error." (:error t)) - ;; Fixme: move to clsql-oracle - (let ((expr (concatenate 'string "DROP TABLE " table-name))) + (let ((expr (etypecase name + ;; keep quotes for strings for mixed-case names + (string (format nil "DROP TABLE ~S" table-name)) + ((or symbol sql-ident) + (concatenate 'string "DROP TABLE " table-name))))) + ;; Fixme: move to clsql-oracle (when (and (find-package 'clsql-oracle) (eq :oracle (database-type database)) (eql 10 (slot-value database @@ -113,6 +111,13 @@ is a string denoting a user name, only tables owned by OWNER are listed. If OWNER is :all then all tables are listed." (database-list-tables database :owner owner)) +(defmethod %table-exists-p (name (database T) &key owner ) + (unless database (setf database *default-database*)) + (let ((name (database-identifier name database)) + (tables (list-tables :owner owner :database database))) + (when (member name tables :test #'string-equal) + t))) + (defun table-exists-p (name &key (owner nil) (database *default-database*)) "Tests for the existence of an SQL table called NAME in DATABASE which defaults to *DEFAULT-DATABASE*. OWNER is nil by default @@ -120,10 +125,7 @@ which means that only tables owned by users are examined. If OWNER is a string denoting a user name, only tables owned by OWNER are examined. If OWNER is :all then all tables are examined." - (when (member (database-identifier name database) - (list-tables :owner owner :database database) - :test #'string-equal) - t)) + (%table-exists-p name database :owner owner)) ;; Views @@ -433,7 +435,7 @@ sequences are examined." (defun set-sequence-position (name position &key (database *default-database*)) "Explicitly set the the position of the sequence called NAME in -DATABASE, which defaults to *DEFAULT-DATABSE*, to POSITION which +DATABASE, which defaults to *DEFAULT-DATABASE*, to POSITION which is returned." (database-set-sequence-position (database-identifier name database) position database))