implement Psqlf; include "pg.m"; pg : Pg; Connection : import pg; include "draw.m"; Psqlf: module { init: fn(ctxt: ref Draw->Context, args: list of string); }; init(nil: ref Draw->Context, nil: list of string) { sys = load Sys Sys->PATH; arg->init(args); arg->setusage("psqlf: -U user -P password -h host [-p port] -d database"); pg = load Pg Pg->PATH; Connection, Recordset : import pg; c := ref Connection; c.user := ""; port := "5432"; database := ""; while((c := arg->opt()) != 0) case c { '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"); } }