comparison sqlpyPlus.py @ 72:db0e1ff5e407

condensed do_setbind with do_print
author catherine@cordelia
date Mon, 14 Apr 2008 16:02:20 -0400
parents 7bb52cc35332
children bce8396ab625
comparison
equal deleted inserted replaced
71:7bb52cc35332 72:db0e1ff5e407
730 except: 730 except:
731 pass 731 pass
732 arg = ' '.join(args) 732 arg = ' '.join(args)
733 self.do_select('* from %s;%d' % (arg, nrows)) 733 self.do_select('* from %s;%d' % (arg, nrows))
734 734
735 def printall(self):
736 for (var, val) in self.binds.items():
737 print ':%s = %s' % (var, val)
738
735 def do_print(self, arg): 739 def do_print(self, arg):
736 'print VARNAME: Show current value of bind variable VARNAME.' 740 'print VARNAME: Show current value of bind variable VARNAME.'
737 if arg: 741 if arg:
738 if arg[0] == ':': 742 if arg[0] == ':':
739 arg = arg[1:] 743 arg = arg[1:]
740 try: 744 try:
741 self.stdout.write(self.binds[arg]+'\n') 745 self.stdout.write(self.binds[arg]+'\n')
742 except KeyError: 746 except KeyError:
743 self.stdout.write('No bind variable %s\n' % arg) 747 self.stdout.write('No bind variable %s\n' % arg)
744 else: 748 else:
745 self.do_setbind('') 749 self.printall()
750
746 def do_setbind(self, arg): 751 def do_setbind(self, arg):
747 args = arg.split(None, 2) 752 args = arg.split(None, 2)
748 if len(args) == 0: 753 if len(args) < 2:
749 for (var, val) in self.binds.items(): 754 self.do_print(arg)
750 print ':%s = %s' % (var, val)
751 elif len(args) == 1:
752 try:
753 print ':%s = %s' % (args[0], self.binds[args[0]])
754 except KeyError, e:
755 print noSuchBindMsg % args[0]
756 elif len(args) > 2 and args[1] in ('=',':='): 755 elif len(args) > 2 and args[1] in ('=',':='):
757 var, val = args[0], args[2] 756 var, val = args[0], args[2]
758 if val[0] == val[-1] == "'" and len(val) > 1: 757 if val[0] == val[-1] == "'" and len(val) > 1:
759 val = val[1:-1] # stripping quotes; is that wise? 758 val = val[1:-1] # stripping quotes; is that wise?
760 self.binds[var] = val # but what if val is a function call? 759 self.binds[var] = val # but what if val is a function call?