comparison sqlpython.py @ 80:83de0cb04f12

prevent crash on lone backslash
author catherine@localhost
date Wed, 14 May 2008 17:23:52 -0400
parents d0bf9e40ba8d
children fa8c9eb8908f
comparison
equal deleted inserted replaced
79:01d578f4e6e7 80:83de0cb04f12
7 # Intended to allow easy customizations and extentions 7 # Intended to allow easy customizations and extentions
8 # Best used with the companion modules sqlpyPlus and mysqlpy 8 # Best used with the companion modules sqlpyPlus and mysqlpy
9 # See also http://twiki.cern.ch/twiki/bin/view/PSSGroup/SqlPython 9 # See also http://twiki.cern.ch/twiki/bin/view/PSSGroup/SqlPython
10 10
11 import cmd2,getpass,binascii,cx_Oracle,re 11 import cmd2,getpass,binascii,cx_Oracle,re
12 import pexpecter 12 import pexpecter, sqlpyPlus
13 13
14 # complication! separate sessions -> 14 # complication! separate sessions ->
15 # separate transactions !!!!! 15 # separate transactions !!!!!
16 # also: timeouts, other session failures 16 # also: timeouts, other session failures
17 17
100 do_sen = do_senora 100 do_sen = do_senora
101 101
102 def default(self, arg, do_everywhere = False): 102 def default(self, arg, do_everywhere = False):
103 self.query = self.finishStatement(arg).strip().rstrip(';') 103 self.query = self.finishStatement(arg).strip().rstrip(';')
104 try: 104 try:
105 self.curs.execute(self.query) 105 self.varsUsed = sqlpyPlus.findBinds(self.query, self.binds, givenBindVars={})
106 self.curs.execute(self.query, self.varsUsed)
106 print '\nExecuted%s\n' % ((self.curs.rowcount > 0) and ' (%d rows)' % self.curs.rowcount or '') 107 print '\nExecuted%s\n' % ((self.curs.rowcount > 0) and ' (%d rows)' % self.curs.rowcount or '')
107 if do_everywhere: 108 if do_everywhere:
108 self.fail(arg, do_everywhere = True ) 109 self.fail(arg, do_everywhere = True )
109 except Exception, e: 110 except Exception, e:
110 result = self.fail(arg) 111 result = self.fail(arg)
138 rowsi = map(str, rows[i]) # current row to process 139 rowsi = map(str, rows[i]) # current row to process
139 split = [] # service var is row split is needed 140 split = [] # service var is row split is needed
140 mustsplit = 0 # flag 141 mustsplit = 0 # flag
141 for j in rcols: 142 for j in rcols:
142 if str(desc[j][1]) == "<type 'cx_Oracle.BINARY'>": # handles RAW columns 143 if str(desc[j][1]) == "<type 'cx_Oracle.BINARY'>": # handles RAW columns
143 rowsi[j] = binascii.b2a_hex(rowsi[j]) 144 rowsi[j] = binascii.b2a_hex(rowsi[j])
144 maxen[j] = max(maxen[j], len(rowsi[j])) # computes max field length 145 maxen[j] = max(maxen[j], len(rowsi[j])) # computes max field length
145 if maxen[j] <= maxlen: 146 if maxen[j] <= maxlen:
146 split.append('') 147 split.append('')
147 else: # split the line is 2 because field is too long 148 else: # split the line is 2 because field is too long
148 mustsplit = 1 149 mustsplit = 1