#1 2013-07-19 16:36:09

lele9
Member
Registered: 2011-10-28
Posts: 170

createandfillprepare with a dinamic array of parameters

hi,
i have used
TMySQLRecord.CreateAndFillPrepare(aClient, aSQLWhere, [const1, const2,..]);

now i would create my array of const dinamically (and decide which parameters pass) but when i write

TmyArray = Array of TVarRec;

myArray: TmyArray;

...

TMySQLRecord.CreateAndFillPrepare(aClient, aSQLWhere, myArray);

i have
[DCC Error] E2250 There is no overloaded version of 'CreateAndFillPrepare' that can be called with these arguments

maybe i lost in a glass of water...how can do this?
thanks

Offline

#2 2013-07-19 17:15:21

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

Re: createandfillprepare with a dinamic array of parameters

This is not possible AFAIK, from the Delphi point of view, unless you use some low level hack.

What you can do is use the "inline" feature of prepared statements of mORMot ORM, so you can put the parameters when you need to.
I'm speaking about :(...): parameters.

Offline

#3 2013-07-22 07:18:38

lele9
Member
Registered: 2011-10-28
Posts: 170

Re: createandfillprepare with a dinamic array of parameters

hi ab,
which methods the orm offer to do this?

Offline

#4 2013-07-22 08:00:18

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

Re: createandfillprepare with a dinamic array of parameters

You can create an "inlined request" using the overloaded FormatUTF8() function of SynCommons.pas:

/// fast Format() function replacement, handling % and ? parameters
// - will include Args[] for every % in Format
// - will inline Params[] for every ? in Format, handling special "inlined"
// parameters, as exected by mORMot.pas unit, i.e. :(1234): for numerical
// values, and :('quoted '' string'): for textual values
// - resulting string has no length limit and uses fast concatenation
// - maximum count of supplied argument in Args is 12
// - note that cardinal values should be type-casted to Int64() (otherwise
// the integer mapped value will be transmitted, therefore wrongly)
function FormatUTF8(Format: PUTF8Char; const Args, Params: array of const): RawUTF8; overload;

AFAIK this "inlining" mechanism is explained in the SAD pdf.
Ensure you read this part, at the beginning of the ORM chapter.

Offline

#5 2013-07-22 08:40:25

lele9
Member
Registered: 2011-10-28
Posts: 170

Re: createandfillprepare with a dinamic array of parameters

sorry but i cant pass an array variable to formatUTF8. Can u make an example please?

Offline

#6 2013-07-22 10:02:20

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

Re: createandfillprepare with a dinamic array of parameters

lele9 wrote:

sorry but i cant pass an array variable to formatUTF8. Can u make an example please?

This is not possible, due to object pascal restrictions, I suppose.

You can use something similar to FormatUTF8() to create your own "inlined" RawUTF8 string, with your own variables array.

But I still do not find out why you need it.

What we can do is adding a new FormatUTF8() method accepting an array of variants instead of an array of const.
Then add an overloaded TSQLRecord.CreateAndFillPrepare() method accepting an array of variants instead of an array of const.
Is it what you need?

Offline

Board footer

Powered by FluxBB