AppLib EXECUTE METHOD
From LucidDB Wiki
Contents |
Declarations
-- executes an object/class method with no params, returns String
create or replace function applib.execute_method(
engine_name varchar(255),
script varchar(65535),
obj_name varchar(255),
method_name varchar(255))
returns varchar(65535)
language java
parameter style system defined java
modifies sql data
external name 'applib.applibJar:org.eigenbase.applib.script.ExecuteScriptUdr.executeUdf';
Syntax
VALUES(APPLIB.EXECUTE_METHOD(engineStr, scriptStrOrFile, ObjNameStr, MethodNameStr));
Purpose
This function provides a way to call predefined object or class methods (that take no arguments) on scripts that support OOP. This can save the user some work of editing already existing files, or to easily provide an OOP structure to their scripts. By default this will return the called function's return value as a string.
Input
- ENGINE_NAME: Script engine to use.
- SCRIPT: Script to run.
- OBJ_NAME: Object or class containing the method to run.
- METHOD_NAME: Method to run.
Examples
0: jdbc:luciddb:> values(applib.execute_method('python', 'class A:
. . . . . . . . > @staticmethod
. . . . . . . . > def boo():
. . . . . . . . > return "hi"
. . . . . . . . > ', 'A', 'boo'));
+---------+
| EXPR$0 |
+---------+
| hi |
+---------+
1 row selected (0.092 seconds)
0: jdbc:luciddb:> values(applib.execute_method('js', 'var myObj = {'
. . . . . . . . > ' "C" : "o",'
. . . . . . . . > ' "o" : "k",'
. . . . . . . . > ' "i" : "e",'
. . . . . . . . > ' "s" : "!",'
. . . . . . . . > ' "love" : function() {'
. . . . . . . . > ' return this.s;'
. . . . . . . . > ' }'
. . . . . . . . > ' }', 'myObj', 'love'));
+---------+
| EXPR$0 |
+---------+
| ! |
+---------+
1 row selected (0.355 seconds)
The same issues of scripting directly in sqlLine when it comes to semicolons and single-quotes arise, so as before, it's suggested to use files.