fix(execute): handle nil parameters in prepared statements

Lua tables are msgpacked with the 'without_hole' setting, resulting
in an object. rawQuery already handles this and converts an object
into an array (filling null where appropriate).

Give rawExecute the same treatment.
This commit is contained in:
Linden committed 2022-03-25 04:41:39 +00:00
1 parent b6f850dbd6
commit 86d85dfa00
2 files changed
+24 -12

No files matched your search

+16 -1
View File
@@ -1,4 +1,6 @@
export const parseExecute = (query: string) => {
import { CFXParameters } from '../types';
export const executeType = (query: string) => {
switch (query.replace(/\s.*/, '')) {
case 'SELECT':
return 'execute';
@@ -12,3 +14,16 @@ export const parseExecute = (query: string) => {
return false;
}
};
export const parseExecute = (query: string, parameters: CFXParameters | CFXParameters[]) => {
if (!Array.isArray(parameters))
if (typeof parameters === 'object') {
const arr: unknown[] = [];
Object.entries(parameters).forEach((entry) => (arr[parseInt(entry[0]) - 1] = entry[1]));
parameters = arr;
} else throw new Error(`Parameters expected an array but received ${typeof parameters} instead`);
if (!parameters.every(Array.isArray)) parameters = [[...parameters]];
return parameters;
};