Debian Codegraph @

src/pl/plperl/sql/plperl_shared.sql

raw
1 -- test plperl.on_plperl_init via the shared hash
2 -- (must be done before plperl is first used)
3
4 -- This test tests setting on_plperl_init before loading plperl
5
6 -- testing on_plperl_init gets run, and that it can alter %_SHARED
7 SET plperl.on_plperl_init = '$_SHARED{on_init} = 42';
8
9 -- test the shared hash
10
11 create function setme(key text, val text) returns void language plperl as $$
12
13 my $key = shift;
14 my $val = shift;
15 $_SHARED{$key}= $val;
16
17 $$;
18
19 create function getme(key text) returns text language plperl as $$
20
21 my $key = shift;
22 return $_SHARED{$key};
23
24 $$;
25
26 select setme('ourkey','ourval');
27
28 select getme('ourkey');
29
30 select getme('on_init');
31
32 -- verify that we can use $_SHARED in strict mode
33 create or replace function perl_shared() returns int as $$
34 use strict;
35 my $val = $_SHARED{'stuff'};
36 $_SHARED{'stuff'} = '1';
37 return $val;
38 $$ language plperl;
39
40 select perl_shared();
41 select perl_shared();