Mercurial > sqlpython
changeset 92:fa8c9eb8908f
accepting command-line args
author | catherine@cordelia |
---|---|
date | Sun, 25 May 2008 01:35:08 -0400 |
parents | 51e1fe3adf0e |
children | f40bb62c625f |
files | mysqlpy.py sqlpyPlus.py sqlpython.py |
diffstat | 3 files changed, 30 insertions(+), 13 deletions(-) [+] |
line wrap: on
line diff
--- a/mysqlpy.py Tue May 20 21:58:55 2008 -0400 +++ b/mysqlpy.py Sun May 25 01:35:08 2008 -0400 @@ -9,7 +9,7 @@ # http://catherine.devlin.googlepages.com/ from sqlpyPlus import * -import binascii, sys +import binascii, sys, tempfile class mysqlpy(sqlpyPlus): ''' @@ -77,6 +77,13 @@ where time_remaining>0; ''' + def do_new(self, args): + 'tells you about new objects' + self.do_select('''owner, + object_name, + object_type +FROM all_objects +WHERE created > SYSDATE - 7''') def do_top9i(self,args): '''Runs query_top9i defined above, to display active sessions in Oracle 9i''' self.do_select(self.query_top9i) @@ -157,10 +164,25 @@ my=mysqlpy() print my.__doc__ try: - my.do_connect(sys.argv[1]) + if sys.argv[1][0] != '@': + my.do_connect(sys.argv.pop(1)) + arg = ' '.join(sys.argv[1:]) + my.onecmd(arg) + ''' + if arg: + tmp = tempfile.TemporaryFile() + tmp.write(arg) + tmp.seek(0) + if my.do__load(tmp) == mysqlpy._STOP_AND_EXIT: + return + ''' except IndexError: pass my.cmdloop() if __name__ == '__main__': - run() + try: + run() + except cmd2.ExitException: + pass +
--- a/sqlpyPlus.py Tue May 20 21:58:55 2008 -0400 +++ b/sqlpyPlus.py Sun May 25 01:35:08 2008 -0400 @@ -341,7 +341,7 @@ class sqlpyPlus(sqlpython.sqlpython): defaultExtension = 'sql' - shortcuts = {'?': 'help', '@': 'getrun', '!': 'shell', ':': 'setbind', '\\': 'psql'} + sqlpython.sqlpython.shortcuts.update({':': 'setbind', '\\': 'psql', '@': '_load'}) multilineCommands = '''select insert update delete tselect create drop alter'''.split() defaultFileName = 'afiedt.buf' @@ -372,6 +372,8 @@ print 'Not connected.' return '', '', '' return cmd, arg, line + + do__load = Cmd.do_load def onecmd_plus_hooks(self, line): line = self.precmd(line) @@ -685,9 +687,6 @@ bufferPosPattern = re.compile('\d+') rangeIndicators = ('-',':') - def do_getrun(self, fname): - 'Brings SQL commands from a file to the in-memory SQL buffer, and executes them.' - Cmd.do_load(self, fname) def do_psql(self, arg): '''Shortcut commands emulating psql's backslash commands. @@ -696,7 +695,7 @@ \e edit \g run \h help - \i getrun + \i load \o spool \p list \q quit
--- a/sqlpython.py Tue May 20 21:58:55 2008 -0400 +++ b/sqlpython.py Sun May 25 01:35:08 2008 -0400 @@ -47,9 +47,6 @@ def emptyline(self): pass - def do_quit(self, arg): - return 1 - def fail(self, arg, do_everywhere=False): if self.failover: success, result = False, '' @@ -118,8 +115,7 @@ self.default('rollback %s;' % (arg), do_everywhere=True) # shortcuts - do_q = do_quit - do_exit = do_quit + do_exit = cmd2.Cmd.do_quit stmtEndSearchString = r'(.*)(%s)\s*(\d+)?\s*$' % terminatorSearchString statementEndPattern = re.compile(stmtEndSearchString, re.MULTILINE | re.DOTALL)