# HG changeset patch # User catherine.devlin@gmail.com # Date 1285191787 14400 # Node ID d37f38652a76c509cf8e524c09ae97e24ce14658 # Parent e86bd0457a8b38b985f460aae7c87587b8f768b6 allow oracle-style logon on non-oracle db diff -r e86bd0457a8b -r d37f38652a76 sqlpython/connections.py --- 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('(?Ppostgres|oracle|mysql|sqlite|mssql)://?(?P.*$)', re.IGNORECASE) + oracle_style_connection_parser = re.compile('(?P[^/\s@]*)(/(?P[^/\s@]*))?(@((?P[^/\s:]*)(:(?P\d{1,4}))?/)?(?P[^/\s:]*))?(\s+as\s+(?Psys(dba|oper)))?', + re.IGNORECASE) connection_parser = re.compile('((?P\S+)(\s+(?P\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