Skip to content

Commit f6b5881

Browse files
authored
fix(query): add missing semi-colon for multi-key statements (#3677)
1 parent 4ea0fc2 commit f6b5881

File tree

2 files changed

+10
-10
lines changed

2 files changed

+10
-10
lines changed

libs/shared/db-layer/src/query/mysql-query.service.spec.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -690,21 +690,21 @@ describe('MysqlQueryService', () => {
690690
currentRow: { k1: 1, k2: 2 },
691691
newRow: { k1: 11, k2: 2 },
692692
keys: ['k1', 'k2'],
693-
query: 'UPDATE `my_table` SET `k1` = 11 WHERE (`k1` = 1) AND (`k2` = 2)',
693+
query: 'UPDATE `my_table` SET `k1` = 11 WHERE (`k1` = 1) AND (`k2` = 2);',
694694
},
695695
{
696696
id: 3,
697697
currentRow: { k1: 1, k2: 2, k3: 3, n1: 1 },
698698
newRow: { k1: 1, k2: 2, k3: 3, n1: 11 },
699699
keys: ['k1', 'k2', 'k3'],
700-
query: 'UPDATE `my_table` SET `n1` = 11 WHERE (`k1` = 1) AND (`k2` = 2) AND (`k3` = 3)',
700+
query: 'UPDATE `my_table` SET `n1` = 11 WHERE (`k1` = 1) AND (`k2` = 2) AND (`k3` = 3);',
701701
},
702702
{
703703
id: 4,
704704
currentRow: { k1: 1, k2: 2, k3: 3, n1: 1 },
705705
newRow: { k1: 1, k2: 2, k3: 33, n1: 11 },
706706
keys: ['k1', 'k2', 'k3'],
707-
query: 'UPDATE `my_table` SET `k3` = 33, `n1` = 11 WHERE (`k1` = 1) AND (`k2` = 2) AND (`k3` = 3)',
707+
query: 'UPDATE `my_table` SET `k3` = 33, `n1` = 11 WHERE (`k1` = 1) AND (`k2` = 2) AND (`k3` = 3);',
708708
},
709709
]) {
710710
it(`should correctly generate the query [${id}]`, () => {
@@ -715,19 +715,19 @@ describe('MysqlQueryService', () => {
715715

716716
describe('getDeleteMultipleKeysQuery', () => {
717717
for (const { id, row, keys, query } of [
718-
{ id: 0, row: {}, keys: [], query: 'DELETE FROM `my_table`' },
719-
{ id: 1, row: { k1: 1 }, keys: ['k1'], query: 'DELETE FROM `my_table` WHERE (`k1` = 1)' },
718+
{ id: 0, row: {}, keys: [], query: 'DELETE FROM `my_table`;' },
719+
{ id: 1, row: { k1: 1 }, keys: ['k1'], query: 'DELETE FROM `my_table` WHERE (`k1` = 1);' },
720720
{
721721
id: 2,
722722
row: { k1: 1, k2: 2 },
723723
keys: ['k1', 'k2'],
724-
query: 'DELETE FROM `my_table` WHERE (`k1` = 1) AND (`k2` = 2)',
724+
query: 'DELETE FROM `my_table` WHERE (`k1` = 1) AND (`k2` = 2);',
725725
},
726726
{
727727
id: 3,
728728
row: { k1: 1, k2: 2, k3: 3 },
729729
keys: ['k1', 'k2', 'k3'],
730-
query: 'DELETE FROM `my_table` WHERE (`k1` = 1) AND (`k2` = 2) AND (`k3` = 3)',
730+
query: 'DELETE FROM `my_table` WHERE (`k1` = 1) AND (`k2` = 2) AND (`k3` = 3);',
731731
},
732732
]) {
733733
it(`should correctly generate the query [${id}]`, () => {

libs/shared/db-layer/src/query/mysql-query.service.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,7 @@ export class MysqlQueryService extends BaseQueryService {
290290
return '';
291291
}
292292
this.addWhereConditionsToQuery(updateQuery, currentRow, primaryKeys);
293-
return updateQuery.toString();
293+
return updateQuery.toString() + ';';
294294
}
295295

296296
// Generates the DELETE query of ONE row using more than 2 keys
@@ -301,7 +301,7 @@ export class MysqlQueryService extends BaseQueryService {
301301
) {
302302
const deleteQuery: Delete = squel.delete(squelConfig).from(tableName);
303303
this.addWhereConditionsToQuery(deleteQuery, row, primaryKeys);
304-
return deleteQuery.toString();
304+
return deleteQuery.toString() + ';';
305305
}
306306

307307
// Generates the full DELETE/INSERT query of ONE row using more than 2 keys
@@ -312,7 +312,7 @@ export class MysqlQueryService extends BaseQueryService {
312312
primaryKeys: string[], // array of the primary keys
313313
) {
314314
const insertQuery: Insert = squel.insert(squelConfig).into(tableName).setFieldsRows([newRow]);
315-
let query: string = this.getDeleteMultipleKeysQuery(tableName, currentRow, primaryKeys) + ';\n';
315+
let query: string = this.getDeleteMultipleKeysQuery(tableName, currentRow, primaryKeys) + '\n';
316316
query += insertQuery.toString() + ';\n';
317317
return this.formatQuery(query);
318318
}

0 commit comments

Comments
 (0)