Plan 9 from Bell Labs’s /usr/web/sources/contrib/maht/limbo/pg/do.b

Copyright © 2021 Plan 9 Foundation.
Distributed under the MIT License.
Download the Plan 9 distribution.


implement Do;

include "pg.m";
	pg : Pg;
	Connection : import pg;


include "draw.m";

Do: 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;
	pg = load Pg Pg->PATH;
	Connection, Recordset : import pg;
	c := ref Connection;
	c.user = "inferno";
	c.password = "dante";
	c.database = "external";

	if(c.connect("192.168.1.14", "5432", nil, nil)) {
		if(c.parse("", "SELECT id, n, INET('127.0.0.1') FROM glenda WHERE n=$1;", nil)) {
			recordset := c.execute("", "", nil, array[1] of {array[1] of {byte('z')}}, array[3] of {1, 0, 0}, 0);
			if(recordset == nil)
				sys->print("recordset nil\n");
			else {
				sys->print("%s\n", recordset.to_string());
				for(r := 0; r <len recordset.rows; r++) {
					(nil, id) := pg->bytes_to_int(recordset.rows[r][0]);
					sys->print("Row : %d - id:%d - n:%s now %s\n", r, id, string recordset.rows[r][1], string recordset.rows[r][2]);
				}

			}
		}
		c.disconnect();
	} else {
		sys->print("Connection failed\n");
	}
}

do_sql(c: ref Connection, sql : string)
{
	r := c.query(sql);
	for(i:= 0; i < len(r.rows); i++) {
		row := r.rows[i];
		for(j:= 0; j < len(row[i]); j++) {
			sys->print("	%s", string row[i][j]);
		}
		sys->print("\n");
	}
}

# Put Limbo do

Bell Labs OSI certified Powered by Plan 9

(Return to Plan 9 Home Page)

Copyright © 2021 Plan 9 Foundation. All Rights Reserved.
Comments to webmaster@9p.io.