jsql-neo 6.8.21 → 6.8.23
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 +1 -1
- package/index.js +1 -1
- package/lib/errors.js +1 -0
- package/lib/mysql_server.js +66 -30
- package/lib/sql.js +31 -2
- package/lib/sqlite_compat.js +18 -4
- package/lib/table.js +3 -2
- package/lib/tui.js +8 -1
- package/lib/wasm_client.js +6 -0
- package/package.json +3 -3
- package/test/issue-258-300.test.js +64 -0
- package/test/issue-265-307.test.js +88 -0
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.
|
|
6
|
+
> **v6.8.23** — 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
|

|
|
9
9
|

|
package/index.js
CHANGED
package/lib/errors.js
CHANGED
|
@@ -57,6 +57,7 @@ const ErrorCodes = {
|
|
|
57
57
|
// 保存点不存在(MySQL 用这个码:SAVEPOINT xxx does not exist)
|
|
58
58
|
ER_SP_DOES_NOT_EXIST: { code: 1305, msg: "SAVEPOINT %s does not exist" },
|
|
59
59
|
ER_FUNCTION_NOT_EXIST: { code: 1305, msg: "FUNCTION %s does not exist" },
|
|
60
|
+
ER_SUBSELECT_NO_1_ROW: { code: 1242, msg: "Subquery returns more than 1 row" },
|
|
60
61
|
ER_WRONG_VALUE_COUNT_ON_ROW: { code: 1136, msg: "Column count doesn't match value count at row %s" },
|
|
61
62
|
ER_TRUNCATE_ILLEGAL_FK: { code: 1701, msg: "Cannot truncate a table referenced in a foreign key constraint (%s)" },
|
|
62
63
|
ER_ROW_IS_REFERENCED_2: { code: 1451, msg: "Cannot delete or update a parent row: a foreign key constraint fails (%s)" },
|
package/lib/mysql_server.js
CHANGED
|
@@ -634,6 +634,23 @@ class MysqlConnection {
|
|
|
634
634
|
break;
|
|
635
635
|
}
|
|
636
636
|
case 0x09: this._send(okPacket(0, 0, SERVER_STATUS_AUTOCOMMIT)); break; // COM_STATISTICS
|
|
637
|
+
case 0x04: { // #307 COM_FIELD_LIST
|
|
638
|
+
(async () => {
|
|
639
|
+
try {
|
|
640
|
+
const table = body.toString('utf8').split('\0')[0];
|
|
641
|
+
const eng = await this.server._getDatabase(this.currentDb);
|
|
642
|
+
const schema = await eng.getTableSchema(table);
|
|
643
|
+
if (!schema) { this._send(errPacket(1146, `Table '${this.currentDb}.${table}' doesn't exist`)); return; }
|
|
644
|
+
for (const [n, d] of Object.entries(schema)) {
|
|
645
|
+
this._send(columnDefinition({ name: n, table, database: this.currentDb, type: columnTypeFromSchema(d), flags: columnFlags(d) }));
|
|
646
|
+
}
|
|
647
|
+
this._send(eofPacket());
|
|
648
|
+
} catch (e) {
|
|
649
|
+
this._send(errPacket(toMysqlErrno(e), e.message));
|
|
650
|
+
}
|
|
651
|
+
})();
|
|
652
|
+
break;
|
|
653
|
+
}
|
|
637
654
|
default:
|
|
638
655
|
this._send(errPacket(1105, `Unsupported command: ${cmd}`));
|
|
639
656
|
}
|
|
@@ -795,42 +812,61 @@ class MysqlConnection {
|
|
|
795
812
|
}
|
|
796
813
|
|
|
797
814
|
_handleStmtPrepare(body) {
|
|
798
|
-
|
|
799
|
-
const sql = body.toString('utf8');
|
|
800
|
-
const numParams = this.countPlaceholders(sql);
|
|
801
|
-
let numColumns = 0;
|
|
815
|
+
(async () => {
|
|
802
816
|
try {
|
|
803
|
-
const
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
817
|
+
const sql = body.toString('utf8');
|
|
818
|
+
const numParams = this.countPlaceholders(sql);
|
|
819
|
+
// #273:列元数据来自真实 SQL/schema,不能再用 col1/col2 占位
|
|
820
|
+
let colDefs = [];
|
|
821
|
+
try {
|
|
822
|
+
const stmt = parseSQL(sql);
|
|
823
|
+
if (stmt && stmt.type === 'select') {
|
|
824
|
+
let schema = null;
|
|
825
|
+
try {
|
|
826
|
+
const eng = await this.server._getDatabase(this.currentDb);
|
|
827
|
+
const from = stmt.from && stmt.from.tables && stmt.from.tables[0];
|
|
828
|
+
if (from && from.table && eng.getTableSchema) schema = await eng.getTableSchema(from.table);
|
|
829
|
+
} catch (e) { schema = null; }
|
|
830
|
+
const cols = stmt.columns || [];
|
|
831
|
+
for (let i = 0; i < cols.length; i++) {
|
|
832
|
+
const c = cols[i];
|
|
833
|
+
if (c.expr === '*' && schema) {
|
|
834
|
+
for (const [n, d] of Object.entries(schema)) {
|
|
835
|
+
colDefs.push({ name: n, table: null, database: this.currentDb, type: columnTypeFromSchema(d), flags: columnFlags(d) });
|
|
836
|
+
}
|
|
837
|
+
continue;
|
|
838
|
+
}
|
|
839
|
+
const name = c.alias || (typeof c.expr === 'string' ? c.expr : 'col' + (i + 1));
|
|
840
|
+
const def = schema && schema[name];
|
|
841
|
+
const type = c.aggregate ? MYSQL_TYPE_DOUBLE : columnTypeFromSchema(def || {});
|
|
842
|
+
colDefs.push({ name, table: null, database: this.currentDb, type, flags: columnFlags(def) });
|
|
843
|
+
}
|
|
844
|
+
}
|
|
845
|
+
} catch (e) { /* 无法解析的 SQL 仍可 prepare */ }
|
|
846
|
+
const numColumns = colDefs.length;
|
|
847
|
+
const stmtId = ++this._stmtSeq;
|
|
848
|
+
this._stmts.set(stmtId, { sql, numParams, numColumns, columnDefs: colDefs });
|
|
849
|
+
|
|
850
|
+
const pkt = Buffer.alloc(12);
|
|
851
|
+
let off = 0;
|
|
852
|
+
pkt[off++] = 0x00;
|
|
853
|
+
pkt.writeUInt32LE(stmtId, off); off += 4;
|
|
854
|
+
pkt.writeUInt16LE(numColumns, off); off += 2;
|
|
855
|
+
pkt.writeUInt16LE(numParams, off); off += 2;
|
|
856
|
+
pkt[off++] = 0x00;
|
|
857
|
+
pkt.writeUInt16LE(0, off);
|
|
858
|
+
this._send(pkt);
|
|
808
859
|
|
|
809
|
-
const pkt = Buffer.alloc(12);
|
|
810
|
-
let off = 0;
|
|
811
|
-
pkt[off++] = 0x00;
|
|
812
|
-
pkt.writeUInt32LE(stmtId, off); off += 4;
|
|
813
|
-
pkt.writeUInt16LE(numColumns, off); off += 2;
|
|
814
|
-
pkt.writeUInt16LE(numParams, off); off += 2;
|
|
815
|
-
pkt[off++] = 0x00;
|
|
816
|
-
pkt.writeUInt16LE(0, off);
|
|
817
|
-
this._send(pkt);
|
|
818
|
-
|
|
819
|
-
if (numParams > 0) {
|
|
820
860
|
for (let i = 0; i < numParams; i++) {
|
|
821
861
|
this._send(columnDefinition({ name: '?', type: MYSQL_TYPE_VAR_STRING }));
|
|
822
862
|
}
|
|
823
|
-
this._send(eofPacket());
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
}
|
|
829
|
-
this._send(eofPacket());
|
|
863
|
+
if (numParams > 0) this._send(eofPacket());
|
|
864
|
+
for (const cd of colDefs) this._send(columnDefinition(cd));
|
|
865
|
+
if (numColumns > 0) this._send(eofPacket());
|
|
866
|
+
} catch (e) {
|
|
867
|
+
this._send(errPacket(toMysqlErrno(e), e.message));
|
|
830
868
|
}
|
|
831
|
-
}
|
|
832
|
-
this._send(errPacket(toMysqlErrno(e), e.message));
|
|
833
|
-
}
|
|
869
|
+
})();
|
|
834
870
|
}
|
|
835
871
|
|
|
836
872
|
_handleStmtClose(body) {
|
package/lib/sql.js
CHANGED
|
@@ -529,7 +529,7 @@ function tokenize(sql) {
|
|
|
529
529
|
const AGG_FUNCS = new Set(['SUM', 'AVG', 'MIN', 'MAX', 'COUNT',
|
|
530
530
|
'GROUP_CONCAT', 'STDDEV', 'STD', 'STDDEV_POP', 'STDDEV_SAMP',
|
|
531
531
|
'VARIANCE', 'VAR_POP', 'VAR_SAMP', 'FIRST', 'LAST',
|
|
532
|
-
'BIT_AND', 'BIT_OR', 'BIT_XOR']);
|
|
532
|
+
'BIT_AND', 'BIT_OR', 'BIT_XOR', 'JSON_ARRAYAGG', 'JSON_OBJECTAGG']);
|
|
533
533
|
|
|
534
534
|
// 方差/标准差族(Issue #114):MySQL 里无后缀的 VARIANCE / STDDEV / STD
|
|
535
535
|
// 都是**总体**口径(= VAR_POP / STDDEV_POP),不是样本。
|
|
@@ -2660,7 +2660,15 @@ class Parser {
|
|
|
2660
2660
|
}
|
|
2661
2661
|
column = { type: 'tuple', items: cols };
|
|
2662
2662
|
} else if (this.peek().type === 'op' && this.peek().value === ',') {
|
|
2663
|
-
if (
|
|
2663
|
+
if (fn === 'JSON_OBJECTAGG') {
|
|
2664
|
+
// JSON_OBJECTAGG(key, value):收集 [key, value] 两个表达式
|
|
2665
|
+
const items = [column];
|
|
2666
|
+
while (this.peek().type === 'op' && this.peek().value === ',') {
|
|
2667
|
+
this.next();
|
|
2668
|
+
items.push(this.parseScalar());
|
|
2669
|
+
}
|
|
2670
|
+
column = { type: 'arglist', items };
|
|
2671
|
+
} else if (VARIANCE_FUNCS.has(fn)) {
|
|
2664
2672
|
// Issue #114:MySQL 的 VARIANCE/STDDEV/STD 只接受单个表达式,
|
|
2665
2673
|
// 但本项目历史上接受 VARIANCE(1,2,3) 这种多参数写法,统一收集成 arglist,
|
|
2666
2674
|
// 让每个参数值都参与统计(多参数时不再误当成 GROUP_CONCAT 的分隔符)。
|
|
@@ -8200,6 +8208,8 @@ class SQLExecutor {
|
|
|
8200
8208
|
}
|
|
8201
8209
|
if (expr.type === 'subquery') {
|
|
8202
8210
|
const res = await this.executeSelect(expr.select);
|
|
8211
|
+
// #258:标量子查询返回多行必须报 1242,不能静默取首行
|
|
8212
|
+
if (res.rows.length > 1) throw createError('ER_SUBSELECT_NO_1_ROW');
|
|
8203
8213
|
expr._value = res.rows.length > 0 ? res.rows[0][0] : null;
|
|
8204
8214
|
// 不改写类型、不 delete select:保留节点以便相关场景逐行重算
|
|
8205
8215
|
return;
|
|
@@ -8305,6 +8315,24 @@ class SQLExecutor {
|
|
|
8305
8315
|
const op = typeof column === 'string' ? { type: 'column', name: column } : column;
|
|
8306
8316
|
// COUNT(*) / COUNT():参数为 star 或缺失,直接按行数算
|
|
8307
8317
|
const noColumn = !op || op.type === 'star';
|
|
8318
|
+
// #293:JSON 聚合按整组求值,不能退化成每组取代表行
|
|
8319
|
+
if (fn === 'JSON_ARRAYAGG') {
|
|
8320
|
+
const out = rows.map(r => resolveOperand(op, r, this.ctx));
|
|
8321
|
+
return out;
|
|
8322
|
+
}
|
|
8323
|
+
if (fn === 'JSON_OBJECTAGG') {
|
|
8324
|
+
const obj = {};
|
|
8325
|
+
const items = op && op.type === 'arglist' ? op.items : [];
|
|
8326
|
+
if (items.length >= 2) {
|
|
8327
|
+
for (const r of rows) {
|
|
8328
|
+
const k = resolveOperand(items[0], r, this.ctx);
|
|
8329
|
+
const v = resolveOperand(items[1], r, this.ctx);
|
|
8330
|
+
if (k === null || k === undefined) continue;
|
|
8331
|
+
obj[String(k)] = v === undefined ? null : v;
|
|
8332
|
+
}
|
|
8333
|
+
}
|
|
8334
|
+
return obj;
|
|
8335
|
+
}
|
|
8308
8336
|
let values = noColumn
|
|
8309
8337
|
? rows.map(r => 1)
|
|
8310
8338
|
// Issue #114:VARIANCE(1,2,3) 这类多参数写法,所有参数值都纳入统计
|
|
@@ -8955,6 +8983,7 @@ class SQLExecutor {
|
|
|
8955
8983
|
node._rowCount = res.rows.length;
|
|
8956
8984
|
} else if (node.type === 'subquery') {
|
|
8957
8985
|
const res = await this.executeSelect(node.select);
|
|
8986
|
+
if (res.rows.length > 1) throw createError('ER_SUBSELECT_NO_1_ROW');
|
|
8958
8987
|
node._value = res.rows.length > 0 ? res.rows[0][0] : null;
|
|
8959
8988
|
} else if (node.type === 'in') {
|
|
8960
8989
|
const res = await this.executeSelect(node.subquery);
|
package/lib/sqlite_compat.js
CHANGED
|
@@ -137,19 +137,33 @@ class Database {
|
|
|
137
137
|
|
|
138
138
|
transaction(fn) {
|
|
139
139
|
if (typeof fn !== 'function') throw new TypeError('Expected a function');
|
|
140
|
+
if (this._txDepth === undefined) this._txDepth = 0;
|
|
140
141
|
const wrapped = (...params) => {
|
|
141
142
|
if (!this.open) throw new SqliteError('The database connection is not open', 'SQLITE_MISUSE');
|
|
142
|
-
|
|
143
|
+
// #265:嵌套事务用 SAVEPOINT,内层提交不能提前提交外层
|
|
144
|
+
const depth = this._txDepth;
|
|
145
|
+
const sp = 'sqlite_tx_' + depth;
|
|
146
|
+
if (depth === 0) this.exec('BEGIN');
|
|
147
|
+
else this.exec('SAVEPOINT ' + sp);
|
|
148
|
+
this._txDepth = depth + 1;
|
|
143
149
|
try {
|
|
144
150
|
const result = fn.apply(this, params);
|
|
145
151
|
if (result && typeof result.then === 'function') {
|
|
146
|
-
this.exec('ROLLBACK');
|
|
152
|
+
if (depth === 0) this.exec('ROLLBACK');
|
|
153
|
+
else { this.exec('ROLLBACK TO ' + sp); this.exec('RELEASE ' + sp); }
|
|
154
|
+
this._txDepth = depth;
|
|
147
155
|
throw new SqliteError('Transaction functions cannot be asynchronous', 'SQLITE_MISUSE');
|
|
148
156
|
}
|
|
149
|
-
this.exec('COMMIT');
|
|
157
|
+
if (depth === 0) this.exec('COMMIT');
|
|
158
|
+
else this.exec('RELEASE ' + sp);
|
|
159
|
+
this._txDepth = depth;
|
|
150
160
|
return result;
|
|
151
161
|
} catch (err) {
|
|
152
|
-
try {
|
|
162
|
+
try {
|
|
163
|
+
if (depth === 0) this.exec('ROLLBACK');
|
|
164
|
+
else { this.exec('ROLLBACK TO ' + sp); this.exec('RELEASE ' + sp); }
|
|
165
|
+
} catch (e) {}
|
|
166
|
+
this._txDepth = depth;
|
|
153
167
|
throw err;
|
|
154
168
|
}
|
|
155
169
|
};
|
package/lib/table.js
CHANGED
|
@@ -693,7 +693,8 @@ class Table {
|
|
|
693
693
|
if (uniqueTracker[field].has(ukey)) throw createError('ER_DUP_ENTRY', String(data[field]), field);
|
|
694
694
|
uniqueTracker[field].add(ukey);
|
|
695
695
|
}
|
|
696
|
-
|
|
696
|
+
// #267:按 Unicode code point 计长度,emoji 算 1 个字符
|
|
697
|
+
if (def.length && typeof data[field] === 'string' && [...data[field]].length > def.length) throw createError('ER_DATA_TOO_LONG', field);
|
|
697
698
|
if (def.type === 'integer' || def.type === 'int' || def.type === 'bigint' || def.type === 'number') {
|
|
698
699
|
const raw = data[field];
|
|
699
700
|
// BigInt 与 number 的 </> 比较是精确的,不要先 Number() 丢精度
|
|
@@ -2117,7 +2118,7 @@ class Table {
|
|
|
2117
2118
|
}
|
|
2118
2119
|
|
|
2119
2120
|
// 长度限制
|
|
2120
|
-
if (def.length && typeof data[field] === 'string' && data[field].length > def.length) {
|
|
2121
|
+
if (def.length && typeof data[field] === 'string' && [...data[field]].length > def.length) {
|
|
2121
2122
|
throw createError('ER_DATA_TOO_LONG', field);
|
|
2122
2123
|
}
|
|
2123
2124
|
|
package/lib/tui.js
CHANGED
|
@@ -13,7 +13,8 @@ const os = require('os');
|
|
|
13
13
|
const Database = require('./database');
|
|
14
14
|
const { executeSQL } = require('./sql');
|
|
15
15
|
|
|
16
|
-
|
|
16
|
+
// #300:历史文件不再内嵌 pid,跨会话可读
|
|
17
|
+
const HISTORY_FILE = path.join(os.homedir(), '.jsql-history');
|
|
17
18
|
const MAX_HISTORY = 500;
|
|
18
19
|
|
|
19
20
|
/* ---------- ANSI helpers ---------- */
|
|
@@ -39,6 +40,10 @@ function wswidth(str) {
|
|
|
39
40
|
let w = 0;
|
|
40
41
|
for (const ch of String(str)) {
|
|
41
42
|
const cp = ch.codePointAt(0);
|
|
43
|
+
// #298:emoji / 宽符号按 2 列,组合符/变体选择符按 0 列
|
|
44
|
+
if (cp >= 0x1f000 && cp <= 0x1faff) { w += 2; continue; }
|
|
45
|
+
if (cp >= 0x2600 && cp <= 0x27bf) { w += 2; continue; }
|
|
46
|
+
if ((cp >= 0x0300 && cp <= 0x036f) || (cp >= 0xfe00 && cp <= 0xfe0f) || cp === 0x200d) { continue; }
|
|
42
47
|
if (cp >= 0x1100 && (cp <= 0x115f || cp === 0x2329 || cp === 0x232a ||
|
|
43
48
|
(cp >= 0x2e80 && cp <= 0xa4cf && cp !== 0x303f) ||
|
|
44
49
|
(cp >= 0xac00 && cp <= 0xd7a3) || (cp >= 0xf900 && cp <= 0xfaff) ||
|
|
@@ -297,6 +302,8 @@ class TUIShell {
|
|
|
297
302
|
let inSQ = false, inDQ = false, parens = 0;
|
|
298
303
|
for (let i = 0; i < sql.length; i++) {
|
|
299
304
|
const c = sql[i];
|
|
305
|
+
// #299:反斜杠转义下一个字符(\' / \"),不能当成引号翻转
|
|
306
|
+
if (c === '\\' && (inSQ || inDQ)) { i++; continue; }
|
|
300
307
|
if (c === "'" && !inDQ) inSQ = !inSQ;
|
|
301
308
|
else if (c === '"' && !inSQ) inDQ = !inDQ;
|
|
302
309
|
else if (!inSQ && !inDQ) {
|
package/lib/wasm_client.js
CHANGED
|
@@ -487,6 +487,12 @@ class JSQL {
|
|
|
487
487
|
|
|
488
488
|
async start() {
|
|
489
489
|
wasmBindings.jsql_reset();
|
|
490
|
+
// #294:stop→start 后底层表已清空,JS 侧元数据必须同步清掉
|
|
491
|
+
this._tableNames.clear();
|
|
492
|
+
this._schemas = {};
|
|
493
|
+
this._buffer = {};
|
|
494
|
+
this._bufferSize = 0;
|
|
495
|
+
this._txId = undefined;
|
|
490
496
|
await this._runHooks('onStart', []);
|
|
491
497
|
this._emit('start', {});
|
|
492
498
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "jsql-neo",
|
|
3
|
-
"version": "6.8.
|
|
3
|
+
"version": "6.8.23",
|
|
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",
|
|
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",
|
|
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",
|
|
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",
|
|
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",
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Regression tests for #258 #293 #298 #299 #300.
|
|
3
|
+
* node test/issue-258-300.test.js
|
|
4
|
+
*/
|
|
5
|
+
const path = require('path');
|
|
6
|
+
const os = require('os');
|
|
7
|
+
const fs = require('fs');
|
|
8
|
+
const ROOT = path.join(__dirname, '..');
|
|
9
|
+
const { Database, executeSQL } = require(path.join(ROOT, 'index.js'));
|
|
10
|
+
let passed = 0, failed = 0;
|
|
11
|
+
function ok(name, cond, extra) {
|
|
12
|
+
if (cond) { passed++; console.log('[OK]', name); }
|
|
13
|
+
else { failed++; console.log('[FAIL]', name, extra !== undefined ? '→ ' + JSON.stringify(extra) : ''); }
|
|
14
|
+
}
|
|
15
|
+
const q = (db, sql) => executeSQL(db, sql, { safety: false });
|
|
16
|
+
|
|
17
|
+
(async () => {
|
|
18
|
+
// #258
|
|
19
|
+
{
|
|
20
|
+
const db = new Database(':memory:');
|
|
21
|
+
await q(db, 'CREATE TABLE t (id INT)');
|
|
22
|
+
await q(db, 'INSERT INTO t VALUES (1),(2)');
|
|
23
|
+
let code = null;
|
|
24
|
+
try { await q(db, 'SELECT (SELECT id FROM t) AS x'); } catch (e) { code = e.code; }
|
|
25
|
+
ok('#258 scalar subquery with multiple rows -> 1242', code === 1242, code);
|
|
26
|
+
db.stop();
|
|
27
|
+
}
|
|
28
|
+
// #293
|
|
29
|
+
{
|
|
30
|
+
const db = new Database(':memory:');
|
|
31
|
+
await q(db, 'CREATE TABLE t (g TEXT, v INT)');
|
|
32
|
+
await q(db, "INSERT INTO t VALUES ('a',1),('a',2),('b',3)");
|
|
33
|
+
const arr = (await q(db, 'SELECT g, JSON_ARRAYAGG(v) AS j FROM t GROUP BY g ORDER BY g')).rows;
|
|
34
|
+
ok('#293 JSON_ARRAYAGG aggregates whole group', JSON.stringify(arr) === JSON.stringify([['a', [1, 2]], ['b', [3]]]), arr);
|
|
35
|
+
const obj = (await q(db, "SELECT JSON_OBJECTAGG(g, v) AS o FROM t")).rows;
|
|
36
|
+
ok('#293 JSON_OBJECTAGG builds object', obj.length === 1 && JSON.stringify(obj[0][0]) === JSON.stringify({ a: 2, b: 3 }), obj);
|
|
37
|
+
db.stop();
|
|
38
|
+
}
|
|
39
|
+
// #298 / #299
|
|
40
|
+
{
|
|
41
|
+
const tui = require(path.join(ROOT, 'lib', 'tui.js'));
|
|
42
|
+
ok('#298 emoji width counted as 2', tui.wswidth('😀') === 2 && tui.wswidth('abc😀') === 5, [tui.wswidth('😀'), tui.wswidth('abc😀')]);
|
|
43
|
+
const shell = Object.create(tui.TUIShell.prototype);
|
|
44
|
+
ok('#299 escaped quote keeps statement balanced', shell._statementComplete("SELECT 'a\\'b';") === true, shell._statementComplete("SELECT 'a\\'b';"));
|
|
45
|
+
}
|
|
46
|
+
// #300 history file has no pid
|
|
47
|
+
{
|
|
48
|
+
const home = fs.mkdtempSync(path.join(os.tmpdir(), 'jsql-home-'));
|
|
49
|
+
const oldHome = process.env.HOME;
|
|
50
|
+
process.env.HOME = home;
|
|
51
|
+
const tuiPath = path.join(ROOT, 'lib', 'tui.js');
|
|
52
|
+
delete require.cache[require.resolve(tuiPath)];
|
|
53
|
+
const tui = require(tuiPath);
|
|
54
|
+
const shell = Object.create(tui.TUIShell.prototype);
|
|
55
|
+
shell.history = ['SELECT 1;'];
|
|
56
|
+
shell._saveHistory();
|
|
57
|
+
const files = fs.readdirSync(home);
|
|
58
|
+
ok('#300 history file is session-independent', files.includes('.jsql-history'), files);
|
|
59
|
+
process.env.HOME = oldHome;
|
|
60
|
+
delete require.cache[require.resolve(tuiPath)];
|
|
61
|
+
}
|
|
62
|
+
console.log(`\n${passed} passed, ${failed} failed`);
|
|
63
|
+
process.exit(failed === 0 ? 0 : 1);
|
|
64
|
+
})().catch((e) => { console.error('FATAL', e); process.exit(1); });
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Regression tests for #265 #267 #273 #294 #307.
|
|
3
|
+
* node test/issue-265-307.test.js
|
|
4
|
+
*/
|
|
5
|
+
const path = require('path');
|
|
6
|
+
const ROOT = path.join(__dirname, '..');
|
|
7
|
+
const { Database, executeSQL, JSQL } = require(path.join(ROOT, 'index.js'));
|
|
8
|
+
const SqliteDatabase = require(path.join(ROOT, 'lib', 'sqlite_compat.js'));
|
|
9
|
+
|
|
10
|
+
let passed = 0, failed = 0;
|
|
11
|
+
function ok(name, cond, extra) {
|
|
12
|
+
if (cond) { passed++; console.log('[OK]', name); }
|
|
13
|
+
else { failed++; console.log('[FAIL]', name, extra !== undefined ? '→ ' + JSON.stringify(extra) : ''); }
|
|
14
|
+
}
|
|
15
|
+
const sleep = (ms) => new Promise(r => setTimeout(r, ms));
|
|
16
|
+
|
|
17
|
+
(async () => {
|
|
18
|
+
// #267
|
|
19
|
+
{
|
|
20
|
+
const db = new Database(':memory:');
|
|
21
|
+
await executeSQL(db, 'CREATE TABLE t (v VARCHAR(3))', { safety: false });
|
|
22
|
+
let e3 = null;
|
|
23
|
+
try { await executeSQL(db, "INSERT INTO t VALUES ('😀😀😀')", { safety: false }); } catch (e) { e3 = e.code; }
|
|
24
|
+
let e4 = null;
|
|
25
|
+
try { await executeSQL(db, "INSERT INTO t VALUES ('😀😀😀😀')", { safety: false }); } catch (e) { e4 = e.code; }
|
|
26
|
+
ok('#267 VARCHAR length counts code points', e3 === null && e4 === 1406, { e3, e4 });
|
|
27
|
+
db.stop();
|
|
28
|
+
}
|
|
29
|
+
// #265
|
|
30
|
+
{
|
|
31
|
+
const db = new SqliteDatabase(':memory:');
|
|
32
|
+
db.exec('CREATE TABLE t (id INTEGER PRIMARY KEY)');
|
|
33
|
+
let caught = null;
|
|
34
|
+
try {
|
|
35
|
+
db.transaction(() => {
|
|
36
|
+
db.prepare('INSERT INTO t VALUES (1)').run();
|
|
37
|
+
db.transaction(() => { db.prepare('INSERT INTO t VALUES (2)').run(); })();
|
|
38
|
+
throw new Error('outer rollback');
|
|
39
|
+
})();
|
|
40
|
+
} catch (e) { caught = e.message; }
|
|
41
|
+
const n = db.prepare('SELECT COUNT(*) c FROM t').get().c;
|
|
42
|
+
ok('#265 nested sqlite transaction rolls back inner writes', caught === 'outer rollback' && n === 0, { caught, n });
|
|
43
|
+
db.close();
|
|
44
|
+
}
|
|
45
|
+
// #294
|
|
46
|
+
{
|
|
47
|
+
const db = new JSQL();
|
|
48
|
+
await db.start();
|
|
49
|
+
await db.createTable('x', { id: { type: 'integer', primaryKey: true } });
|
|
50
|
+
await db.stop();
|
|
51
|
+
await db.start();
|
|
52
|
+
const tables = await db.getTables();
|
|
53
|
+
ok('#294 wasm stop/start clears JS table metadata', Array.isArray(tables) && tables.length === 0, tables);
|
|
54
|
+
await db.stop();
|
|
55
|
+
}
|
|
56
|
+
// #273 / #307 via protocol-level unit invocation
|
|
57
|
+
{
|
|
58
|
+
const { MysqlConnection } = require(path.join(ROOT, 'lib', 'mysql_server.js'));
|
|
59
|
+
const engine = new Database(':memory:');
|
|
60
|
+
await engine.createTable('t', { id: { type: 'integer', primaryKey: true }, name: { type: 'string' } });
|
|
61
|
+
const makeConn = () => {
|
|
62
|
+
const c = Object.create(MysqlConnection.prototype);
|
|
63
|
+
c.sequence = 0;
|
|
64
|
+
c.authenticated = true;
|
|
65
|
+
c._stmtSeq = 0;
|
|
66
|
+
c._stmts = new Map();
|
|
67
|
+
c.currentDb = 'app';
|
|
68
|
+
c.server = { _getDatabase: async () => engine };
|
|
69
|
+
c.packets = [];
|
|
70
|
+
c.socket = { writable: true, write: (b) => c.packets.push(b.slice(4)), end() {} };
|
|
71
|
+
return c;
|
|
72
|
+
};
|
|
73
|
+
const conn = makeConn();
|
|
74
|
+
conn._handleStmtPrepare(Buffer.from('SELECT id, name FROM t'));
|
|
75
|
+
await sleep(50);
|
|
76
|
+
const joined = Buffer.concat(conn.packets).toString('latin1');
|
|
77
|
+
ok('#273 prepare column metadata uses real names', joined.includes('id') && joined.includes('name') && !joined.includes('col1'), conn.packets.length);
|
|
78
|
+
|
|
79
|
+
const conn2 = makeConn();
|
|
80
|
+
conn2._handlePacket(Buffer.concat([Buffer.from([0x04]), Buffer.from('t\0\0')]), 0);
|
|
81
|
+
await sleep(50);
|
|
82
|
+
const fieldList = Buffer.concat(conn2.packets).toString('latin1');
|
|
83
|
+
ok('#307 COM_FIELD_LIST returns column definitions', fieldList.includes('id') && fieldList.includes('name'), conn2.packets.length);
|
|
84
|
+
engine.stop();
|
|
85
|
+
}
|
|
86
|
+
console.log(`\n${passed} passed, ${failed} failed`);
|
|
87
|
+
process.exit(failed === 0 ? 0 : 1);
|
|
88
|
+
})().catch((e) => { console.error('FATAL', e); process.exit(1); });
|