mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-17 18:12:04 +00:00
fix(MySQL Node): Query to statements splitting fix (#9207)
This commit is contained in:
@@ -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",
|
||||
]);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user