#1 2014-12-04 13:31:08

itSDS
Member
From: Germany
Registered: 2014-04-24
Posts: 516

delphi question Dynamic Params for Execute

Hi AB i have a delphi question i can not solve by myself:

I'm writing an interface with Mormot. One Param is RawJSON containing an array auf Strings.
I wan't to give the Strings of this array as Params to:

TSQLDBConnectionProperties.Execute(const aSQL: RawUTF8; const Params: array of const

so i have to create an dynamic array of const and add some RawUtf8 Values to it.
But i dont' know how to do this ?!

var
  pArray : array of const; // does not work
  pArray : TVarRec;  // does
begin
  Connection.Execute('select * from tabelle where id in [?,?,?,?]', pArray)

the ? are generated for every array item.

Can you help me how to code this ?


Rad Studio 12.1 Santorini

Offline

#2 2014-12-04 14:21:01

itSDS
Member
From: Germany
Registered: 2014-04-24
Posts: 516

Re: delphi question Dynamic Params for Execute

May be i found the solution. But it looks very complicated ?!

function Getxyz(cinst AStatus : RawJSON) : RawJSON;
var
  Stmt : ISQLDBRows;
  LAStatus : array of TVarRec;
  LVStatus : variant;
  i : integer;
  sFragezeichen : RawUtf8;
begin
    LVStatus := _JsonFast(AStatus);
    SetLength(LAStatus, DocVariantData(LVStatus).Count);
    sFragezeichen := '';
    for i := 0 to DocVariantData(LVStatus).Count-1 do begin
      if Length(sFragezeichen) > 0 then
        sFragezeichen := sFragezeichen + ',';
      VariantToVarRec(DocVariantData(LVStatus).Values[i], LAStatus[i]);
      sFragezeichen := sFragezeichen + '?';
    end;
    Stmt := Connection.Execute('select * from tabelle where status in (' + sFragezeichen + ')', LAStatus);
    exit(Stmt.FetchAllAsJSON(false));
end;

is there an easier way ?


Rad Studio 12.1 Santorini

Offline

#3 2014-12-04 18:06:52

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,661
Website

Re: delphi question Dynamic Params for Execute

You can use ExecuteInlined() with the parameters inlined with

:("string"):

instead of the ?.

See FormatUTF8() for instance, and the information about inlined parameters in http://synopse.info/files/html/Synopse% … ml#TITL_61

Offline

#4 2014-12-05 12:18:28

itSDS
Member
From: Germany
Registered: 2014-04-24
Posts: 516

Re: delphi question Dynamic Params for Execute

TYVM

Sometimes i have a board in front of the head.


Rad Studio 12.1 Santorini

Offline

Board footer

Powered by FluxBB