Mercurial > sqlpython
comparison sqlpyPlus.py @ 105:1e69f3a26216
fixed python2.4 compat
author | catherine@localhost |
---|---|
date | Mon, 09 Jun 2008 12:34:06 -0400 |
parents | 2619e81c5772 |
children | 31de4c0b06ee |
comparison
equal
deleted
inserted
replaced
104:fd1f06e700ea | 105:1e69f3a26216 |
---|---|
391 if itm is None: | 391 if itm is None: |
392 return 'NULL' | 392 return 'NULL' |
393 if needsquotes: | 393 if needsquotes: |
394 return "'%s'" % str(itm) | 394 return "'%s'" % str(itm) |
395 return str(itm) | 395 return str(itm) |
396 def str_or_empty(self, itm): | |
397 if itm is None: | |
398 return '' | |
399 return str(itm) | |
396 def output_as_insert_statements(self): | 400 def output_as_insert_statements(self): |
397 usequotes = [d[1] != cx_Oracle.NUMBER for d in self.curs.description] | 401 usequotes = [d[1] != cx_Oracle.NUMBER for d in self.curs.description] |
398 def formatRow(row): | 402 def formatRow(row): |
399 return ','.join(self.sql_format_itm(itm, useq) | 403 return ','.join(self.sql_format_itm(itm, useq) |
400 for (itm, useq) in zip(row, usequotes)) | 404 for (itm, useq) in zip(row, usequotes)) |
403 for row in self.rows] | 407 for row in self.rows] |
404 return '\n'.join(result) | 408 return '\n'.join(result) |
405 | 409 |
406 def output_row_as_xml(self, row): | 410 def output_row_as_xml(self, row): |
407 result = [' <%s>\n %s\n </%s>' % | 411 result = [' <%s>\n %s\n </%s>' % |
408 (colname.lower(), str('' if (itm is None) else itm), colname.lower()) | 412 (colname.lower(), self.str_or_empty(itm), colname.lower()) |
409 for (itm, colname) in zip(row, self.colnames)] | 413 for (itm, colname) in zip(row, self.colnames)] |
410 return '\n'.join(result) | 414 return '\n'.join(result) |
411 def output_as_xml(self): | 415 def output_as_xml(self): |
412 result = ['<%s>\n%s\n</%s>' % | 416 result = ['<%s>\n%s\n</%s>' % |
413 (self.tblname, self.output_row_as_xml(row), self.tblname) | 417 (self.tblname, self.output_row_as_xml(row), self.tblname) |
418 result = ''.join('<th>%s</th>' % c for c in self.colnames) | 422 result = ''.join('<th>%s</th>' % c for c in self.colnames) |
419 result = [' <tr>\n %s\n </tr>' % result] | 423 result = [' <tr>\n %s\n </tr>' % result] |
420 for row in self.rows: | 424 for row in self.rows: |
421 result.append(' <tr>\n %s\n </tr>' % | 425 result.append(' <tr>\n %s\n </tr>' % |
422 (''.join('<td>%s</td>' % | 426 (''.join('<td>%s</td>' % |
423 str('' if (itm is None) else itm) | 427 self.str_or_empty(itm) |
424 for itm in row))) | 428 for itm in row))) |
425 result = '''<table id="%s"> | 429 result = '''<table id="%s"> |
426 %s | 430 %s |
427 </table>''' % (self.tblname, '\n'.join(result)) | 431 </table>''' % (self.tblname, '\n'.join(result)) |
428 return result | 432 return result |