batchquery.py
changeset 83 515fadd3d286
parent 39 0cef3540b69f
child 93 b72591087495
equal deleted inserted replaced
82:7b82dc1fb6f5 83:515fadd3d286
     1 #!/usr/bin/env python3.2
     1 #!/usr/bin/env python3.2
     2 
     2 
     3 from pgtoolkit import toolbase
     3 from pgtoolkit import toolbase
     4 from pgtoolkit.highlight import highlight
       
     5 
     4 
     6 
     5 
     7 class BatchQueryTool(toolbase.SimpleTool):
     6 class BatchQueryTool(toolbase.SimpleTool):
     8     def __init__(self):
     7     def __init__(self):
     9         toolbase.SimpleTool.__init__(self, name='batchquery', desc='Run a query using columns from CSV file as arguments.')
     8         toolbase.SimpleTool.__init__(self, name='batchquery', desc='Run a query using columns from CSV file as arguments.')
    51             if self.args.outputfunc:
    50             if self.args.outputfunc:
    52                 with open(self.args.outputfunc, 'r', encoding='utf8') as f:
    51                 with open(self.args.outputfunc, 'r', encoding='utf8') as f:
    53                     d = dict()
    52                     d = dict()
    54                     exec(f.read(), d)
    53                     exec(f.read(), d)
    55                     format_row = d['format_row']
    54                     format_row = d['format_row']
    56             
    55 
    57             with open(self.args.output, 'w', encoding='utf8') as f:
    56             with open(self.args.output, 'w', encoding='utf8') as f:
    58                 for args, rows in results:
    57                 for args, rows in results:
    59                     if format_row:
    58                     if format_row:
    60                         f.write(format_row(args, rows))
    59                         f.write(format_row(args, rows))
    61                     else:
    60                     else: