File: find_function.out

package info (click to toggle)
pljs 1.0.3-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 6,916 kB
  • sloc: ansic: 69,358; javascript: 5,408; sql: 880; makefile: 446; sh: 123
file content (61 lines) | stat: -rw-r--r-- 1,666 bytes parent folder | download
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
58
59
60
61
CREATE FUNCTION callee(a int) RETURNS int AS $$ return a * a $$ LANGUAGE pljs;
CREATE FUNCTION sqlf(int) RETURNS int AS $$ SELECT $1 * $1 $$ LANGUAGE sql;
CREATE FUNCTION caller(a int, t int) RETURNS int AS $$
  var func;
  if (t == 1) {
    func = pljs.find_function("callee");
  } else if (t == 2) {
    func = pljs.find_function("callee(int)");
  } else if (t == 3) {
    func = pljs.find_function("sqlf");
  } else if (t == 4) {
    func = pljs.find_function("callee(int, int)");
  } else if (t == 5) {
    try{
      func = pljs.find_function("caller()");
    }catch(e){
      func = function(a){ return a };
    }
  }
  return func(a);
$$ LANGUAGE pljs;
SELECT caller(10, 1);
 caller 
--------
    100
(1 row)

SELECT caller(10, 2);
 caller 
--------
    100
(1 row)

SELECT caller(10, 3);
ERROR:  execution error
DETAIL:  Error: javascript function is not found for "sqlf"
    at caller (<function>:9:30)

SELECT caller(10, 4);
ERROR:  execution error
DETAIL:  Error: javascript function is not found for "callee(int, int)"
    at caller (<function>:11:30)

SELECT caller(10, 5);
 caller 
--------
     10
(1 row)

-- test find_function permissions failure
CREATE FUNCTION perm() RETURNS void AS $$ pljs.elog(NOTICE, 'nope'); $$ LANGUAGE pljs;
CREATE ROLE someone_else;
REVOKE EXECUTE ON FUNCTION perm() FROM public;
SET ROLE TO someone_else;
DO $$ const func = pljs.find_function('perm') $$ LANGUAGE pljs;
WARNING:  failed to find or no permission for js function perm
DO $$ const func = pljs.find_function('perm()') $$ LANGUAGE pljs;
WARNING:  failed to find or no permission for js function perm()
RESET ROLE;
DROP ROLE someone_else;
DROP FUNCTION perm();