-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(
cqn2sql
): smart quoting also for update statements (#475)
this was missing, smart quotation is already in place for other statements
- Loading branch information
1 parent
30e1e7b
commit 1688f77
Showing
4 changed files
with
69 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
'use strict' | ||
const cds = require('../../test/cds.js') | ||
const { expect } = cds.test(__dirname + '/resources') | ||
|
||
describe('keywords', () => { | ||
test('insert, update, select', async () => { | ||
const { Order } = cds.entities | ||
const data = { | ||
ID: 1, | ||
alter: [ | ||
{ | ||
ID: 42, | ||
number: null, | ||
order_ID: 1, | ||
}, | ||
{ | ||
ID: 43, | ||
number: null, | ||
order_ID: 1, | ||
}, | ||
], | ||
} | ||
await INSERT(data).into(Order) | ||
const select = await cds.run(CQL`SELECT from Order { ID, alter { * } } where exists alter`) | ||
expect(select[0]).to.deep.eql(data) | ||
|
||
data.alter.forEach(e => (e.number = 99)) // change data | ||
await UPDATE.entity(Order).with(data).where('exists alter') | ||
|
||
const selectAfterChange = await cds.run(CQL`SELECT from Order { ID, alter { * } } where exists alter`) | ||
expect(selectAfterChange[0]).to.deep.eql(data) | ||
}) | ||
|
||
test('insert as select', async () => { | ||
const { Alter, ASC } = cds.entities | ||
// fill other table first | ||
await cds.run(INSERT({ ID: 1, alias: 42 }).into(ASC)) | ||
await INSERT.into(Alter) | ||
.columns(['ID', 'number']) | ||
.as( | ||
SELECT.from(ASC) | ||
.columns(['ID', 'alias']) | ||
.where({ ref: ['alias'] }, '=', { val: 42 }), | ||
) | ||
const select = await SELECT.from(Alter).where('number = 42') | ||
expect(select[0]).to.eql({ ID: 1, number: 42, order_ID: null }) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
// ORDER / ALTER / ASC / NUMBER are reserved words in ANSI SQL standard | ||
entity Order { | ||
key ID : Integer; | ||
alter: composition of many Alter on alter.order = $self; | ||
} | ||
|
||
entity Alter { | ||
key ID : Integer; | ||
number: Integer; | ||
order: Association to Order; | ||
} | ||
entity ASC { | ||
key ID : Integer; | ||
alias: Integer; | ||
} |