Comments (7)
hi @gregorwolf
we expect number of affected rows as result of an UPDATE
. below lib/pg/execute.js
fixes this issue (i didn't run the tests!).
best,
sebastian
[...]
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,
}
from cds-pg.
Hi @mrkarthi,
according to the CAP Documentation PUT Requests = UPDATE or PATCH? you should not use PUT to create a record.
Best regards
Gregor
from cds-pg.
Hi @gregorwolf,
I had raised this question in SAP community for UPSERT operation and the scenario worked with SQLITE as DB.
I am trying now to use the same kind of approach with postgresql.
https://answers.sap.com/questions/13355492/multiple-records-in-post-method-in-capm.html
Please advice...
Thank you.
Regards,
Karthi M R.
from cds-pg.
Please create a test like I've described in #123. You can start the test project also with:
npm run test:as-sqlite
to check the behaviour in SQLITE.
from cds-pg.
Hi @gregorwolf,
I have deployed the app in the git repo and sharing the link here.
As, I had difficulties in 'cds deploy' to sqlite --in-memory, I have modified the cds.requires.db.kind parameter in package.json to 'sqlite' to run the testing in sqlite db.
https://github.com/mrkarthi/pg-app
Please check and let me know your valuable suggestions.
Thank you.
Regards,
Karthi M R.
from cds-pg.
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:
[cds] - PUT /beershop/Beers(4c11c6a5-1b96-48da-8af4-02c91ec27716)
[cds.cds-pg] - sql > UPDATE csw_Beers SET name = $1, ID = $2, abv = $3, ibu = $4, brewery_ID = $5, modifiedAt = $6, modifiedBy = $7 WHERE ID = $8
[cds.cds-pg] - values > [
'Testbier with PUT',
'4c11c6a5-1b96-48da-8af4-02c91ec27716',
null,
null,
null,
'NOW ()',
'ANONYMOUS',
'4c11c6a5-1b96-48da-8af4-02c91ec27716'
]
[cds.cds-pg] - sql > SELECT ID AS "ID", createdAt AS "createdAt", createdBy AS "createdBy", modifiedAt AS "modifiedAt", modifiedBy AS "modifiedBy", name AS "name", abv AS "abv", ibu AS "ibu", brewery_ID AS "brewery_ID" FROM BeershopService_Beers ALIAS_1 WHERE ID = $1
[cds.cds-pg] - values > [ '4c11c6a5-1b96-48da-8af4-02c91ec27716' ]
With sqlite I see:
[cds] - PUT /beershop/Beers(4c11c6a5-1b96-48da-8af4-02c91ec27716)
[cds.sqlite] - BEGIN
[cds.sqlite] - UPDATE csw_Beers SET name = ?, ID = ?, abv = ?, ibu = ?, brewery_ID = ?, modifiedAt = ?, modifiedBy = ? WHERE ID = ? [
'Testbier with PUT',
'4c11c6a5-1b96-48da-8af4-02c91ec27716',
null,
null,
null,
'2021-05-07T20:44:20.041Z',
'anonymous',
'4c11c6a5-1b96-48da-8af4-02c91ec27716'
]
[cds.sqlite] - SELECT 1 FROM BeershopService_Beers ALIAS_1 WHERE ID = ? [ '4c11c6a5-1b96-48da-8af4-02c91ec27716' ]
[cds.sqlite] - INSERT INTO csw_Beers ( name, ID, createdAt, createdBy, modifiedAt, modifiedBy ) VALUES ( ?, ?, ?, ?, ?, ? ) [
'Testbier with PUT',
'4c11c6a5-1b96-48da-8af4-02c91ec27716',
'2021-05-07T20:44:20.041Z',
'anonymous',
'2021-05-07T20:44:20.041Z',
'anonymous'
]
[cds.sqlite] - SELECT ID, createdAt, createdBy, modifiedAt, modifiedBy, name, abv, ibu, brewery_ID FROM BeershopService_Beers ALIAS_1 WHERE ID = ? [ '4c11c6a5-1b96-48da-8af4-02c91ec27716' ]
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.
from cds-pg.
Thank you @sjvans I've added the code and a test. Works now like the sqlite version.
from cds-pg.
Related Issues (20)
- Invalid SQL query when Draft Entity make reference to other Draft Entity in OData call. HOT 3
- Vulnerability in momentjs 2.9.1 HOT 3
- Error upon modifying view in service HOT 1
- Strong security issue regarding indirect dependency to jsonwebtoken npm-module 8.x
- PATCH is executed on active entity for drafts with compositions HOT 3
- Error: [cds-dbm] - failed to load model undefined (STDERR, APP/TASK/deploy-to-postgresql)# HOT 2
- TypeError: Cannot read properties of undefined (reading 'definitions') HOT 4
- connection closed after each query
- Date conversion interprets timezone incorrectly
- Get request on entity not working
- Retain Column Name as case sensitive during deployment
- Wrong type cast of boolean HOT 1
- Query draft entities on db layer
- broken connectivity in 0.1.36 when using "cds watch" instead of "cds serve". using cap cds 6.6
- error: relation "[tablename]" does not exist
- duplicate key entry HOT 2
- cds-pg deploy fails with "Cannot find module '@sap/cds/lib/deploy'"
- Initial Release schedule?
- ERROR: syntax error at or near "LOCK" at character - STATEMENT: SELECT 1 FROM My_Type ALIAS_1 WHERE ( code = 1 ) LIMIT 1 FOR SHARE LOCK
- Query values must be an array ERROR
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from cds-pg.