{##############################################################################}
{# NexusDB: scrEcho.nxscript                                                  #}
{# Copyright (c) Nexus Database Systems Pty. Ltd. %COPYRIGHT%                 #}
{# All rights reserved.                                                       #}
{##############################################################################}
{# NexusDB: Scripted SQL Function to echo the input argument                  #}
{##############################################################################}
function RegisterSQLFunctions: string;
var
  ab : TnxSQLFunctionInfo;
begin
{
    constructor TnxSQLFunctionInfo.Create(aFunctionName: WideString; aArgCount: integer; aReturnType: TnxSqlReturnTypeType;
                                          aEnabled: Boolean; aExample, aSyntax: WideString; aReturnFieldType: TnxFieldType;
                                          aDecimalPlaces: Integer; aSize: Integer; aCharacterSet: WideString;
                                          aCodePage: Integer; aCollationName: WideString; aLocale: Integer);
}
  RegisteredSQLFunctions.AddObject('scrEcho', TnxSQLFunctionInfo.Create(
          'scrEcho', 1 , rttAsArg1x, true, '', '', nxtWideString, 0, 0, '', 0, '', 0));
  RegisteredSQLFunctions.AddObject('scrUpper', TnxSQLFunctionInfo.Create(
          'scrUpper', 1 , rttAsArg1x, true, '', '', nxtWideString, 0, 0, '', 0, '', 0));
  RegisteredSQLFunctions.AddObject('scrReturnInt32', TnxSQLFunctionInfo.Create(
          'scrReturnInt32', 1 , rttExplicit, true, '', '', nxtInt32, 0, 0, '', 0, '', 0));
  RegisteredSQLFunctions.AddObject('scrReturnWideStringPadded', TnxSQLFunctionInfo.Create(
          'scrReturnWideString', 1 , rttExplicit, true, '', '', nxtWideString, 4, 5, '', 0, '', 0));
  RegisteredSQLFunctions.AddObject('scrReturnWideString', TnxSQLFunctionInfo.Create(
          'scrReturnWideString', 1 , rttExplicit, true, '', '', nxtWideString, 0, 100, '', 0, '', 0));
end;

function scrEcho(aInput: variant): variant;
begin
  result:=aInput;
end;

function scrUpper(aInput: variant): variant;
begin
  result:=UpperCase(aInput);
end;

function scrReturnInt32(aInput: variant): variant;
begin
  if vartype( aInput ) = 8 then
    begin
      try
        result := strtoint( aInput );
      except
        result := 0;
      end;
    end
  else if vartype( aInput ) = 20 then
    begin
      result := aInput;
    end
  else
    begin
      result := vartype( aInput );
    end;
end;

function scrReturnWideString(aInput: variant): variant;
begin
  result:= aInput;
end;

begin
end.



