oracle: fixed commit

This commit is contained in:
Jan Prochazka 2024-06-01 08:36:13 +02:00
parent 68a40e5da6
commit 0cc7a98391
2 changed files with 96 additions and 88 deletions

View File

@ -67,8 +67,11 @@ const drivers = driverBases.map(driverBase => ({
return pool.end(); return pool.end();
}, },
async query(client, sql) { async query(client, sql) {
//console.log('query sql', sql); if (sql.trim() == 'COMMIT;') {
if (sql == null) {a sql = 'COMMIT';
}
if (sql == null) {
return { return {
rows: [], rows: [],
columns: [], columns: [],

View File

@ -2,108 +2,113 @@ const { SqlDumper, arrayToHexString, testEqualTypes } = global.DBGATE_TOOLS;
class Dumper extends SqlDumper { class Dumper extends SqlDumper {
createDatabase(name) { createDatabase(name) {
this.putCmd(`CREATE USER c##${name} this.putCmd(
`CREATE USER c##${name}
IDENTIFIED BY ${name} IDENTIFIED BY ${name}
DEFAULT TABLESPACE users DEFAULT TABLESPACE users
TEMPORARY TABLESPACE temp TEMPORARY TABLESPACE temp
QUOTA 10M ON users;`, name); QUOTA 10M ON users;`,
name
);
} }
// oracle uses implicit transactions
beginTransaction() {}
/** @param type {import('dbgate-types').TransformType} */ // /** @param type {import('dbgate-types').TransformType} */
transform(type, dumpExpr) { // transform(type, dumpExpr) {
switch (type) { // switch (type) {
case 'GROUP:YEAR': // case 'GROUP:YEAR':
case 'YEAR': // case 'YEAR':
this.put('^extract(^year ^from %c)', dumpExpr); // this.put('^extract(^year ^from %c)', dumpExpr);
break; // break;
case 'MONTH': // case 'MONTH':
this.put('^extract(^month ^from %c)', dumpExpr); // this.put('^extract(^month ^from %c)', dumpExpr);
break; // break;
case 'DAY': // case 'DAY':
this.put('^extract(^day ^from %c)', dumpExpr); // this.put('^extract(^day ^from %c)', dumpExpr);
break; // break;
case 'GROUP:MONTH': // case 'GROUP:MONTH':
this.put("^to_char(%c, '%s')", dumpExpr, 'YYYY-MM'); // this.put("^to_char(%c, '%s')", dumpExpr, 'YYYY-MM');
break; // break;
case 'GROUP:DAY': // case 'GROUP:DAY':
this.put("^to_char(%c, '%s')", dumpExpr, 'YYYY-MM-DD'); // this.put("^to_char(%c, '%s')", dumpExpr, 'YYYY-MM-DD');
break; // break;
default: // default:
dumpExpr(); // dumpExpr();
break; // break;
} // }
} // }
dropRecreatedTempTable(tmptable) { // dropRecreatedTempTable(tmptable) {
this.putCmd('^drop ^table %i ^cascade', tmptable); // this.putCmd('^drop ^table %i ^cascade', tmptable);
} // }
renameTable(obj, newname) { // renameTable(obj, newname) {
this.putCmd('^alter ^table %f ^rename ^to %i', obj, newname); // this.putCmd('^alter ^table %f ^rename ^to %i', obj, newname);
} // }
renameColumn(column, newcol) { // renameColumn(column, newcol) {
this.putCmd('^alter ^table %f ^rename ^column %i ^to %i', column, column.columnName, newcol); // this.putCmd('^alter ^table %f ^rename ^column %i ^to %i', column, column.columnName, newcol);
} // }
dropTable(obj, options = {}) { // dropTable(obj, options = {}) {
this.put('^drop ^table'); // this.put('^drop ^table');
if (options.testIfExists) this.put(' ^if ^exists'); // if (options.testIfExists) this.put(' ^if ^exists');
this.put(' %f', obj); // this.put(' %f', obj);
this.endCommand(); // this.endCommand();
} // }
//public override void CreateIndex(IndexInfo ix) // //public override void CreateIndex(IndexInfo ix)
//{ // //{
//} // //}
enableConstraints(table, enabled) { // enableConstraints(table, enabled) {
this.putCmd('^alter ^table %f %k ^trigger ^all', table, enabled ? 'enable' : 'disable'); // this.putCmd('^alter ^table %f %k ^trigger ^all', table, enabled ? 'enable' : 'disable');
} // }
columnDefinition(col, options) { // columnDefinition(col, options) {
if (col.autoIncrement) { // if (col.autoIncrement) {
this.put('^serial'); // this.put('^serial');
return; // return;
} // }
super.columnDefinition(col, options); // super.columnDefinition(col, options);
} // }
changeColumn(oldcol, newcol, constraints) { // changeColumn(oldcol, newcol, constraints) {
if (oldcol.columnName != newcol.columnName) { // if (oldcol.columnName != newcol.columnName) {
this.putCmd('^alter ^table %f ^rename ^column %i ^to %i', oldcol, oldcol.columnName, newcol.columnName); // this.putCmd('^alter ^table %f ^rename ^column %i ^to %i', oldcol, oldcol.columnName, newcol.columnName);
} // }
if (!testEqualTypes(oldcol, newcol)) { // if (!testEqualTypes(oldcol, newcol)) {
this.putCmd('^alter ^table %f ^alter ^column %i ^type %s', oldcol, newcol.columnName, newcol.dataType); // this.putCmd('^alter ^table %f ^alter ^column %i ^type %s', oldcol, newcol.columnName, newcol.dataType);
} // }
if (oldcol.notNull != newcol.notNull) { // if (oldcol.notNull != newcol.notNull) {
if (newcol.notNull) this.putCmd('^alter ^table %f ^alter ^column %i ^set ^not ^null', newcol, newcol.columnName); // 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); // else this.putCmd('^alter ^table %f ^alter ^column %i ^drop ^not ^null', newcol, newcol.columnName);
} // }
if (oldcol.defaultValue != newcol.defaultValue) { // if (oldcol.defaultValue != newcol.defaultValue) {
if (newcol.defaultValue == null) { // if (newcol.defaultValue == null) {
this.putCmd('^alter ^table %f ^alter ^column %i ^drop ^default', newcol, newcol.columnName); // this.putCmd('^alter ^table %f ^alter ^column %i ^drop ^default', newcol, newcol.columnName);
} else { // } else {
this.putCmd( // this.putCmd(
'^alter ^table %f ^alter ^column %i ^set ^default %s', // '^alter ^table %f ^alter ^column %i ^set ^default %s',
newcol, // newcol,
newcol.columnName, // newcol.columnName,
newcol.defaultValue // newcol.defaultValue
); // );
} // }
} // }
} // }
putValue(value) { // putValue(value) {
if (value === true) this.putRaw('true'); // if (value === true) this.putRaw('true');
else if (value === false) this.putRaw('false'); // else if (value === false) this.putRaw('false');
else super.putValue(value); // else super.putValue(value);
} // }
putByteArrayValue(value) { // putByteArrayValue(value) {
this.putRaw(`e'\\\\x${arrayToHexString(value)}'`); // this.putRaw(`e'\\\\x${arrayToHexString(value)}'`);
} // }
} }
module.exports = Dumper; module.exports = Dumper;