fix(MySQL Node): Query to statements splitting fix (#9207)

This commit is contained in:
Michael Kret
2024-04-25 16:30:59 +03:00
committed by GitHub
parent 093dcefafc
commit dc844528f4
4 changed files with 61 additions and 8 deletions

View File

@@ -8,6 +8,7 @@ import {
addSortRules,
replaceEmptyStringsByNulls,
escapeSqlIdentifier,
splitQueryToStatements,
} from '../../v2/helpers/utils';
const mySqlMockNode: INode = {
@@ -175,3 +176,29 @@ describe('Test MySql V2, escapeSqlIdentifier', () => {
expect(escapedIdentifier).toEqual('`db_name`.`some.dotted.tbl_name`');
});
});
describe('Test MySql V2, splitQueryToStatements', () => {
it('should split query into statements', () => {
const query =
"insert into models (`created_at`, custom_ship_time, id) values ('2023-09-07 10:26:20', 'some random; data with a semicolon', 1); insert into models (`created_at`, custom_ship_time, id) values ('2023-09-07 10:27:55', 'random data without semicolon\n', 2);";
const statements = splitQueryToStatements(query);
expect(statements).toBeDefined();
expect(statements).toEqual([
"insert into models (`created_at`, custom_ship_time, id) values ('2023-09-07 10:26:20', 'some random; data with a semicolon', 1)",
"insert into models (`created_at`, custom_ship_time, id) values ('2023-09-07 10:27:55', 'random data without semicolon', 2)",
]);
});
it('should not split by ; inside string literal', () => {
const query =
"SELECT custom_ship_time FROM models WHERE models.custom_ship_time LIKE CONCAT('%', ';', '%') LIMIT 10";
const statements = splitQueryToStatements(query);
expect(statements).toBeDefined();
expect(statements).toEqual([
"SELECT custom_ship_time FROM models WHERE models.custom_ship_time LIKE CONCAT('%', ';', '%') LIMIT 10",
]);
});
});