# HG changeset patch # User catherine@DellZilla # Date 1250016809 14400 # Node ID 05758f4bcac1473c5ee93e9b7b0f96713ac17f9f # Parent 2fd766784ff260bb8be9b0b58d5bfd33c43f6fcb bugfixes in setbind diff -r 2fd766784ff2 -r 05758f4bcac1 sqlpython/sqlpyPlus.py --- a/sqlpython/sqlpyPlus.py Tue Aug 11 10:14:27 2009 -0400 +++ b/sqlpython/sqlpyPlus.py Tue Aug 11 14:53:29 2009 -0400 @@ -1274,14 +1274,24 @@ assignmentSplitter = re.compile(':?=') def interpret_variable_assignment(self, arg): ''' - Accepts strings like `foo = 'bar'` or `baz := 22`, returning Python - variables as appropriate + Accepts strings like `foo = 'bar'` or `baz := 22`, + returns (assigned? (T/F), variable, new-value) + + >>> s = sqlpyPlus() + >>> s.interpret_variable_assignment(s.parsed("foo = 'bar'")) + (True, 'foo', 'bar') + >>> s.interpret_variable_assignment(s.parsed("baz := 22")) + (True, 'baz', 22) + >>> s.interpret_variable_assignment(s.parsed("foo")) + (False, 'foo', None) ''' + arg = self.parsed(arg) try: var, val = self.assignmentSplitter.split(arg.parsed.expanded, maxsplit=1) except ValueError: - return False, arg.parsed.expanded.split()[0] or None, None + return False, arg.parsed.expanded.split()[-1] or None, None var = var.split()[-1] + val = val.strip() if (len(val) > 1) and ((val[0] == val[-1] == "'") or (val[0] == val[-1] == '"')): return True, var, val[1:-1] try: @@ -1326,7 +1336,7 @@ def do_exec(self, arg): if arg.startswith(':'): - self.do_setbind(arg[1:]) + self.do_setbind(arg.parsed.expanded.split(':',1)[1]) else: varsUsed = self.findBinds(arg, {}) try: @@ -1559,6 +1569,3 @@ if __name__ == "__main__": "Silent return implies that all unit tests succeeded. Use -v to see details." _test() -if __name__ == "__main__": - "Silent return implies that all unit tests succeeded. Use -v to see details." - _test() diff -r 2fd766784ff2 -r 05758f4bcac1 sqlpython/sqlpython.py --- a/sqlpython/sqlpython.py Tue Aug 11 10:14:27 2009 -0400 +++ b/sqlpython/sqlpython.py Tue Aug 11 14:53:29 2009 -0400 @@ -9,7 +9,7 @@ # See also http://twiki.cern.ch/twiki/bin/view/PSSGroup/SqlPython import cmd2,getpass,binascii,cx_Oracle,re,os -import sqlpyPlus, sqlalchemy, pyparsing +import sqlalchemy, pyparsing __version__ = '1.6.7' class Parser(object):