コード例 #1
0
ファイル: sqlide_grt.py プロジェクト: Vescatur/DatabaseTest
def verticalOutput(editor):
    statement = editor.currentStatement
    if statement:
        rsets = editor.owner.executeScript(statement)
        output = [ '> %s\n' % statement ]
        for idx, rset in enumerate(rsets):
            if len(rsets) > 1:
                output.append('Result set %i' % (idx+1))
            column_name_length = max(len(col.name) for col in rset.columns)
            ok = rset.goToFirstRow()
            while ok:
                output.append('******************** %s. row *********************' % (rset.currentRow + 1))
                for i, column in enumerate(rset.columns):
                    col_name, col_value = column.name.rjust(column_name_length), rset.stringFieldValue(i)
                    output.append('%s: %s' % (col_name, col_value if col_value is not None else 'NULL'))
                ok = rset.nextRow()
            output.append('%d rows in set' % (rset.currentRow + 1))
            rset.reset_references()            
            if len(rsets) > 1:
              output.append('')
        view = TextOutputTab('\n'.join(output) + '\n')
        
        dock = mforms.fromgrt(editor.resultDockingPoint)
        dock.dock_view(view, '', 0)
        dock.select_view(view)
        view.set_title('Vertical Output')


    return 0
コード例 #2
0
ファイル: sqlide_grt.py プロジェクト: juanga16/p111mil
def verticalOutput(editor):
    statements = editor.selectedText or editor.script
    if statements:
        rsets = editor.owner.executeScript(statements)
        for rset in rsets:
            column_name_length = max(len(col.name) for col in rset.columns)
            output = [ '> %s\n' % rset.sql ]
            ok = rset.goToFirstRow()
            while ok:
                output.append('******************** %s. row *********************' % (rset.currentRow + 1))
                for column in rset.columns:
                    col_name, col_value = column.name.rjust(column_name_length), rset.stringFieldValueByName(column.name)
                    output.append('%s: %s' % (col_name, col_value if col_value is not None else 'NULL'))
                ok = rset.nextRow()
            output.append('%d rows in set' % (rset.currentRow + 1))

            view = TextOutputTab('\n'.join(output) + '\n')
            
            dock = mforms.fromgrt(editor.resultDockingPoint)
            dock.dock_view(view, '', 0)
            dock.set_view_title(view, 'Vertical Output')
          
            rset.reset_references()
            
    return 0
コード例 #3
0
ファイル: sqlide_grt.py プロジェクト: Vescatur/DatabaseTest
def executeQueryAsText(qbuffer):
  
    editor = qbuffer.owner
    sql = qbuffer.selectedText or qbuffer.script
    resultsets = editor.executeScript(sql)
  
    if resultsets:
        view = TextOutputTab("")

        dock = mforms.fromgrt(qbuffer.resultDockingPoint)
        dock.dock_view(view, "", 0)
        view.set_title("Query Output")
        dock.select_view(view)

        for result in resultsets:
            output = ["Execute:"]
            output.append("> %s\n" % result.sql)
            line = []
            column_lengths = []
            ncolumns = len(result.columns)
            for column in result.columns:
                line.append(column.name + " "*5)
                column_lengths.append(len(column.name)+5)

            separator = []
            for c in column_lengths:
                separator.append("-"*c)
            separator = " + ".join(separator)
            output.append("+ "+separator+" +")

            line = " | ".join(line)
            output.append("| "+line+" |")

            output.append("+ "+separator+" +\n")

            ok = result.goToFirstRow()
            if ok:
                view.textbox.append_text('\n'.join(output))

            import time
            
            last_flush = 0
            rows = []
            while ok:
                line = []
                for i in range(ncolumns):
                  value = result.stringFieldValue(i)
                  if value is None:
                    value = "NULL"
                  line.append(value.ljust(column_lengths[i]))
                line= " | ".join(line)
                rows.append("| "+line+" |")
                
                # flush text every 1/2s
                if time.time() - last_flush >= 0.5:
                    last_flush = time.time()
                    view.textbox.append_text("\n".join(rows)+"\n")
                    rows = []
                ok = result.nextRow()

            if rows:
                view.textbox.append_text("\n".join(rows)+"\n")

            view.textbox.append_text("+ "+separator+" +\n")
            view.textbox.append_text("%i rows\n\n" % (result.currentRow + 1))

    return 0