Mercurial > sqlpython
changeset 112:5e57765073f4
worked out terminator keeping
author | catherine@Elli.myhome.westell.com |
---|---|
date | Mon, 23 Jun 2008 20:52:27 -0400 |
parents | 289b0a472b65 |
children | d48034a42b26 |
files | sqlpyPlus.py |
diffstat | 1 files changed, 26 insertions(+), 10 deletions(-) [+] |
line wrap: on
line diff
--- a/sqlpyPlus.py Fri Jun 13 15:53:03 2008 -0400 +++ b/sqlpyPlus.py Mon Jun 23 20:52:27 2008 -0400 @@ -10,7 +10,7 @@ - SQL*Plus-style describe, spool - write sends query result directly to file - comments shows table and column comments - - compare ... to ... graphically compares results of two queries + - compare ... to ... grweaphically compares results of two queries - commands are case-insensitive Use 'help' within sqlpython for details. @@ -340,6 +340,7 @@ sqlpython.sqlpython.shortcuts.update({':': 'setbind', '\\': 'psql', '@': '_load'}) multilineCommands = '''select insert update delete tselect create drop alter'''.split() + terminatorKeepingCommands = ['select'] defaultFileName = 'afiedt.buf' def __init__(self): sqlpython.sqlpython.__init__(self) @@ -465,6 +466,21 @@ result.append('%s: %s' % (colname, itm)) return '\n'.join(result) + + rowlimit_pattern = pyparsing.Optional(pyparsing.Word(pyparsing.nums)) + terminators = [pyparsing.Literal(';') + rowlimit_pattern, + pyparsing.Literal('\\i') + rowlimit_pattern, + pyparsing.Literal('\\x') + rowlimit_pattern, + pyparsing.Literal('\\g') + rowlimit_pattern, + pyparsing.Literal('\\G') + rowlimit_pattern, + pyparsing.Literal('\\s') + rowlimit_pattern, + pyparsing.Literal('\\S') + rowlimit_pattern, + pyparsing.Literal('\\c') + rowlimit_pattern, + pyparsing.Literal('\\C') + rowlimit_pattern, + pyparsing.Literal('\\h') + rowlimit_pattern, + pyparsing.Literal('\\t') + rowlimit_pattern, + '\n\n' + ] tableNameFinder = re.compile(r'from\s+([\w$#_"]+)', re.IGNORECASE | re.MULTILINE | re.DOTALL) def output(self, outformat, rowlimit): self.tblname = self.tableNameFinder.search(self.curs.statement).group(1) @@ -505,13 +521,6 @@ statementEndPattern = re.compile(r'(.*)(;|\\[gGhtxicCsS])\s*(\d*)\s*$', re.DOTALL | re.MULTILINE) # what about quote-enclosed? - def findTerminator(self, statement): - m = self.statementEndPattern.search(statement) - if m: - return m.groups() - else: - return statement, None, None - legalOracle = re.compile('[a-zA-Z_$#]') def do_select(self, arg, bindVarsIn=None, override_terminator=None): @@ -526,10 +535,17 @@ """ bindVarsIn = bindVarsIn or {} self.query = 'select ' + arg - (self.query, terminator, rowlimit) = self.findTerminator(self.query) + terminator = self.commmand_terminator_finder(self.query) + if terminator: + (self.query, terminator, dummy) = terminator + else: + terminator = [';'] + if len(terminator) == 1: + terminator, rowlimit = terminator[0], 0 + else: + terminator, rowlimit = terminator[0], int(terminator[1]) if override_terminator: terminator = override_terminator - rowlimit = int(rowlimit or 0) try: self.varsUsed = findBinds(self.query, self.binds, bindVarsIn) self.curs.execute(self.query, self.varsUsed)