mirror of
https://github.com/DeNNiiInc/dbgate.git
synced 2026-04-30 04:33:57 +00:00
Cancel script execution after first error #1070
This commit is contained in:
@@ -401,14 +401,18 @@ async function handleExecuteSessionQuery({ sesid, sql }) {
|
|||||||
//process.send({ msgtype: 'error', error: e.message });
|
//process.send({ msgtype: 'error', error: e.message });
|
||||||
}
|
}
|
||||||
|
|
||||||
const resultIndexHolder = {
|
const queryStreamInfoHolder = {
|
||||||
value: 0,
|
resultIndex: 0,
|
||||||
|
canceled: false,
|
||||||
};
|
};
|
||||||
for (const sqlItem of splitQuery(sql, {
|
for (const sqlItem of splitQuery(sql, {
|
||||||
...driver.getQuerySplitterOptions('stream'),
|
...driver.getQuerySplitterOptions('stream'),
|
||||||
returnRichInfo: true,
|
returnRichInfo: true,
|
||||||
})) {
|
})) {
|
||||||
await handleQueryStream(dbhan, driver, resultIndexHolder, sqlItem, sesid);
|
await handleQueryStream(dbhan, driver, queryStreamInfoHolder, sqlItem, sesid);
|
||||||
|
if (queryStreamInfoHolder.canceled) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
process.send({ msgtype: 'done', sesid });
|
process.send({ msgtype: 'done', sesid });
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -138,18 +138,23 @@ async function handleExecuteQuery({ sql, autoCommit }) {
|
|||||||
|
|
||||||
executingScripts++;
|
executingScripts++;
|
||||||
try {
|
try {
|
||||||
const resultIndexHolder = {
|
const queryStreamInfoHolder = {
|
||||||
value: 0,
|
resultIndex: 0,
|
||||||
|
canceled: false,
|
||||||
};
|
};
|
||||||
for (const sqlItem of splitQuery(sql, {
|
for (const sqlItem of splitQuery(sql, {
|
||||||
...driver.getQuerySplitterOptions('stream'),
|
...driver.getQuerySplitterOptions('stream'),
|
||||||
returnRichInfo: true,
|
returnRichInfo: true,
|
||||||
})) {
|
})) {
|
||||||
await handleQueryStream(dbhan, driver, resultIndexHolder, sqlItem);
|
await handleQueryStream(dbhan, driver, queryStreamInfoHolder, sqlItem);
|
||||||
// const handler = new StreamHandler(resultIndex);
|
// const handler = new StreamHandler(resultIndex);
|
||||||
// const stream = await driver.stream(systemConnection, sqlItem, handler);
|
// const stream = await driver.stream(systemConnection, sqlItem, handler);
|
||||||
// handler.stream = stream;
|
// handler.stream = stream;
|
||||||
// resultIndex = handler.resultIndex;
|
// resultIndex = handler.resultIndex;
|
||||||
|
|
||||||
|
if (queryStreamInfoHolder.canceled) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
process.send({ msgtype: 'done', autoCommit });
|
process.send({ msgtype: 'done', autoCommit });
|
||||||
} finally {
|
} finally {
|
||||||
|
|||||||
@@ -91,7 +91,7 @@ class QueryStreamTableWriter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
class StreamHandler {
|
class StreamHandler {
|
||||||
constructor(resultIndexHolder, resolve, startLine, sesid = undefined) {
|
constructor(queryStreamInfoHolder, resolve, startLine, sesid = undefined) {
|
||||||
this.recordset = this.recordset.bind(this);
|
this.recordset = this.recordset.bind(this);
|
||||||
this.startLine = startLine;
|
this.startLine = startLine;
|
||||||
this.sesid = sesid;
|
this.sesid = sesid;
|
||||||
@@ -104,7 +104,7 @@ class StreamHandler {
|
|||||||
// this.stream = null;
|
// this.stream = null;
|
||||||
|
|
||||||
this.plannedStats = false;
|
this.plannedStats = false;
|
||||||
this.resultIndexHolder = resultIndexHolder;
|
this.queryStreamInfoHolder = queryStreamInfoHolder;
|
||||||
this.resolve = resolve;
|
this.resolve = resolve;
|
||||||
// currentHandlers = [...currentHandlers, this];
|
// currentHandlers = [...currentHandlers, this];
|
||||||
}
|
}
|
||||||
@@ -121,9 +121,9 @@ class StreamHandler {
|
|||||||
this.currentWriter = new QueryStreamTableWriter(this.sesid);
|
this.currentWriter = new QueryStreamTableWriter(this.sesid);
|
||||||
this.currentWriter.initializeFromQuery(
|
this.currentWriter.initializeFromQuery(
|
||||||
Array.isArray(columns) ? { columns } : columns,
|
Array.isArray(columns) ? { columns } : columns,
|
||||||
this.resultIndexHolder.value
|
this.queryStreamInfoHolder.resultIndex
|
||||||
);
|
);
|
||||||
this.resultIndexHolder.value += 1;
|
this.queryStreamInfoHolder.resultIndex += 1;
|
||||||
|
|
||||||
// this.writeCurrentStats();
|
// this.writeCurrentStats();
|
||||||
|
|
||||||
@@ -153,14 +153,17 @@ class StreamHandler {
|
|||||||
line: this.startLine + info.line,
|
line: this.startLine + info.line,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
if (info.severity == 'error') {
|
||||||
|
this.queryStreamInfoHolder.canceled = true;
|
||||||
|
}
|
||||||
process.send({ msgtype: 'info', info, sesid: this.sesid });
|
process.send({ msgtype: 'info', info, sesid: this.sesid });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function handleQueryStream(dbhan, driver, resultIndexHolder, sqlItem, sesid = undefined) {
|
function handleQueryStream(dbhan, driver, queryStreamInfoHolder, sqlItem, sesid = undefined) {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
const start = sqlItem.trimStart || sqlItem.start;
|
const start = sqlItem.trimStart || sqlItem.start;
|
||||||
const handler = new StreamHandler(resultIndexHolder, resolve, start && start.line, sesid);
|
const handler = new StreamHandler(queryStreamInfoHolder, resolve, start && start.line, sesid);
|
||||||
driver.stream(dbhan, sqlItem.text, handler);
|
driver.stream(dbhan, sqlItem.text, handler);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user