comparison mysqlpy.py @ 92:fa8c9eb8908f

accepting command-line args
author catherine@cordelia
date Sun, 25 May 2008 01:35:08 -0400
parents 047f82acdc8f
children f40bb62c625f
comparison
equal deleted inserted replaced
91:51e1fe3adf0e 92:fa8c9eb8908f
7 # 'sqlplus inside python' 7 # 'sqlplus inside python'
8 # See also: http://twiki.cern.ch/twiki/bin/view/PSSGroup/SqlPython 8 # See also: http://twiki.cern.ch/twiki/bin/view/PSSGroup/SqlPython
9 # http://catherine.devlin.googlepages.com/ 9 # http://catherine.devlin.googlepages.com/
10 10
11 from sqlpyPlus import * 11 from sqlpyPlus import *
12 import binascii, sys 12 import binascii, sys, tempfile
13 13
14 class mysqlpy(sqlpyPlus): 14 class mysqlpy(sqlpyPlus):
15 ''' 15 '''
16 MySqlPy V1.3 - 'sqlplus in python' 16 MySqlPy V1.3 - 'sqlplus in python'
17 Author: Luca.Canali@cern.ch 17 Author: Luca.Canali@cern.ch
75 inst_id,sid,username,time_remaining remaining, elapsed_seconds elapsed, sql_hash_value hash, opname,message 75 inst_id,sid,username,time_remaining remaining, elapsed_seconds elapsed, sql_hash_value hash, opname,message
76 from gv$session_longops 76 from gv$session_longops
77 where time_remaining>0; 77 where time_remaining>0;
78 ''' 78 '''
79 79
80 def do_new(self, args):
81 'tells you about new objects'
82 self.do_select('''owner,
83 object_name,
84 object_type
85 FROM all_objects
86 WHERE created > SYSDATE - 7''')
80 def do_top9i(self,args): 87 def do_top9i(self,args):
81 '''Runs query_top9i defined above, to display active sessions in Oracle 9i''' 88 '''Runs query_top9i defined above, to display active sessions in Oracle 9i'''
82 self.do_select(self.query_top9i) 89 self.do_select(self.query_top9i)
83 90
84 def do_top(self,args): 91 def do_top(self,args):
155 162
156 def run(): 163 def run():
157 my=mysqlpy() 164 my=mysqlpy()
158 print my.__doc__ 165 print my.__doc__
159 try: 166 try:
160 my.do_connect(sys.argv[1]) 167 if sys.argv[1][0] != '@':
168 my.do_connect(sys.argv.pop(1))
169 arg = ' '.join(sys.argv[1:])
170 my.onecmd(arg)
171 '''
172 if arg:
173 tmp = tempfile.TemporaryFile()
174 tmp.write(arg)
175 tmp.seek(0)
176 if my.do__load(tmp) == mysqlpy._STOP_AND_EXIT:
177 return
178 '''
161 except IndexError: 179 except IndexError:
162 pass 180 pass
163 my.cmdloop() 181 my.cmdloop()
164 182
165 if __name__ == '__main__': 183 if __name__ == '__main__':
166 run() 184 try:
185 run()
186 except cmd2.ExitException:
187 pass
188