Skip to content
This repository was archived by the owner on Apr 29, 2025. It is now read-only.

Commit fa1cdcc

Browse files
committed
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.
1 parent 9511af7 commit fa1cdcc

File tree

3 files changed

+12
-13
lines changed

3 files changed

+12
-13
lines changed

fxmanifest.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ game 'common'
33

44
name 'oxmysql'
55
description 'Database wrapper for FiveM utilising node-mysql2 offering improved performance and security.'
6-
version '2.2.3'
6+
version '2.2.4'
77
url 'https://github.com/overextended/oxmysql'
88
author 'overextended'
99

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "oxmysql",
3-
"version": "2.2.3",
3+
"version": "2.2.4",
44
"description": "FXServer to MySQL communication via node-mysql2",
55
"repository": "[email protected]:overextended/oxmysql.git",
66
"author": "dunak-debug <[email protected]>",

src/database/rawExecute.ts

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,9 @@ export const rawExecute = async (
1414
) => {
1515
const type = executeType(query);
1616
parameters = parseExecute(parameters);
17-
1817
let single: boolean;
1918

20-
if (!parameters.every(Array.isArray)) {
21-
single = true;
22-
parameters = [[...parameters]];
23-
}
19+
if (!parameters.every(Array.isArray)) parameters = [[...parameters]];
2420

2521
const length = parameters.length - 1;
2622

@@ -41,15 +37,18 @@ export const rawExecute = async (
4137
connection.execute(query, values, (err, results: RowDataPacket[][]) => {
4238
if (err) return reject([connection, err]);
4339

44-
if (results.length > 1) {
45-
for (const value of results) {
46-
response.push(parseResponse(type, value));
47-
}
48-
} else response.push(parseResponse(type, results));
40+
if (cb) {
41+
if (results.length > 1) {
42+
for (const value of results) {
43+
response.push(parseResponse(type, value));
44+
}
45+
} else response.push(parseResponse(type, results));
46+
}
4947

5048
logQuery(invokingResource, query, process.hrtime(executionTime)[1] / 1e6, values as typeof parameters);
5149

5250
if (index === length) {
51+
single = response.length === 1;
5352
if (!single && type !== null) connection.commit();
5453
connection.release();
5554

@@ -59,7 +58,7 @@ export const rawExecute = async (
5958
});
6059
};
6160

62-
if (single || type !== null) {
61+
if (type === null) {
6362
execute();
6463
} else
6564
connection.beginTransaction((err) => {

0 commit comments

Comments
 (0)