Mercurial > sqlpython
changeset 257:6d4d90fb2082
dbms_output.put_line working
author | catherine@Elli.myhome.westell.com |
---|---|
date | Sat, 14 Mar 2009 21:49:34 -0400 |
parents | d09f16b71f66 |
children | a94fec8155da |
files | sqlpython/mysqlpy.py sqlpython/sqlpyPlus.py sqlpython/sqlpython.py |
diffstat | 3 files changed, 28 insertions(+), 12 deletions(-) [+] |
line wrap: on
line diff
--- a/sqlpython/mysqlpy.py Fri Mar 13 17:55:42 2009 -0400 +++ b/sqlpython/mysqlpy.py Sat Mar 14 21:49:34 2009 -0400 @@ -108,16 +108,7 @@ def do_hello(self, arg): print 'Hello, World!' - - @options([make_option('-u', '--uppercase', action='store_true', - help='use ALL CAPS')]) - def do_greet(self, arg, opts): - 'Provides a personalized greeting.' - result = 'Hello %s!\n' % arg - if opts.uppercase: - result = result.upper() - self.stdout.write(result) - + def do_db(self,args,filepath='pass.txt'): '''Exec do_connect to db_alias in args (credentials form the file pass.txt) ''' try:
--- a/sqlpython/sqlpyPlus.py Fri Mar 13 17:55:42 2009 -0400 +++ b/sqlpython/sqlpyPlus.py Sat Mar 14 21:49:34 2009 -0400 @@ -360,7 +360,7 @@ def __init__(self): sqlpython.sqlpython.__init__(self) self.binds = CaselessDict() - self.settable += 'autobind commit_on_exit maxfetch maxtselctrows sql_echo timeout heading wildsql'.split() + self.settable += 'autobind commit_on_exit maxfetch maxtselctrows serveroutput sql_echo timeout heading wildsql'.split() self.settable.remove('case_insensitive') self.settable.sort() self.stdoutBeforeSpool = sys.stdout @@ -369,7 +369,8 @@ self.autobind = False self.heading = True self.wildsql = False - + self.serveroutput = True + # overrides cmd's parseline def parseline(self, line): """Parse the line into a command name and a string containing @@ -386,6 +387,22 @@ return cmd, arg, line do__load = Cmd.do_load + + def dbms_output(self): + "Dumps contents of Oracle's DBMS_OUTPUT buffer (where PUT_LINE goes)" + line = self.curs.var(cx_Oracle.STRING) + status = self.curs.var(cx_Oracle.NUMBER) + self.curs.callproc('dbms_output.get_line', [line, status]) + while not status.getvalue(): + self.stdout.write(line.getvalue()) + self.stdout.write('\n') + self.curs.callproc('dbms_output.get_line', [line, status]) + + def postcmd(self, stop, line): + """Hook method executed just after a command dispatch is finished.""" + if self.serveroutput: + self.dbms_output() + return stop def do_remark(self, line): ''' @@ -418,6 +435,12 @@ stop = self.onecmd(line) stop = self.postcmd(stop, line) + def _onchange_serveroutput(self, old, new): + if new: + self.curs.callproc('dbms_output.enable', []) + else: + self.curs.callproc('dbms_output.disable', []) + def do_shortcuts(self,arg): """Lists available first-character shortcuts (i.e. '!dir' is equivalent to 'shell dir')"""
--- a/sqlpython/sqlpython.py Fri Mar 13 17:55:42 2009 -0400 +++ b/sqlpython/sqlpython.py Sat Mar 14 21:49:34 2009 -0400 @@ -66,6 +66,8 @@ self.prompt = '%s@%s> ' % (orauser, self.sid) except Exception, e: print e + if self.serveroutput: + self.curs.callproc('dbms_output.enable', []) do_host = cmd2.Cmd.do_shell