comparison sqlpyPlus.py @ 42:05c20d6bcec4

picking up from hiatus
author devlinjs@FA7CZA6N1254998.wrightpatterson.afmc.ds.af.mil
date Mon, 04 Feb 2008 10:20:09 -0500
parents 33c9bc61db66
children abbfb5a7e32c
comparison
equal deleted inserted replaced
41:33c9bc61db66 42:05c20d6bcec4
339 print 'Bind variable %s not defined.' % (varname) 339 print 'Bind variable %s not defined.' % (varname)
340 return result 340 return result
341 341
342 class sqlpyPlus(sqlpython.sqlpython): 342 class sqlpyPlus(sqlpython.sqlpython):
343 defaultExtension = 'sql' 343 defaultExtension = 'sql'
344 shortcuts = {'?': 'help', '@': 'getrun', '!': 'shell', ':': 'setbind', '\\': 'psql'}
344 multilineCommands = '''select insert update delete tselect 345 multilineCommands = '''select insert update delete tselect
345 create drop alter'''.split() 346 create drop alter'''.split()
347 defaultFileName = 'afiedt.buf'
346 def __init__(self): 348 def __init__(self):
347 sqlpython.sqlpython.__init__(self) 349 sqlpython.sqlpython.__init__(self)
348 self.binds = CaselessDict() 350 self.binds = CaselessDict()
349 self.sqlBuffer = [] 351 self.sqlBuffer = []
350 self.settable = ['maxtselctrows', 'maxfetch', 'autobind', 'failover', 'timeout'] # settables must be lowercase 352 self.settable = ['maxtselctrows', 'maxfetch', 'autobind', 'failover', 'timeout'] # settables must be lowercase
355 def default(self, arg, do_everywhere=False): 357 def default(self, arg, do_everywhere=False):
356 sqlpython.sqlpython.default(self, arg, do_everywhere) 358 sqlpython.sqlpython.default(self, arg, do_everywhere)
357 self.sqlBuffer.append(self.query) 359 self.sqlBuffer.append(self.query)
358 360
359 # overrides cmd's parseline 361 # overrides cmd's parseline
360 shortcuts = {'?': 'help', '@': 'getrun', '!': 'shell', ':': 'setbind', '\\': 'psql'}
361 def parseline(self, line): 362 def parseline(self, line):
362 """Parse the line into a command name and a string containing 363 """Parse the line into a command name and a string containing
363 the arguments. Returns a tuple containing (command, args, line). 364 the arguments. Returns a tuple containing (command, args, line).
364 'command' and 'args' may be None if the line couldn't be parsed. 365 'command' and 'args' may be None if the line couldn't be parsed.
365 Overrides cmd.cmd.parseline to accept variety of shortcuts..""" 366 Overrides cmd.cmd.parseline to accept variety of shortcuts.."""
480 if m: 481 if m:
481 return m.groups() 482 return m.groups()
482 else: 483 else:
483 return statement, None, None 484 return statement, None, None
484 485
486 legalOracle = re.compile('[a-zA-Z_$#]')
487
485 def do_select(self, arg, bindVarsIn=None, override_terminator=None): 488 def do_select(self, arg, bindVarsIn=None, override_terminator=None):
486 """Fetch rows from a table. 489 """Fetch rows from a table.
487 490
488 Limit the number of rows retrieved by appending 491 Limit the number of rows retrieved by appending
489 an integer after the terminator 492 an integer after the terminator
509 if self.rc == 0: 512 if self.rc == 0:
510 print '\nNo rows Selected.\n' 513 print '\nNo rows Selected.\n'
511 elif self.rc == 1: 514 elif self.rc == 1:
512 print '\n1 row selected.\n' 515 print '\n1 row selected.\n'
513 if self.autobind: 516 if self.autobind:
514 self.binds.update(dict(zip([d[0] for d in self.desc], self.rows[0]))) 517 self.binds.update(dict(zip([''.join(l for l in d[0] if l.isalnum()) for d in self.desc], self.rows[0])))
518 if len(self.desc) == 1:
519 self.binds['_'] = self.rows[0][0]
515 elif self.rc < self.maxfetch: 520 elif self.rc < self.maxfetch:
516 print '\n%d rows selected.\n' % self.rc 521 print '\n%d rows selected.\n' % self.rc
517 else: 522 else:
518 print '\nSelected Max Num rows (%d)' % self.rc 523 print '\nSelected Max Num rows (%d)' % self.rc
519 except Exception, e: 524 except Exception, e: