TLiteUserFunction

Discussion of open issues, suggestions and bugs regarding LiteDAC (SQLite Data Access Components) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
Mark2018
Posts: 7
Joined: Sat 04 Aug 2018 20:03

TLiteUserFunction

Post by Mark2018 » Tue 27 Nov 2018 16:15

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 ?

MaximG
Devart Team
Posts: 1473
Joined: Mon 06 Jul 2015 11:34

Re: TLiteUserFunction

Post by MaximG » Thu 29 Nov 2018 10:10

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.

Post Reply