fix: demo page deep-copies query results to prevent reference sharing between statements
This commit is contained in:
+3
-1
@@ -221,7 +221,9 @@ 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);
|
||||||
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) {
|
||||||
|
|||||||
Reference in New Issue
Block a user