# HG changeset patch # User catherine@cordelia # Date 1208201523 14400 # Node ID 13edc2731d6b7beb8bf5bc882d60dfafcea13036 # Parent e5054588bf9bafb17b31c810a800bafc428d6fe7 begin, declare diff -r e5054588bf9b -r 13edc2731d6b sqlpyPlus.py --- a/sqlpyPlus.py Mon Apr 07 09:56:25 2008 -0400 +++ b/sqlpyPlus.py Mon Apr 14 15:32:03 2008 -0400 @@ -327,6 +327,7 @@ pipeSeparator = Parser(pyparsing.SkipTo((pyparsing.Literal('|') ^ pyparsing.StringEnd()), include=True), retainSeparator=False) bindScanner = Parser(pyparsing.Literal(':') + pyparsing.Word( pyparsing.alphanums + "_$#" )) commandSeparator = Parser(pyparsing.SkipTo((pyparsing.Literal(';') ^ pyparsing.StringEnd()), include=True)) +anonBlockScanner = Parser(pyparsing.SkipTo(pyparsing.CaselessKeyword('END'))) def findBinds(target, existingBinds, givenBindVars = {}): result = givenBindVars @@ -766,6 +767,32 @@ else: self.default('exec %s' % arg) + def anonBlockDone(self, statement): + try: + p = anonBlockScanner.scanner.parseString(statement) + s = 1 + except pyparsing.ParseException: + return False + return True + + def anon_plsql(self, line1): + lines = [line1] + while True: + line = self.pseudo_raw_input(self.continuationPrompt) + if line.strip() == '/': + try: + self.curs.execute('\n'.join(lines)) + except Exception, e: + print e + return + lines.append(line) + + def do_begin(self, arg): + self.anon_plsql('begin ' + arg) + + def do_declare(self, arg): + self.anon_plsql('declare ' + arg) + def do_cat(self, arg): targets = arg.split() for target in targets: