diff options
author | Bruce Momjian <bruce@momjian.us> | 2002-10-18 18:41:22 +0000 |
---|---|---|
committer | Bruce Momjian <bruce@momjian.us> | 2002-10-18 18:41:22 +0000 |
commit | aa4c702eac936964649f905741b4a99f4b489200 (patch) | |
tree | 517d3c28aa3d28eb95b19c8676c940b5cefe2031 /contrib/lo | |
parent | fb9bc342fffc157d6ca4b635aeeaccb3c1370b91 (diff) | |
download | postgresql-aa4c702eac936964649f905741b4a99f4b489200.tar.gz |
Update /contrib for "autocommit TO 'on'".
Create objects in public schema.
Make spacing/capitalization consistent.
Remove transaction block use for object creation.
Remove unneeded function GRANTs.
Diffstat (limited to 'contrib/lo')
-rw-r--r-- | contrib/lo/lo.sql.in | 70 | ||||
-rw-r--r-- | contrib/lo/lo_drop.sql | 11 | ||||
-rw-r--r-- | contrib/lo/lo_test.sql | 52 |
3 files changed, 78 insertions, 55 deletions
diff --git a/contrib/lo/lo.sql.in b/contrib/lo/lo.sql.in index e60b46ce09..0d9f6c890d 100644 --- a/contrib/lo/lo.sql.in +++ b/contrib/lo/lo.sql.in @@ -1,56 +1,62 @@ -- -- PostgreSQL code for LargeObjects -- --- $Id: lo.sql.in,v 1.7 2002/08/22 00:01:39 tgl Exp $ +-- $Id: lo.sql.in,v 1.8 2002/10/18 18:41:20 momjian Exp $ -- -- -- Create the data type -- -- used by the lo type, it takes an oid and returns an lo object -create function lo_in(cstring) - returns lo - as 'MODULE_PATHNAME' - language 'c'; + +-- Adjust this setting to control where the objects get created. +SET search_path = public; + +SET autocommit TO 'on'; + +CREATE FUNCTION lo_in(cstring) +RETURNS lo +AS 'MODULE_PATHNAME' +LANGUAGE 'C'; -- used by the lo type, it returns the oid of the object -create function lo_out(lo) - returns cstring - as 'MODULE_PATHNAME' - language 'c'; +CREATE FUNCTION lo_out(lo) +RETURNS cstring +AS 'MODULE_PATHNAME' +LANGUAGE 'C'; -- finally the type itself -create type lo ( - internallength = 4, - externallength = variable, - input = lo_in, - output = lo_out +CREATE TYPE lo ( + INTERNALLENGTH = 4, + EXTERNALLENGTH = variable, + INPUT = lo_in, + OUTPUT = lo_out ); -- this returns the oid associated with a lo object -create function lo_oid(lo) - returns oid - as 'MODULE_PATHNAME' - language 'c'; +CREATE FUNCTION lo_oid(lo) +RETURNS oid +AS 'MODULE_PATHNAME' +LANGUAGE 'C'; -- same function, named to allow it to be used as a type coercion, eg: --- create table a (image lo); --- select image::oid from a; +-- CREATE TABLE a (image lo); +-- SELECT image::oid FROM a; -- -create function oid(lo) - returns oid - as 'MODULE_PATHNAME', 'lo_oid' - language 'c'; +CREATE FUNCTION oid(lo) +RETURNS oid +AS 'MODULE_PATHNAME', 'lo_oid' +LANGUAGE 'C'; -- this allows us to convert an oid to a managed lo object -- ie: insert into test values (lo_import('/fullpath/file')::lo); -create function lo(oid) - returns lo - as 'MODULE_PATHNAME' - language 'c'; +CREATE FUNCTION lo(oid) +RETURNS lo +AS 'MODULE_PATHNAME' +LANGUAGE 'C'; -- This is used in triggers -create function lo_manage() - returns trigger - as 'MODULE_PATHNAME' - language 'c'; +CREATE FUNCTION lo_manage() +RETURNS trigger +AS 'MODULE_PATHNAME' +LANGUAGE 'C'; diff --git a/contrib/lo/lo_drop.sql b/contrib/lo/lo_drop.sql index 4e4602836c..d7f34f8bed 100644 --- a/contrib/lo/lo_drop.sql +++ b/contrib/lo/lo_drop.sql @@ -3,13 +3,18 @@ -- It's used just for development -- +-- Adjust this setting to control where the objects get created. +SET search_path = public; + +SET autocommit TO 'on'; + -- remove our test table -drop table a; +DROP TABLE a; -- now drop the type and associated C functions -drop type lo CASCADE; +DROP TYPE lo CASCADE; -- the trigger function has no dependency on the type, so drop separately -drop function lo_manage(); +DROP FUNCTION lo_manage(); -- the lo stuff is now removed from the system diff --git a/contrib/lo/lo_test.sql b/contrib/lo/lo_test.sql index 0c0da2cfd6..9acc47debd 100644 --- a/contrib/lo/lo_test.sql +++ b/contrib/lo/lo_test.sql @@ -5,53 +5,65 @@ -- -- ignore any errors here - simply drop the table if it already exists -drop table a; +DROP TABLE a; -- create the test table -create table a (fname name,image lo); +CREATE TABLE a (fname name,image lo); -- insert a null object -insert into a values ('null'); +INSERT INTO a VALUES ('null'); -- insert an empty large object -insert into a values ('empty',''); +INSERT INTO a VALUES ('empty',''); -- insert a large object based on a file -insert into a values ('/etc/group',lo_import('/etc/group')::lo); +INSERT INTO a VALUES ('/etc/group',lo_import('/etc/group')::lo); -- now select the table -select * from a; +SELECT * FROM a; -- this select also returns an oid based on the lo column -select *,image::oid from a; +SELECT *,image::oid from a; -- now test the trigger -create trigger t_a before update or delete on a for each row execute procedure lo_manage(image); +CREATE TRIGGER t_a +BEFORE UPDATE OR DELETE ON a +FOR EACH ROW +EXECUTE PROCEDURE lo_manage(image); -- insert -insert into a values ('aa',''); -select * from a where fname like 'aa%'; +INSERT INTO a VALUES ('aa',''); +SELECT * FROM a +WHERE fname LIKE 'aa%'; -- update -update a set image=lo_import('/etc/group')::lo where fname='aa'; -select * from a where fname like 'aa%'; +UPDATE a SET image=lo_import('/etc/group')::lo +WHERE fname='aa'; +SELECT * FROM a +WHERE fname LIKE 'aa%'; -- update the 'empty' row which should be null -update a set image=lo_import('/etc/hosts')::lo where fname='empty'; -select * from a where fname like 'empty%'; -update a set image=null where fname='empty'; -select * from a where fname like 'empty%'; +UPDATE a SET image=lo_import('/etc/hosts')::lo +WHERE fname='empty'; +SELECT * FROM a +WHERE fname LIKE 'empty%'; +UPDATE a SET image=null +WHERE fname='empty'; +SELECT * FROM a +WHERE fname LIKE 'empty%'; -- delete the entry -delete from a where fname='aa'; -select * from a where fname like 'aa%'; +DELETE FROM a +WHERE fname='aa'; +SELECT * FROM a +WHERE fname LIKE 'aa%'; -- This deletes the table contents. Note, if you comment this out, and -- expect the drop table to remove the objects, think again. The trigger -- doesn't get thrown by drop table. -delete from a; +DELETE FROM a; -- finally drop the table -drop table a; +DROP TABLE a; -- end of tests |