Page 1 of 1

TLiteUserFunction

Posted: Tue 27 Nov 2018 16:15
by Mark2018
Hi,
can you give any example on TLiteUserFunction to get back a result parameter ?
And how to register the function ? I expected an Execute method or Active prop...

I have defined a simple function funCountStatus2 as

Code: Select all

SELECT COUNT(*) FROM :aTable WHERE STATUS = 2;
I have set

Code: Select all

LiteUserFunction.FunctionName := 'funCountStatus2';
but from manual it's not clear how use TLiteUserFunction
I have used a TLiteSQL to call the function

Code: Select all

SELECT funCountSendStatus1(:aTable) as count;
but don't know how get back the result...
Can you help ?

Re: TLiteUserFunction

Posted: Thu 29 Nov 2018 10:10
by MaximG
LiteDAŠ” includes the TLiteUserFunction component, which allows creating custom functions (or override the existing ones) in your project code: https://www.devart.com/litedac/docs/dev ... nction.htm
The below code snippet demonstrates using TLiteUserFunction :

Code: Select all

var 
     UserFunction: TLiteUserFunction;
   begin
     UserFunction:=TLiteUserFunction.Create(nil);
     UserFunction.FunctionName:='funCountStatus2';
     UserFunction.FunctionKind:=fkScalar;
     UserFunction.Connection:=<your LiteConnection>;
     UserFunction.Params.CreateParam(ftString, 'TableName', ptInput);
     UserFunction.OnExecute:=LiteFunctionExecuteEvent;
     ... 
   end;

   procedure LiteFunctionExecuteEvent(Sender: TObject; Params: TDAParams; var ResultValue: Variant);
   var
     TableName: String;
   begin
     TableName := Params[0].AsString;
   ...
    < implementation of your function >
   ...
    ResultValue := <the returned result>;
  end;
The samples of custom functions are available in the demo project LiteDacDemo distributed with our components.