r11018: 12 Aug 2006 Kevin Rosenberg <kevin@rosenberg.net>
authorKevin M. Rosenberg <kevin@rosenberg.net>
Sat, 12 Aug 2006 21:19:22 +0000 (21:19 +0000)
committerKevin M. Rosenberg <kevin@rosenberg.net>
Sat, 12 Aug 2006 21:19:22 +0000 (21:19 +0000)
        * Version 3.6.5
        * sql/generic-postgresql.lisp: Add slot for has-table-pg_roles to
        lazily cache if pg_roles tables exist. Selectively use SQL from
        Joel's previous patch if pg_roles table exists. Should now work
        with both postgresql 7.4 and 8.x.

ChangeLog
debian/changelog
sql/generic-postgresql.lisp

index c7394da352976a4e822863479565178675269097..b5c8ae6191c4019b2abd598ee8d89bffee162227 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+12 Aug 2006  Kevin Rosenberg <kevin@rosenberg.net>
+       * Version 3.6.5
+       * sql/generic-postgresql.lisp: Add slot for has-table-pg_roles to
+       lazily cache if pg_roles tables exist. Selectively use SQL from
+       Joel's previous patch if pg_roles table exists. Should now work
+       with both postgresql 7.4 and 8.x.
+       
 12 Aug 2006  Kevin Rosenberg <kevin@rosenberg.net>
        * Version 3.6.4
        * clsql.asd: Add support for c:\etc\clsql-init.lisp as possible
index 6719c0f572567d628745846cc3555453a5a11107..6a2352615f6dd2a9bdc61dc92eb041c7ff96d6f5 100644 (file)
@@ -1,3 +1,9 @@
+cl-sql (3.6.5-1) unstable; urgency=low
+
+  * New upstream
+
+ -- Kevin M. Rosenberg <kmr@debian.org>  Sat, 12 Aug 2006 15:18:47 -0600
+
 cl-sql (3.6.4-1) unstable; urgency=low
 
   * New upstream
index 4958eaa72b74eb9effd8e3bd693850efdacccf3b..6843d7202c57af35b3a5dc5882e0909112c8e3b9 100644 (file)
@@ -15,7 +15,7 @@
 (in-package #:clsql-sys)
 
 (defclass generic-postgresql-database (database)
-  ()
+  ((has-table-pg_roles :type boolean :reader has-table-pg_roles :initform nil))
   (:documentation "Encapsulate same behavior across postgresql and postgresql-socket backends."))
 
 
     (format nil " AND (NOT (relowner=1))"))
    (t "")))
 
+(defun has-table (name database)
+  (let ((name-retrieved
+         (caar (database-query
+                (format nil "SELECT relname FROM pg_class WHERE relname='~A'"
+                        name)
+                database nil nil))))
+    (if (and (stringp name-retrieved) (plusp (length name-retrieved)))
+        t
+        nil)))
+
+(defmethod slot-unbound (class (obj generic-postgresql-database)
+                         (slot (eql 'has-table-pg_roles)))
+  ;; Lazily cache slot value
+  (setf (slot-value obj 'has-table-pg_roles) (has-table "pg_roles" obj)))
+
 (defun database-list-objects-of-type (database type owner)
   (mapcar #'car
          (database-query
           (format nil
-                  "SELECT relname FROM pg_class WHERE (relkind = '~A')~A"
-                   #+nil
-                   (if (not (eq owner :all))
-                       ;; The below query fails on versions of postgresql
-                       ;; (such as 7.4) that lack the pg_roles table
+                   (if (and (has-table-pg_roles database)
+                            (not (eq owner :all)))
                        "
  SELECT c.relname
  FROM pg_catalog.pg_class c