comparison sqlpyPlus.py @ 74:bfc81b9b99a7

sql setbinds partially done?
author catherine@cordelia
date Mon, 14 Apr 2008 16:56:44 -0400
parents bce8396ab625
children 2060f9e4b27b
comparison
equal deleted inserted replaced
73:bce8396ab625 74:bfc81b9b99a7
743 self.stdout.write('No bind variable %s\n' % arg) 743 self.stdout.write('No bind variable %s\n' % arg)
744 else: 744 else:
745 for (var, val) in self.binds.items(): 745 for (var, val) in self.binds.items():
746 print ':%s = %s' % (var, val) 746 print ':%s = %s' % (var, val)
747 747
748 # keep bind vars in sync on both sides?
749
750 def push_binds(self):
751 commands = [":%s := '%s'" for b in self.binds.items()]
752 curs.execute('begin\n%s\nend;' % '\n'.join(commands))
753 def pull_binds(self):
754 i DON'T THINK THIS WILL WORK!
755
756
748 def do_setbind(self, arg): 757 def do_setbind(self, arg):
749 args = arg.split(None, 2) 758 args = arg.split(None, 2)
750 if len(args) < 2: 759 if len(args) < 2:
751 self.do_print(arg) 760 self.do_print(arg)
752 elif len(args) > 2 and args[1] in ('=',':='): 761 elif len(args) > 2 and args[1] in ('=',':='):
753 var, val = args[0], args[2] 762 var, val = args[0], args[2]
754 if val[0] == val[-1] == "'" and len(val) > 1: 763 if val[0] == val[-1] == "'" and len(val) > 1:
755 val = val[1:-1] # stripping quotes; is that wise? 764 val = val[1:-1]
765 try:
766 val = int(val)
767 except ValueError:
768 try:
769 val = float(val)
770 except ValueError:
771 val = self.curs.callfunc(val, [])
772 # submit to sql
756 self.binds[var] = val # but what if val is a function call? 773 self.binds[var] = val # but what if val is a function call?
757 else: 774 else:
758 print 'Could not parse ', args 775 print 'Could not parse ', args
759 776
760 def do_exec(self, arg): 777 def do_exec(self, arg):