Skip to content

Commit 610ead9

Browse files
fix(MySQL Node): Query Parameters parse string to number (#9011)
1 parent 3dd70a1 commit 610ead9

File tree

4 files changed

+51
-2
lines changed

4 files changed

+51
-2
lines changed

packages/nodes-base/nodes/MySql/MySql.node.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ export class MySql extends VersionedNodeType {
1111
name: 'mySql',
1212
icon: 'file:mysql.svg',
1313
group: ['input'],
14-
defaultVersion: 2.2,
14+
defaultVersion: 2.3,
1515
description: 'Get, add and update data in MySQL',
1616
parameterPane: 'wide',
1717
};
@@ -21,6 +21,7 @@ export class MySql extends VersionedNodeType {
2121
2: new MySqlV2(baseDescription),
2222
2.1: new MySqlV2(baseDescription),
2323
2.2: new MySqlV2(baseDescription),
24+
2.3: new MySqlV2(baseDescription),
2425
};
2526

2627
super(nodeVersions, baseDescription);

packages/nodes-base/nodes/MySql/test/v2/operations.test.ts

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,47 @@ describe('Test MySql V2, operations', () => {
254254
);
255255
expect(connectionQuerySpy).toBeCalledWith('select * from `test_table`');
256256
});
257+
it('executeQuery, should parse numbers', async () => {
258+
const nodeParameters: IDataObject = {
259+
operation: 'executeQuery',
260+
query: 'SELECT * FROM users LIMIT $1, $2',
261+
options: {
262+
queryBatching: 'independently',
263+
queryReplacement: '2, 5',
264+
nodeVersion: 2.3,
265+
},
266+
};
267+
268+
const nodeOptions = nodeParameters.options as IDataObject;
269+
270+
const fakeConnectionCopy = { ...fakeConnection };
271+
272+
fakeConnectionCopy.query = jest.fn(async (query?: string) => {
273+
return [{ query }];
274+
});
275+
const pool = createFakePool(fakeConnectionCopy);
276+
277+
const connectionQuerySpy = jest.spyOn(fakeConnectionCopy, 'query');
278+
279+
const fakeExecuteFunction = createMockExecuteFunction(nodeParameters, mySqlMockNode);
280+
281+
const runQueries: QueryRunner = configureQueryRunner.call(
282+
fakeExecuteFunction,
283+
nodeOptions,
284+
pool,
285+
);
286+
287+
const result = await executeQuery.execute.call(
288+
fakeExecuteFunction,
289+
emptyInputItems,
290+
runQueries,
291+
nodeOptions,
292+
);
293+
294+
expect(result).toBeDefined();
295+
296+
expect(connectionQuerySpy).toBeCalledWith('SELECT * FROM users LIMIT 2, 5');
297+
});
257298

258299
it('select, should call runQueries with', async () => {
259300
const nodeParameters: IDataObject = {

packages/nodes-base/nodes/MySql/v2/actions/database/executeQuery.operation.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,13 @@ export async function execute(
8181

8282
const preparedQuery = prepareQueryAndReplacements(rawQuery, values);
8383

84+
if ((nodeOptions.nodeVersion as number) >= 2.3) {
85+
const parsedNumbers = preparedQuery.values.map((value) => {
86+
return Number(value) ? Number(value) : value;
87+
});
88+
preparedQuery.values = parsedNumbers;
89+
}
90+
8491
queries.push(preparedQuery);
8592
}
8693

packages/nodes-base/nodes/MySql/v2/actions/versionDescription.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ export const versionDescription: INodeTypeDescription = {
88
name: 'mySql',
99
icon: 'file:mysql.svg',
1010
group: ['input'],
11-
version: [2, 2.1, 2.2],
11+
version: [2, 2.1, 2.2, 2.3],
1212
subtitle: '={{ $parameter["operation"] }}',
1313
description: 'Get, add and update data in MySQL',
1414
defaults: {

0 commit comments

Comments
 (0)