You are not logged in.
Hi All,
I need to exclude an autoinc field from generate SQL that is automatically generate from a DB sequence;
I need to read it in Torm fill but I don't want that is present in insert SQL, because DB generate an error if that fields is already in SQL command.
There is way/directive for exclude a field from INSERT/UPDATE command, but that is retrieved on query?
Thanks in advance!
Stefano
Offline
Hi AB,
thank you;
I have solved with
tmpBits := tmpObj.OrmProps.FieldBitsFromExcludingCsv('field01, field02');
ServerMormot.RestServerDb.Add(tmpObj, tmpBits, true, true);
Thanks a lot;
Question: there is a way for set those TFieldBits "permanently" at ORM level (for select, insert, update) ?
Thanks in advance!
Offline
You can try to change TMyOrmClass.OrmProps.SimpleFieldsBits[ooInsert] and [ooUpdate].
But it is not an easy change.
For instance, if you use client/server Batch you should do it on both sides, client and server.
And it should be done ASAP, before you even define the REST model and server/client.
To be fair, I never tested it, so it is unsupported yet.
Offline
I don't use client/server but only server (http).
I will try if "TMyOrmClass.OrmProps.SimpleFieldsBits[ooInsert] and [ooUpdate]" works or not.
Thanks a lot!
Offline
Or maybe you can try a scheme like this:
TOrmMyObject = class(TOrm)
private
FAddFieldBits: TFieldBits;
public
function OrmAdd(const pmcRestOrm: IRestOrm): Boolean;
published
property Name: RawUtf8 ...
function TOrmMyObject.OrmAdd(const pmcRestOrm: IRestOrm): Boolean;
begin
Result := False;
if pmcRestOrm = Nil then Exit; //=>
if IsZero(FAddFieldBits) then
FAddFieldBits := OrmProps.FieldBitsFrom(['Name']);
Result := pmcRestOrm.Add(Self, FAddFieldBits);
end;
var
myObject: TOrmMyObject;
begin
myObject := TOrmMyObject.Create;
try
...
myObject.OrmAdd(MyRestServerDB);
With best regards
Thomas
Offline
HI AB,
>> You can try to change TMyOrmClass.OrmProps.SimpleFieldsBits[ooInsert] and [ooUpdate].
It seems that it works, from my few tests
Thanks a lot
Offline
Thanks Thomas
Offline