changeset 505:d37f38652a76

allow oracle-style logon on non-oracle db
author catherine.devlin@gmail.com
date Wed, 22 Sep 2010 17:43:07 -0400
parents e86bd0457a8b
children 5d9dddc289e1
files sqlpython/connections.py
diffstat 1 files changed, 12 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/sqlpython/connections.py	Wed Sep 22 15:24:27 2010 -0400
+++ b/sqlpython/connections.py	Wed Sep 22 17:43:07 2010 -0400
@@ -83,6 +83,8 @@
     database = None
     mode = 0
     connection_uri_parser = re.compile('(?P<rdbms>postgres|oracle|mysql|sqlite|mssql)://?(?P<connect_string>.*$)', re.IGNORECASE)    
+    oracle_style_connection_parser = re.compile('(?P<username>[^/\s@]*)(/(?P<password>[^/\s@]*))?(@((?P<hostname>[^/\s:]*)(:(?P<port>\d{1,4}))?/)?(?P<database>[^/\s:]*))?(\s+as\s+(?P<mode>sys(dba|oper)))?',
+                                     re.IGNORECASE)
     connection_parser = re.compile('((?P<database>\S+)(\s+(?P<username>\S+))?)?')    
     def __init__(self, arg, opts, default_rdbms = 'oracle'):
         'no docstring'
@@ -114,8 +116,10 @@
         self.default_rdbms = default_rdbms
         self.determine_rdbms()  # may be altered later as connect string is parsed
         if not self.parse_connect_uri(arg):
-            self.set_defaults()        
+            self.set_defaults()       
             connectargs = self.connection_parser.search(self.arg)
+            if '@' in connectargs.group('database'):
+                connectargs = OracleInstance.connection_parser.search(self.arg)
             if connectargs:
                 for param in ('username', 'password', 'database', 'port', 'hostname', 'mode'):
                     if hasattr(opts, param) and getattr(opts, param):
@@ -306,12 +310,13 @@
     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 table_schema, table_type, table_name
-                        FROM   information_schema.tables
-                        WHERE  ( (table_schema %(owner)s) OR (table_schema = 'public') )
-                        AND    table_type %(type)s
-                        AND    table_name %(name)s
-                        ORDER BY table_schema, table_type, table_name %(sort)s"""
+    all_object_qry = """SELECT a.rolname, t.typname, c.relname
+                        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"""
     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