From 0cc7a983916a7a6782662147e39315811c24108e Mon Sep 17 00:00:00 2001 From: Jan Prochazka Date: Sat, 1 Jun 2024 08:36:13 +0200 Subject: [PATCH] oracle: fixed commit --- .../src/backend/drivers.js | 7 +- .../src/frontend/Dumper.js | 177 +++++++++--------- 2 files changed, 96 insertions(+), 88 deletions(-) diff --git a/plugins/dbgate-plugin-oracle/src/backend/drivers.js b/plugins/dbgate-plugin-oracle/src/backend/drivers.js index eb10a4e5..2520bb5b 100644 --- a/plugins/dbgate-plugin-oracle/src/backend/drivers.js +++ b/plugins/dbgate-plugin-oracle/src/backend/drivers.js @@ -67,8 +67,11 @@ const drivers = driverBases.map(driverBase => ({ return pool.end(); }, async query(client, sql) { - //console.log('query sql', sql); - if (sql == null) {a + if (sql.trim() == 'COMMIT;') { + sql = 'COMMIT'; + } + + if (sql == null) { return { rows: [], columns: [], diff --git a/plugins/dbgate-plugin-oracle/src/frontend/Dumper.js b/plugins/dbgate-plugin-oracle/src/frontend/Dumper.js index b60deb8f..9c8a2f9f 100644 --- a/plugins/dbgate-plugin-oracle/src/frontend/Dumper.js +++ b/plugins/dbgate-plugin-oracle/src/frontend/Dumper.js @@ -2,108 +2,113 @@ const { SqlDumper, arrayToHexString, testEqualTypes } = global.DBGATE_TOOLS; class Dumper extends SqlDumper { createDatabase(name) { - this.putCmd(`CREATE USER c##${name} + this.putCmd( + `CREATE USER c##${name} IDENTIFIED BY ${name} DEFAULT TABLESPACE users TEMPORARY TABLESPACE temp - QUOTA 10M ON users;`, name); + QUOTA 10M ON users;`, + name + ); } + // oracle uses implicit transactions + beginTransaction() {} - /** @param type {import('dbgate-types').TransformType} */ - transform(type, dumpExpr) { - switch (type) { - case 'GROUP:YEAR': - case 'YEAR': - this.put('^extract(^year ^from %c)', dumpExpr); - break; - case 'MONTH': - this.put('^extract(^month ^from %c)', dumpExpr); - break; - case 'DAY': - this.put('^extract(^day ^from %c)', dumpExpr); - break; - case 'GROUP:MONTH': - this.put("^to_char(%c, '%s')", dumpExpr, 'YYYY-MM'); - break; - case 'GROUP:DAY': - this.put("^to_char(%c, '%s')", dumpExpr, 'YYYY-MM-DD'); - break; - default: - dumpExpr(); - break; - } - } + // /** @param type {import('dbgate-types').TransformType} */ + // transform(type, dumpExpr) { + // switch (type) { + // case 'GROUP:YEAR': + // case 'YEAR': + // this.put('^extract(^year ^from %c)', dumpExpr); + // break; + // case 'MONTH': + // this.put('^extract(^month ^from %c)', dumpExpr); + // break; + // case 'DAY': + // this.put('^extract(^day ^from %c)', dumpExpr); + // break; + // case 'GROUP:MONTH': + // this.put("^to_char(%c, '%s')", dumpExpr, 'YYYY-MM'); + // break; + // case 'GROUP:DAY': + // this.put("^to_char(%c, '%s')", dumpExpr, 'YYYY-MM-DD'); + // break; + // default: + // dumpExpr(); + // break; + // } + // } - dropRecreatedTempTable(tmptable) { - this.putCmd('^drop ^table %i ^cascade', tmptable); - } + // dropRecreatedTempTable(tmptable) { + // this.putCmd('^drop ^table %i ^cascade', tmptable); + // } - renameTable(obj, newname) { - this.putCmd('^alter ^table %f ^rename ^to %i', obj, newname); - } + // renameTable(obj, newname) { + // this.putCmd('^alter ^table %f ^rename ^to %i', obj, newname); + // } - renameColumn(column, newcol) { - this.putCmd('^alter ^table %f ^rename ^column %i ^to %i', column, column.columnName, newcol); - } + // renameColumn(column, newcol) { + // this.putCmd('^alter ^table %f ^rename ^column %i ^to %i', column, column.columnName, newcol); + // } - dropTable(obj, options = {}) { - this.put('^drop ^table'); - if (options.testIfExists) this.put(' ^if ^exists'); - this.put(' %f', obj); - this.endCommand(); - } + // dropTable(obj, options = {}) { + // this.put('^drop ^table'); + // if (options.testIfExists) this.put(' ^if ^exists'); + // this.put(' %f', obj); + // this.endCommand(); + // } - //public override void CreateIndex(IndexInfo ix) - //{ - //} + // //public override void CreateIndex(IndexInfo ix) + // //{ + // //} - enableConstraints(table, enabled) { - this.putCmd('^alter ^table %f %k ^trigger ^all', table, enabled ? 'enable' : 'disable'); - } + // enableConstraints(table, enabled) { + // this.putCmd('^alter ^table %f %k ^trigger ^all', table, enabled ? 'enable' : 'disable'); + // } - columnDefinition(col, options) { - if (col.autoIncrement) { - this.put('^serial'); - return; - } - super.columnDefinition(col, options); - } + // columnDefinition(col, options) { + // if (col.autoIncrement) { + // this.put('^serial'); + // return; + // } + // super.columnDefinition(col, options); + // } - changeColumn(oldcol, newcol, constraints) { - if (oldcol.columnName != newcol.columnName) { - this.putCmd('^alter ^table %f ^rename ^column %i ^to %i', oldcol, oldcol.columnName, newcol.columnName); - } - if (!testEqualTypes(oldcol, newcol)) { - this.putCmd('^alter ^table %f ^alter ^column %i ^type %s', oldcol, newcol.columnName, newcol.dataType); - } - if (oldcol.notNull != newcol.notNull) { - if (newcol.notNull) this.putCmd('^alter ^table %f ^alter ^column %i ^set ^not ^null', newcol, newcol.columnName); - else this.putCmd('^alter ^table %f ^alter ^column %i ^drop ^not ^null', newcol, newcol.columnName); - } - if (oldcol.defaultValue != newcol.defaultValue) { - if (newcol.defaultValue == null) { - this.putCmd('^alter ^table %f ^alter ^column %i ^drop ^default', newcol, newcol.columnName); - } else { - this.putCmd( - '^alter ^table %f ^alter ^column %i ^set ^default %s', - newcol, - newcol.columnName, - newcol.defaultValue - ); - } - } - } + // changeColumn(oldcol, newcol, constraints) { + // if (oldcol.columnName != newcol.columnName) { + // this.putCmd('^alter ^table %f ^rename ^column %i ^to %i', oldcol, oldcol.columnName, newcol.columnName); + // } + // if (!testEqualTypes(oldcol, newcol)) { + // this.putCmd('^alter ^table %f ^alter ^column %i ^type %s', oldcol, newcol.columnName, newcol.dataType); + // } + // if (oldcol.notNull != newcol.notNull) { + // if (newcol.notNull) this.putCmd('^alter ^table %f ^alter ^column %i ^set ^not ^null', newcol, newcol.columnName); + // else this.putCmd('^alter ^table %f ^alter ^column %i ^drop ^not ^null', newcol, newcol.columnName); + // } + // if (oldcol.defaultValue != newcol.defaultValue) { + // if (newcol.defaultValue == null) { + // this.putCmd('^alter ^table %f ^alter ^column %i ^drop ^default', newcol, newcol.columnName); + // } else { + // this.putCmd( + // '^alter ^table %f ^alter ^column %i ^set ^default %s', + // newcol, + // newcol.columnName, + // newcol.defaultValue + // ); + // } + // } + // } - putValue(value) { - if (value === true) this.putRaw('true'); - else if (value === false) this.putRaw('false'); - else super.putValue(value); - } + // putValue(value) { + // if (value === true) this.putRaw('true'); + // else if (value === false) this.putRaw('false'); + // else super.putValue(value); + // } - putByteArrayValue(value) { - this.putRaw(`e'\\\\x${arrayToHexString(value)}'`); - } + // putByteArrayValue(value) { + // this.putRaw(`e'\\\\x${arrayToHexString(value)}'`); + // } } module.exports = Dumper;