fix(execute): incorrect response parsing

Fixes several regressions and issues from ef0dfaa.
Sending a single parameter would set 'single' to true, ignoring multiple
results from the database and returning 'null'.
SELECT should not trigger transactions, not the other way around.
Results should not be parsed when no callback is defined.
This commit is contained in:
Linden committed 2022-04-03 03:52:07 +11:00
1 parent 9511af734b
commit fa1cdcc668
3 files changed
+12 -13

No files matched your search

+1 -1
View File
@@ -3,7 +3,7 @@ game 'common'
name 'oxmysql' name 'oxmysql'
description 'Database wrapper for FiveM utilising node-mysql2 offering improved performance and security.' description 'Database wrapper for FiveM utilising node-mysql2 offering improved performance and security.'
version '2.2.3' version '2.2.4'
url 'https://github.com/overextended/oxmysql' url 'https://github.com/overextended/oxmysql'
author 'overextended' author 'overextended'
+1 -1
View File
@@ -1,6 +1,6 @@
{ {
"name": "oxmysql", "name": "oxmysql",
"version": "2.2.3", "version": "2.2.4",
"description": "FXServer to MySQL communication via node-mysql2", "description": "FXServer to MySQL communication via node-mysql2",
"repository": "[email protected]:overextended/oxmysql.git", "repository": "[email protected]:overextended/oxmysql.git",
"author": "dunak-debug <[email protected]>", "author": "dunak-debug <[email protected]>",
+10 -11
View File
@@ -14,13 +14,9 @@ export const rawExecute = async (
) => { ) => {
const type = executeType(query); const type = executeType(query);
parameters = parseExecute(parameters); parameters = parseExecute(parameters);
let single: boolean; let single: boolean;
if (!parameters.every(Array.isArray)) { if (!parameters.every(Array.isArray)) parameters = [[...parameters]];
single = true;
parameters = [[...parameters]];
}
const length = parameters.length - 1; const length = parameters.length - 1;
@@ -41,15 +37,18 @@ export const rawExecute = async (
connection.execute(query, values, (err, results: RowDataPacket[][]) => { connection.execute(query, values, (err, results: RowDataPacket[][]) => {
if (err) return reject([connection, err]); if (err) return reject([connection, err]);
if (results.length > 1) { if (cb) {
for (const value of results) { if (results.length > 1) {
response.push(parseResponse(type, value)); for (const value of results) {
} response.push(parseResponse(type, value));
} else response.push(parseResponse(type, results)); }
} else response.push(parseResponse(type, results));
}
logQuery(invokingResource, query, process.hrtime(executionTime)[1] / 1e6, values as typeof parameters); logQuery(invokingResource, query, process.hrtime(executionTime)[1] / 1e6, values as typeof parameters);
if (index === length) { if (index === length) {
single = response.length === 1;
if (!single && type !== null) connection.commit(); if (!single && type !== null) connection.commit();
connection.release(); connection.release();
@@ -59,7 +58,7 @@ export const rawExecute = async (
}); });
}; };
if (single || type !== null) { if (type === null) {
execute(); execute();
} else } else
connection.beginTransaction((err) => { connection.beginTransaction((err) => {