changeset 506:5d9dddc289e1

ls beginning to work on postgresql
author catherine.devlin@gmail.com
date Wed, 22 Sep 2010 18:10:05 -0400
parents d37f38652a76
children fcaf28842db7
files sqlpython/connections.py
diffstat 1 files changed, 19 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/sqlpython/connections.py	Wed Sep 22 17:43:07 2010 -0400
+++ b/sqlpython/connections.py	Wed Sep 22 18:10:05 2010 -0400
@@ -200,7 +200,7 @@
         replacements = {'name1_comparitor': self.comparitor(names[0]),
                         'name2_comparitor': self.comparitor(names[1]),
                         'object_type_comparitor': self.comparitor(object_type),
-                        'sort_order': 'ASC',
+                        'sort': 'ASC',
                         'all': '1 = 0'}
         if hasattr(opts, 'reverse') and opts.reverse:
             replacements['sort'] = 'DESC'
@@ -310,13 +310,25 @@
     def bindVariables(self, binds):
         'Puts a tuple of (name, value) pairs into the bind format desired by psycopg2'
         return dict((b[0], b[1].lower()) for b in binds)
-    all_object_qry = """SELECT a.rolname, t.typname, c.relname
+    all_object_qry = """SELECT * FROM (
+                        SELECT a.rolname AS owner, 
+                               CASE c.relkind
+                               WHEN 'r' THEN 'table'
+                               WHEN 'i' THEN 'index'
+                               WHEN 's' THEN 'sequence'
+                               WHEN 'v' THEN 'view'
+                               WHEN 'c' THEN 'composite type'
+                               WHEN 't' THEN 'toast table'
+                               END AS object_type, 
+                               c.relname AS object_name, 
+                               NULL AS synonym_name
                         FROM   pg_authid a
                         JOIN   pg_class c ON (a.oid = c.relowner)
-                        JOIN   pg_type t ON (c.reltype = t.oid)
-                        WHERE  t.typname %(object_type_comparitor)s %%(object_type)s
-                        AND    a.rolname = %%(schema)s
-                        AND    c.relname %(name1_comparitor)s %%(name1)s"""
+                        WHERE  a.rolname = %%(schema)s
+                        AND    c.relname %(name1_comparitor)s %%(name1)s 
+                        ) subq
+                        WHERE  object_type %(object_type_comparitor)s %%(object_type)s
+                        ORDER BY object_type, owner, object_name %(sort)s"""
     column_qry = """SELECT c.table_schema, t.table_type, c.table_name, c.column_name      
                     FROM   information_schema.columns c
                     JOIN   information_schema.tables t ON (c.table_schema = t.table_schema
@@ -399,7 +411,7 @@
                         AND    ao.object_type %(object_type_comparitor)s :object_type
                         AND    asyn.synonym_name %(name2_comparitor)s :name2
                         AND    asyn.owner %(name1_comparitor)s :name1
-                        ) ORDER BY object_type, owner, object_name ASC"""
+                        ) ORDER BY object_type, owner, object_name %(sort)s"""
     column_qry = """SELECT atc.owner, ao.object_type, atc.table_name, atc.column_name      
                     FROM   all_tab_columns atc
                     JOIN   all_objects ao ON (atc.table_name = ao.object_name AND atc.owner = ao.owner)