Skip to content

Commit e93df71

Browse files
authored
fix: Do not work with Numeric / Boolean fields on HANA DB (#61)
Fix issues: 1. #45 2. #47 And also try to use local environment to connect HANA DB for testing. The error message “Cannot set parameter at row: 1. Argument must be a string” will no longer display when enabled change tracking for a Boolean or Numeric fields.
1 parent 1c244c2 commit e93df71

File tree

5 files changed

+50
-9
lines changed

5 files changed

+50
-9
lines changed

lib/change-log.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -301,8 +301,8 @@ function _trackedChanges4 (srv, target, diff) {
301301
entity: getDBEntity(element.parent).name,
302302
serviceEntity: element.parent.name,
303303
attribute: element["@odata.foreignKey4"] || key,
304-
valueChangedFrom: from || '',
305-
valueChangedTo: to || '',
304+
valueChangedFrom: from?? '',
305+
valueChangedTo: to?? '',
306306
valueDataType: element.type,
307307
modification: row._op,
308308
keys,
@@ -367,7 +367,11 @@ async function track_changes (req) {
367367
entity: dbEntity.name,
368368
entityKey: entityKey,
369369
serviceEntity: target.name,
370-
changes: changes.filter(c => c.valueChangedFrom || c.valueChangedTo),
370+
changes: changes.filter(c => c.valueChangedFrom || c.valueChangedTo).map((c) => ({
371+
...c,
372+
valueChangedFrom: `${c.valueChangedFrom ?? ''}`,
373+
valueChangedTo: `${c.valueChangedTo ?? ''}`,
374+
})),
371375
})
372376
}
373377

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
ID;title;descr;author_ID;stock;price;genre_ID;bookStore_ID
2-
9d703c23-54a8-4eff-81c1-cdce6b8376b1;Wuthering Heights;"Wuthering Heights, Emily Brontë's only novel, was published in 1847 under the pseudonym ""Ellis Bell"". It was written between October 1845 and June 1846. Wuthering Heights and Anne Brontë's Agnes Grey were accepted by publisher Thomas Newby before the success of their sister Charlotte's novel Jane Eyre. After Emily's death, Charlotte edited the manuscript of Wuthering Heights and arranged for the edited version to be published as a posthumous second edition in 1850.";d4d4a1b3-5b83-4814-8a20-f039af6f0387;12;11.11;11;64625905-c234-4d0d-9bc1-283ee8946770
3-
676059d4-8851-47f1-b558-3bdc461bf7d5;Jane Eyre;"Jane Eyre /ɛər/ (originally published as Jane Eyre: An Autobiography) is a novel by English writer Charlotte Brontë, published under the pen name ""Currer Bell"", on 16 October 1847, by Smith, Elder & Co. of London. The first American edition was published the following year by Harper & Brothers of New York. Primarily a bildungsroman, Jane Eyre follows the experiences of its eponymous heroine, including her growth to adulthood and her love for Mr. Rochester, the brooding master of Thornfield Hall. The novel revolutionised prose fiction in that the focus on Jane's moral and spiritual development is told through an intimate, first-person narrative, where actions and events are coloured by a psychological intensity. The book contains elements of social criticism, with a strong sense of Christian morality at its core and is considered by many to be ahead of its time because of Jane's individualistic character and how the novel approaches the topics of class, sexuality, religion and feminism.";47f97f40-4f41-488a-b10b-a5725e762d5e;11;12.34;11;5ab2a87b-3a56-4d97-a697-7af72334a384
4-
42bc7997-f6ce-4ae9-8a64-ee5e02ef1087;The Raven;"""The Raven"" is a narrative poem by American writer Edgar Allan Poe. First published in January 1845, the poem is often noted for its musicality, stylized language, and supernatural atmosphere. It tells of a talking raven's mysterious visit to a distraught lover, tracing the man's slow fall into madness. The lover, often identified as being a student, is lamenting the loss of his love, Lenore. Sitting on a bust of Pallas, the raven seems to further distress the protagonist with its constant repetition of the word ""Nevermore"". The poem makes use of folk, mythological, religious, and classical references.";5c30d395-db0a-4095-bd7e-d4de34646607;333;13.13;16;5ab2a87b-3a56-4d97-a697-7af72334a384
5-
9297e4ea-396e-47a4-8815-cd4622dea8b1;Eleonora;"""Eleonora"" is a short story by Edgar Allan Poe, first published in 1842 in Philadelphia in the literary annual The Gift. It is often regarded as somewhat autobiographical and has a relatively ""happy"" ending.";5c30d395-db0a-4095-bd7e-d4de34646607;555;14;16;8aaed432-8336-4b0d-be7e-3ef1ce7f13ea
6-
574c8add-0ee3-4175-ab62-ca09a92c723c;Catweazle;Catweazle is a British fantasy television series, starring Geoffrey Bayldon in the title role, and created by Richard Carpenter for London Weekend Television. The first series, produced and directed by Quentin Lawrence, was screened in the UK on ITV in 1970. The second series, directed by David Reid and David Lane, was shown in 1971. Each series had thirteen episodes, most but not all written by Carpenter, who also published two books based on the scripts.;a45da28a-7f55-4b53-8a63-48b61132d1b9;22;15;13;8aaed432-8336-4b0d-be7e-3ef1ce7f13ea
1+
ID;title;descr;isUsed;author_ID;stock;price;genre_ID;bookStore_ID
2+
9d703c23-54a8-4eff-81c1-cdce6b8376b1;Wuthering Heights;"Wuthering Heights, Emily Brontë's only novel, was published in 1847 under the pseudonym ""Ellis Bell"". It was written between October 1845 and June 1846. Wuthering Heights and Anne Brontë's Agnes Grey were accepted by publisher Thomas Newby before the success of their sister Charlotte's novel Jane Eyre. After Emily's death, Charlotte edited the manuscript of Wuthering Heights and arranged for the edited version to be published as a posthumous second edition in 1850.";true;d4d4a1b3-5b83-4814-8a20-f039af6f0387;12;11.11;11;64625905-c234-4d0d-9bc1-283ee8946770
3+
676059d4-8851-47f1-b558-3bdc461bf7d5;Jane Eyre;"Jane Eyre /ɛər/ (originally published as Jane Eyre: An Autobiography) is a novel by English writer Charlotte Brontë, published under the pen name ""Currer Bell"", on 16 October 1847, by Smith, Elder & Co. of London. The first American edition was published the following year by Harper & Brothers of New York. Primarily a bildungsroman, Jane Eyre follows the experiences of its eponymous heroine, including her growth to adulthood and her love for Mr. Rochester, the brooding master of Thornfield Hall. The novel revolutionised prose fiction in that the focus on Jane's moral and spiritual development is told through an intimate, first-person narrative, where actions and events are coloured by a psychological intensity. The book contains elements of social criticism, with a strong sense of Christian morality at its core and is considered by many to be ahead of its time because of Jane's individualistic character and how the novel approaches the topics of class, sexuality, religion and feminism.";true;47f97f40-4f41-488a-b10b-a5725e762d5e;11;12.34;11;5ab2a87b-3a56-4d97-a697-7af72334a384
4+
42bc7997-f6ce-4ae9-8a64-ee5e02ef1087;The Raven;"""The Raven"" is a narrative poem by American writer Edgar Allan Poe. First published in January 1845, the poem is often noted for its musicality, stylized language, and supernatural atmosphere. It tells of a talking raven's mysterious visit to a distraught lover, tracing the man's slow fall into madness. The lover, often identified as being a student, is lamenting the loss of his love, Lenore. Sitting on a bust of Pallas, the raven seems to further distress the protagonist with its constant repetition of the word ""Nevermore"". The poem makes use of folk, mythological, religious, and classical references.";true;5c30d395-db0a-4095-bd7e-d4de34646607;333;13.13;16;5ab2a87b-3a56-4d97-a697-7af72334a384
5+
9297e4ea-396e-47a4-8815-cd4622dea8b1;Eleonora;"""Eleonora"" is a short story by Edgar Allan Poe, first published in 1842 in Philadelphia in the literary annual The Gift. It is often regarded as somewhat autobiographical and has a relatively ""happy"" ending.";true;5c30d395-db0a-4095-bd7e-d4de34646607;555;14;16;8aaed432-8336-4b0d-be7e-3ef1ce7f13ea
6+
574c8add-0ee3-4175-ab62-ca09a92c723c;Catweazle;Catweazle is a British fantasy television series, starring Geoffrey Bayldon in the title role, and created by Richard Carpenter for London Weekend Television. The first series, produced and directed by Quentin Lawrence, was screened in the UK on ITV in 1970. The second series, directed by David Reid and David Lane, was shown in 1971. Each series had thirteen episodes, most but not all written by Carpenter, who also published two books based on the scripts.;true;a45da28a-7f55-4b53-8a63-48b61132d1b9;22;15;13;8aaed432-8336-4b0d-be7e-3ef1ce7f13ea

tests/bookshop/db/schema.cds

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ entity Books : managed, cuid {
4949
genre : Association to Genres;
5050
stock : Integer;
5151
price : Decimal;
52+
isUsed : Boolean;
5253
image : LargeBinary @Core.MediaType : 'image/png';
5354
@title : '{i18n>books.bookType}'
5455
bookType : BookTypeCodes;

tests/bookshop/srv/admin-service.cds

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ annotate AdminService.Books with @changelog : [
4848
]{
4949
title @changelog;
5050
descr @changelog;
51+
isUsed @changelog;
5152
author @changelog : [
5253
author.name.firstName,
5354
author.name.lastName

tests/integration/fiori-draft-enabled.test.js

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ describe("change log integration test", () => {
3535
author_ID: "d4d4a1b3-5b83-4814-8a20-f039af6f0387",
3636
stock: 1,
3737
price: 1.0,
38+
isUsed: true
3839
}
3940
);
4041
await utils.apiAction("admin", "BookStores", "64625905-c234-4d0d-9bc1-283ee8946770", "AdminService", action);
@@ -88,13 +89,30 @@ describe("change log integration test", () => {
8889
expect(authorChange.entity).to.equal("Book");
8990
expect(authorChange.valueChangedFrom).to.equal("");
9091
expect(authorChange.valueChangedTo).to.equal("Emily, Brontë");
92+
93+
const isUsedChanges = await adminService.run(
94+
SELECT.from(ChangeView).where({
95+
entity: "sap.capire.bookshop.Books",
96+
attribute: "isUsed",
97+
})
98+
);
99+
expect(isUsedChanges.length).to.equal(1);
100+
const isUsedChange = isUsedChanges[0];
101+
expect(isUsedChange.entityKey).to.equal("64625905-c234-4d0d-9bc1-283ee8946770");
102+
expect(isUsedChange.attribute).to.equal("isUsed");
103+
expect(isUsedChange.modification).to.equal("Create");
104+
expect(isUsedChange.objectID).to.equal("test title, Emily, Brontë");
105+
expect(isUsedChange.entity).to.equal("Book");
106+
expect(isUsedChange.valueChangedFrom).to.equal("");
107+
expect(isUsedChange.valueChangedTo).to.equal("true");
91108
});
92109

93110
it("2.2 Child entity update - should log basic data type changes (ERP4SMEPREPWORKAPPPLAT-32 ERP4SMEPREPWORKAPPPLAT-613)", async () => {
94111
const action = PATCH.bind({}, `/admin/Books(ID=9d703c23-54a8-4eff-81c1-cdce6b8376b1,IsActiveEntity=false)`, {
95112
title: "new title",
96113
author_ID: "47f97f40-4f41-488a-b10b-a5725e762d5e",
97114
genre_ID: 16,
115+
isUsed: false
98116
});
99117
await utils.apiAction("admin", "BookStores", "64625905-c234-4d0d-9bc1-283ee8946770", "AdminService", action);
100118
const bookChanges = await adminService.run(
@@ -166,6 +184,23 @@ describe("change log integration test", () => {
166184
expect(genreChange.entity).to.equal("Book");
167185
expect(genreChange.valueChangedFrom).to.equal("11");
168186
expect(genreChange.valueChangedTo).to.equal("16");
187+
188+
const isUsedChanges = await adminService.run(
189+
SELECT.from(ChangeView).where({
190+
entity: "sap.capire.bookshop.Books",
191+
attribute: "isUsed",
192+
})
193+
);
194+
expect(isUsedChanges.length).to.equal(1);
195+
const isUsedChange = isUsedChanges[0];
196+
expect(isUsedChange.entityKey).to.equal("64625905-c234-4d0d-9bc1-283ee8946770");
197+
expect(isUsedChange.attribute).to.equal("isUsed");
198+
expect(isUsedChange.modification).to.equal("Update");
199+
expect(isUsedChange.objectID).to.equal("new title, Charlotte, Brontë");
200+
expect(isUsedChange.entity).to.equal("Book");
201+
expect(isUsedChange.valueChangedFrom).to.equal("true");
202+
expect(isUsedChange.valueChangedTo).to.equal("false");
203+
169204
});
170205

171206
it("2.3 Child entity delete - should log basic data type changes (ERP4SMEPREPWORKAPPPLAT-32 ERP4SMEPREPWORKAPPPLAT-613)", async () => {

0 commit comments

Comments
 (0)