Mercurial > sqlpython
changeset 429:76bf7f767c10
continuing connection transition
author | catherine@dellzilla |
---|---|
date | Mon, 25 Jan 2010 15:59:00 -0500 |
parents | 6cd30b785885 |
children | aa1a603740fe |
files | sqlpython/sqlpyPlus.py sqlpython/sqlpython.py |
diffstat | 2 files changed, 21 insertions(+), 8 deletions(-) [+] |
line wrap: on
line diff
--- a/sqlpython/sqlpyPlus.py Mon Jan 25 15:51:00 2010 -0500 +++ b/sqlpython/sqlpyPlus.py Mon Jan 25 15:59:00 2010 -0500 @@ -1517,12 +1517,12 @@ 'XML SCHEMA') def metadata(self): - username = self.conn.username + username = self.current_instance.username if self.rdbms == 'oracle': username = username.upper() elif self.rdbms == 'postgres': username = username.lower() - return (username, self.conn.schemas) + return (username, self.current_instance.schemas) def _to_sql_wildcards(self, original): return original.replace('*','%').replace('?','_')
--- a/sqlpython/sqlpython.py Mon Jan 25 15:51:00 2010 -0500 +++ b/sqlpython/sqlpython.py Mon Jan 25 15:59:00 2010 -0500 @@ -59,15 +59,15 @@ def no_instance(self): self.prompt = 'SQL.No_Connection> ' self.curs = None - self.conn = None + self.current_instance = None self.instance_number = None def make_instance_current(self, instance_number): db_instance = self.instances[instance_number] - self.prompt = conn.prompt - self.rdbms = conn.rdbms + self.prompt = db_instance.prompt + self.rdbms = db_instance.rdbms self.instance_number = instance_number - self.curs = conn.connection.cursor() + self.curs = db_instance.connection.cursor() self.current_instance = db_instance def list_instances(self): @@ -107,7 +107,20 @@ postgresql_connect_parser = pyparsing.Optional(legal_sql_word('db_name') + pyparsing.Optional(legal_sql_word('username'))) - + def successfully_connect_to_number(self, arg): + try: + instance_number = int(arg) + except ValueError: + return False + try: + self.make_instance_current(instance_number) + except IndexError: + self.list_instances() + return False + if (self.rdbms == 'oracle') and self.serveroutput: + self.curs.callproc('dbms_output.enable', []) + return True + @cmd2.options([cmd2.make_option('-a', '--add', action='store_true', help='add connection (keep current connection)'), cmd2.make_option('-c', '--close', action='store_true', @@ -152,7 +165,7 @@ except ValueError: self.instance_number = 0 db_instance.set_instance_number(self.instance_number) - self.instances[self.instance_number] = conn + self.instances[self.instance_number] = db_instance self.make_instance_current(self.instance_number) if (self.rdbms == 'oracle') and self.serveroutput: self.curs.callproc('dbms_output.enable', [])