]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
- fix to the initial checkfirst for tables to take current schema into account [ticke...
authorMike Bayer <mike_mp@zzzcomputing.com>
Wed, 17 Jan 2007 18:47:36 +0000 (18:47 +0000)
committerMike Bayer <mike_mp@zzzcomputing.com>
Wed, 17 Jan 2007 18:47:36 +0000 (18:47 +0000)
CHANGES
lib/sqlalchemy/databases/postgres.py

diff --git a/CHANGES b/CHANGES
index 97710b56cf1904a7010c01eb0b1b7350e484a960..0dc9411c840514386cdb9ad99a2e2482b96fe347 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -23,6 +23,7 @@
   - added an NVarchar type (produces NVARCHAR), also MSUnicode which provides Unicode-translation
   for the NVarchar regardless of dialect convert_unicode setting.
 - postgres:
+  - fix to the initial checkfirst for tables to take current schema into account [ticket:424]
   - postgres has an optional "server_side_cursors=True" flag which will utilize
     server side cursors.  these are appropriate for fetching only partial results 
     and are necessary for working with very large unbounded result sets.
index 94519a5acc1785578da470f9120aa754cb8f157f..6f22113b6b11219b39203635a7fff585de4f643d 100644 (file)
@@ -298,9 +298,12 @@ class PGDialect(ansisql.ANSIDialect):
     def dbapi(self):
         return self.module
 
-    def has_table(self, connection, table_name):
-        # TODO: why are we case folding here ?
-        cursor = connection.execute("""select relname from pg_class where lower(relname) = %(name)s""", {'name':table_name.lower()})
+    def has_table(self, connection, table_name, schema=None):
+        # seems like case gets folded in pg_class...
+        if schema is None:
+            cursor = connection.execute("""select relname from pg_class c join pg_namespace n on n.oid=c.relnamespace where n.nspname=current_schema() and relname=%(name)s""", {'name':table_name.lower()});
+        else:
+            cursor = connection.execute("""select relname from pg_class c join pg_namespace n on n.oid=c.relnamespace where n.nspname=%(schema)s and relname=%(name)s""", {'name':table_name.lower(), 'schema':schema});
         return bool( not not cursor.rowcount )
 
     def has_sequence(self, connection, sequence_name):