Further in my code i invoke inserting in database of several objects which fail with error:
...raised exception class EPgNativeException with message
'[FireDAC][Phys][PG][libpq] ERROR: column "import_data" is of type json
but expression is of type text.
You will need to rewrite or cast the expression.'.
Note that Aurelius doesn't save or load anything in the database by itself. It always use another database component for that - in your case, FireDAC.
I'd suggest you first learn how FireDAC itself handles JSON fields. What parameter type does it need to properly save the JSON value? ftMemo? ftBlob? When doing a SELECT, how does FireDAC retrieves the field type? ftMemo? ftString? ftBlob?
That would give a hint about how to map it in Aurelius. It might be a TBlob with [DBTypeMemo], like you did. Or maybe just a regular TBlob without extra attributes.
If FireDAC can save the JSON as a simple ftWideMemo parameter, then it should work normally, that's what Aurelius does when you flag the field as [DBTypeWideMemo].
INSERT INTO public.data_import (importtype, import_data)
VALUES (:importtype, :import_data::json)
You cast second parameter to be json type (not text as you provide it ) and it work fine.
On mOrmot i can tweak queries but here in Aureilius i don't see such option.
initialization
TMappingExplorer.Default.Events.OnSqlExecuting.Subscribe(
procedure(Args: TSQLExecutingArgs)
var
i: integer;
strline: string;
Param: TDBParam;
begin
if pos('insert into data_import', LowerCase(Args.SQL)) > 0 then
begin
Args.SQL := stringreplace(Args.SQL, 'p3', 'p3::json', [rfIgnoreCase]);
strline := '';
for Param in Args.Params do
begin
strline := strline + param.ParamName+'= '+param.ToString+#$D#$A;
end;
ShowMessage(strline);
end;
end
);
It looks like it is work fine because previous error disappeared but this event fire on every transaction to db which i make. Is it possible to make him active only for specific objects ?
Also now i get this error:
ERROR: cannot insert a non-DEFAULT value into column "id".
Column "id" is an identity column defined as GENERATED ALWAYS..
Use OVERRIDING SYSTEM VALUE to override.'.
I checked and see that it provides value for ID of TDataImport class
No, it's fired for every SQL executed by Aurelius.
Since you defined a Sequence attribute for your class, Aurelius will use the sequence to retrieve the next value and use it in the INSERT statement (if the database supports sequences). If you don't want to use sequences and want Aurelius to leave the id generation to the database, then remove the Sequence attribute.