mm_mysql 1.7.3 → 1.7.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/sql.js +27 -5
- package/test.js +10 -10
package/package.json
CHANGED
package/sql.js
CHANGED
|
@@ -525,13 +525,18 @@ Sql.prototype.toSet = function(obj) {
|
|
|
525
525
|
*/
|
|
526
526
|
Sql.prototype.toAddSql = function(item) {
|
|
527
527
|
var key = "";
|
|
528
|
-
var
|
|
528
|
+
var value = "";
|
|
529
529
|
for (var k in item) {
|
|
530
530
|
key += "," + escapeId(k);
|
|
531
|
-
val
|
|
531
|
+
var val = item[k];
|
|
532
|
+
if (val && typeof(val) == "string") {
|
|
533
|
+
val = val.trim("'");
|
|
534
|
+
}
|
|
535
|
+
value += "," + escape(val);
|
|
532
536
|
}
|
|
533
537
|
var sql = "INSERT INTO `{0}` ({1}) VALUES ({2});";
|
|
534
|
-
return sql.replace("{0}", this.table).replace("{1}", key.replace(",", "")).replace("{2}",
|
|
538
|
+
return sql.replace("{0}", this.table).replace("{1}", key.replace(",", "")).replace("{2}", value.replace(",",
|
|
539
|
+
""));
|
|
535
540
|
};
|
|
536
541
|
|
|
537
542
|
/**
|
|
@@ -764,11 +769,18 @@ Sql.prototype.tpl_query = function(paramDt, sqlDt) {
|
|
|
764
769
|
var sl = "(";
|
|
765
770
|
var len = arr.length;
|
|
766
771
|
for (var i = 0; i < len; i++) {
|
|
767
|
-
|
|
772
|
+
var val = arr[i];
|
|
773
|
+
if (val && typeof(val) == "string") {
|
|
774
|
+
val = val.trim("'");
|
|
775
|
+
}
|
|
776
|
+
sl += " || " + tpl.replaceAll("{0}", escape(val).trim("'"));
|
|
768
777
|
}
|
|
769
778
|
sl = sl.replace(" || ", "") + ")";
|
|
770
779
|
sql += " && " + sl;
|
|
771
780
|
} else {
|
|
781
|
+
if (value && typeof(value) == "string") {
|
|
782
|
+
value = value.trim("'");
|
|
783
|
+
}
|
|
772
784
|
sql += " && " + tpl.replaceAll("{0}", escape(value).trim("'"));
|
|
773
785
|
}
|
|
774
786
|
} else {
|
|
@@ -777,11 +789,18 @@ Sql.prototype.tpl_query = function(paramDt, sqlDt) {
|
|
|
777
789
|
var sl = "(";
|
|
778
790
|
var len = arr.length;
|
|
779
791
|
for (var i = 0; i < len; i++) {
|
|
780
|
-
|
|
792
|
+
var val = arr[i];
|
|
793
|
+
if (val && typeof(val) == "string") {
|
|
794
|
+
val = val.trim("'");
|
|
795
|
+
}
|
|
796
|
+
sl += " || " + escapeId(key) + " = " + escape(val);
|
|
781
797
|
}
|
|
782
798
|
sl = sl.replace(" || ", "") + ")";
|
|
783
799
|
sql += " && " + sl;
|
|
784
800
|
} else {
|
|
801
|
+
if (value && typeof(value) == "string") {
|
|
802
|
+
value = value.trim("'");
|
|
803
|
+
}
|
|
785
804
|
sql += " && " + escapeId(key) + " = " + escape(value);
|
|
786
805
|
}
|
|
787
806
|
}
|
|
@@ -789,6 +808,9 @@ Sql.prototype.tpl_query = function(paramDt, sqlDt) {
|
|
|
789
808
|
} else {
|
|
790
809
|
for (var key in paramDt) {
|
|
791
810
|
var value = paramDt[key];
|
|
811
|
+
if (value && typeof(value) == "string") {
|
|
812
|
+
value = value.trim("'");
|
|
813
|
+
}
|
|
792
814
|
value = escape(value);
|
|
793
815
|
if (sqlDt[key]) {
|
|
794
816
|
sql += " && " + sqlDt[key].replaceAll("{0}", value.trim("'"));
|
package/test.js
CHANGED
|
@@ -81,7 +81,7 @@ async function test_tpl_get() {
|
|
|
81
81
|
db.table = 'user_account';
|
|
82
82
|
var query = {
|
|
83
83
|
gm_min: 2,
|
|
84
|
-
username: '
|
|
84
|
+
username: 'ad%m'
|
|
85
85
|
};
|
|
86
86
|
db.page = 1;
|
|
87
87
|
db.size = 5;
|
|
@@ -91,15 +91,15 @@ async function test_tpl_get() {
|
|
|
91
91
|
console.log('查询结果', ret);
|
|
92
92
|
console.log('SQL语句', db.sql);
|
|
93
93
|
|
|
94
|
-
var o = ret.list[0];
|
|
95
|
-
console.log("查询结果", o);
|
|
96
|
-
o.user_id = await db.count() + 1;
|
|
97
|
-
o.
|
|
98
|
-
// await db.add(o);
|
|
99
|
-
await db.addOrSet({
|
|
100
|
-
|
|
101
|
-
}, o);
|
|
102
|
-
console.log(db.sql);
|
|
94
|
+
// var o = ret.list[0];
|
|
95
|
+
// console.log("查询结果", o);
|
|
96
|
+
// // o.user_id = await db.count() + 1;
|
|
97
|
+
// o.gm = "'5";
|
|
98
|
+
// // await db.add(o);
|
|
99
|
+
// await db.addOrSet({
|
|
100
|
+
// user_id: o.user_id
|
|
101
|
+
// }, o);
|
|
102
|
+
// console.log(db.sql);
|
|
103
103
|
|
|
104
104
|
ret = await db.groupSumSql(query_str, "mc", "gm");
|
|
105
105
|
console.log('求和查询结果', ret);
|