Mercurial > sqlpython
comparison sqlpyPlus.py @ 21:8b55aaa52ce9
working on load, and preserving stdin/out
author | devlinjs@FA7CZA6N1254998.wrightpatterson.afmc.ds.af.mil |
---|---|
date | Wed, 19 Dec 2007 13:40:39 -0500 |
parents | d6d64c2e3b98 |
children | c99853267a44 |
comparison
equal
deleted
inserted
replaced
20:d6d64c2e3b98 | 21:8b55aaa52ce9 |
---|---|
340 if not givenBindVars.has_key(varname): | 340 if not givenBindVars.has_key(varname): |
341 print 'Bind variable %s not defined.' % (varname) | 341 print 'Bind variable %s not defined.' % (varname) |
342 return result | 342 return result |
343 | 343 |
344 class sqlpyPlus(sqlpython.sqlpython): | 344 class sqlpyPlus(sqlpython.sqlpython): |
345 defaultExtension = 'sql' | |
346 multilineCommands = '''select insert update delete tselect | |
347 create drop alter'''.split() | |
345 def __init__(self): | 348 def __init__(self): |
346 sqlpython.sqlpython.__init__(self) | 349 sqlpython.sqlpython.__init__(self) |
347 self.binds = CaselessDict() | 350 self.binds = CaselessDict() |
348 self.sqlBuffer = [] | 351 self.sqlBuffer = [] |
349 self.settable = ['maxtselctrows', 'maxfetch', 'autobind', 'failover', 'timeout'] # settables must be lowercase | 352 self.settable = ['maxtselctrows', 'maxfetch', 'autobind', 'failover', 'timeout'] # settables must be lowercase |
350 self.stdoutBeforeSpool = sys.stdout | 353 self.stdoutBeforeSpool = sys.stdout |
351 self.spoolFile = None | 354 self.spoolFile = None |
352 self.autobind = False | 355 self.autobind = False |
353 self.failover = False | 356 self.failover = False |
354 self.multiline = '''select insert update delete tselect | |
355 create drop alter'''.split() | |
356 | |
357 def default(self, arg, do_everywhere=False): | 357 def default(self, arg, do_everywhere=False): |
358 sqlpython.sqlpython.default(self, arg, do_everywhere) | 358 sqlpython.sqlpython.default(self, arg, do_everywhere) |
359 self.sqlBuffer.append(self.query) | 359 self.sqlBuffer.append(self.query) |
360 | 360 |
361 # overrides cmd's parseline | 361 # overrides cmd's parseline |
747 runme = self.last_matching(arg) | 747 runme = self.last_matching(arg) |
748 print runme | 748 print runme |
749 self.onecmd_plus_hooks(runme) | 749 self.onecmd_plus_hooks(runme) |
750 do_r = do_run | 750 do_r = do_run |
751 | 751 |
752 def load(self, fname): | |
753 """Pulls command(s) into sql buffer. Returns number of commands loaded.""" | |
754 try: | |
755 f = open(fname, 'r') | |
756 except IOError, e: | |
757 try: | |
758 f = open('%s.sql' % fname, 'r') | |
759 except: | |
760 print 'Problem opening file %s: \n%s' % (fname, e) | |
761 return 0 | |
762 txt = f.read() | |
763 f.close() | |
764 result = commandSeparator.separate(txt) | |
765 self.history.extend(result) | |
766 return len(result) | |
767 def do_ed(self, arg): | 752 def do_ed(self, arg): |
768 'ed [N]: brings up SQL from N commands ago in text editor, and puts result in SQL buffer.' | 753 'ed [N]: brings up SQL from N commands ago in text editor, and puts result in SQL buffer.' |
769 fname = 'sqlpython_temp.sql' | 754 fname = 'sqlpython_temp.sql' |
770 buffer = self.last_matching(arg) | 755 buffer = self.last_matching(arg) |
771 if not buffer: | 756 if not buffer: |