Mercurial > sqlpython
comparison sqlpyPlus.py @ 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 | 5d3f0b9c01df |
comparison
equal
deleted
inserted
replaced
122:61e2a824b66b | 123:898ed97bec38 |
---|---|
342 defaultFileName = 'afiedt.buf' | 342 defaultFileName = 'afiedt.buf' |
343 def __init__(self): | 343 def __init__(self): |
344 sqlpython.sqlpython.__init__(self) | 344 sqlpython.sqlpython.__init__(self) |
345 self.binds = CaselessDict() | 345 self.binds = CaselessDict() |
346 self.sqlBuffer = [] | 346 self.sqlBuffer = [] |
347 self.settable = ['maxtselctrows', 'maxfetch', 'autobind', 'failover', 'timeout'] # settables must be lowercase | 347 self.settable = ['maxtselctrows', 'maxfetch', 'autobind', |
348 'failover', 'timeout', 'commit_on_exit'] # settables must be lowercase | |
348 self.stdoutBeforeSpool = sys.stdout | 349 self.stdoutBeforeSpool = sys.stdout |
349 self.spoolFile = None | 350 self.spoolFile = None |
350 self.autobind = False | 351 self.autobind = False |
351 self.failover = False | 352 self.failover = False |
352 def default(self, arg, do_everywhere=False): | 353 def default(self, arg, do_everywhere=False): |
838 except ValueError: | 839 except ValueError: |
839 try: | 840 try: |
840 self.binds[var] = float(val) | 841 self.binds[var] = float(val) |
841 return | 842 return |
842 except ValueError: | 843 except ValueError: |
843 try: | 844 statekeeper = Statekeeper(self, ('autobind',)) |
844 statekeeper = Statekeeper(self, ('autobind',)) | 845 self.autobind = True |
845 self.autobind = True | 846 self.do_select('%s AS %s FROM dual;' % (val, var)) |
846 self.do_select('%s AS %s FROM dual;' % (val, var)) | 847 statekeeper.restore() |
847 statekeeper.restore() | |
848 return | |
849 except: | |
850 pass | |
851 | |
852 print 'Could not parse' | |
853 | 848 |
854 def do_exec(self, arg): | 849 def do_exec(self, arg): |
855 if arg[0] == ':': | 850 if arg[0] == ':': |
856 self.do_setbind(arg[1:]) | 851 self.do_setbind(arg[1:]) |
857 else: | 852 else: |
858 arg = self.parsed(arg).statement | 853 arg = self.parsed(arg).unterminated |
859 varsUsed = findBinds(arg, self.binds, {}) | 854 varsUsed = findBinds(arg, self.binds, {}) |
860 try: | 855 try: |
861 # save autobind to state | |
862 # select varname from ... | |
863 # restore state | |
864 self.curs.execute('begin\n%s;end;' % arg, varsUsed) | 856 self.curs.execute('begin\n%s;end;' % arg, varsUsed) |
865 except Exception, e: | 857 except Exception, e: |
866 print e | 858 print e |
867 ''' | 859 |
868 exec :x := 'box' | 860 ''' |
869 exec :y := sysdate | |
870 ''' | |
871 | |
872 '''Works: | |
873 exec myproc() | |
874 begin | |
875 myproc(); | |
876 end; | |
877 | |
878 Fails: | 861 Fails: |
879 select n into :n from test; | 862 select n into :n from test;''' |
880 :d := sysdate | |
881 :n := myfunc()''' | |
882 | |
883 | |
884 | 863 |
885 def anon_plsql(self, line1): | 864 def anon_plsql(self, line1): |
886 lines = [line1] | 865 lines = [line1] |
887 while True: | 866 while True: |
888 line = self.pseudo_raw_input(self.continuationPrompt) | 867 line = self.pseudo_raw_input(self.continuationPrompt) |