changeset 374:05758f4bcac1

bugfixes in setbind
author catherine@DellZilla
date Tue, 11 Aug 2009 14:53:29 -0400
parents 2fd766784ff2
children 9d0a3ab7f573 c0df8426dcbd
files sqlpython/sqlpyPlus.py sqlpython/sqlpython.py
diffstat 2 files changed, 15 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- 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()
--- 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):