Skip to content

Commit

Permalink
fix: only consider persisted columns for simple operations (#592)
Browse files Browse the repository at this point in the history
it doesnt make sense to `UPDATE`, `DELETE` or to `INSERT` a virtual
element, which only exists during runtime, such as:

- `virtual` elements
- calculated elements
- associations

---------

Co-authored-by: Bob den Os <[email protected]>
  • Loading branch information
patricebender and BobdenOs authored Apr 19, 2024
1 parent ed2253e commit 6e31bda
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 7 deletions.
5 changes: 3 additions & 2 deletions db-service/lib/cqn2sql.js
Original file line number Diff line number Diff line change
Expand Up @@ -749,8 +749,9 @@ class CQN2SQLRenderer {
if (_with) _add(_with, x => this.expr(x))
function _add(data, sql4) {
for (let c in data) {
if (!elements || (c in elements && !elements[c].virtual)) {
if (cds.unfold && elements?.[c].is_struct) continue // skip structs from universal csn
const columnExistsInDatabase =
elements && c in elements && !elements[c].virtual && !elements[c].isAssociation && !elements[c].value
if (!elements || columnExistsInDatabase) {
columns.push({ name: c, sql: sql4(data[c]) })
}
}
Expand Down
10 changes: 5 additions & 5 deletions test/bookshop/db/data/sap.capire.bookshop-Authors.csv
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
ID;name;dateOfBirth;placeOfBirth;dateOfDeath;placeOfDeath
101;Emily Brontë;1818-07-30;Thornton, Yorkshire;1848-12-19;Haworth, Yorkshire
107;Charlotte Brontë;1818-04-21;Thornton, Yorkshire;1855-03-31;Haworth, Yorkshire
150;Edgar Allen Poe;1809-01-19;Boston, Massachusetts;1849-10-07;Baltimore, Maryland
170;Richard Carpenter;1929-08-14;King’s Lynn, Norfolk;2012-02-26;Hertfordshire, England
ID;name;dateOfBirth;placeOfBirth;dateOfDeath;placeOfDeath; city; street;
101;Emily Brontë;1818-07-30;Thornton, Yorkshire;1848-12-19;Haworth, Yorkshire; Bradford; 1 Main Street
107;Charlotte Brontë;1818-04-21;Thornton, Yorkshire;1855-03-31;Haworth, Yorkshire; Bradford; 2 Main Street
150;Edgar Allen Poe;1809-01-19;Boston, Massachusetts;1849-10-07;Baltimore, Maryland; Baltimore; 1 Main Street
170;Richard Carpenter;1929-08-14;King’s Lynn, Norfolk;2012-02-26;Hertfordshire, England; London; 1 Main Street
6 changes: 6 additions & 0 deletions test/bookshop/db/schema.cds
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ entity Books : managed {
currency : Currency;
image : LargeBinary @Core.MediaType : 'image/png';
footnotes: array of String;

authorsAddress: String = author.address;
}

entity Authors : managed {
Expand All @@ -22,6 +24,10 @@ entity Authors : managed {
placeOfBirth : String;
placeOfDeath : String;
books : Association to many Books on books.author = $self;

street: String;
city: String;
address: String = street || ', ' || city;
}

/** Hierarchically organized Code List for Genres */
Expand Down

0 comments on commit 6e31bda

Please sign in to comment.