# ./psqlf -U www -P wangforlife -h 10.0.0.1 -d study
implement Psqlf;
include "sys.m";
sys : Sys;
include "bufio.m";
bufio : Bufio;
Iobuf : import bufio;
include "arg.m";
arg : Arg;
include "pg.m";
pg : Pg;
Connection, Recordset : import pg;
include "draw.m";
Psqlf: module
{
init: fn(ctxt: ref Draw->Context, args: list of string);
};
init(nil: ref Draw->Context, args: list of string)
{
sys = load Sys Sys->PATH;
arg = load Arg Arg->PATH;
arg->init(args);
arg->setusage("psqlf: -U user -P password -h host [-p port] -d database");
pg = load Pg Pg->PATH;
c := ref Connection;
port := "5432";
host := "";
while((a := arg->opt()) != 0)
case a {
'U' => c.user = arg->arg();
'P' => c.password = arg->arg();
'h' => host = arg->arg();
'p' => port = arg->arg();
'd' => c.database = arg->arg();
}
if(c.connect(host, port, nil, nil)) {
if(c.parse("speeder", "SELECT proname, pronargs, proargtypes, proargnames, prorettype, prosrc FROM pg_proc WHERE proowner=$1;", nil)) {
portal := "";
name := "speeder";
parameter_format_codes : array of int;
parameter_format_codes = nil; # array of int
parameters := array[1] of {array of byte "101"};
result_format_codes := array[6] of {0, 0, 0, 0, 0, 0}; # get them all as text
rows_to_return := 0; # no limit
recordset := c.execute(portal, name, nil, parameters, result_format_codes, rows_to_return);
if(recordset == nil)
sys->print("recordset nil\n");
else {
for(r:=0; r < len recordset.rows; r++) {
sys->print("proname %s nargs:%s argtypes:%s argnames:%s returntype:%s src %s\n", string recordset.rows[r][0], string recordset.rows[r][1], string recordset.rows[r][2], string recordset.rows[r][3], string recordset.rows[r][4], string recordset.rows[r][5]);
}
}
}
c.disconnect();
} else {
sys->print("Connection failed\n");
}
}
|