From: David Stanaway <david@netventures.com.au>
To: pgsql-sql@postgresql.org
Cc: charlie <ctoohey@pacbell.net>
Subject: Re: Support for bulk reads/writes ?
Date: Tue, 12 Feb 2002 09:58:12 +1100
Message-ID: <D3091A3D-1F42-11D6-8FB4-0003930FDAB2@netventures.com.au> (raw)
In-Reply-To: <200202112006.g1BK6KE13063@postgresql.org>
You may find these code snippets handy
CREATE FUNCTION editpresentationparam(int,text[][])
RETURNS int
AS 'DECLARE
prid ALIAS FOR $1;
pairs ALIAS FOR $2;
result int;
rc int;
i int;
BEGIN
result := 0;
i := 1;
DELETE FROM tblPresentationParam WHERE ppprID = prid;
WHILE pairs[i][1] != '''' LOOP
INSERT INTO tblPresentationParam (ppprID,pppnID,ppValue)
SELECT prid, pnID, pairs[i][2] FROM
tblPresentationParamName WHERE pnName = pairs[i][1];
GET DIAGNOSTICS rc = ROW_COUNT;
result := result + rc;
i := i + 1;
END LOOP;
RETURN result;
END;'
LANGUAGE 'plpgsql';
<?php
//Turns a pair of values into a postgres array literal
//EG: "name","Bloggs, Bill 'owdy" ->
// '{"name","Bloggs, Bill ''owdy"}'
function makepair($p1,$p2) {
$pat = array ("/\\\\/","/\"/","/'/");
$rep = array ( '\\\\' , '\"' ,"''");
return '{"'.preg_replace($pat,$rep,$p1).
'","'. preg_replace($pat,$rep,$p2).'"}';
}
function updatepresentationparam($formvars) {
if(isset($formvars['ref'])&&preg_match('/^\d+$/',($formvars['ref']))) {
$q="SELECT editpresentationparam(".$formvars['ref'].",'{";
reset($formvars);
while (list($pnname,$ppvalue) = each($formvars)) {
if($pnname != "ref" && $pnname != "func" && $ppvalue != "") {
$q.=makepair($pnname,$ppvalue).",";
}
}
$q.="{,}}')";
if(! ($res=psql_query_wrap($q))) {
return -1;
} else {
$row = pg_fetch_array($res,0);
return $row[0];
}
} else return -1;
}
?>
==============================
David Stanaway
Personal: david@stanaway.net
Work: david@netventures.com.au
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-sql@postgresql.org
Cc: david@netventures.com.au, ctoohey@pacbell.net
Subject: Re: Support for bulk reads/writes ?
In-Reply-To: <D3091A3D-1F42-11D6-8FB4-0003930FDAB2@netventures.com.au>
References: <200202112006.g1BK6KE13063@postgresql.org> <D3091A3D-1F42-11D6-8FB4-0003930FDAB2@netventures.com.au>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox