diff --git a/packages/api/src/controllers/sessions.js b/packages/api/src/controllers/sessions.js index bb5338699..5091fa6a8 100644 --- a/packages/api/src/controllers/sessions.js +++ b/packages/api/src/controllers/sessions.js @@ -66,6 +66,9 @@ module.exports = { if (session.loadingReader_jslid) { socket.emit(`session-jslid-done-${session.loadingReader_jslid}`); } + if (props.autoCommit) { + this.executeControlCommand({ sesid, command: 'commitTransaction' }); + } if (session.killOnDone) { this.kill({ sesid }); } @@ -135,7 +138,7 @@ module.exports = { }, executeQuery_meta: true, - async executeQuery({ sesid, sql }) { + async executeQuery({ sesid, sql, autoCommit }) { const session = this.opened.find(x => x.sesid == sesid); if (!session) { throw new Error('Invalid session'); @@ -143,7 +146,7 @@ module.exports = { logger.info({ sesid, sql }, 'Processing query'); this.dispatchMessage(sesid, 'Query execution started'); - session.subprocess.send({ msgtype: 'executeQuery', sql }); + session.subprocess.send({ msgtype: 'executeQuery', sql, autoCommit }); return { state: 'ok' }; }, diff --git a/packages/api/src/proc/sessionProcess.js b/packages/api/src/proc/sessionProcess.js index 182f422b7..e81abda1c 100644 --- a/packages/api/src/proc/sessionProcess.js +++ b/packages/api/src/proc/sessionProcess.js @@ -285,7 +285,7 @@ async function handleExecuteControlCommand({ command }) { } } -async function handleExecuteQuery({ sql }) { +async function handleExecuteQuery({ sql, autoCommit }) { lastActivity = new Date().getTime(); await waitConnected(); @@ -319,7 +319,7 @@ async function handleExecuteQuery({ sql }) { // handler.stream = stream; // resultIndex = handler.resultIndex; } - process.send({ msgtype: 'done' }); + process.send({ msgtype: 'done', autoCommit }); } finally { executingScripts--; } diff --git a/packages/web/src/tabs/QueryTab.svelte b/packages/web/src/tabs/QueryTab.svelte index 2617207d6..4cf1aed4a 100644 --- a/packages/web/src/tabs/QueryTab.svelte +++ b/packages/web/src/tabs/QueryTab.svelte @@ -339,9 +339,13 @@ sesid = resp.sesid; sessionId = sesid; } + if (driver?.implicitTransactions) { + isInTransaction = true; + } await apiCall('sessions/execute-query', { sesid, sql, + autoCommit: driver?.implicitTransactions && isAutocommit, }); await apiCall('query-history/write', { data: { @@ -463,7 +467,7 @@ } export function endTransactionEnabled() { - return !!sessionId && driver?.supportsTransactions && isInTransaction && !busy; + return !!sessionId && driver?.supportsTransactions && isInTransaction && !busy && !isAutocommit; } export function autocommitOffSwitch() { @@ -493,6 +497,9 @@ const handleSessionDone = () => { busy = false; + if (isAutocommit) { + isInTransaction = false; + } timerLabel.stop(); };