Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(MySQL Node): Query Parameters parse string to number #9011

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion packages/nodes-base/nodes/MySql/MySql.node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export class MySql extends VersionedNodeType {
name: 'mySql',
icon: 'file:mysql.svg',
group: ['input'],
defaultVersion: 2.2,
defaultVersion: 2.3,
description: 'Get, add and update data in MySQL',
parameterPane: 'wide',
};
Expand All @@ -21,6 +21,7 @@ export class MySql extends VersionedNodeType {
2: new MySqlV2(baseDescription),
2.1: new MySqlV2(baseDescription),
2.2: new MySqlV2(baseDescription),
2.3: new MySqlV2(baseDescription),
};

super(nodeVersions, baseDescription);
Expand Down
41 changes: 41 additions & 0 deletions packages/nodes-base/nodes/MySql/test/v2/operations.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,47 @@ describe('Test MySql V2, operations', () => {
);
expect(connectionQuerySpy).toBeCalledWith('select * from `test_table`');
});
it('executeQuery, should parse numbers', async () => {
const nodeParameters: IDataObject = {
operation: 'executeQuery',
query: 'SELECT * FROM users LIMIT $1, $2',
options: {
queryBatching: 'independently',
queryReplacement: '2, 5',
nodeVersion: 2.3,
},
};

const nodeOptions = nodeParameters.options as IDataObject;

const fakeConnectionCopy = { ...fakeConnection };

fakeConnectionCopy.query = jest.fn(async (query?: string) => {
return [{ query }];
});
const pool = createFakePool(fakeConnectionCopy);

const connectionQuerySpy = jest.spyOn(fakeConnectionCopy, 'query');

const fakeExecuteFunction = createMockExecuteFunction(nodeParameters, mySqlMockNode);

const runQueries: QueryRunner = configureQueryRunner.call(
fakeExecuteFunction,
nodeOptions,
pool,
);

const result = await executeQuery.execute.call(
fakeExecuteFunction,
emptyInputItems,
runQueries,
nodeOptions,
);

expect(result).toBeDefined();

expect(connectionQuerySpy).toBeCalledWith('SELECT * FROM users LIMIT 2, 5');
});

it('select, should call runQueries with', async () => {
const nodeParameters: IDataObject = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,13 @@ export async function execute(

const preparedQuery = prepareQueryAndReplacements(rawQuery, values);

if ((nodeOptions.nodeVersion as number) >= 2.3) {
const parsedNumbers = preparedQuery.values.map((value) => {
return Number(value) ? Number(value) : value;
});
preparedQuery.values = parsedNumbers;
}

queries.push(preparedQuery);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export const versionDescription: INodeTypeDescription = {
name: 'mySql',
icon: 'file:mysql.svg',
group: ['input'],
version: [2, 2.1, 2.2],
version: [2, 2.1, 2.2, 2.3],
subtitle: '={{ $parameter["operation"] }}',
description: 'Get, add and update data in MySQL',
defaults: {
Expand Down
Loading