-
-
Notifications
You must be signed in to change notification settings - Fork 43
Update doesn't insert new entries #121
Comments
Hi @mrkarthi, according to the CAP Documentation PUT Requests = UPDATE or PATCH? you should not use PUT to create a record. Best regards |
Hi @gregorwolf, I had raised this question in SAP community for UPSERT operation and the scenario worked with SQLITE as DB. https://answers.sap.com/questions/13355492/multiple-records-in-post-method-in-capm.html Please advice... Thank you. |
Please create a test like I've described in #123. You can start the test project also with:
to check the behaviour in SQLITE. |
Hi @gregorwolf, I have deployed the app in the git repo and sharing the link here. https://github.com/mrkarthi/pg-app Please check and let me know your valuable suggestions. Thank you. Regards, |
I've created https://github.com/gregorwolf/cds-pg/tree/PUT-for-create where I'm able to replicate your issue using the REST Client requests in tests/assets/cap-proj/rest-client-test/beers.http. So when a PUT request is sent to cds-pg the following SQL_ statements are issued:
With sqlite I see:
So the issue is that in cds-pg we do not test if the entry was created and do only the UPDATE and not the INSERT. Perhaps @sjvans can guide us in the right direction. |
hi @gregorwolf we expect number of affected rows as result of an best, [...]
const executeUpdateCQN = async (model, dbc, cqn) => {
const result = await executeGenericCQN(model, dbc, cqn)
return Array.isArray(result) ? result.length : result
}
module.exports = {
delete: executeGenericCQN,
insert: executeInsertCQN,
update: executeUpdateCQN,
read: executeSelectCQN,
//stream: executeSelectStreamCQN,
cqn: executeGenericCQN,
sql: executePlainSQL,
} |
Thank you @sjvans I've added the code and a test. Works now like the sqlite version. |
Hi Team,
I am trying to insert an entry in PUT method in $batch mode. I want to update the entry if already present in db, insert if not present. The response I received in postman client is 200 Ok. But, the data is not available in postgresql.
Request
--batch_1d53-d596-e511
Content-Type: multipart/mixed; boundary=changeset_892a-a8e3-582b
--changeset_892a-a8e3-582b
Content-Type: application/http
Content-Transfer-Encoding: binary
PUT data(id='5',code='5') HTTP/1.1
Accept: application/json
Content-Type: application/json
{"id":"5","code":"5","name":"Desc 005"}
--changeset_892a-a8e3-582b--
--batch_1d53-d596-e511--
Response
--changeset_892a-a8e3-582b
content-type: application/http
content-transfer-encoding: binary
HTTP/1.1 200 OK
odata-version: 4.0
content-type: application/json;odata.metadata=minimal
{"@odata.context":"$metadata#data/$entity","id":"5","code":"5","name":"Desc 005"}
--changeset_892a-a8e3-582b--
Please advice if I missed any steps.
Thank you.
Regards,
Karthi M R.
The text was updated successfully, but these errors were encountered: