Debian Codegraph @

src/pl/plperl/sql/plperl_env.sql

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