comparison mysqlpy.py @ 5:65ae6cec71c6

expanded desc good so far
author devlinjs@FA7CZA6N1254998.wrightpatterson.afmc.ds.af.mil
date Tue, 04 Dec 2007 17:19:18 -0500
parents 23c3a58d7804
children de6278a3bf53
comparison
equal deleted inserted replaced
4:23c3a58d7804 5:65ae6cec71c6
105 try: 105 try:
106 exec(arg) 106 exec(arg)
107 except Exception, e: 107 except Exception, e:
108 print e 108 print e
109 109
110 def do_tselect(self, arg, rowlimit=None): 110 def do_tselect(self, arg):
111 '''executes a query and prints the result in trasposed form. Useful when querying tables with many columns''' 111 '''executes a query and prints the result in trasposed form. Useful when querying tables with many columns'''
112 self.query = 'select ' + arg # sqlpython.finishStatement('select '+arg) 112
113 (self.query, terminator, rowlimit) = sqlpython.findTerminator(self.query) 113 self.do_select(arg, override_terminator='\\t')
114 try:
115 self.curs.execute(self.query)
116 rows = self.curs.fetchmany(min(self.maxtselctrows, rowlimit or self.maxtselctrows))
117 desc = self.curs.description
118 self.rc = self.curs.rowcount
119 rows.insert(0,[desc[x][0] for x in range(len(desc))]) # adds column name to the row set
120 transpr = [[rows[y][x] for y in range(len(rows))]for x in range(len(rows[0]))] # matrix transpose
121 newdesc = [['ROW N.'+str(y),10] for y in range(len(rows))]
122 for x in range(len(desc)):
123 if str(desc[x][1]) == "<type 'cx_Oracle.BINARY'>": # handles RAW columns
124 rname = transpr[x][0]
125 transpr[x] = map(binascii.b2a_hex, transpr[x])
126 transpr[x][0] = rname
127 self.debg=transpr
128 newdesc[0][0] = 'COLUMN NAME'
129 if self.rc > 0:
130 print '\n' + sqlpython.pmatrix(transpr,newdesc)
131 if self.rc == 0:
132 print '\nNo rows Selected.\n'
133 elif self.rc == 1:
134 print '\n1 row selected.\n'
135 elif self.rc < self.maxtselctrows:
136 print '\n%d rows selected.\n' % self.rc
137 else:
138 print '\nSelected Max Num rows (%d)' % self.rc
139 except Exception, e:
140 print e
141
142 114
143 def do_sql(self,args): 115 def do_sql(self,args):
144 '''prints sql statement give the sql_id (Oracle 10gR2)''' 116 '''prints sql statement give the sql_id (Oracle 10gR2)'''
145 self.query = "select inst_id, sql_fulltext from gv$sqlstats where sql_id='"+args+"'" 117 self.query = "select inst_id, sql_fulltext from gv$sqlstats where sql_id='"+args+"'"
146 try: 118 try: