From: | David Stanaway <david(at)netventures(dot)com(dot)au> |
---|---|
To: | pgsql-sql(at)postgresql(dot)org |
Cc: | charlie <ctoohey(at)pacbell(dot)net> |
Subject: | Re: Support for bulk reads/writes ? |
Date: | 2002-02-11 22:58:12 |
Message-ID: | D3091A3D-1F42-11D6-8FB4-0003930FDAB2@netventures.com.au |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-sql |
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(at)stanaway(dot)net
Work: david(at)netventures(dot)com(dot)au
From | Date | Subject | |
---|---|---|---|
Next Message | Tom Lane | 2002-02-12 00:49:57 | Re: RTLD_LAZY considered harmful (Re: pltlc and pltlcu |
Previous Message | Andrew Perrin | 2002-02-11 20:24:35 | Re: Support for bulk reads/writes ? |