changeset 308:4d24fea42364

py scripts working again
author catherine@Elli.myhome.westell.com
date Wed, 25 Mar 2009 17:16:23 -0400
parents e804c08292b3
children 0d16630d8e04
files sqlpython/sqlpyPlus.py sqlpython/sqlpython.py
diffstat 2 files changed, 10 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/sqlpython/sqlpyPlus.py	Wed Mar 25 16:32:54 2009 -0400
+++ b/sqlpython/sqlpyPlus.py	Wed Mar 25 17:16:23 2009 -0400
@@ -573,7 +573,9 @@
             plot.draw()
             return ''
         else:
-            result = sqlpython.pmatrix(self.rows, self.curs.description, self.maxfetch, heading=self.heading)
+            result = sqlpython.pmatrix(self.rows, self.curs.description, 
+                                       self.maxfetch, heading=self.heading, 
+                                       restructuredtext = (outformat == '\\r'))
         return result
         
     legalOracle = re.compile('[a-zA-Z_$#]')
@@ -747,7 +749,7 @@
         return raw
     
     rowlimitPattern = pyparsing.Word(pyparsing.nums)('rowlimit')
-    terminators = '; \\C \\t \\i \\p \\l \\L \\b '.split() + output_templates.keys()
+    terminators = '; \\C \\t \\i \\p \\l \\L \\b \\r'.split() + output_templates.keys()
 
     @options([make_option('-r', '--row', type="int", default=-1,
                           help='Bind row #ROW instead of final row (zero-based)')])    
--- a/sqlpython/sqlpython.py	Wed Mar 25 16:32:54 2009 -0400
+++ b/sqlpython/sqlpython.py	Wed Mar 25 17:16:23 2009 -0400
@@ -217,6 +217,7 @@
 \\h   HTML table
 \\i   INSERT statements
 \\j   JSON
+\\r   ReStructured Text
 \\s   CSV (with headings)
 \\S   CSV (no headings)
 \\t   transposed
@@ -253,7 +254,7 @@
     do_exit = do_quit
     do_q = do_quit
     
-def pmatrix(rows,desc,maxlen=30,heading=True):
+def pmatrix(rows,desc,maxlen=30,heading=True,restructuredtext=False):
     '''prints a matrix, used by sqlpython to print queries' result sets'''
     names = []
     maxen = []
@@ -299,8 +300,11 @@
         toprint[j] = ' '.join(toprint[j])
     names = ' '.join(names)
     sepcols = ' '.join(sepcols)
-    if heading:
+    if heading or restructuredtext:
         toprint.insert(0, sepcols)
         toprint.insert(0, names)
+    if restructuredtext:
+        toprint.insert(0, sepcols)
+        toprint.append(sepcols)
     return '\n'.join(toprint)