Register a function to be accessible to this SqlEngine.
SqlEngine.registerFunction(return_type, function_name, function, n_arguments)
When a function is registered using this method, it will be accessible to this SqlEngine.
NB: This method is reentrant. In the current Python API a SqlEngine is implicitly created by a cursor, so this method is rarely needed. Also please note the following:
bool, int, long, float, string, unicoden_arguments argument can be -1: in this case the function can accept a varying number of parameters.n_arguments argument is 2 and function is called with just one parameter, then it is considered as an aggregate (For an example of this see the EMA function in the SDK sample “samples/python/sql/sqlbasic” - a snippet of which is shown below).| Exception | An exception is thrown with the appropriate error message |
def ema(agg,val):
a = 2.0 / (14 + 1)
return a*val + (1-a)*agg
...
dict = exdb.load_dictionary(schema, persistent=is_disk, debug=is_debug)
db = exdb.open_database(dbname='opendb', dictionary=dict, is_disk=is_disk, db_segment_size=128*1024*1024);
exdb.register_function(float, "ema", ema, 2)
...
conn = db.connect()
conn.engine.registerFunction(float, "ema", ema, 2)