comparison sqlpyPlus.py @ 41:33c9bc61db66

separation surgery successful?
author devlinjs@FA7CZA6N1254998.wrightpatterson.afmc.ds.af.mil
date Fri, 18 Jan 2008 15:37:45 -0500
parents 1fb9f7dee7d8
children 05c20d6bcec4
comparison
equal deleted inserted replaced
40:1fb9f7dee7d8 41:33c9bc61db66
362 """Parse the line into a command name and a string containing 362 """Parse the line into a command name and a string containing
363 the arguments. Returns a tuple containing (command, args, line). 363 the arguments. Returns a tuple containing (command, args, line).
364 'command' and 'args' may be None if the line couldn't be parsed. 364 'command' and 'args' may be None if the line couldn't be parsed.
365 Overrides cmd.cmd.parseline to accept variety of shortcuts..""" 365 Overrides cmd.cmd.parseline to accept variety of shortcuts.."""
366 366
367 cmd, arg. line = sqlpython.parseline(self, line) 367 cmd, arg, line = sqlpython.sqlpython.parseline(self, line)
368 if cmd in ('select', 'sleect', 'insert', 'update', 'delete', 'describe', 368 if cmd in ('select', 'sleect', 'insert', 'update', 'delete', 'describe',
369 'desc', 'comments', 'pull', 'refs', 'desc', 'triggers', 'find') \ 369 'desc', 'comments', 'pull', 'refs', 'desc', 'triggers', 'find') \
370 and not hasattr(self, 'curs'): 370 and not hasattr(self, 'curs'):
371 print 'Not connected.' 371 print 'Not connected.'
372 return '', '', '' 372 return '', '', ''
373 return cmd, arg, line 373 return cmd, arg, line
374
375 def precmd(self, line):
376 """Hook method executed just before the command line is
377 interpreted, but after the input prompt is generated and issued.
378 Makes commands case-insensitive (but unfortunately does not alter command completion).
379 """
380
381 '''
382 pipedCommands = pipeSeparator.separate(line)
383 if len(pipedCommands) > 1:
384 pipefilename = 'sqlpython.pipe.tmp'
385 for (idx, pipedCommand) in enumerate(pipedCommands[:-1]):
386 savestdout = sys.stdout
387 f = open(pipefilename,'w')
388 sys.stdout = f
389 self.precmd(pipedCommand)
390 self.onecmd(pipedCommand)
391 self.postcmd(False, pipedCommands[0])
392 f.close()
393 sys.stdout = savestdout
394 f = os.popen('%s < %s' % (pipedCommands[idx+1], pipefilename))
395 f.read()
396
397 '''
398 try:
399 args = line.split(None,1)
400 args[0] = args[0].lower()
401 statement = ' '.join(args)
402 if args[0] in self.multiline:
403 statement = sqlpython.finishStatement(statement)
404 return statement
405 except Exception:
406 return line
407 374
408 def onecmd_plus_hooks(self, line): 375 def onecmd_plus_hooks(self, line):
409 line = self.precmd(line) 376 line = self.precmd(line)
410 stop = self.onecmd(line) 377 stop = self.onecmd(line)
411 stop = self.postcmd(stop, line) 378 stop = self.postcmd(stop, line)
506 result = '\n' + sqlpython.pmatrix(transpr,newdesc) 473 result = '\n' + sqlpython.pmatrix(transpr,newdesc)
507 else: 474 else:
508 result = sqlpython.pmatrix(self.rows, self.curs.description, self.maxfetch) 475 result = sqlpython.pmatrix(self.rows, self.curs.description, self.maxfetch)
509 return result 476 return result
510 477
511 def findTerminator(statement): 478 def findTerminator(self, statement):
512 m = self.statementEndPattern.search(statement) 479 m = self.statementEndPattern.search(statement)
513 if m: 480 if m:
514 return m.groups() 481 return m.groups()
515 else: 482 else:
516 return statement, None, None 483 return statement, None, None