comparison sqlpyPlus.py @ 71:7bb52cc35332

before reworking setbind
author catherine@cordelia
date Mon, 14 Apr 2008 15:56:59 -0400
parents 13edc2731d6b
children db0e1ff5e407
comparison
equal deleted inserted replaced
70:13edc2731d6b 71:7bb52cc35332
325 return itms 325 return itms
326 326
327 pipeSeparator = Parser(pyparsing.SkipTo((pyparsing.Literal('|') ^ pyparsing.StringEnd()), include=True), retainSeparator=False) 327 pipeSeparator = Parser(pyparsing.SkipTo((pyparsing.Literal('|') ^ pyparsing.StringEnd()), include=True), retainSeparator=False)
328 bindScanner = Parser(pyparsing.Literal(':') + pyparsing.Word( pyparsing.alphanums + "_$#" )) 328 bindScanner = Parser(pyparsing.Literal(':') + pyparsing.Word( pyparsing.alphanums + "_$#" ))
329 commandSeparator = Parser(pyparsing.SkipTo((pyparsing.Literal(';') ^ pyparsing.StringEnd()), include=True)) 329 commandSeparator = Parser(pyparsing.SkipTo((pyparsing.Literal(';') ^ pyparsing.StringEnd()), include=True))
330 anonBlockScanner = Parser(pyparsing.SkipTo(pyparsing.CaselessKeyword('END')))
331 330
332 def findBinds(target, existingBinds, givenBindVars = {}): 331 def findBinds(target, existingBinds, givenBindVars = {}):
333 result = givenBindVars 332 result = givenBindVars
334 for finding, startat, endat in bindScanner.scanner.scanString(target): 333 for finding, startat, endat in bindScanner.scanner.scanString(target):
335 varname = finding[1] 334 varname = finding[1]
755 except KeyError, e: 754 except KeyError, e:
756 print noSuchBindMsg % args[0] 755 print noSuchBindMsg % args[0]
757 elif len(args) > 2 and args[1] in ('=',':='): 756 elif len(args) > 2 and args[1] in ('=',':='):
758 var, val = args[0], args[2] 757 var, val = args[0], args[2]
759 if val[0] == val[-1] == "'" and len(val) > 1: 758 if val[0] == val[-1] == "'" and len(val) > 1:
760 val = val[1:-1] 759 val = val[1:-1] # stripping quotes; is that wise?
761 self.binds[var] = val 760 self.binds[var] = val # but what if val is a function call?
762 else: 761 else:
763 print 'Could not parse ', args 762 print 'Could not parse ', args
763
764 def do_exec(self, arg): 764 def do_exec(self, arg):
765 if arg[0] == ':': 765 if arg[0] == ':':
766 self.do_setbind(arg[1:]) 766 self.do_setbind(arg[1:])
767 else: 767 else:
768 self.default('exec %s' % arg) 768 try:
769 769 self.curs.execute('begin\n%s;end;' % arg)
770 def anonBlockDone(self, statement): 770 except Exception, e:
771 try: 771 print e
772 p = anonBlockScanner.scanner.parseString(statement) 772 '''
773 s = 1 773 exec :x := 'box'
774 except pyparsing.ParseException: 774 exec :y := sysdate
775 return False 775 '''
776 return True 776
777
778 def anon_plsql(self, line1): 777 def anon_plsql(self, line1):
779 lines = [line1] 778 lines = [line1]
780 while True: 779 while True:
781 line = self.pseudo_raw_input(self.continuationPrompt) 780 line = self.pseudo_raw_input(self.continuationPrompt)
782 if line.strip() == '/': 781 if line.strip() == '/':