Exemplo n.º 1
0
def select(sql, table_expr):
    table = get_table(table_expr)
    Globals.update(_locals)
    rs = table.execute(sql)
    if not rs: return
    pt = PrettyTable()
    for row in rs:
        pt.add_row(row)
    print pt
Exemplo n.º 2
0
def select(sql, table_expr):
    table = get_table(table_expr)
    Globals.update(_locals)
    rs = table.execute(sql)
    if not rs: return

    width = [0] * len(rs[0])
    for row in rs:
        for i, r in enumerate(row):
            w = len(str(r))
            if w > width[i]:
                width[i] = w
    print '-' * (sum(width) + len(width) * 3 + 1)
    for row in rs:
        for i, r in enumerate(row):
            print('| %% %ds' % width[i]) % r,
        print '|'
    print '-' * (sum(width) + len(width) * 3 + 1)
Exemplo n.º 3
0
def select(sql, table_expr):
    table = get_table(table_expr)
    Globals.update(_locals)
    rs = table.execute(sql)
    if not rs: return

    width = [0] * len(rs[0])
    for row in rs:
        for i, r in enumerate(row):
            w = len(str(r))
            if w > width[i]:
                width[i] = w
    print '-' * (sum(width) + len(width) * 3 + 1)
    for row in rs:
        for i, r in enumerate(row):
            print ('| %% %ds' % width[i]) % r,
        print '|'
    print '-' * (sum(width) + len(width) * 3 + 1)