comparison sqlpyPlus.py @ 2:59903dcaf327

working on history
author devlinjs@FA7CZA6N1254998.wrightpatterson.afmc.ds.af.mil
date Mon, 03 Dec 2007 14:29:16 -0500
parents 8fa146b9a2d7
children cd23cd62de3c
comparison
equal deleted inserted replaced
1:8fa146b9a2d7 2:59903dcaf327
270 self.settable = ['maxtselctrows', 'maxfetch', 'autobind', 'failover', 'timeout'] # settables must be lowercase 270 self.settable = ['maxtselctrows', 'maxfetch', 'autobind', 'failover', 'timeout'] # settables must be lowercase
271 self.stdoutBeforeSpool = sys.stdout 271 self.stdoutBeforeSpool = sys.stdout
272 self.spoolFile = None 272 self.spoolFile = None
273 self.autobind = False 273 self.autobind = False
274 self.failover = False 274 self.failover = False
275 self.singleline = '''desc describe'''.split() 275 self.singleline = '''select insert update delete
276 create drop alter'''.split()
276 277
277 def default(self, arg, do_everywhere=False): 278 def default(self, arg, do_everywhere=False):
278 sqlpython.sqlpython.default(self, arg, do_everywhere) 279 sqlpython.sqlpython.default(self, arg, do_everywhere)
279 self.sqlBuffer.append(self.query) 280 self.sqlBuffer.append(self.query)
280 281
322 os.system('%s < %s' % (pipedCommands[1], pipefilename)) 323 os.system('%s < %s' % (pipedCommands[1], pipefilename))
323 ''' 324 '''
324 try: 325 try:
325 args = line.split(None,1) 326 args = line.split(None,1)
326 args[0] = args[0].lower() 327 args[0] = args[0].lower()
327 statement = ' '.join(args) 328 statement = ' '.join(args)
328 if args[0] not in self.singleline: 329 if args[0] in self.singleline:
329 statement = finishStatement(statement) 330 statement = sqlpython.finishStatement(statement)
330 return statement 331 return statement
331 except Exception: 332 except Exception:
332 return line 333 return line
333 334
334 def do_shortcuts(self,arg): 335 def do_shortcuts(self,arg):
369 return '\n'.join(result) 370 return '\n'.join(result)
370 371
371 def output_as_html_table(self): 372 def output_as_html_table(self):
372 result = ''.join('<th>%s</th>' % c for c in self.colnames) 373 result = ''.join('<th>%s</th>' % c for c in self.colnames)
373 result = [' <tr>\n %s\n </tr>' % result] 374 result = [' <tr>\n %s\n </tr>' % result]
374 print result
375 print type(result)
376 for row in self.rows: 375 for row in self.rows:
377 result.append(' <tr>\n %s\n </tr>' % 376 result.append(' <tr>\n %s\n </tr>' %
378 (''.join('<td>%s</td>' % 377 (''.join('<td>%s</td>' %
379 str('' if (itm is None) else itm) 378 str('' if (itm is None) else itm)
380 for itm in row))) 379 for itm in row)))
438 return 437 return
439 else: 438 else:
440 try: 439 try:
441 self.varsUsed = findBinds(self.query, self.binds, bindVarsIn) 440 self.varsUsed = findBinds(self.query, self.binds, bindVarsIn)
442 self.curs.execute(self.query, self.varsUsed) 441 self.curs.execute(self.query, self.varsUsed)
443 self.rows = self.curs.fetchmany(min(self.maxfetch, (stmt.rowlimit or self.maxfetch))) 442 self.rows = self.curs.fetchmany(min(self.maxfetch, (rowlimit or self.maxfetch)))
444 self.desc = self.curs.description 443 self.desc = self.curs.description
445 self.rc = self.curs.rowcount 444 self.rc = self.curs.rowcount
446 if self.rc > 0: 445 if self.rc > 0:
447 print '\n' + self.output(outformat, rowlimit) 446 print '\n' + self.output(terminator, rowlimit)
448 if self.rc == 0: 447 if self.rc == 0:
449 print '\nNo rows Selected.\n' 448 print '\nNo rows Selected.\n'
450 elif self.rc == 1: 449 elif self.rc == 1:
451 print '\n1 row selected.\n' 450 print '\n1 row selected.\n'
452 if self.autobind: 451 if self.autobind: