mirror of
https://github.com/DeNNiiInc/dbgate.git
synced 2026-04-30 15:03:57 +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) {
|
handle_done(sesid, props) {
|
||||||
socket.emit(`session-done-${sesid}`);
|
socket.emit(`session-done-${sesid}`);
|
||||||
if (!props.skipFinishedMessage) {
|
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);
|
const session = this.opened.find(x => x.sesid == sesid);
|
||||||
if (session.loadingReader_jslid) {
|
if (session.loadingReader_jslid) {
|
||||||
@@ -144,6 +148,20 @@ module.exports = {
|
|||||||
return { state: 'ok' };
|
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,
|
executeReader_meta: true,
|
||||||
async executeReader({ conid, database, sql, queryName, appFolder }) {
|
async executeReader({ conid, database, sql, queryName, appFolder }) {
|
||||||
const { sesid } = await this.create({ conid, database });
|
const { sesid } = await this.create({ conid, database });
|
||||||
|
|||||||
@@ -245,6 +245,46 @@ async function handleStopProfiler({ jslid }) {
|
|||||||
currentProfiler = null;
|
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 }) {
|
async function handleExecuteQuery({ sql }) {
|
||||||
lastActivity = new Date().getTime();
|
lastActivity = new Date().getTime();
|
||||||
|
|
||||||
@@ -323,6 +363,7 @@ function handlePing() {
|
|||||||
const messageHandlers = {
|
const messageHandlers = {
|
||||||
connect: handleConnect,
|
connect: handleConnect,
|
||||||
executeQuery: handleExecuteQuery,
|
executeQuery: handleExecuteQuery,
|
||||||
|
executeControlCommand: handleExecuteControlCommand,
|
||||||
executeReader: handleExecuteReader,
|
executeReader: handleExecuteReader,
|
||||||
startProfiler: handleStartProfiler,
|
startProfiler: handleStartProfiler,
|
||||||
stopProfiler: handleStopProfiler,
|
stopProfiler: handleStopProfiler,
|
||||||
|
|||||||
@@ -353,6 +353,26 @@
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function executeControlCommand(command) {
|
||||||
|
busy = true;
|
||||||
|
timerLabel.start();
|
||||||
|
visibleResultTabs = true;
|
||||||
|
|
||||||
|
let sesid = sessionId;
|
||||||
|
if (!sesid) {
|
||||||
|
const resp = await apiCall('sessions/create', {
|
||||||
|
conid,
|
||||||
|
database,
|
||||||
|
});
|
||||||
|
sesid = resp.sesid;
|
||||||
|
sessionId = sesid;
|
||||||
|
}
|
||||||
|
await apiCall('sessions/execute-control-command', {
|
||||||
|
sesid,
|
||||||
|
command,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
export async function executeCurrent() {
|
export async function executeCurrent() {
|
||||||
const cmd = domEditor.getCurrentCommandText();
|
const cmd = domEditor.getCurrentCommandText();
|
||||||
await executeCore(cmd.text, cmd.line);
|
await executeCore(cmd.text, cmd.line);
|
||||||
@@ -426,10 +446,8 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function beginTransaction() {
|
export function beginTransaction() {
|
||||||
const dmp = driver.createDumper();
|
|
||||||
dmp.beginTransaction();
|
|
||||||
executeCore(dmp.s);
|
|
||||||
isInTransaction = true;
|
isInTransaction = true;
|
||||||
|
executeControlCommand('beginTransaction');
|
||||||
}
|
}
|
||||||
|
|
||||||
export function beginTransactionEnabled() {
|
export function beginTransactionEnabled() {
|
||||||
@@ -457,17 +475,13 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function commitTransaction() {
|
export function commitTransaction() {
|
||||||
const dmp = driver.createDumper();
|
|
||||||
dmp.commitTransaction();
|
|
||||||
executeCore(dmp.s);
|
|
||||||
isInTransaction = false;
|
isInTransaction = false;
|
||||||
|
executeControlCommand('commitTransaction');
|
||||||
}
|
}
|
||||||
|
|
||||||
export function rollbackTransaction() {
|
export function rollbackTransaction() {
|
||||||
const dmp = driver.createDumper();
|
|
||||||
dmp.rollbackTransaction();
|
|
||||||
executeCore(dmp.s);
|
|
||||||
isInTransaction = false;
|
isInTransaction = false;
|
||||||
|
executeControlCommand('rollbackTransaction');
|
||||||
}
|
}
|
||||||
|
|
||||||
const handleMesageClick = message => {
|
const handleMesageClick = message => {
|
||||||
|
|||||||
Reference in New Issue
Block a user