#1 2016-03-30 13:37:02

hnb
Member
Registered: 2015-06-15
Posts: 290

Insert new record and Bad Request (400)

Hi,

there is small issue for client/server, for ORM table with EngineAddIgnoreID = true .

when I try to add a new record to the database (by using http server POST), always is returned "Bad Request (400)", despite the proper insert into DB.

Can we somehow get ride of this? I think we can adjust the method TSQLRestServerURIContext.ExecuteORMWrite to receive somehow info about EngineAddIgnoreID for table from TableEngine to return correct value.


best regards,
Maciej Izak

Offline

#2 2016-03-30 13:51:02

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

Re: Insert new record and Bad Request (400)

AFAIK TSQLRestStorageExternal.EngineAdd() is called from ExecuteORMWrite.
Then it calls TSQLRestStorageExternal.ExecuteFromJSON().
Which retrieves the ID as sent by the client, via JSONGetID(pointer(SentData),InsertedID).

So why is not the ID returned by EngineAdd() in your case?

Offline

#3 2016-03-30 14:31:55

hnb
Member
Registered: 2015-06-15
Posts: 290

Re: Insert new record and Bad Request (400)

Because EngineAddIgnoreID is set to true for my table. All works as expected (even 0 returned by EngineAdd) except returned HTML code hmm. ExecuteORMWrite has no info about used "EngineAddIgnoreID".


best regards,
Maciej Izak

Offline

#4 2016-03-30 16:05:58

hnb
Member
Registered: 2015-06-15
Posts: 290

Re: Insert new record and Bad Request (400)

ID must be 0 for EngineAddIgnoreID feature, just look at TSQLRestStorageExternal.EngineLockedNextID (which is called from TSQLRestStorageExternal.EngineAdd)


best regards,
Maciej Izak

Offline

#5 2016-03-30 16:57:46

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

Re: Insert new record and Bad Request (400)

No, if you use EngineAddIgnoreID then the client should supply the ID when adding.

Doc wrote:

"in this case, the ID is expected to be supplied"

    /// disable internal ID generation for INSERT
    // - by default, a new ID will be set (either with 'select max(ID)' or via
    // the OnEngineLockedNextID event)
    // - define this property to TRUE so that no ID would be computed or set:
    // in this case, the ID is expected to be supplied
    property EngineAddIgnoreID: boolean read fEngineAddIgnoreID write fEngineAddIgnoreID;

Offline

#6 2016-03-30 17:38:00

hnb
Member
Registered: 2015-06-15
Posts: 290

Re: Insert new record and Bad Request (400)

Not at all, I am the author of EngineAddIgnoreID/OnEngineLockedNextID ... ( http://synopse.info/forum/viewtopic.php?id=2842 )

The main idea of usage/introducing EngineAddIgnoreID is final SQL for ORM Add without ID:

insert into x (a, b) values (1, 2)

Important for "database-first" approach and for merging mORMot into existing projects. I need to omit OnEngineLockedNextID, 'select max(ID)' and I can't provide ID.

It works perfect for my projects since 2015-09-01 (was introduced to omit ID in insert) but I got 400 error in my "fiddler logs" which is a little confusing since all is correctly inserted into DB.


best regards,
Maciej Izak

Offline

Board footer

Powered by FluxBB