Revert "fix: ALTER TABLE DROP COLUMN only modifies schema, demo page deep-copies query results to prevent reference sharing"
CI / test (18.x) (push) Successful in 10m7s
CI / test (20.x) (push) Successful in 9m57s
CI / test (22.x) (push) Successful in 9m55s
CI / test (24.x) (push) Successful in 9m53s

This reverts commit 29f8fd52a1.
This commit is contained in:
thzxx
2026-07-29 22:34:36 +08:00
parent 4a78dc870c
commit 9d53bb7124
9 changed files with 36 additions and 11 deletions
+8 -1
View File
@@ -5667,8 +5667,15 @@ class QueryExecutor {
if (!schema.columns[stmt.column.name]) { if (!schema.columns[stmt.column.name]) {
throw new DatabaseError(`Column "${stmt.column.name}" does not exist in table "${stmt.name}"`, 'COLUMN_NOT_FOUND'); throw new DatabaseError(`Column "${stmt.column.name}" does not exist in table "${stmt.name}"`, 'COLUMN_NOT_FOUND');
} }
// 从 schema 引用上删除列定义,不碰行数据(避免引用共享导致查询结果被篡改 // 从 schema 引用上删除列定义(保留所有行数据
delete schema.columns[stmt.column.name]; delete schema.columns[stmt.column.name];
// 清除已有行中该列的值(MemoryEngine 的 find 返回引用,delete 直接生效)
const rows = await this.engine.find(stmt.name, { table: stmt.name });
const colName = stmt.column.name;
for (const row of rows) {
if (colName in row)
delete row[colName];
}
} }
} }
async executeTruncateTable(stmt) { async executeTruncateTable(stmt) {
+1 -1
View File
File diff suppressed because one or more lines are too long
+8 -1
View File
@@ -5663,8 +5663,15 @@ class QueryExecutor {
if (!schema.columns[stmt.column.name]) { if (!schema.columns[stmt.column.name]) {
throw new DatabaseError(`Column "${stmt.column.name}" does not exist in table "${stmt.name}"`, 'COLUMN_NOT_FOUND'); throw new DatabaseError(`Column "${stmt.column.name}" does not exist in table "${stmt.name}"`, 'COLUMN_NOT_FOUND');
} }
// 从 schema 引用上删除列定义,不碰行数据(避免引用共享导致查询结果被篡改 // 从 schema 引用上删除列定义(保留所有行数据
delete schema.columns[stmt.column.name]; delete schema.columns[stmt.column.name];
// 清除已有行中该列的值(MemoryEngine 的 find 返回引用,delete 直接生效)
const rows = await this.engine.find(stmt.name, { table: stmt.name });
const colName = stmt.column.name;
for (const row of rows) {
if (colName in row)
delete row[colName];
}
} }
} }
async executeTruncateTable(stmt) { async executeTruncateTable(stmt) {
+1 -1
View File
File diff suppressed because one or more lines are too long
+8 -1
View File
@@ -5669,8 +5669,15 @@
if (!schema.columns[stmt.column.name]) { if (!schema.columns[stmt.column.name]) {
throw new DatabaseError(`Column "${stmt.column.name}" does not exist in table "${stmt.name}"`, 'COLUMN_NOT_FOUND'); throw new DatabaseError(`Column "${stmt.column.name}" does not exist in table "${stmt.name}"`, 'COLUMN_NOT_FOUND');
} }
// 从 schema 引用上删除列定义,不碰行数据(避免引用共享导致查询结果被篡改 // 从 schema 引用上删除列定义(保留所有行数据
delete schema.columns[stmt.column.name]; delete schema.columns[stmt.column.name];
// 清除已有行中该列的值(MemoryEngine 的 find 返回引用,delete 直接生效)
const rows = await this.engine.find(stmt.name, { table: stmt.name });
const colName = stmt.column.name;
for (const row of rows) {
if (colName in row)
delete row[colName];
}
} }
} }
async executeTruncateTable(stmt) { async executeTruncateTable(stmt) {
+1 -1
View File
File diff suppressed because one or more lines are too long
+1 -1
View File
File diff suppressed because one or more lines are too long
+1 -3
View File
@@ -221,9 +221,7 @@ async function runQuery() {
const allResults = []; const allResults = [];
for (const stmt of statements) { for (const stmt of statements) {
const result = await db.query(stmt); const result = await db.query(stmt);
// 深拷贝结果,避免引用共享导致后续操作(如 ALTER TABLE DROP COLUMN)修改已渲染的结果 allResults.push({ sql: stmt, result });
const resultCopy = Array.isArray(result) ? result.map(r => ({ ...r })) : result;
allResults.push({ sql: stmt, result: resultCopy });
} }
if (allResults.length === 1) { if (allResults.length === 1) {
+7 -1
View File
@@ -306,8 +306,14 @@ export class QueryExecutor {
if (!schema.columns[stmt.column.name]) { if (!schema.columns[stmt.column.name]) {
throw new DatabaseError(`Column "${stmt.column.name}" does not exist in table "${stmt.name}"`, 'COLUMN_NOT_FOUND'); throw new DatabaseError(`Column "${stmt.column.name}" does not exist in table "${stmt.name}"`, 'COLUMN_NOT_FOUND');
} }
// 从 schema 引用上删除列定义,不碰行数据(避免引用共享导致查询结果被篡改 // 从 schema 引用上删除列定义(保留所有行数据
delete schema.columns[stmt.column.name]; delete schema.columns[stmt.column.name];
// 清除已有行中该列的值(MemoryEngine 的 find 返回引用,delete 直接生效)
const rows = await this.engine.find(stmt.name, { table: stmt.name });
const colName = stmt.column.name;
for (const row of rows) {
if (colName in row) delete row[colName];
}
} }
} }