SYNC: commit/rollback - control commands

This commit is contained in:
SPRINX0\prochazka
2025-02-25 09:28:03 +01:00
committed by Diflow
parent f81207737c
commit 11d193a6dd
3 changed files with 83 additions and 10 deletions

View File

@@ -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 });

View File

@@ -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,