mirror of
https://github.com/DeNNiiInc/dbgate.git
synced 2026-04-19 22:26:01 +00:00
SYNC: commit/rollback - control commands
This commit is contained in:
committed by
Diflow
parent
f81207737c
commit
11d193a6dd
@@ -56,7 +56,11 @@ module.exports = {
|
||||
handle_done(sesid, props) {
|
||||
socket.emit(`session-done-${sesid}`);
|
||||
if (!props.skipFinishedMessage) {
|
||||
this.dispatchMessage(sesid, 'Query execution finished');
|
||||
if (props.controlCommand) {
|
||||
this.dispatchMessage(sesid, `${_.startCase(props.controlCommand)} finished`);
|
||||
} else {
|
||||
this.dispatchMessage(sesid, 'Query execution finished');
|
||||
}
|
||||
}
|
||||
const session = this.opened.find(x => x.sesid == sesid);
|
||||
if (session.loadingReader_jslid) {
|
||||
@@ -144,6 +148,20 @@ module.exports = {
|
||||
return { state: 'ok' };
|
||||
},
|
||||
|
||||
executeControlCommand_meta: true,
|
||||
async executeControlCommand({ sesid, command }) {
|
||||
const session = this.opened.find(x => x.sesid == sesid);
|
||||
if (!session) {
|
||||
throw new Error('Invalid session');
|
||||
}
|
||||
|
||||
logger.info({ sesid, command }, 'Processing control command');
|
||||
this.dispatchMessage(sesid, `${_.startCase(command)} started`);
|
||||
session.subprocess.send({ msgtype: 'executeControlCommand', command });
|
||||
|
||||
return { state: 'ok' };
|
||||
},
|
||||
|
||||
executeReader_meta: true,
|
||||
async executeReader({ conid, database, sql, queryName, appFolder }) {
|
||||
const { sesid } = await this.create({ conid, database });
|
||||
|
||||
@@ -245,6 +245,46 @@ async function handleStopProfiler({ jslid }) {
|
||||
currentProfiler = null;
|
||||
}
|
||||
|
||||
async function handleExecuteControlCommand({ command }) {
|
||||
lastActivity = new Date().getTime();
|
||||
|
||||
await waitConnected();
|
||||
const driver = requireEngineDriver(storedConnection);
|
||||
|
||||
if (command == 'commitTransaction' && !allowExecuteCustomScript(driver)) {
|
||||
process.send({
|
||||
msgtype: 'info',
|
||||
info: {
|
||||
message: 'Connection without read-only sessions is read only',
|
||||
severity: 'error',
|
||||
},
|
||||
});
|
||||
process.send({ msgtype: 'done', skipFinishedMessage: true });
|
||||
return;
|
||||
//process.send({ msgtype: 'error', error: e.message });
|
||||
}
|
||||
|
||||
executingScripts++;
|
||||
try {
|
||||
const dmp = driver.createDumper();
|
||||
switch (command) {
|
||||
case 'commitTransaction':
|
||||
await dmp.commitTransaction();
|
||||
break;
|
||||
case 'rollbackTransaction':
|
||||
await dmp.rollbackTransaction();
|
||||
break;
|
||||
case 'beginTransaction':
|
||||
await dmp.beginTransaction();
|
||||
break;
|
||||
}
|
||||
await driver.query(dbhan, dmp.s, { discardResult: true });
|
||||
process.send({ msgtype: 'done', controlCommand: command });
|
||||
} finally {
|
||||
executingScripts--;
|
||||
}
|
||||
}
|
||||
|
||||
async function handleExecuteQuery({ sql }) {
|
||||
lastActivity = new Date().getTime();
|
||||
|
||||
@@ -323,6 +363,7 @@ function handlePing() {
|
||||
const messageHandlers = {
|
||||
connect: handleConnect,
|
||||
executeQuery: handleExecuteQuery,
|
||||
executeControlCommand: handleExecuteControlCommand,
|
||||
executeReader: handleExecuteReader,
|
||||
startProfiler: handleStartProfiler,
|
||||
stopProfiler: handleStopProfiler,
|
||||
|
||||
Reference in New Issue
Block a user