annotate sqlpython/mysqlpy.py @ 348:c652478be4fd

migrated \dt to gerald
author catherine@cordelia
date Fri, 24 Apr 2009 15:09:29 -0400
parents 8fbf49d3abe8
children
rev   line source
189
c5398d87498e cat bug
catherine@dellzilla
parents:
diff changeset
1 #!/usr/bin/python
324
9cbea1d8872e version 1.6.4, works with cmd2 0.5.2 for more flexible testing
Catherine Devlin <catherine.devlin@gmail.com>
parents: 323
diff changeset
2 # MySqlPy V1.6.4
189
c5398d87498e cat bug
catherine@dellzilla
parents:
diff changeset
3 # Author: Luca.Canali@cern.ch
c5398d87498e cat bug
catherine@dellzilla
parents:
diff changeset
4 #
c5398d87498e cat bug
catherine@dellzilla
parents:
diff changeset
5 #
c5398d87498e cat bug
catherine@dellzilla
parents:
diff changeset
6 # Companion of SqlPython, a python module that reproduces Oracle's command line within python
c5398d87498e cat bug
catherine@dellzilla
parents:
diff changeset
7 # 'sqlplus inside python'
c5398d87498e cat bug
catherine@dellzilla
parents:
diff changeset
8 # See also: http://twiki.cern.ch/twiki/bin/view/PSSGroup/SqlPython
c5398d87498e cat bug
catherine@dellzilla
parents:
diff changeset
9 # http://catherine.devlin.googlepages.com/
c5398d87498e cat bug
catherine@dellzilla
parents:
diff changeset
10
c5398d87498e cat bug
catherine@dellzilla
parents:
diff changeset
11 from sqlpyPlus import *
206
ed46f2dba929 fixed sessinfo
catherine@Elli.myhome.westell.com
parents: 202
diff changeset
12 import sys, tempfile, optparse, unittest
323
b97f1b8cdecd added usage notes for transcript testing
Catherine Devlin <catherine.devlin@gmail.com>
parents: 320
diff changeset
13 import sqlalchemy
189
c5398d87498e cat bug
catherine@dellzilla
parents:
diff changeset
14
c5398d87498e cat bug
catherine@dellzilla
parents:
diff changeset
15 class mysqlpy(sqlpyPlus):
c5398d87498e cat bug
catherine@dellzilla
parents:
diff changeset
16 '''
324
9cbea1d8872e version 1.6.4, works with cmd2 0.5.2 for more flexible testing
Catherine Devlin <catherine.devlin@gmail.com>
parents: 323
diff changeset
17 MySqlPy V1.6.4 - 'sqlplus in python'
189
c5398d87498e cat bug
catherine@dellzilla
parents:
diff changeset
18 Author: Luca.Canali@cern.ch
324
9cbea1d8872e version 1.6.4, works with cmd2 0.5.2 for more flexible testing
Catherine Devlin <catherine.devlin@gmail.com>
parents: 323
diff changeset
19 Rev: 1.6.4, 03-Apr-09
189
c5398d87498e cat bug
catherine@dellzilla
parents:
diff changeset
20
c5398d87498e cat bug
catherine@dellzilla
parents:
diff changeset
21 Companion of SqlPython, a python module that reproduces Oracle's command line within python
c5398d87498e cat bug
catherine@dellzilla
parents:
diff changeset
22 and sqlpyPlus. Major contributions by Catherine Devlin, http://catherinedevlin.blogspot.com
c5398d87498e cat bug
catherine@dellzilla
parents:
diff changeset
23
c5398d87498e cat bug
catherine@dellzilla
parents:
diff changeset
24 Usage: sqlpython [connect string] [single-word command] ["multi-word command"]...
c5398d87498e cat bug
catherine@dellzilla
parents:
diff changeset
25
c5398d87498e cat bug
catherine@dellzilla
parents:
diff changeset
26 Quick start command list:
c5398d87498e cat bug
catherine@dellzilla
parents:
diff changeset
27
c5398d87498e cat bug
catherine@dellzilla
parents:
diff changeset
28 - top -> executes a query to list all active sessions in (Oracle 10g and RAC)
c5398d87498e cat bug
catherine@dellzilla
parents:
diff changeset
29 (use: instance activity monitoring, a DBA tool)
c5398d87498e cat bug
catherine@dellzilla
parents:
diff changeset
30 - tselect -> prints the result set in trasposed form, useful to print result sets with
c5398d87498e cat bug
catherine@dellzilla
parents:
diff changeset
31 many columns such as dba_ or v$ views (ex: dba_tables or v$instance)
c5398d87498e cat bug
catherine@dellzilla
parents:
diff changeset
32 - py -> execute a python command (C.D.)
c5398d87498e cat bug
catherine@dellzilla
parents:
diff changeset
33 - db -> quick connect using credentials in pass.txt file
c5398d87498e cat bug
catherine@dellzilla
parents:
diff changeset
34 (Ex: write username and pass in pass.txt and then "db db_alias" to connect)
c5398d87498e cat bug
catherine@dellzilla
parents:
diff changeset
35 - sql -> prints the sql text from the cache. parameter: sql_id of the statement
c5398d87498e cat bug
catherine@dellzilla
parents:
diff changeset
36 (Ex: sql fzqa1qj65nagki)
c5398d87498e cat bug
catherine@dellzilla
parents:
diff changeset
37 - explain -> prints the execution plan from the cache. parameter: sql_id of the statement
c5398d87498e cat bug
catherine@dellzilla
parents:
diff changeset
38 - sessinfo-> prints session information. 1 parameter sid (Ex: sql 101 print info for sid 101)
c5398d87498e cat bug
catherine@dellzilla
parents:
diff changeset
39 - longops -> prints from gv$session_longops (running full scans, etc)
c5398d87498e cat bug
catherine@dellzilla
parents:
diff changeset
40 - load -> prints the OS load on all cluster nodes (10g RAC)
c5398d87498e cat bug
catherine@dellzilla
parents:
diff changeset
41 - sleect,slect -> alias for select (I mistyped select this way too many times...)
c5398d87498e cat bug
catherine@dellzilla
parents:
diff changeset
42 - top9i -> 9i (and single instance) version of top
c5398d87498e cat bug
catherine@dellzilla
parents:
diff changeset
43 - describe, @, !, spool, show, set, list, get, write -> sql*plus-like, from sqlpyPlus (C.D.)
c5398d87498e cat bug
catherine@dellzilla
parents:
diff changeset
44 - shortcuts: \c (connect), \d (describe), etc, from sqlpyPlus (C.D.)
c5398d87498e cat bug
catherine@dellzilla
parents:
diff changeset
45 - :myvarname = xx, set autobind 1, print -> bind variables management extension, to sqlplus (C.D.)
c5398d87498e cat bug
catherine@dellzilla
parents:
diff changeset
46
c5398d87498e cat bug
catherine@dellzilla
parents:
diff changeset
47 Example:
c5398d87498e cat bug
catherine@dellzilla
parents:
diff changeset
48 SQL> connect username@dbalias or username/pass@dbalias
c5398d87498e cat bug
catherine@dellzilla
parents:
diff changeset
49 SQL> select sysdate from dual;
c5398d87498e cat bug
catherine@dellzilla
parents:
diff changeset
50 SQL> exit
c5398d87498e cat bug
catherine@dellzilla
parents:
diff changeset
51 '''
c5398d87498e cat bug
catherine@dellzilla
parents:
diff changeset
52
c5398d87498e cat bug
catherine@dellzilla
parents:
diff changeset
53 def __init__(self):
c5398d87498e cat bug
catherine@dellzilla
parents:
diff changeset
54 sqlpyPlus.__init__(self)
c5398d87498e cat bug
catherine@dellzilla
parents:
diff changeset
55 self.maxtselctrows = 10
c5398d87498e cat bug
catherine@dellzilla
parents:
diff changeset
56 self.query_load10g = '''
c5398d87498e cat bug
catherine@dellzilla
parents:
diff changeset
57 ins.instance_name,ins.host_name,round(os.value,2) load
c5398d87498e cat bug
catherine@dellzilla
parents:
diff changeset
58 from gv$osstat os, gv$instance ins
c5398d87498e cat bug
catherine@dellzilla
parents:
diff changeset
59 where os.inst_id=ins.inst_id and os.stat_name='LOAD'
c5398d87498e cat bug
catherine@dellzilla
parents:
diff changeset
60 order by 3 desc
c5398d87498e cat bug
catherine@dellzilla
parents:
diff changeset
61 '''
c5398d87498e cat bug
catherine@dellzilla
parents:
diff changeset
62 self.query_top9i = '''SELECT
c5398d87498e cat bug
catherine@dellzilla
parents:
diff changeset
63 sid,username,osuser||'@'||terminal "Server User@terminal",program,taddr, status,
c5398d87498e cat bug
catherine@dellzilla
parents:
diff changeset
64 module, sql_hash_value hash, fixed_table_sequence seq, last_call_et elaps
c5398d87498e cat bug
catherine@dellzilla
parents:
diff changeset
65 from v$session
c5398d87498e cat bug
catherine@dellzilla
parents:
diff changeset
66 where username is not null and program not like 'emagent%' and status='ACTIVE'
c5398d87498e cat bug
catherine@dellzilla
parents:
diff changeset
67 and audsid !=sys_context('USERENV','SESSIONID') ;
c5398d87498e cat bug
catherine@dellzilla
parents:
diff changeset
68 '''
c5398d87498e cat bug
catherine@dellzilla
parents:
diff changeset
69 self.query_ractop = '''SELECT
c5398d87498e cat bug
catherine@dellzilla
parents:
diff changeset
70 inst_id||'_'||sid inst_sid,username,osuser||'@'||terminal "User@Term",program, decode(taddr,null,null,'NN') tr,
c5398d87498e cat bug
catherine@dellzilla
parents:
diff changeset
71 sql_id, '.'||mod(fixed_table_sequence,1000) seq, state||': '||event event,
c5398d87498e cat bug
catherine@dellzilla
parents:
diff changeset
72 case state when 'WAITING' then seconds_in_wait else wait_time end w_tim, last_call_et elaps
c5398d87498e cat bug
catherine@dellzilla
parents:
diff changeset
73 from gv$session
c5398d87498e cat bug
catherine@dellzilla
parents:
diff changeset
74 where status='ACTIVE' and username is not null
c5398d87498e cat bug
catherine@dellzilla
parents:
diff changeset
75 and not (event like '% waiting for messages in the queue' and state='WAITING')
c5398d87498e cat bug
catherine@dellzilla
parents:
diff changeset
76 and audsid !=sys_context('USERENV','SESSIONID');
c5398d87498e cat bug
catherine@dellzilla
parents:
diff changeset
77 '''
c5398d87498e cat bug
catherine@dellzilla
parents:
diff changeset
78 self.query_longops = '''SELECT
c5398d87498e cat bug
catherine@dellzilla
parents:
diff changeset
79 inst_id,sid,username,time_remaining remaining, elapsed_seconds elapsed, sql_hash_value hash, opname,message
c5398d87498e cat bug
catherine@dellzilla
parents:
diff changeset
80 from gv$session_longops
c5398d87498e cat bug
catherine@dellzilla
parents:
diff changeset
81 where time_remaining>0;
c5398d87498e cat bug
catherine@dellzilla
parents:
diff changeset
82 '''
c5398d87498e cat bug
catherine@dellzilla
parents:
diff changeset
83
c5398d87498e cat bug
catherine@dellzilla
parents:
diff changeset
84 def do_new(self, args):
c5398d87498e cat bug
catherine@dellzilla
parents:
diff changeset
85 'tells you about new objects'
c5398d87498e cat bug
catherine@dellzilla
parents:
diff changeset
86 self.onecmd('''SELECT owner,
c5398d87498e cat bug
catherine@dellzilla
parents:
diff changeset
87 object_name,
c5398d87498e cat bug
catherine@dellzilla
parents:
diff changeset
88 object_type
c5398d87498e cat bug
catherine@dellzilla
parents:
diff changeset
89 FROM all_objects
c5398d87498e cat bug
catherine@dellzilla
parents:
diff changeset
90 WHERE created > SYSDATE - 7;''')
c5398d87498e cat bug
catherine@dellzilla
parents:
diff changeset
91 def do_top9i(self,args):
c5398d87498e cat bug
catherine@dellzilla
parents:
diff changeset
92 '''Runs query_top9i defined above, to display active sessions in Oracle 9i'''
c5398d87498e cat bug
catherine@dellzilla
parents:
diff changeset
93 self.onecmd(self.query_top9i)
c5398d87498e cat bug
catherine@dellzilla
parents:
diff changeset
94
c5398d87498e cat bug
catherine@dellzilla
parents:
diff changeset
95 def do_top(self,args):
c5398d87498e cat bug
catherine@dellzilla
parents:
diff changeset
96 '''Runs query_ractop defined above, to display active sessions in Oracle 10g (and RAC)'''
c5398d87498e cat bug
catherine@dellzilla
parents:
diff changeset
97 self.onecmd(self.query_ractop)
c5398d87498e cat bug
catherine@dellzilla
parents:
diff changeset
98
c5398d87498e cat bug
catherine@dellzilla
parents:
diff changeset
99 def do_longops(self,args):
c5398d87498e cat bug
catherine@dellzilla
parents:
diff changeset
100 '''Runs query_longops defined above, to display long running operations (full scans, etc)'''
c5398d87498e cat bug
catherine@dellzilla
parents:
diff changeset
101 self.onecmd(self.query_longops)
284
ad20675a17f7 working on adding accept, prompt
catherine@dellzilla
parents: 281
diff changeset
102
189
c5398d87498e cat bug
catherine@dellzilla
parents:
diff changeset
103 def do_load(self,args):
c5398d87498e cat bug
catherine@dellzilla
parents:
diff changeset
104 '''Runs query_load10g defined above, to display OS load on cluster nodes (10gRAC)
c5398d87498e cat bug
catherine@dellzilla
parents:
diff changeset
105 Do not confuse with `GET myfile.sql` and `@myfile.sql`,
c5398d87498e cat bug
catherine@dellzilla
parents:
diff changeset
106 which get and run SQL scripts from disk.'''
208
545d98ed07f3 fix for do_load
catherine@dellzilla
parents: 206
diff changeset
107 self.onecmd(self.query_load10g)
257
6d4d90fb2082 dbms_output.put_line working
catherine@Elli.myhome.westell.com
parents: 255
diff changeset
108
189
c5398d87498e cat bug
catherine@dellzilla
parents:
diff changeset
109 def do_db(self,args,filepath='pass.txt'):
c5398d87498e cat bug
catherine@dellzilla
parents:
diff changeset
110 '''Exec do_connect to db_alias in args (credentials form the file pass.txt) '''
255
39ecc4b65b11 smart prompt now works with db connect
catherine@Elli.myhome.westell.com
parents: 252
diff changeset
111 try:
39ecc4b65b11 smart prompt now works with db connect
catherine@Elli.myhome.westell.com
parents: 252
diff changeset
112 f = open(filepath,'r')
39ecc4b65b11 smart prompt now works with db connect
catherine@Elli.myhome.westell.com
parents: 252
diff changeset
113 except IOError:
333
1cde0ec62e61 send up
Catherine Devlin <catherine.devlin@gmail.com>
parents: 324
diff changeset
114 self.perror('Need a file %s containing username/password' % filepath)
255
39ecc4b65b11 smart prompt now works with db connect
catherine@Elli.myhome.westell.com
parents: 252
diff changeset
115 raise
39ecc4b65b11 smart prompt now works with db connect
catherine@Elli.myhome.westell.com
parents: 252
diff changeset
116 connectstr = f.readline().strip()
39ecc4b65b11 smart prompt now works with db connect
catherine@Elli.myhome.westell.com
parents: 252
diff changeset
117 if args:
39ecc4b65b11 smart prompt now works with db connect
catherine@Elli.myhome.westell.com
parents: 252
diff changeset
118 connectstr += '@'+args
189
c5398d87498e cat bug
catherine@dellzilla
parents:
diff changeset
119 self.do_connect(connectstr)
c5398d87498e cat bug
catherine@dellzilla
parents:
diff changeset
120 f.close()
c5398d87498e cat bug
catherine@dellzilla
parents:
diff changeset
121
c5398d87498e cat bug
catherine@dellzilla
parents:
diff changeset
122 def do_tselect(self, arg):
281
701f0aae837a got maxtselctrows working again
catherine@dellzilla
parents: 271
diff changeset
123 '''
701f0aae837a got maxtselctrows working again
catherine@dellzilla
parents: 271
diff changeset
124 Executes a query and prints the result in trasposed form;
701f0aae837a got maxtselctrows working again
catherine@dellzilla
parents: 271
diff changeset
125 equivalent to terminating query with `\\t` instead of `;`.
701f0aae837a got maxtselctrows working again
catherine@dellzilla
parents: 271
diff changeset
126 Useful when querying tables with many columns and few rows.'''
206
ed46f2dba929 fixed sessinfo
catherine@Elli.myhome.westell.com
parents: 202
diff changeset
127 self.do_select(self.parsed(arg, terminator='\\t'))
189
c5398d87498e cat bug
catherine@dellzilla
parents:
diff changeset
128
c5398d87498e cat bug
catherine@dellzilla
parents:
diff changeset
129 def do_sql(self,args):
c5398d87498e cat bug
catherine@dellzilla
parents:
diff changeset
130 '''prints sql statement give the sql_id (Oracle 10gR2)'''
c5398d87498e cat bug
catherine@dellzilla
parents:
diff changeset
131 self.query = "select inst_id, sql_fulltext from gv$sqlstats where sql_id='"+args+"'"
c5398d87498e cat bug
catherine@dellzilla
parents:
diff changeset
132 try:
c5398d87498e cat bug
catherine@dellzilla
parents:
diff changeset
133 self.curs.execute(self.query)
c5398d87498e cat bug
catherine@dellzilla
parents:
diff changeset
134 row = self.curs.fetchone()
333
1cde0ec62e61 send up
Catherine Devlin <catherine.devlin@gmail.com>
parents: 324
diff changeset
135 self.poutput("\nSQL statement from cache")
1cde0ec62e61 send up
Catherine Devlin <catherine.devlin@gmail.com>
parents: 324
diff changeset
136 self.poutput("------------------------\n")
189
c5398d87498e cat bug
catherine@dellzilla
parents:
diff changeset
137 while row:
333
1cde0ec62e61 send up
Catherine Devlin <catherine.devlin@gmail.com>
parents: 324
diff changeset
138 self.poutput("\nINST_ID = "+str(row[0])+" - SQL TEXT:\n" + row[1].read())
189
c5398d87498e cat bug
catherine@dellzilla
parents:
diff changeset
139 row = self.curs.next()
c5398d87498e cat bug
catherine@dellzilla
parents:
diff changeset
140 except Exception, e:
333
1cde0ec62e61 send up
Catherine Devlin <catherine.devlin@gmail.com>
parents: 324
diff changeset
141 self.perror(e)
189
c5398d87498e cat bug
catherine@dellzilla
parents:
diff changeset
142
c5398d87498e cat bug
catherine@dellzilla
parents:
diff changeset
143 def do_explain(self,args):
c5398d87498e cat bug
catherine@dellzilla
parents:
diff changeset
144 '''prints the plan of a given statement from the sql cache. 1 parameter: sql_id, see also do_sql '''
320
af4106fca5d9 fixed misspelling of split(), thanks Igor
Catherine Devlin <catherine.devlin@gmail.com>
parents: 313
diff changeset
145 words = args.split()
251
aa33f495a289 reworked \di - not truly better?
catherine@Elli.myhome.westell.com
parents: 250
diff changeset
146 if len(words) > 2 and words[0].lower() == 'plan' and words[1].lower() == 'for':
aa33f495a289 reworked \di - not truly better?
catherine@Elli.myhome.westell.com
parents: 250
diff changeset
147 self.curs.execute('explain %s' % args)
333
1cde0ec62e61 send up
Catherine Devlin <catherine.devlin@gmail.com>
parents: 324
diff changeset
148 self.pfeedback('Explained. (see plan table)')
226
6701c3f097f9 more comments
catherine@Elli.myhome.westell.com
parents: 213
diff changeset
149 return
189
c5398d87498e cat bug
catherine@dellzilla
parents:
diff changeset
150 self.query = "select * from table(dbms_xplan.display_cursor('"+args+"'))"
c5398d87498e cat bug
catherine@dellzilla
parents:
diff changeset
151 try:
c5398d87498e cat bug
catherine@dellzilla
parents:
diff changeset
152 self.curs.execute(self.query)
c5398d87498e cat bug
catherine@dellzilla
parents:
diff changeset
153 rows = self.curs.fetchall()
c5398d87498e cat bug
catherine@dellzilla
parents:
diff changeset
154 desc = self.curs.description
c5398d87498e cat bug
catherine@dellzilla
parents:
diff changeset
155 self.rc = self.curs.rowcount
c5398d87498e cat bug
catherine@dellzilla
parents:
diff changeset
156 if self.rc > 0:
337
Catherine Devlin <catherine.devlin@gmail.com>
parents: 333
diff changeset
157 self.poutput('\n' + self.pmatrix(rows,desc,200))
189
c5398d87498e cat bug
catherine@dellzilla
parents:
diff changeset
158 except Exception, e:
333
1cde0ec62e61 send up
Catherine Devlin <catherine.devlin@gmail.com>
parents: 324
diff changeset
159 self.perror(e)
189
c5398d87498e cat bug
catherine@dellzilla
parents:
diff changeset
160
c5398d87498e cat bug
catherine@dellzilla
parents:
diff changeset
161 def do_sessinfo(self,args):
206
ed46f2dba929 fixed sessinfo
catherine@Elli.myhome.westell.com
parents: 202
diff changeset
162 '''Reports session info for the given sid, extended to RAC with gv$'''
ed46f2dba929 fixed sessinfo
catherine@Elli.myhome.westell.com
parents: 202
diff changeset
163 try:
ed46f2dba929 fixed sessinfo
catherine@Elli.myhome.westell.com
parents: 202
diff changeset
164 if not args:
ed46f2dba929 fixed sessinfo
catherine@Elli.myhome.westell.com
parents: 202
diff changeset
165 self.curs.execute('SELECT sid FROM v$mystat')
ed46f2dba929 fixed sessinfo
catherine@Elli.myhome.westell.com
parents: 202
diff changeset
166 args = self.curs.fetchone()[0]
ed46f2dba929 fixed sessinfo
catherine@Elli.myhome.westell.com
parents: 202
diff changeset
167 self.onecmd('SELECT * from gv$session where sid=%s\\t' % args)
ed46f2dba929 fixed sessinfo
catherine@Elli.myhome.westell.com
parents: 202
diff changeset
168 except cx_Oracle.DatabaseError, e:
ed46f2dba929 fixed sessinfo
catherine@Elli.myhome.westell.com
parents: 202
diff changeset
169 if 'table or view does not exist' in str(e):
333
1cde0ec62e61 send up
Catherine Devlin <catherine.devlin@gmail.com>
parents: 324
diff changeset
170 self.perror('This account has not been granted SELECT privileges to v$mystat or gv$session.')
206
ed46f2dba929 fixed sessinfo
catherine@Elli.myhome.westell.com
parents: 202
diff changeset
171 else:
ed46f2dba929 fixed sessinfo
catherine@Elli.myhome.westell.com
parents: 202
diff changeset
172 raise
189
c5398d87498e cat bug
catherine@dellzilla
parents:
diff changeset
173
c5398d87498e cat bug
catherine@dellzilla
parents:
diff changeset
174 def do_sleect(self,args):
c5398d87498e cat bug
catherine@dellzilla
parents:
diff changeset
175 '''implements sleect = select, a common typo'''
c5398d87498e cat bug
catherine@dellzilla
parents:
diff changeset
176 self.do_select(args)
c5398d87498e cat bug
catherine@dellzilla
parents:
diff changeset
177
c5398d87498e cat bug
catherine@dellzilla
parents:
diff changeset
178 do_slect = do_sleect
c5398d87498e cat bug
catherine@dellzilla
parents:
diff changeset
179
c5398d87498e cat bug
catherine@dellzilla
parents:
diff changeset
180 def run():
c5398d87498e cat bug
catherine@dellzilla
parents:
diff changeset
181 my=mysqlpy()
c5398d87498e cat bug
catherine@dellzilla
parents:
diff changeset
182 print my.__doc__
c5398d87498e cat bug
catherine@dellzilla
parents:
diff changeset
183 try:
c5398d87498e cat bug
catherine@dellzilla
parents:
diff changeset
184 if sys.argv[1][0] != '@':
c5398d87498e cat bug
catherine@dellzilla
parents:
diff changeset
185 connectstring = sys.argv.pop(1)
348
c652478be4fd migrated \dt to gerald
catherine@cordelia
parents: 337
diff changeset
186 if len(sys.argv) >= 3 and sys.argv[1].lower() == 'as': # attach AS SYSDBA or AS SYSOPER if present
c652478be4fd migrated \dt to gerald
catherine@cordelia
parents: 337
diff changeset
187 for i in (1,2):
c652478be4fd migrated \dt to gerald
catherine@cordelia
parents: 337
diff changeset
188 connectstring += ' ' + sys.argv.pop(1)
189
c5398d87498e cat bug
catherine@dellzilla
parents:
diff changeset
189 my.do_connect(connectstring)
c5398d87498e cat bug
catherine@dellzilla
parents:
diff changeset
190 for arg in sys.argv[1:]:
292
d727f209acf9 py really working right now
catherine@dellzilla
parents: 284
diff changeset
191 if my.onecmd(arg + '\n') == my._STOP_AND_EXIT:
189
c5398d87498e cat bug
catherine@dellzilla
parents:
diff changeset
192 return
c5398d87498e cat bug
catherine@dellzilla
parents:
diff changeset
193 except IndexError:
c5398d87498e cat bug
catherine@dellzilla
parents:
diff changeset
194 pass
c5398d87498e cat bug
catherine@dellzilla
parents:
diff changeset
195 my.cmdloop()
323
b97f1b8cdecd added usage notes for transcript testing
Catherine Devlin <catherine.devlin@gmail.com>
parents: 320
diff changeset
196
189
c5398d87498e cat bug
catherine@dellzilla
parents:
diff changeset
197 class TestCase(Cmd2TestCase):
c5398d87498e cat bug
catherine@dellzilla
parents:
diff changeset
198 CmdApp = mysqlpy
c5398d87498e cat bug
catherine@dellzilla
parents:
diff changeset
199
c5398d87498e cat bug
catherine@dellzilla
parents:
diff changeset
200 if __name__ == '__main__':
c5398d87498e cat bug
catherine@dellzilla
parents:
diff changeset
201 parser = optparse.OptionParser()
c5398d87498e cat bug
catherine@dellzilla
parents:
diff changeset
202 parser.add_option('-t', '--test', dest='unittests', action='store_true', default=False, help='Run unit test suite')
c5398d87498e cat bug
catherine@dellzilla
parents:
diff changeset
203 (callopts, callargs) = parser.parse_args()
c5398d87498e cat bug
catherine@dellzilla
parents:
diff changeset
204 if callopts.unittests:
323
b97f1b8cdecd added usage notes for transcript testing
Catherine Devlin <catherine.devlin@gmail.com>
parents: 320
diff changeset
205 mysqlpy.testfiles = callargs
189
c5398d87498e cat bug
catherine@dellzilla
parents:
diff changeset
206 sys.argv = [sys.argv[0]] # the --test argument upsets unittest.main()
c5398d87498e cat bug
catherine@dellzilla
parents:
diff changeset
207 unittest.main()
c5398d87498e cat bug
catherine@dellzilla
parents:
diff changeset
208 else:
c5398d87498e cat bug
catherine@dellzilla
parents:
diff changeset
209 run()