mirror of
https://github.com/darksaid98/oxmysql.git
synced 2026-12-01 22:21:51 +00:00
fix(execute): handle nil values in nested arrays
Lua tables are msgpacked with the "without_hole" setting. Nested tables being sent with "prepare" failed to account for nil values in tables unpacking into objects.
This commit is contained in:
1 parent
b5190f98e9
commit
25f8feb793
2 files changed
+25
-7
No files matched your search
@@ -15,7 +15,7 @@ export const executeType = (query: string) => {
|
||||
}
|
||||
};
|
||||
|
||||
export const parseExecute = (parameters: CFXParameters) => {
|
||||
export const parseExecute = (placeholders: number, parameters: CFXParameters) => {
|
||||
if (!Array.isArray(parameters)) {
|
||||
if (typeof parameters === 'object') {
|
||||
const arr: unknown[] = [];
|
||||
@@ -24,6 +24,28 @@ export const parseExecute = (parameters: CFXParameters) => {
|
||||
} else throw new Error(`Parameters expected an array but received ${typeof parameters} instead`);
|
||||
}
|
||||
|
||||
if (!parameters.every(Array.isArray)) {
|
||||
if (parameters.every((item) => typeof item === 'object')) {
|
||||
const arr: unknown[][] = [];
|
||||
|
||||
parameters.forEach((value, index) => {
|
||||
arr[index] = new Array(placeholders);
|
||||
|
||||
if (!Array.isArray(value)) {
|
||||
Object.entries(value).forEach((entry) => {
|
||||
arr[index][parseInt(entry[0]) - 1] = entry[1];
|
||||
});
|
||||
} else arr[index] = parameters[index];
|
||||
|
||||
for (let i = 0; i < placeholders; i++) {
|
||||
if (!arr[index][i]) arr[index][i] = null;
|
||||
}
|
||||
|
||||
parameters = arr;
|
||||
});
|
||||
} else parameters = [[...parameters]];
|
||||
}
|
||||
|
||||
return parameters;
|
||||
};
|
||||
|
||||
|
||||
Reference in new issue
Block a user