mm_sqlite 1.5.6 → 1.5.7

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/lib/sql.js CHANGED
@@ -1382,25 +1382,29 @@ Sql.prototype.tplQuery = function (param_dt, sql_dt) {
1382
1382
  * @returns {string} 返回拼接的查询参数
1383
1383
  */
1384
1384
  Sql.prototype.tplBody = function (param_dt, sql_dt) {
1385
- var sql = '';
1386
- if (!sql_dt || sql_dt.length === 0) {
1385
+ if (!param_dt) {
1386
+ return '';
1387
+ }
1388
+ var parts = [];
1389
+ if (!sql_dt || Object.keys(sql_dt).length === 0) {
1387
1390
  for (var key in param_dt) {
1388
- sql += ', ' + this.escapeId(key) + ' = ' + this.escape(val[key]);
1391
+ parts.push(this.escapeId(key) + ' = ' + this.escape(param_dt[key]));
1389
1392
  }
1390
1393
  } else {
1391
- for (var key in param_dt) {
1392
- var value = this.escape(param_dt[key]);
1393
- let sql = sql_dt[key];
1394
- if (sql) {
1394
+ for (var k in param_dt) {
1395
+ var value = this.escape(param_dt[k]);
1396
+ // 不能再用 sql 作局部变量名,否则会遮蔽累加结果,SET 子句恒为空
1397
+ var tpl = sql_dt[k];
1398
+ if (tpl) {
1395
1399
  // 使用直接替换方式,避免模板替换错误
1396
- let replaced = sql.replaceAll('{0}', value.trim("'"));
1397
- sql += ', ' + replaced.replace('+ -', '- ').replace('- -', '+ ');
1400
+ var replaced = tpl.replaceAll('{0}', value.trim("'"));
1401
+ parts.push(replaced.replace(/\+ -/g, '- ').replace(/- -/g, '+ '));
1398
1402
  } else {
1399
- sql += ', ' + this.escapeId(key) + ' = ' + value;
1403
+ parts.push(this.escapeId(k) + ' = ' + value);
1400
1404
  }
1401
1405
  }
1402
1406
  }
1403
- return sql.replace(/^, /, '');
1407
+ return parts.join(', ');
1404
1408
  };
1405
1409
 
1406
1410
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mm_sqlite",
3
- "version": "1.5.6",
3
+ "version": "1.5.7",
4
4
  "description": "高性能SQLite数据库操作模块,提供与mm_mysql完全兼容的API接口,支持异步操作、事务处理和批量操作",
5
5
  "main": "index.js",
6
6
  "scripts": {
Binary file