jsql-neo 6.8.24 → 6.8.25

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/README.md CHANGED
@@ -3,7 +3,7 @@
3
3
  > **One engine to rule them all** — a Rust-powered embedded database that speaks your language:
4
4
  > MySQL, PostgreSQL, MongoDB, Redis, SQL, TypeScript, **and the browser**.
5
5
 
6
- > **v6.8.24** — stable release · [github.com/vexify-org/JSQL-neo](https://github.com/vexify-org/JSQL-neo) · [jsql.vexify.top](https://jsql.vexify.top)
6
+ > **v6.8.25** — stable release · [github.com/vexify-org/JSQL-neo](https://github.com/vexify-org/JSQL-neo) · [jsql.vexify.top](https://jsql.vexify.top)
7
7
 
8
8
  ![Engines](https://img.shields.io/badge/engines-Native%20%7C%20WASM%20%7C%20Pure%20JS-7ee787)
9
9
  ![MySQL](https://img.shields.io/badge/protocol-MySQL%20compatible-1f6feb)
package/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /**
2
- * JSQL-NEO v6.8.24 — Rust-Powered Embedded Database (WASM + HTTP)
2
+ * JSQL-NEO v6.8.25 — Rust-Powered Embedded Database (WASM + HTTP)
3
3
  *
4
4
  * @example
5
5
  * const jsql = require('jsql-neo');
package/lib/sql.js CHANGED
@@ -1509,7 +1509,8 @@ class Parser {
1509
1509
  this.next();
1510
1510
  spec.partitionBy = [];
1511
1511
  for (;;) {
1512
- spec.partitionBy.push(this.parseOperand());
1512
+ // #323:PARTITION BY 允许二元表达式
1513
+ spec.partitionBy.push(this.parseArgExpr());
1513
1514
  if (this.peek().type === 'op' && this.peek().value === ',') { this.next(); continue; }
1514
1515
  break;
1515
1516
  }
@@ -1520,7 +1521,8 @@ class Parser {
1520
1521
  this.next();
1521
1522
  spec.orderBy = [];
1522
1523
  for (;;) {
1523
- const col = this.parseOperand();
1524
+ // #323:ORDER BY 允许二元表达式
1525
+ const col = this.parseArgExpr();
1524
1526
  let dir = 'asc';
1525
1527
  if (this.isWord('ASC')) { this.next(); }
1526
1528
  else if (this.isWord('DESC')) { this.next(); dir = 'desc'; }
@@ -3210,7 +3212,8 @@ class Parser {
3210
3212
  parseCase() {
3211
3213
  let base = null;
3212
3214
  if (!this.isKeyword('WHEN')) {
3213
- base = this.parseOperand();
3215
+ // #322:基表达式允许完整的二元表达式(CASE 1 + 1 WHEN ...)
3216
+ base = this.parseArgExpr();
3214
3217
  }
3215
3218
  const branches = [];
3216
3219
  while (this.isKeyword('WHEN')) {
@@ -3218,7 +3221,7 @@ class Parser {
3218
3221
  // 简单 CASE: CASE x WHEN v THEN ... ; 搜索 CASE: CASE WHEN cond THEN ...
3219
3222
  let cond;
3220
3223
  if (base) {
3221
- const v = this.parseOperand();
3224
+ const v = this.parseArgExpr();
3222
3225
  cond = { type: 'compare', op: '=', left: base, right: v };
3223
3226
  } else {
3224
3227
  // 条件可能是完整比较(WHEN a > 1),也可能是裸值/裸列(WHEN 1、WHEN flag)。
@@ -3232,11 +3235,11 @@ class Parser {
3232
3235
  : { type: 'isTruth', operand: this.parseArgExpr(), not: false, truth: true };
3233
3236
  }
3234
3237
  this.expectKeyword('THEN');
3235
- const val = this.parseOperand();
3238
+ const val = this.parseArgExpr();
3236
3239
  branches.push({ cond, val });
3237
3240
  }
3238
3241
  let elseVal = null;
3239
- if (this.isKeyword('ELSE')) { this.next(); elseVal = this.parseOperand(); }
3242
+ if (this.isKeyword('ELSE')) { this.next(); elseVal = this.parseArgExpr(); }
3240
3243
  this.expectKeyword('END');
3241
3244
  return { type: 'case', branches, elseVal };
3242
3245
  }
@@ -3507,11 +3510,13 @@ function applyCast(value, dataType) {
3507
3510
  const scale = m && m[2] !== undefined ? parseInt(m[2], 10) : 0;
3508
3511
  let n = Number(value);
3509
3512
  if (!Number.isFinite(n)) return null;
3513
+ // #325:MySQL 的 DECIMAL 舍入是「半远离零」,Math.round 对负半值朝 +∞
3514
+ const roundHalfAway = (x) => (x < 0 ? -Math.round(-x) : Math.round(x));
3510
3515
  if (scale > 0) {
3511
3516
  const factor = Math.pow(10, scale);
3512
- n = Math.round(n * factor) / factor;
3517
+ n = roundHalfAway(n * factor) / factor;
3513
3518
  } else {
3514
- n = Math.round(n);
3519
+ n = roundHalfAway(n);
3515
3520
  }
3516
3521
  return n;
3517
3522
  }
@@ -3916,6 +3921,15 @@ function compareSqlValues(av, bv, dir) {
3916
3921
  return desc ? -r : r;
3917
3922
  }
3918
3923
 
3924
+ function mysqlWeekMode0(d) {
3925
+ // #324:周日为一周之始,第 1 周是本年第一个含周日的周(之前为第 0 周)
3926
+ const jan1Dow = new Date(Date.UTC(d.getUTCFullYear(), 0, 1)).getUTCDay(); // 0=周日
3927
+ const firstSunday = jan1Dow === 0 ? 1 : 8 - jan1Dow;
3928
+ const doy = Math.round((d - Date.UTC(d.getUTCFullYear(), 0, 0)) / 86400000);
3929
+ if (doy < firstSunday) return 0;
3930
+ return Math.floor((doy - firstSunday) / 7) + 1;
3931
+ }
3932
+
3919
3933
  function resolveOperand(operand, row, ctx) {
3920
3934
  if (operand === null || operand === undefined) return null;
3921
3935
  if (typeof operand === 'string') return resolveOperand({ type: 'column', name: operand }, row, ctx);
@@ -4731,12 +4745,7 @@ function applyScalarFunction(fnNode, row, ctx) {
4731
4745
  const mode = args[1] != null ? Number(args[1]) : 0;
4732
4746
  // mode 1/3(周一为一周之始且首周需 ≥4 天)走 ISO 周序;其余按 MySQL 默认 mode 0
4733
4747
  if (mode === 1 || mode === 3) return pgDatePart('week', d);
4734
- // mode 0:周日为一周之始,第 1 周是本年第一个含周日的周(之前为第 0 周)
4735
- const jan1Dow = new Date(Date.UTC(d.getUTCFullYear(), 0, 1)).getUTCDay(); // 0=周日
4736
- const firstSunday = jan1Dow === 0 ? 1 : 8 - jan1Dow;
4737
- const doy = Math.round((d - Date.UTC(d.getUTCFullYear(), 0, 0)) / 86400000);
4738
- if (doy < firstSunday) return 0;
4739
- return Math.floor((doy - firstSunday) / 7) + 1;
4748
+ return mysqlWeekMode0(d);
4740
4749
  }
4741
4750
  case 'WEEKOFYEAR': { // ISO 周序(同 WEEK(date,3))
4742
4751
  const d = parseSqlDate(args[0]);
@@ -4745,7 +4754,8 @@ function applyScalarFunction(fnNode, row, ctx) {
4745
4754
  case 'YEARWEEK': {
4746
4755
  const d = parseSqlDate(args[0]);
4747
4756
  if (!d) return null;
4748
- const mode = args[1] != null ? Number(args[1]) : 3;
4757
+ // #324:MySQL 单参默认 mode=0(周日为周首日),与 WEEK(date,0) 同源
4758
+ const mode = args[1] != null ? Number(args[1]) : 0;
4749
4759
  if (mode === 1 || mode === 3) {
4750
4760
  const week = pgDatePart('week', d);
4751
4761
  const thu = new Date(Date.UTC(d.getUTCFullYear(), d.getUTCMonth(), d.getUTCDate()));
@@ -4753,11 +4763,7 @@ function applyScalarFunction(fnNode, row, ctx) {
4753
4763
  thu.setUTCDate(thu.getUTCDate() - dow + 3); // 该周星期四决定 ISO 年
4754
4764
  return thu.getUTCFullYear() * 100 + week;
4755
4765
  }
4756
- const week = (() => {
4757
- const jan1 = new Date(Date.UTC(d.getUTCFullYear(), 0, 1));
4758
- return Math.floor((d - jan1) / 604800000) + 1;
4759
- })();
4760
- return d.getUTCFullYear() * 100 + week;
4766
+ return d.getUTCFullYear() * 100 + mysqlWeekMode0(d);
4761
4767
  }
4762
4768
  case 'DAYOFWEEK': { // MySQL:1=周日 … 7=周六
4763
4769
  const d = parseSqlDate(args[0]);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "jsql-neo",
3
- "version": "6.8.24",
3
+ "version": "6.8.25",
4
4
  "description": "JSQL-NEO — Rust-powered embedded database with WASM, REST API, B-Tree indexes, WAL, crash recovery",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",
@@ -52,12 +52,12 @@
52
52
  "build:native": "node scripts/build-native.js",
53
53
  "check:release": "node scripts/check-release-metadata.js",
54
54
  "release:prep": "node scripts/release.js",
55
- "test": "npm run check:release && node test/smoke.js && node test/result-raw.test.js && node test/native-install.test.js && node test/native-cli.test.js && node test/finalize-bigint.test.js && node test/native.test.js && node test/json-functions.test.js && node test/sql-parser.test.js && node test/readme-audit.test.js && node test/query-opt.test.js && node test/wal-recovery.test.js && node test/mysql-compat-hijack.test.js && node test/dml-constraints.test.js && node test/star-nag.test.js && node test/plugin-xql.test.js && node test/bug-regression-2.test.js && node test/issue-34-35-36.test.js && node test/issue-g4.test.js && node test/issue-38.test.js && node test/issue-39.test.js && node test/issue-40.test.js && node test/issue-44.test.js && node test/issue-45.test.js && node test/issue-46.test.js && node test/issue-47.test.js && node test/issue-48.test.js && node test/issue-50.test.js && node test/issue-51.test.js && node test/issue-52.test.js && node test/issue-53.test.js && node test/issue-54.test.js && node test/issue-55.test.js && node test/issue-56.test.js && node test/issue-57.test.js && node test/issue-58.test.js && node test/issue-59.test.js && node test/issue-60.test.js && node test/issue-63-68.test.js && node test/network-policy.test.js && node test/issue-69-70.test.js && node test/issue-71-72.test.js && node test/issue-73-76.test.js && node test/issue-77-84.test.js && node test/issue-86-99.test.js && node test/issue-101-103.test.js && node test/issue-105.test.js && node test/issue-118-136.test.js && node test/issue-127.test.js && node test/issue-138-156.test.js && node test/issue-157-161.test.js && node test/issue-162-179.test.js && node test/issue-181-186.test.js && node test/issue-187.test.js && node test/issue-188-237.test.js && node test/issue-238-241.test.js && node test/bigint-math.test.js && node test/release-metadata.test.js && node test/date-conversions.test.js && node test/mysql-utility-functions.test.js && node test/limit-pushdown.test.js && node test/columnar.test.js && node test/columnar-vector.test.js && node test/cast-rounding.test.js && node test/convert-subquery.test.js && node test/mongo-persistence.test.js && node test/mongo-objectid.test.js && node test/mongo-arrays.test.js && node test/issue-117.test.js && node test/issue-314-321.test.js && node test/issue-312-320.test.js && node test/issue-243-289.test.js && node test/issue-284-292.test.js && node test/issue-301-305.test.js && node test/issue-248-252.test.js && node test/issue-259-264.test.js && node test/issue-255-270.test.js && node test/issue-253-269.test.js && node test/issue-280-310.test.js && node test/issue-272-311.test.js && node test/issue-279-306.test.js && node test/issue-271-283.test.js && node test/issue-265-307.test.js && node test/issue-258-300.test.js && node test/issue-247-295-277.test.js",
55
+ "test": "npm run check:release && node test/smoke.js && node test/result-raw.test.js && node test/native-install.test.js && node test/native-cli.test.js && node test/finalize-bigint.test.js && node test/native.test.js && node test/json-functions.test.js && node test/sql-parser.test.js && node test/readme-audit.test.js && node test/query-opt.test.js && node test/wal-recovery.test.js && node test/mysql-compat-hijack.test.js && node test/dml-constraints.test.js && node test/star-nag.test.js && node test/plugin-xql.test.js && node test/bug-regression-2.test.js && node test/issue-34-35-36.test.js && node test/issue-g4.test.js && node test/issue-38.test.js && node test/issue-39.test.js && node test/issue-40.test.js && node test/issue-44.test.js && node test/issue-45.test.js && node test/issue-46.test.js && node test/issue-47.test.js && node test/issue-48.test.js && node test/issue-50.test.js && node test/issue-51.test.js && node test/issue-52.test.js && node test/issue-53.test.js && node test/issue-54.test.js && node test/issue-55.test.js && node test/issue-56.test.js && node test/issue-57.test.js && node test/issue-58.test.js && node test/issue-59.test.js && node test/issue-60.test.js && node test/issue-63-68.test.js && node test/network-policy.test.js && node test/issue-69-70.test.js && node test/issue-71-72.test.js && node test/issue-73-76.test.js && node test/issue-77-84.test.js && node test/issue-86-99.test.js && node test/issue-101-103.test.js && node test/issue-105.test.js && node test/issue-118-136.test.js && node test/issue-127.test.js && node test/issue-138-156.test.js && node test/issue-157-161.test.js && node test/issue-162-179.test.js && node test/issue-181-186.test.js && node test/issue-187.test.js && node test/issue-188-237.test.js && node test/issue-238-241.test.js && node test/bigint-math.test.js && node test/release-metadata.test.js && node test/date-conversions.test.js && node test/mysql-utility-functions.test.js && node test/limit-pushdown.test.js && node test/columnar.test.js && node test/columnar-vector.test.js && node test/cast-rounding.test.js && node test/convert-subquery.test.js && node test/mongo-persistence.test.js && node test/mongo-objectid.test.js && node test/mongo-arrays.test.js && node test/issue-117.test.js && node test/issue-314-321.test.js && node test/issue-312-320.test.js && node test/issue-243-289.test.js && node test/issue-284-292.test.js && node test/issue-301-305.test.js && node test/issue-248-252.test.js && node test/issue-259-264.test.js && node test/issue-255-270.test.js && node test/issue-253-269.test.js && node test/issue-280-310.test.js && node test/issue-272-311.test.js && node test/issue-279-306.test.js && node test/issue-271-283.test.js && node test/issue-265-307.test.js && node test/issue-258-300.test.js && node test/issue-247-295-277.test.js && node test/issue-322-325.test.js",
56
56
  "test:parser": "node test/sql-parser.test.js",
57
57
  "test:btree": "node test/btree.test.js",
58
58
  "test:native": "node test/native.test.js",
59
59
  "test:regress": "node test/regress-5.1.0.js",
60
- "test:all": "npm run check:release && node test/smoke.js && node test/result-raw.test.js && node test/native-install.test.js && node test/native-cli.test.js && node test/finalize-bigint.test.js && node test/sql-parser.test.js && node test/readme-audit.test.js && node test/native.test.js && node test/native-multi-instance.test.js && node test/wal-recovery.test.js && node test/mysql-compat-hijack.test.js && node test/wasm.test.js && node test/coverage.js && node test/regress-5.1.0.js && node test/join.test.js && node test/btree.test.js && node test/dml-constraints.test.js && node test/savepoint.test.js && node test/alter-table.test.js && node test/null-semantics.test.js && node test/identifier-keywords.test.js && node test/issue-34-35-36.test.js && node test/sql-semantics.test.js && node test/extra-coverage.test.js && node test/filter-compile.test.js && node test/recursive-cte.test.js && node test/index-ddl.test.js && node test/mongo-group.test.js && node test/multiprotocol.test.js && node test/issue-g4.test.js && node test/issue-38.test.js && node test/issue-39.test.js && node test/issue-40.test.js && node test/issue-44.test.js && node test/issue-45.test.js && node test/issue-46.test.js && node test/issue-47.test.js && node test/issue-48.test.js && node test/issue-50.test.js && node test/issue-51.test.js && node test/issue-52.test.js && node test/issue-53.test.js && node test/issue-54.test.js && node test/issue-55.test.js && node test/issue-56.test.js && node test/issue-57.test.js && node test/issue-58.test.js && node test/issue-59.test.js && node test/issue-60.test.js && node test/issue-63-68.test.js && node test/network-policy.test.js && node test/issue-69-70.test.js && node test/issue-71-72.test.js && node test/issue-77-84.test.js && node test/issue-86-99.test.js && node test/issue-101-103.test.js && node test/issue-105.test.js && node test/issue-118-136.test.js && node test/issue-127.test.js && node test/issue-138-156.test.js && node test/issue-157-161.test.js && node test/issue-162-179.test.js && node test/issue-181-186.test.js && node test/issue-187.test.js && node test/issue-188-237.test.js && node test/issue-238-241.test.js && node test/bigint-math.test.js && node test/release-metadata.test.js && node test/date-conversions.test.js && node test/mysql-utility-functions.test.js && node test/limit-pushdown.test.js && node test/columnar.test.js && node test/columnar-vector.test.js && node test/cast-rounding.test.js && node test/convert-subquery.test.js && node test/mongo-persistence.test.js && node test/mongo-objectid.test.js && node test/mongo-arrays.test.js && node test/issue-117.test.js && node test/issue-314-321.test.js && node test/issue-312-320.test.js && node test/issue-243-289.test.js && node test/issue-284-292.test.js && node test/issue-301-305.test.js && node test/issue-248-252.test.js && node test/issue-259-264.test.js && node test/issue-255-270.test.js && node test/issue-253-269.test.js && node test/issue-280-310.test.js && node test/issue-272-311.test.js && node test/issue-279-306.test.js && node test/issue-271-283.test.js && node test/issue-265-307.test.js && node test/issue-258-300.test.js && node test/issue-247-295-277.test.js",
60
+ "test:all": "npm run check:release && node test/smoke.js && node test/result-raw.test.js && node test/native-install.test.js && node test/native-cli.test.js && node test/finalize-bigint.test.js && node test/sql-parser.test.js && node test/readme-audit.test.js && node test/native.test.js && node test/native-multi-instance.test.js && node test/wal-recovery.test.js && node test/mysql-compat-hijack.test.js && node test/wasm.test.js && node test/coverage.js && node test/regress-5.1.0.js && node test/join.test.js && node test/btree.test.js && node test/dml-constraints.test.js && node test/savepoint.test.js && node test/alter-table.test.js && node test/null-semantics.test.js && node test/identifier-keywords.test.js && node test/issue-34-35-36.test.js && node test/sql-semantics.test.js && node test/extra-coverage.test.js && node test/filter-compile.test.js && node test/recursive-cte.test.js && node test/index-ddl.test.js && node test/mongo-group.test.js && node test/multiprotocol.test.js && node test/issue-g4.test.js && node test/issue-38.test.js && node test/issue-39.test.js && node test/issue-40.test.js && node test/issue-44.test.js && node test/issue-45.test.js && node test/issue-46.test.js && node test/issue-47.test.js && node test/issue-48.test.js && node test/issue-50.test.js && node test/issue-51.test.js && node test/issue-52.test.js && node test/issue-53.test.js && node test/issue-54.test.js && node test/issue-55.test.js && node test/issue-56.test.js && node test/issue-57.test.js && node test/issue-58.test.js && node test/issue-59.test.js && node test/issue-60.test.js && node test/issue-63-68.test.js && node test/network-policy.test.js && node test/issue-69-70.test.js && node test/issue-71-72.test.js && node test/issue-77-84.test.js && node test/issue-86-99.test.js && node test/issue-101-103.test.js && node test/issue-105.test.js && node test/issue-118-136.test.js && node test/issue-127.test.js && node test/issue-138-156.test.js && node test/issue-157-161.test.js && node test/issue-162-179.test.js && node test/issue-181-186.test.js && node test/issue-187.test.js && node test/issue-188-237.test.js && node test/issue-238-241.test.js && node test/bigint-math.test.js && node test/release-metadata.test.js && node test/date-conversions.test.js && node test/mysql-utility-functions.test.js && node test/limit-pushdown.test.js && node test/columnar.test.js && node test/columnar-vector.test.js && node test/cast-rounding.test.js && node test/convert-subquery.test.js && node test/mongo-persistence.test.js && node test/mongo-objectid.test.js && node test/mongo-arrays.test.js && node test/issue-117.test.js && node test/issue-314-321.test.js && node test/issue-312-320.test.js && node test/issue-243-289.test.js && node test/issue-284-292.test.js && node test/issue-301-305.test.js && node test/issue-248-252.test.js && node test/issue-259-264.test.js && node test/issue-255-270.test.js && node test/issue-253-269.test.js && node test/issue-280-310.test.js && node test/issue-272-311.test.js && node test/issue-279-306.test.js && node test/issue-271-283.test.js && node test/issue-265-307.test.js && node test/issue-258-300.test.js && node test/issue-247-295-277.test.js && node test/issue-322-325.test.js",
61
61
  "test:coverage": "c8 --all --include='lib/**' --exclude='lib/web_ui.js' --reporter=text --reporter=lcov node test/coverage.js",
62
62
  "test:orms": "node examples/orms/run-all.js",
63
63
  "test:dml": "node test/dml-constraints.test.js",
@@ -101,7 +101,7 @@ async function csvRoundTrip() {
101
101
  async function scalarFunctions() {
102
102
  const db = new Database(':memory:');
103
103
  const val = async (sql) => (await q(db, sql)).rows[0][0];
104
- ok('#185 YEARWEEK', await val("SELECT YEARWEEK('2026-11-21')") === 202647);
104
+ ok('#185 YEARWEEK', await val("SELECT YEARWEEK('2026-11-21')") === 202646);
105
105
  ok('#185 WEEKOFYEAR', await val("SELECT WEEKOFYEAR('2026-11-21')") === 47);
106
106
  ok('#185 MID alias', await val("SELECT MID('abcdef',2,3)") === 'bcd');
107
107
  ok('#185 PERIOD_ADD', await val('SELECT PERIOD_ADD(202601,3)') === 202604);
@@ -0,0 +1,59 @@
1
+ /*
2
+ * Regression tests for #322 #323 #324 #325.
3
+ */
4
+ const path = require('path');
5
+ const ROOT = path.join(__dirname, '..');
6
+ const { Database, executeSQL } = require(path.join(ROOT, 'index.js'));
7
+ let passed = 0, failed = 0;
8
+ function ok(name, cond, extra) {
9
+ if (cond) { passed++; console.log('[OK]', name); }
10
+ else { failed++; console.log('[FAIL]', name, extra !== undefined ? '→ ' + JSON.stringify(extra) : ''); }
11
+ }
12
+ const q = (db, sql) => executeSQL(db, sql, { safety: false });
13
+
14
+ (async () => {
15
+ const db = new Database(':memory:');
16
+ await q(db, 'SELECT 1');
17
+ // #322 CASE 各子表达式支持二元表达式
18
+ const cases = [
19
+ [["SELECT CASE WHEN 1 THEN 1 + 2 END"], 3],
20
+ [["SELECT CASE WHEN 1 THEN 1 / 2 END"], 0.5],
21
+ [["SELECT CASE WHEN 0 THEN 'y' ELSE 1 + 0 END"], 1],
22
+ [["SELECT CASE 1 + 1 WHEN 2 THEN 'two' END"], 'two'],
23
+ [["SELECT CASE WHEN 1 THEN 1 = 1 END"], 1],
24
+ [["SELECT CASE WHEN 1 THEN 1 AND 0 END"], 0],
25
+ ];
26
+ for (const [sql, expected] of cases) {
27
+ let got, err;
28
+ try { got = (await q(db, sql[0])).rows[0][0]; } catch (e) { err = e.message; }
29
+ ok('#322 ' + sql[0], !err && String(got) === String(expected), err || got);
30
+ }
31
+ // #323 窗口 PARTITION BY / ORDER BY 二元表达式
32
+ {
33
+ await q(db, 'CREATE TABLE w (id INT, g INT, v INT)');
34
+ await q(db, 'INSERT INTO w VALUES (1,1,10),(2,1,20),(3,2,30)');
35
+ let rows, err;
36
+ try {
37
+ rows = (await q(db, 'SELECT id, SUM(v) OVER (PARTITION BY g % 2 ORDER BY v + 0) AS s FROM w')).rows;
38
+ } catch (e) { err = e.message; }
39
+ ok('#323 window expression parses and computes', !err && rows.length === 3, err || rows);
40
+ }
41
+ // #324 YEARWEEK 默认 mode 0
42
+ {
43
+ const one = async (sql) => (await q(db, sql)).rows[0][0];
44
+ ok('#324 YEARWEEK default 2023-01-01', Number(await one("SELECT YEARWEEK('2023-01-01')")) === 202301, await one("SELECT YEARWEEK('2023-01-01')"));
45
+ ok('#324 YEARWEEK default 2026-01-01', Number(await one("SELECT YEARWEEK('2026-01-01')")) === 202600, await one("SELECT YEARWEEK('2026-01-01')"));
46
+ ok('#324 YEARWEEK mode 0 matches WEEK', Number(await one("SELECT YEARWEEK('2026-01-01', 0)")) === 202600, await one("SELECT YEARWEEK('2026-01-01', 0)"));
47
+ }
48
+ // #325 DECIMAL 负数半值远离零
49
+ {
50
+ const one = async (sql) => (await q(db, sql)).rows[0][0];
51
+ ok('#325 CAST -1.5 DECIMAL(10,0)', Number(await one('SELECT CAST(-1.5 AS DECIMAL(10,0))')) === -2, await one('SELECT CAST(-1.5 AS DECIMAL(10,0))'));
52
+ ok('#325 CAST -1.25 DECIMAL(10,1)', Number(await one('SELECT CAST(-1.25 AS DECIMAL(10,1))')) === -1.3, await one('SELECT CAST(-1.25 AS DECIMAL(10,1))'));
53
+ ok('#325 CAST -1.5 string DECIMAL(10,0)', Number(await one("SELECT CAST('-1.5' AS DECIMAL(10,0))")) === -2, await one("SELECT CAST('-1.5' AS DECIMAL(10,0))"));
54
+ ok('#325 positive half unchanged', Number(await one('SELECT CAST(1.25 AS DECIMAL(10,1))')) === 1.3, await one('SELECT CAST(1.25 AS DECIMAL(10,1))'));
55
+ }
56
+ db.stop();
57
+ console.log(`\n${passed} passed, ${failed} failed`);
58
+ process.exit(failed === 0 ? 0 : 1);
59
+ })().catch((e) => { console.error('FATAL', e); process.exit(1); });