fix: ALTER TABLE DROP COLUMN only modifies schema, demo page deep-copies query results to prevent reference sharing
This commit is contained in:
Vendored
+1
-8
@@ -5667,15 +5667,8 @@ class QueryExecutor {
|
||||
if (!schema.columns[stmt.column.name]) {
|
||||
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];
|
||||
// 清除已有行中该列的值(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) {
|
||||
|
||||
Vendored
+1
-1
File diff suppressed because one or more lines are too long
Vendored
+1
-8
@@ -5663,15 +5663,8 @@ class QueryExecutor {
|
||||
if (!schema.columns[stmt.column.name]) {
|
||||
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];
|
||||
// 清除已有行中该列的值(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) {
|
||||
|
||||
Vendored
+1
-1
File diff suppressed because one or more lines are too long
Vendored
+1
-8
@@ -5669,15 +5669,8 @@
|
||||
if (!schema.columns[stmt.column.name]) {
|
||||
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];
|
||||
// 清除已有行中该列的值(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) {
|
||||
|
||||
Vendored
+1
-1
File diff suppressed because one or more lines are too long
Vendored
+1
-1
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user