note 63911 added to function.pdo-pgsqllobcreate

From: Date: Mon, 03 Apr 2006 16:38:23 +0000
Subject: note 63911 added to function.pdo-pgsqllobcreate
Groups: php.notes 
Request: Send a blank email to php-notes+get-107236@lists.php.net to get a copy of this message
IMHO, there's a better way to handle the deletion of lob objects than the suggested here. The programmer can easily forget to unlink the lob. With the following trigger, no programmer actions are required. By the way, one problem with bytea fields is that when you query the database, if you ask for that field, the data is actually retrieved. When you query for and oid, only the oid is retrieved and then you can open the lob whenever you want (if it's required). CREATE OR REPLACE FUNCTION oidtable_after_update_delete() RETURNS "trigger" AS $BODY$ BEGIN IF (TG_OP = 'UPDATE') THEN IF (OLD.oidfield = NEW.oidfield) OR (OLD.oidfield IS NULL) THEN RETURN NEW; END IF; END IF; IF (EXISTS (SELECT 1 FROM pg_largeobject WHERE loid = OLD.oidfield)) THEN PERFORM LO_UNLINK (OLD.oidfield); END IF; RETURN NEW; END; $BODY$ LANGUAGE 'plpgsql' VOLATILE; CREATE TRIGGER oidtable_after_update_delete AFTER UPDATE OR DELETE ON oidtable FOR EACH ROW EXECUTE PROCEDURE oidtable_after_update_delete(); ---- Server IP: 200.59.45.3 Probable Submitter: 24.232.66.187 ---- X-Spam-Status: No, hits=3.9 required=5.0 tests=DATE_MISSING,FROM_NO_LOWER, UPPERCASE_50_75 autolearn=no version=2.64 ---- Manual Page -- http://www.php.net/manual/en/function.pdo-pgsqllobcreate.php Edit -- http://master.php.net/note/edit/63911 Del: integrated -- http://master.php.net/note/delete/63911/integrated Del: useless -- http://master.php.net/note/delete/63911/useless Del: bad code -- http://master.php.net/note/delete/63911/bad+code Del: spam -- http://master.php.net/note/delete/63911/spam Del: non-english -- http://master.php.net/note/delete/63911/non-english Del: in docs -- http://master.php.net/note/delete/63911/in+docs Del: other reasons-- http://master.php.net/note/delete/63911 Reject -- http://master.php.net/note/reject/63911 Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#107236) next »