Skip to content

Commit

Permalink
fix: INSERT with first undefined value (#484)
Browse files Browse the repository at this point in the history
  • Loading branch information
etimr authored Feb 28, 2024
1 parent 2580c24 commit c21e3c4
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
4 changes: 2 additions & 2 deletions db-service/lib/cqn2sql.js
Original file line number Diff line number Diff line change
Expand Up @@ -465,10 +465,11 @@ class CQN2SQLRenderer {

let sepsub = ''
for (const key in row) {
let val = row[key]
if (val === undefined) continue
const keyJSON = `${sepsub}${JSON.stringify(key)}:`
if (!sepsub) sepsub = ','

let val = row[key]
if (val instanceof Readable) {
buffer += `${keyJSON}"`

Expand All @@ -484,7 +485,6 @@ class CQN2SQLRenderer {

buffer += '"'
} else {
if (val === undefined) continue
if (elements[key]?.type in BINARY_TYPES) {
val = transformBase64(val)
}
Expand Down
6 changes: 6 additions & 0 deletions test/scenarios/bookshop/insert.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,10 @@ describe('Bookshop - Insert', () => {
// expect(err instanceof Error).to.be.true
expect(err.message).to.be.eq('ENTITY_ALREADY_EXISTS')
})

test('insert with undefined value works', async () => {
const { Books } = cds.entities('sap.capire.bookshop')
const resp = await cds.run(INSERT({ stock: undefined, ID: 223, title: 'Harry Potter' }).into(Books))
expect(resp | 0).to.be.eq(1)
})
})

0 comments on commit c21e3c4

Please sign in to comment.