You are not logged in.
Hi everyone,
I’m using mORMot 2 and I’ve run into a strange limit with FormatUTF8.
I build an SQL string template like this (with many % placeholders) and then call:
sql := FormatUTF8(jsonTemplate, TDocVariantData(bounds).ToArrayOfConst);
As soon as I use more than ~30 placeholders/arguments, I start getting errors like “too many arguments” or the formatting simply fails.
If I take the same template and the same arguments and run it through Delphi/FPC’s Format() instead, it works fine with more parameters.
So my question is:
Does FormatUTF8 in mORMot 2 have a built-in limit for the number of arguments, or is this a known issue/bug?
And is there a recommended way to handle cases where I need 40+ parameters (e.g. big SQL UPDATE statements)?
Thanks in advance!
Offline
There is indeed a limitation of number of parameters - see TFormatUtf8 record in mormot.core.text:
blocks: array[0..63] of TTempUtf8;But is on purpose, because it is to be build from source, so 32 parameters seems big enough in real source code.
Use a local TTextWriter instead, e.g. via TTextWriter.CreateOwnedStream(tmp).
Anyway, don't go this way. Use SQL parameters. Pre-rendering the UPDATE as SQL with inlined parameters is unsafe, subject to SQL injection. And slower, since the statement can't be prepared and reused between calls.
Offline