From: Russ Tyndall Date: Mon, 14 Dec 2009 23:04:27 +0000 (-0500) Subject: fixed bugs in the postgresql-socket3 backend with list-tables and table-exists-p... X-Git-Url: http://git.kpe.io/?a=commitdiff_plain;h=1b0508ae2a7b61334494d29571fcbb05825daf5e;p=clsql.git fixed bugs in the postgresql-socket3 backend with list-tables and table-exists-p, both of which were broken. This involved makeing a generic backend to table-exists-p --- diff --git a/db-postgresql-socket3/sql.lisp b/db-postgresql-socket3/sql.lisp index e251500..548d219 100644 --- a/db-postgresql-socket3/sql.lisp +++ b/db-postgresql-socket3/sql.lisp @@ -333,4 +333,22 @@ (defmethod read-sql-value (val (type (eql 'generalized-boolean)) (database postgresql-socket3-database) db-type) (declare (ignore database db-type)) - val) \ No newline at end of file + val) + +(defmethod clsql-sys::%table-exists-p (name (database postgresql-socket3-database) &key owner ) + (unless database (setf database *default-database*)) + (when (clsql:query (command-object "SELECT 1 FROM information_schema.tables WHERE table_name=$1 and ($2::text IS NULL or table_schema = $2::text)" + (list name owner)) + :flatp T + :database database) + T)) + +(defmethod database-list-tables ((database postgresql-socket3-database) &key owner) + (clsql:query (command-object " +SELECT $1::Text as table_name +UNION +SELECT table_name FROM information_schema.tables + WHERE ($1::Text IS NULL or table_schema = $1::text)" + (list (or owner :null))) + :flatp T + :database database)) diff --git a/sql/fddl.lisp b/sql/fddl.lisp index 47323c3..0770dc5 100644 --- a/sql/fddl.lisp +++ b/sql/fddl.lisp @@ -113,6 +113,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 +127,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