File: lo_test.sql

package info (click to toggle)
postgresql 7.2.1-2woody8
  • links: PTS
  • area: main
  • in suites: woody
  • size: 42,424 kB
  • ctags: 30,027
  • sloc: ansic: 290,568; java: 18,529; sh: 12,197; sql: 11,401; yacc: 11,189; tcl: 8,063; perl: 4,067; makefile: 3,332; xml: 2,874; lex: 2,799; python: 1,237; cpp: 845; pascal: 81; asm: 70; awk: 20; sed: 8
file content (57 lines) | stat: -rw-r--r-- 1,517 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
--
-- This runs some common tests against the type
--
-- It's used just for development
--

-- ignore any errors here - simply drop the table if it already exists
drop table a;

-- create the test table
create table a (fname name,image lo);

-- insert a null object
insert into a values ('null');

-- insert an empty large object
insert into a values ('empty','');

-- insert a large object based on a file
insert into a values ('/etc/group',lo_import('/etc/group')::lo);

-- now select the table
select * from a;

-- this select also returns an oid based on the lo column
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);

-- insert
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 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%';

-- delete the entry
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;

-- finally drop the table
drop table a;

-- end of tests