#1 2022-05-17 16:29:53

Stemon63
Member
Registered: 2016-10-24
Posts: 50

TORM: Hhow to exclude a field from generated SQL ?

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

#2 2022-05-17 16:39:17

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

Re: TORM: Hhow to exclude a field from generated SQL ?

I am not sure I understand your problem...

But anyway, the Add/Update methods do have a field set of bits, or a CSV list of fields to be written.

Offline

#3 2022-05-18 16:12:10

Stemon63
Member
Registered: 2016-10-24
Posts: 50

Re: TORM: Hhow to exclude a field from generated SQL ?

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

#4 2022-05-18 18:01:05

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

Re: TORM: Hhow to exclude a field from generated SQL ?

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

#5 2022-05-19 08:01:29

Stemon63
Member
Registered: 2016-10-24
Posts: 50

Re: TORM: Hhow to exclude a field from generated SQL ?

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

#6 2022-05-19 08:22:42

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

Re: TORM: Hhow to exclude a field from generated SQL ?

It "should work" (tm). wink

Offline

#7 2022-05-19 13:00:24

tbo
Member
Registered: 2015-04-20
Posts: 353

Re: TORM: Hhow to exclude a field from generated SQL ?

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

#8 2022-05-26 16:50:35

Stemon63
Member
Registered: 2016-10-24
Posts: 50

Re: TORM: Hhow to exclude a field from generated SQL ?

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

#9 2022-05-26 16:51:39

Stemon63
Member
Registered: 2016-10-24
Posts: 50

Re: TORM: Hhow to exclude a field from generated SQL ?

Thanks Thomas

Offline

Board footer

Powered by FluxBB