mirror of
https://github.com/DeNNiiInc/dbgate.git
synced 2026-04-17 23:45:59 +00:00
query excecute fixes
This commit is contained in:
@@ -95,15 +95,15 @@ module.exports = {
|
||||
return { state: 'ok' };
|
||||
},
|
||||
|
||||
cancel_meta: 'post',
|
||||
async cancel({ sesid }) {
|
||||
const session = this.opened.find((x) => x.sesid == sesid);
|
||||
if (!session) {
|
||||
throw new Error('Invalid session');
|
||||
}
|
||||
session.subprocess.send({ msgtype: 'cancel' });
|
||||
return { state: 'ok' };
|
||||
},
|
||||
// cancel_meta: 'post',
|
||||
// async cancel({ sesid }) {
|
||||
// const session = this.opened.find((x) => x.sesid == sesid);
|
||||
// if (!session) {
|
||||
// throw new Error('Invalid session');
|
||||
// }
|
||||
// session.subprocess.send({ msgtype: 'cancel' });
|
||||
// return { state: 'ok' };
|
||||
// },
|
||||
|
||||
kill_meta: 'post',
|
||||
async kill({ sesid }) {
|
||||
@@ -112,6 +112,7 @@ module.exports = {
|
||||
throw new Error('Invalid session');
|
||||
}
|
||||
session.subprocess.kill();
|
||||
this.dispatchMessage(sesid, 'Connection closed');
|
||||
return { state: 'ok' };
|
||||
},
|
||||
|
||||
|
||||
@@ -11,7 +11,7 @@ const requireEngineDriver = require('../utility/requireEngineDriver');
|
||||
let systemConnection;
|
||||
let storedConnection;
|
||||
let afterConnectCallbacks = [];
|
||||
let currentHandlers = [];
|
||||
// let currentHandlers = [];
|
||||
|
||||
class TableWriter {
|
||||
constructor(columns, resultIndex) {
|
||||
@@ -64,17 +64,20 @@ class TableWriter {
|
||||
}
|
||||
|
||||
class StreamHandler {
|
||||
constructor(resultIndex) {
|
||||
constructor(resultIndexHolder, resolve) {
|
||||
this.recordset = this.recordset.bind(this);
|
||||
this.row = this.row.bind(this);
|
||||
// this.error = this.error.bind(this);
|
||||
this.done = this.done.bind(this);
|
||||
this.info = this.info.bind(this);
|
||||
// use this for cancelling
|
||||
this.stream = null;
|
||||
|
||||
// use this for cancelling - not implemented
|
||||
// this.stream = null;
|
||||
|
||||
this.plannedStats = false;
|
||||
this.resultIndex = resultIndex;
|
||||
currentHandlers = [...currentHandlers, this];
|
||||
this.resultIndexHolder = resultIndexHolder;
|
||||
this.resolve = resolve;
|
||||
// currentHandlers = [...currentHandlers, this];
|
||||
}
|
||||
|
||||
closeCurrentWriter() {
|
||||
@@ -86,7 +89,8 @@ class StreamHandler {
|
||||
|
||||
recordset(columns) {
|
||||
this.closeCurrentWriter();
|
||||
this.currentWriter = new TableWriter(columns, this.resultIndex);
|
||||
this.currentWriter = new TableWriter(columns, this.resultIndexHolder.value);
|
||||
this.resultIndexHolder.value += 1;
|
||||
|
||||
// this.writeCurrentStats();
|
||||
|
||||
@@ -107,14 +111,21 @@ class StreamHandler {
|
||||
// }
|
||||
done(result) {
|
||||
this.closeCurrentWriter();
|
||||
process.send({ msgtype: 'done', result });
|
||||
currentHandlers = currentHandlers.filter((x) => x != this);
|
||||
// currentHandlers = currentHandlers.filter((x) => x != this);
|
||||
this.resolve();
|
||||
}
|
||||
info(info) {
|
||||
process.send({ msgtype: 'info', info });
|
||||
}
|
||||
}
|
||||
|
||||
function handleStream(driver, resultIndexHolder, sql) {
|
||||
return new Promise((resolve, reject) => {
|
||||
const handler = new StreamHandler(resultIndexHolder, resolve);
|
||||
driver.stream(systemConnection, sql, handler);
|
||||
});
|
||||
}
|
||||
|
||||
async function handleConnect(connection) {
|
||||
storedConnection = connection;
|
||||
|
||||
@@ -126,11 +137,11 @@ async function handleConnect(connection) {
|
||||
afterConnectCallbacks = [];
|
||||
}
|
||||
|
||||
function handleCancel() {
|
||||
for (const handler of currentHandlers) {
|
||||
if (handler.stream) handler.stream.cancel();
|
||||
}
|
||||
}
|
||||
// function handleCancel() {
|
||||
// for (const handler of currentHandlers) {
|
||||
// if (handler.stream) handler.stream.cancel();
|
||||
// }
|
||||
// }
|
||||
|
||||
function waitConnected() {
|
||||
if (systemConnection) return Promise.resolve();
|
||||
@@ -143,19 +154,23 @@ async function handleExecuteQuery({ sql }) {
|
||||
await waitConnected();
|
||||
const driver = requireEngineDriver(storedConnection);
|
||||
|
||||
let resultIndex = 0;
|
||||
const resultIndexHolder = {
|
||||
value: 0,
|
||||
};
|
||||
for (const sqlItem of goSplit(sql)) {
|
||||
const handler = new StreamHandler(resultIndex);
|
||||
const stream = await driver.stream(systemConnection, sqlItem, handler);
|
||||
handler.stream = stream;
|
||||
resultIndex += 1;
|
||||
await handleStream(driver, resultIndexHolder, sqlItem);
|
||||
// const handler = new StreamHandler(resultIndex);
|
||||
// const stream = await driver.stream(systemConnection, sqlItem, handler);
|
||||
// handler.stream = stream;
|
||||
// resultIndex = handler.resultIndex;
|
||||
}
|
||||
process.send({ msgtype: 'done' });
|
||||
}
|
||||
|
||||
const messageHandlers = {
|
||||
connect: handleConnect,
|
||||
executeQuery: handleExecuteQuery,
|
||||
cancel: handleCancel,
|
||||
// cancel: handleCancel,
|
||||
};
|
||||
|
||||
async function handleMessage({ msgtype, ...other }) {
|
||||
|
||||
@@ -2,16 +2,16 @@ import React from 'react';
|
||||
import useHasPermission from '../utility/useHasPermission';
|
||||
import ToolbarButton from '../widgets/ToolbarButton';
|
||||
|
||||
export default function QueryToolbar({ execute, cancel, isDatabaseDefined, busy, save, format, isConnected, kill }) {
|
||||
export default function QueryToolbar({ execute, isDatabaseDefined, busy, save, format, isConnected, kill }) {
|
||||
const hasPermission = useHasPermission();
|
||||
return (
|
||||
<>
|
||||
<ToolbarButton disabled={!isDatabaseDefined || busy} onClick={execute} icon="icon run">
|
||||
Execute
|
||||
</ToolbarButton>
|
||||
<ToolbarButton disabled={!busy} onClick={cancel} icon="icon close">
|
||||
{/* <ToolbarButton disabled={!busy} onClick={cancel} icon="icon close">
|
||||
Cancel
|
||||
</ToolbarButton>
|
||||
</ToolbarButton> */}
|
||||
<ToolbarButton disabled={!isConnected} onClick={kill} icon="icon close">
|
||||
Kill
|
||||
</ToolbarButton>
|
||||
|
||||
@@ -24,6 +24,7 @@ import useExtensions from '../utility/useExtensions';
|
||||
|
||||
export default function QueryTab({ tabid, conid, database, initialArgs, tabVisible, toolbarPortalRef, ...other }) {
|
||||
const [sessionId, setSessionId] = React.useState(null);
|
||||
const [visibleResultTabs, setVisibleResultTabs] = React.useState(false);
|
||||
const [executeNumber, setExecuteNumber] = React.useState(0);
|
||||
const setOpenedTabs = useSetOpenedTabs();
|
||||
const socket = useSocket();
|
||||
@@ -63,6 +64,7 @@ export default function QueryTab({ tabid, conid, database, initialArgs, tabVisib
|
||||
const handleExecute = async () => {
|
||||
if (busy) return;
|
||||
setExecuteNumber((num) => num + 1);
|
||||
setVisibleResultTabs(true);
|
||||
const selectedText = editorRef.current.editor.getSelectedText();
|
||||
|
||||
let sesid = sessionId;
|
||||
@@ -81,14 +83,14 @@ export default function QueryTab({ tabid, conid, database, initialArgs, tabVisib
|
||||
});
|
||||
};
|
||||
|
||||
const handleCancel = () => {
|
||||
axios.post('sessions/cancel', {
|
||||
sesid: sessionId,
|
||||
});
|
||||
};
|
||||
// const handleCancel = () => {
|
||||
// axios.post('sessions/cancel', {
|
||||
// sesid: sessionId,
|
||||
// });
|
||||
// };
|
||||
|
||||
const handleKill = () => {
|
||||
axios.post('sessions/kill', {
|
||||
const handleKill = async () => {
|
||||
await axios.post('sessions/kill', {
|
||||
sesid: sessionId,
|
||||
});
|
||||
setSessionId(null);
|
||||
@@ -135,7 +137,7 @@ export default function QueryTab({ tabid, conid, database, initialArgs, tabVisib
|
||||
conid={conid}
|
||||
database={database}
|
||||
/>
|
||||
{sessionId && (
|
||||
{visibleResultTabs && (
|
||||
<ResultTabs sessionId={sessionId} executeNumber={executeNumber}>
|
||||
<TabPage label="Messages" key="messages">
|
||||
<SocketMessagesView
|
||||
@@ -157,7 +159,7 @@ export default function QueryTab({ tabid, conid, database, initialArgs, tabVisib
|
||||
isDatabaseDefined={conid && database}
|
||||
execute={handleExecute}
|
||||
busy={busy}
|
||||
cancel={handleCancel}
|
||||
// cancel={handleCancel}
|
||||
format={handleFormatCode}
|
||||
save={saveFileModalState.open}
|
||||
isConnected={!!sessionId}
|
||||
|
||||
Reference in New Issue
Block a user