# HG changeset patch # User catherine@Elli.myhome.westell.com # Date 1217430370 14400 # Node ID 898ed97bec38b7002c796cd53ec20d6e9c8c2b29 # Parent 61e2a824b66bf2ac658f9f66b1be285d4c98e256 fixed bug in setting parameters diff -r 61e2a824b66b -r 898ed97bec38 sqlpyPlus.py --- a/sqlpyPlus.py Wed Jul 30 10:35:16 2008 -0400 +++ b/sqlpyPlus.py Wed Jul 30 11:06:10 2008 -0400 @@ -344,7 +344,8 @@ sqlpython.sqlpython.__init__(self) self.binds = CaselessDict() self.sqlBuffer = [] - self.settable = ['maxtselctrows', 'maxfetch', 'autobind', 'failover', 'timeout'] # settables must be lowercase + self.settable = ['maxtselctrows', 'maxfetch', 'autobind', + 'failover', 'timeout', 'commit_on_exit'] # settables must be lowercase self.stdoutBeforeSpool = sys.stdout self.spoolFile = None self.autobind = False @@ -840,47 +841,25 @@ self.binds[var] = float(val) return except ValueError: - try: - statekeeper = Statekeeper(self, ('autobind',)) - self.autobind = True - self.do_select('%s AS %s FROM dual;' % (val, var)) - statekeeper.restore() - return - except: - pass - - print 'Could not parse' + statekeeper = Statekeeper(self, ('autobind',)) + self.autobind = True + self.do_select('%s AS %s FROM dual;' % (val, var)) + statekeeper.restore() def do_exec(self, arg): if arg[0] == ':': self.do_setbind(arg[1:]) else: - arg = self.parsed(arg).statement + arg = self.parsed(arg).unterminated varsUsed = findBinds(arg, self.binds, {}) try: - # save autobind to state - # select varname from ... - # restore state self.curs.execute('begin\n%s;end;' % arg, varsUsed) except Exception, e: print e - ''' - exec :x := 'box' - exec :y := sysdate - ''' - '''Works: - exec myproc() - begin - myproc(); - end; - + ''' Fails: - select n into :n from test; - :d := sysdate - :n := myfunc()''' - - + select n into :n from test;''' def anon_plsql(self, line1): lines = [line1] diff -r 61e2a824b66b -r 898ed97bec38 sqlpython.py --- a/sqlpython.py Wed Jul 30 10:35:16 2008 -0400 +++ b/sqlpython.py Wed Jul 30 11:06:10 2008 -0400 @@ -25,6 +25,7 @@ self.failoverSessions = [] self.terminator = ';' self.timeout = 30 + self.commit_on_exit = True connection_modes = {re.compile(' AS SYSDBA', re.IGNORECASE): cx_Oracle.SYSDBA, re.compile(' AS SYSOPER', re.IGNORECASE): cx_Oracle.SYSOPER} @@ -141,9 +142,12 @@ self.default('commit %s;' % (arg), do_everywhere=True) def do_rollback(self, arg): self.default('rollback %s;' % (arg), do_everywhere=True) - - # shortcuts - do_exit = cmd2.Cmd.do_quit + def do_quit(self, arg): + if self.commit_on_exit: + self.default('commit;') + cmd2.Cmd.do_quit() + do_exit = do_quit + do_q = do_quit def pmatrix(rows,desc,maxlen=30): '''prints a matrix, used by sqlpython to print queries' result sets'''