From 91a4807b887ad6e8b92dcd83a18c39d0be4d38e5 Mon Sep 17 00:00:00 2001 From: "Kevin M. Rosenberg" Date: Sat, 12 Aug 2006 21:19:22 +0000 Subject: [PATCH] r11018: 12 Aug 2006 Kevin Rosenberg * 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 | 7 +++++++ debian/changelog | 6 ++++++ sql/generic-postgresql.lisp | 24 ++++++++++++++++++------ 3 files changed, 31 insertions(+), 6 deletions(-) diff --git a/ChangeLog b/ChangeLog index c7394da..b5c8ae6 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +12 Aug 2006 Kevin Rosenberg + * 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 * Version 3.6.4 * clsql.asd: Add support for c:\etc\clsql-init.lisp as possible diff --git a/debian/changelog b/debian/changelog index 6719c0f..6a23526 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,3 +1,9 @@ +cl-sql (3.6.5-1) unstable; urgency=low + + * New upstream + + -- Kevin M. Rosenberg Sat, 12 Aug 2006 15:18:47 -0600 + cl-sql (3.6.4-1) unstable; urgency=low * New upstream diff --git a/sql/generic-postgresql.lisp b/sql/generic-postgresql.lisp index 4958eaa..6843d72 100644 --- a/sql/generic-postgresql.lisp +++ b/sql/generic-postgresql.lisp @@ -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.")) @@ -73,15 +73,27 @@ (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 -- 2.34.1