Debian Codegraph @

src/pl/plperl/expected/plperl_env.out

raw
1 --
2 -- Test the environment setting
3 --
4 -- directory path and dlsuffix are passed to us in environment variables
5 \getenv libdir PG_LIBDIR
6 \getenv dlsuffix PG_DLSUFFIX
7 \set regresslib :libdir '/regress' :dlsuffix
8 CREATE FUNCTION get_environ()
9 RETURNS text[]
10 AS :'regresslib', 'get_environ'
11 LANGUAGE C STRICT;
12 -- fetch the process environment
13 CREATE FUNCTION process_env () RETURNS text[]
14 LANGUAGE plpgsql AS
15 $$
16
17 declare
18 res text[];
19 tmp text[];
20 f record;
21 begin
22 for f in select unnest(get_environ()) as t loop
23 tmp := regexp_split_to_array(f.t, '=');
24 if array_length(tmp, 1) = 2 then
25 res := res || tmp;
26 end if;
27 end loop;
28 return res;
29 end
30
31 $$;
32 -- plperl should not be able to affect the process environment
33 DO
34 $$
35 $ENV{TEST_PLPERL_ENV_FOO} = "shouldfail";
36 untie %ENV;
37 $ENV{TEST_PLPERL_ENV_FOO} = "testval";
38 my $penv = spi_exec_query("select unnest(process_env()) as pe");
39 my %received;
40 for (my $f = 0; $f < $penv->{processed}; $f += 2)
41 {
42 my $k = $penv->{rows}[$f]->{pe};
43 my $v = $penv->{rows}[$f+1]->{pe};
44 $received{$k} = $v;
45 }
46 unless (exists $received{TEST_PLPERL_ENV_FOO})
47 {
48 elog(NOTICE, "environ unaffected")
49 }
50
51 $$ LANGUAGE plperl;
52 WARNING: attempted alteration of $ENV{TEST_PLPERL_ENV_FOO} at line 12.
53 NOTICE: environ unaffected
54 -- clean up to simplify cross-version upgrade testing
55 DROP FUNCTION get_environ();