fix: Parameter parsing, new update export, null parameter warning

- fix https://github.com/overextended/oxmysql/issues/14
- fix ? https://github.com/overextended/oxmysql/issues/16
- fix https://github.com/overextended/oxmysql/issues/15
This commit is contained in:
dunak-debug committed 2021-09-17 00:54:13 +02:00
1 parent b01e30d7b1
commit cc74fac733
3 files changed
+173 -76

No files matched your search

+11 -13
View File
@@ -1,5 +1,5 @@
diff --git a/node_modules/named-placeholders/index.js b/node_modules/named-placeholders/index.js
index 527d723..1a955b4 100644
index 527d723..1fb4003 100644
--- a/node_modules/named-placeholders/index.js
+++ b/node_modules/named-placeholders/index.js
@@ -3,7 +3,7 @@
@@ -11,25 +11,23 @@ index 527d723..1a955b4 100644
DQUOTE = 34,
SQUOTE = 39,
BSLASH = 92;
@@ -94,15 +94,27 @@ function createCompiler(config) {
@@ -94,15 +94,25 @@ function createCompiler(config) {
if (typeof params == 'undefined')
throw new Error('Named query contains placeholders, but parameters object is undefined');
+ let parsedParams = {}
+
+ for(const key in params) {
+ parsedParams[key.charAt(0) == '@' ? key.substring(1) : key] = params[key]
+ if(key.charAt(0) === '@' || key.charAt(0) === ':') {
+ params[key.substring(1)] = params[key];
+ delete params[key];
+ }
+ }
+
const tokens = tree[1];
for (let i=0; i < tokens.length; ++i) {
- arr.push(params[tokens[i]]);
+ if(typeof tokens[i] === 'number') {
+ const param = parsedParams[(tokens[i] + 1).toString()];
+ arr.push(param !== undefined ? param : null);
+ } else {
+ arr.push(parsedParams[tokens[i]] !== undefined ? parsedParams[tokens[i]] : null);
+ }
+ const param = params[tokens[i]];
+ if(!param) console.warn(`Parameter ${tokens[i]} has NULL value (Sending nil from lua?)`, tree);
+ arr.push(param || null);
}
+
return [tree[0], arr];
@@ -41,7 +39,7 @@ index 527d723..1a955b4 100644
return s.slice(0, -1);
}
return s;
@@ -115,7 +127,7 @@ function createCompiler(config) {
@@ -115,7 +125,7 @@ function createCompiler(config) {
let unnamed = noTailingSemicolon(tree[0][0]);
for (let i=1; i < tree[0].length; ++i) {
@@ -50,7 +48,7 @@ index 527d723..1a955b4 100644
unnamed += config.placeholder;
}
unnamed += config.placeholder;
@@ -124,7 +136,7 @@ function createCompiler(config) {
@@ -124,7 +134,7 @@ function createCompiler(config) {
const last = tree[0][tree[0].length -1];
if (tree[0].length == tree[1].length) {