diff --git a/src/components/sql-file/SqlFileExecutionDialog.vue b/src/components/sql-file/SqlFileExecutionDialog.vue index ddef42cf9f..4d5d13abf2 100644 --- a/src/components/sql-file/SqlFileExecutionDialog.vue +++ b/src/components/sql-file/SqlFileExecutionDialog.vue @@ -49,6 +49,8 @@ const continueOnError = ref(false); const running = ref(false); const cancelling = ref(false); +const cancelRequested = ref(false); +const executionStarted = ref(false); const executionId = ref(""); const progress = ref(null); const terminalStatus = ref("idle"); @@ -145,6 +147,8 @@ function chooseDatabase(names: string[], id: string) { function resetExecution() { running.value = false; cancelling.value = false; + cancelRequested.value = false; + executionStarted.value = false; executionId.value = ""; progress.value = null; terminalStatus.value = "idle"; @@ -233,6 +237,8 @@ async function startExecution() { executionId.value = id; running.value = true; cancelling.value = false; + cancelRequested.value = false; + executionStarted.value = false; terminalStatus.value = "running"; terminalError.value = ""; progress.value = null; @@ -240,6 +246,10 @@ async function startExecution() { let unlisten: (() => void) | undefined; try { await store.ensureConnected(connectionId.value); + if (cancelRequested.value) { + terminalStatus.value = "cancelled"; + return; + } unlisten = await listenSqlFileProgress((next) => { if (next.executionId !== id) return; @@ -252,6 +262,12 @@ async function startExecution() { } }); + if (cancelRequested.value) { + terminalStatus.value = "cancelled"; + return; + } + + executionStarted.value = true; await executeSqlFile({ executionId: id, connectionId: connectionId.value, @@ -260,22 +276,27 @@ async function startExecution() { continueOnError: continueOnError.value, }); if (!isTerminalStatus(terminalStatus.value)) { - terminalStatus.value = "done"; + terminalStatus.value = cancelRequested.value ? "cancelled" : "done"; } } catch (e: any) { - terminalStatus.value = cancelling.value ? "cancelled" : "error"; + terminalStatus.value = cancelRequested.value ? "cancelled" : "error"; terminalError.value = e?.message || String(e); - toast(terminalError.value, 5000); + if (!cancelRequested.value) { + toast(terminalError.value, 5000); + } } finally { unlisten?.(); running.value = false; cancelling.value = false; + executionStarted.value = false; } } async function cancelExecution() { if (!executionId.value || !running.value || cancelling.value) return; + cancelRequested.value = true; cancelling.value = true; + if (!executionStarted.value) return; try { await cancelSqlFileExecution(executionId.value); } catch (e: any) { @@ -440,22 +461,22 @@ watch(open, (value) => { /> -
-
-
{{ t('sqlFile.statement') }}
-
{{ progress?.statementIndex ?? 0 }}
+
+
+
{{ t('sqlFile.statement') }}
+
{{ progress?.statementIndex ?? 0 }}
-
-
{{ t('sqlFile.succeeded') }}
-
{{ progress?.successCount ?? 0 }}
+
+
{{ t('sqlFile.succeeded') }}
+
{{ progress?.successCount ?? 0 }}
-
-
{{ t('sqlFile.failed') }}
-
{{ progress?.failureCount ?? 0 }}
+
+
{{ t('sqlFile.failed') }}
+
{{ progress?.failureCount ?? 0 }}
-
-
{{ t('sqlFile.affectedRows') }}
-
{{ (progress?.affectedRows ?? 0).toLocaleString() }}
+
+
{{ t('sqlFile.affectedRows') }}
+
{{ (progress?.affectedRows ?? 0).toLocaleString() }}