blob: 5355c584d72bae637bfaf7126e4e510872ba2811 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
|
#! /usr/local/bin/python
# pgtools.py - valuable functions for PostGreSQL tutorial
# written 1995 by Pascal ANDRE
import sys
# number of rows
scr_size = 24
# waits for a key
def wait_key():
print "Press <enter>"
sys.stdin.read(1)
# displays a table for a select query result
def display(fields, result):
print result
# gets cols width
fmt = []
sep = '+'
head = '|'
for i in range(0, len(fields)):
max = len(fields[i])
for j in range(0, len(result)):
if i < len(result[j]):
if len(result[j][i]) > max:
max = len(result[j][i])
fmt.append(" %%%ds |" % max)
for j in range(0, max):
sep = sep + '-'
sep = sep + '--+'
for i in range(0, len(fields)):
head = head + fmt[i] % fields[i]
print sep + '\n' + head + '\n' + sep
pos = 6
for i in range(0, len(result)):
str = '|'
for j in range(0, len(result[i])):
str = str + fmt[j] % result[i][j]
print str
pos = pos + 1
if pos == scr_size:
print sep
wait_key()
print sep + '\n' + head + '\n' + sep
pos = 6
print sep
wait_key()
|