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