Mercurial > sqlpython
changeset 123:898ed97bec38
fixed bug in setting parameters
author | catherine@Elli.myhome.westell.com |
---|---|
date | Wed, 30 Jul 2008 11:06:10 -0400 |
parents | 61e2a824b66b |
children | 2b42b7bc29cb |
files | sqlpyPlus.py sqlpython.py |
diffstat | 2 files changed, 16 insertions(+), 33 deletions(-) [+] |
line wrap: on
line diff
--- 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]
--- 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'''