lightdb object支持authid current_user

文章目录

  • 背景
  • 语法
  • 示例

背景

在信创适配中,从Oracle迁移过来的程序使用authid current_user。为此LightDB从24.1版本开始,对该功能进行了语法层面上的支持。

语法


CREATE [ OR REPLACE ] TYPE name opt_invoker_rights_clause as_is OBJECT ( [ object_type_element_list ] )

 where opt_invoker_rights_clause is:
 
 [ AUTHID CURRENT | AUTHID DEFINER ]
 
 and as_is is:

 AS | IS

 and object_type_element_list is:

 TableFuncElementList [ object_type_func_list ]

 and TableFuncElementList is:

 attribute_name data_type [ COLLATE collation ] [, ... ]

 and object_type_func_list is:

 { type_function_spec | type_procedure_spec } [, ... ]

 and type_function_spec is:

 MEMBER FUNCTION func_name ( [ [ argmode ] [ argname ] argtype [ { DEFAULT | = } default_expr ] [, ...] ] ) RETURN rettype
 
 STATIC FUNCTION func_name ( [ [ argmode ] [ argname ] argtype [ { DEFAULT | = } default_expr ] [, ...] ] ) RETURN rettype

 and type_procedure_spec is:

 MEMBER PROCEDURE func_name ( [ [ argmode ] [ argname ] argtype [ { DEFAULT | = } default_expr ] [, ...] ] )

 STATIC PROCEDURE func_name ( [ [ argmode ] [ argname ] argtype [ { DEFAULT | = } default_expr ] [, ...] ] )

CREATE [ OR REPLACE ] TYPE BODY name as_is subprog_decl_in_type_list END

 where subprog_decl_in_type_list is:
 { func_decl_in_type | proc_decl_in_type }  [ ... ]

 and func_decl_in_type is:
 MEMBER FUNCTION func_name ( [ [ argmode ] [ argname ] argtype [ { DEFAULT | = } default_expr ] [, ...] ] ) RETURN rettype as_is pl_block ;
 
 STATIC FUNCTION func_name ( [ [ argmode ] [ argname ] argtype [ { DEFAULT | = } default_expr ] [, ...] ] ) RETURN rettype as_is pl_block ;

 and proc_decl_in_type is:
 MEMBER PROCEDURE func_name ( [ [ argmode ] [ argname ] argtype [ { DEFAULT | = } default_expr ] [, ...] ] ) as_is pl_block ;
 
 STATIC PROCEDURE func_name ( [ [ argmode ] [ argname ] argtype [ { DEFAULT | = } default_expr ] [, ...] ] ) as_is pl_block ;

 and as_is  is:
 AS | IS

 and pl_block  is:
 [ DECLARE decl_stmts ] BEGIN statement [ , ... ] END

示例

CREATE OR REPLACE TYPE tp_point authid current_user as object (
    x int,
    y int,
    member procedure plus_x(v number),
    member procedure plus_y(v number),
    static procedure p_display(p tp_point),
    static function  f_display(p tp_point) return varchar
);

CREATE OR REPLACE TYPE BODY tp_point AS 
    member procedure plus_x(v number) is 
    BEGIN
        self.x := self.x + v;
    end;

    member procedure plus_y(v number) is 
    BEGIN
        self.y := self.y + v;
    end;

    static procedure p_display(p tp_point) is 
    BEGIN
        dbms_output.put_line('x=' || p.x || ',' || 'y=' || p.y);
    end;

    static function f_display(p tp_point) return varchar is 
    BEGIN
        return 'x=' || p.x || ',' || 'y=' || p.y;
    end;
END;
/


declare
    p tp_point := tp_point(1.0, 2.0);
BEGIN
    tp_point.p_display(p);
    p.plus_x(1.0);
    p.plus_y(2.0);
    dbms_output.put_line(tp_point.f_display(p));
end;
/
x=1,y=2
x=2,y=4
DO

你可能感兴趣的:(lightdb)