changeset 492:1fff6f7bac1e

DatabaseInstance methods return cursors
author Catherine Devlin <catherine.devlin@gmail.com>
date Tue, 07 Sep 2010 19:19:42 -0400
parents d30471cc95ac
children 30e314597285
files sqlpython/connections.py
diffstat 1 files changed, 25 insertions(+), 20 deletions(-) [+]
line wrap: on
line diff
--- a/sqlpython/connections.py	Tue Sep 07 03:14:02 2010 -0400
+++ b/sqlpython/connections.py	Tue Sep 07 19:19:42 2010 -0400
@@ -56,6 +56,12 @@
                                 compiled.match(self.type + r'/') or
                                  compiled.match(self.unqualified_name) or
                                  compiled.match(self.unqualified_path))
+       
+class DBOjbect(object):
+    def __init__(self, schema, object_type, name):
+        self.schema = schema
+        self.type = object_type
+        self.name = name
         
 class OptionTestDummy(object):
     mysql = None
@@ -218,8 +224,9 @@
         clauses.append(sort_direction)
         qry = self.all_object_qry % tuple(clauses)
         binds = (('owner', identifier['owner']), ('type', identifier['type']), ('name', identifier['name']))
-        result = self.connection.cursor().execute(qry, self.bindVariables(binds)) 
-        return result
+        curs = self.connection.cursor()
+        curs.execute(qry, self.bindVariables(binds)) 
+        return curs
     def columns(self, target, opts):
         if opts.all:
             owner = '%'
@@ -228,8 +235,9 @@
         qry = self.column_qry % (self.comparison_operator(owner), self.bindSyntax('owner'),
                                  self.comparison_operator(target), self.bindSyntax('colname'))
         binds = (('owner', owner), ('colname', target))
-        result = self.connection.cursor().execute(qry, self.bindVariables(binds))
-        return result
+        curs = self.connection.cursor()
+        curs.execute(qry, self.bindVariables(binds))
+        return curs
     def source(self, target, opts):
         if opts.all:
             owner = '%'
@@ -238,8 +246,9 @@
         qry = self.source_qry % (self.comparison_operator(owner), self.bindSyntax('owner'),
                                                                   self.bindSyntax('target'))
         binds = (('owner', owner), ('target', target))
-        result = self.connection.cursor().execute(qry, self.bindVariables(binds))
-        return result
+        curs = self.connection.cursor()
+        curs.execute(qry, self.bindVariables(binds))
+        return curs
         
     gerald_types = {'TABLE': gerald.oracle_schema.Table,
                     'VIEW': gerald.oracle_schema.View}
@@ -313,30 +322,23 @@
         '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 table_schema, table_type, table_name
-                        FROM   
-                               ( SELECT table_schema, table_type, table_name
-                                 FROM   information_schema.tables
-                                 UNION ALL
-                                 SELECT table_schema, 'view', table_name
-                                 FROM   information_schema.views )
+                        FROM   information_schema.tables
                         WHERE  ( (table_schema %s) OR (table_schema = 'public') )
                         AND    table_type %s
                         AND    table_name %s
                         ORDER BY table_schema, table_type, table_name %s"""
-    column_qry = """SELECT c.table_schema, o.object_type, c.table_name, c.column_name      
+    column_qry = """SELECT c.table_schema, t.table_type, c.table_name, c.column_name      
                     FROM   information_schema.columns c
-                    JOIN   ( SELECT table_type AS object_type, table_schema, table_name
-                             FROM   information_schema.tables
-                             UNION ALL
-                             SELECT 'view' AS object_type, table_schema, table_name
-                             FROM   information_schema.views ) o ON (    c.table_schema = o.table_schema
-                                                                     AND c.table_name = o.table_name )
+                    JOIN   information_schema.tables t ON (c.table_schema = t.table_schema
+                                                           AND c.table_name = t.table_name)
                     WHERE  ( (c.table_schema %s %s) OR (c.table_schema = 'public'))
                     AND    c.column_name %s %s """
     source_qry = """SELECT owner, type, name, line, text
                     FROM   all_source
                     WHERE  owner %s %s
                     AND    UPPER(text) LIKE %s"""
+    gerald_types = {'BASE TABLE': gerald.postgres_schema.Table,
+                    'VIEW': gerald.postgres_schema.View}
 
 class OracleInstance(DatabaseInstance):
     rdbms = 'oracle'
@@ -394,7 +396,10 @@
     def bindVariables(self, binds):
         'Puts a tuple of (name, value) pairs into the bind format desired by cx_Oracle'
         return dict((b[0], b[1].upper()) for b in binds)
-                 
+    gerald_types = {'TABLE': gerald.oracle_schema.Table,
+                    'VIEW': gerald.postgres_schema.View}
+
+                
 if __name__ == '__main__':
     opts = OptionTestDummy(password='password')
     db = DatabaseInstance('oracle://system:twttatl@orcl', opts)