From 753f720cb8b9c8e66ab486b1b6a7379e472b9a7a Mon Sep 17 00:00:00 2001 From: "Marc G. Fournier" Date: Sun, 25 Jan 1998 06:09:40 +0000 Subject: Merge in D'Arcy Cain's python interface (PyGreSQL 2.0) --- src/interfaces/python/tutorial/pgtools.py | 47 +++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100755 src/interfaces/python/tutorial/pgtools.py (limited to 'src/interfaces/python/tutorial/pgtools.py') diff --git a/src/interfaces/python/tutorial/pgtools.py b/src/interfaces/python/tutorial/pgtools.py new file mode 100755 index 00000000000..738d221c1c5 --- /dev/null +++ b/src/interfaces/python/tutorial/pgtools.py @@ -0,0 +1,47 @@ +#! /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 " + sys.stdin.read(1) + +# displays a table for a select query result +def display(fields, 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() -- cgit v1.2.3