mirror of
https://github.com/DeNNiiInc/dbgate.git
synced 2026-04-17 23:45:59 +00:00
oracle - implemented scope identity
This commit is contained in:
@@ -183,17 +183,22 @@ describe('Query', () => {
|
||||
test.each(engines.filter(x => !x.skipDataDuplicator).map(engine => [engine.label, engine]))(
|
||||
'Select scope identity - %s',
|
||||
testWrapper(async (conn, driver, engine) => {
|
||||
const table = {
|
||||
pureName: 't1',
|
||||
columns: [
|
||||
{ columnName: 'id', dataType: 'int', notNull: true, autoIncrement: true },
|
||||
{ columnName: 'val', dataType: 'varchar(50)' },
|
||||
],
|
||||
primaryKey: {
|
||||
columns: [{ columnName: 'id' }],
|
||||
},
|
||||
};
|
||||
await runCommandOnDriver(conn, driver, dmp => dmp.createTable(table));
|
||||
await runCommandOnDriver(conn, driver, dmp =>
|
||||
dmp.createTable({
|
||||
pureName: 't1',
|
||||
columns: [
|
||||
{ columnName: 'id', dataType: 'int', notNull: true, autoIncrement: true },
|
||||
{ columnName: 'val', dataType: 'varchar(50)' },
|
||||
],
|
||||
primaryKey: {
|
||||
columns: [{ columnName: 'id' }],
|
||||
},
|
||||
})
|
||||
);
|
||||
|
||||
const structure = await driver.analyseFull(conn);
|
||||
const table = structure.tables.find(x => x.pureName == 't1');
|
||||
|
||||
let res;
|
||||
if (driver.dialect.requireStandaloneSelectForScopeIdentity) {
|
||||
await runCommandOnDriver(conn, driver, dmp => dmp.put("INSERT INTO ~t1 (~val) VALUES ('aaa')"));
|
||||
@@ -205,13 +210,8 @@ describe('Query', () => {
|
||||
});
|
||||
}
|
||||
const row = res.rows[0];
|
||||
// console.log('*******************');
|
||||
// console.log(JSON.stringify(res, null, 2));
|
||||
// console.log(JSON.stringify(row, null, 2));
|
||||
const keys = Object.keys(row);
|
||||
// console.log(JSON.stringify(row, null, 2));
|
||||
expect(keys.length).toEqual(1);
|
||||
// console.log(JSON.stringify(row[keys[0]], null, 2));
|
||||
expect(row[keys[0]] == 1).toBeTruthy();
|
||||
})
|
||||
);
|
||||
|
||||
@@ -142,6 +142,9 @@ class Analyser extends DatabaseAnalyser {
|
||||
..._.pick(col, ['columnName']),
|
||||
})),
|
||||
})),
|
||||
identitySequenceName: (columnsGrouped[columnGroup(table)] || [])
|
||||
.find(x => x?.default_value?.endsWith('.nextval'))
|
||||
?.default_value?.match(/\"([^"]+)\"\.nextval/)?.[1],
|
||||
};
|
||||
}),
|
||||
views: views.rows.map(view => ({
|
||||
|
||||
@@ -109,23 +109,13 @@ class Dumper extends SqlDumper {
|
||||
this.putCmd('^alter ^table %f ^modify (%i ^default ^null)', newcol, newcol.columnName);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 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
|
||||
// );
|
||||
// }
|
||||
// }
|
||||
selectScopeIdentity(table) {
|
||||
const sequence = table.identitySequenceName;
|
||||
if (sequence) {
|
||||
this.put('^select %i.CURRVAL FROM DUAL', sequence);
|
||||
}
|
||||
}
|
||||
|
||||
// putValue(value) {
|
||||
|
||||
@@ -22,6 +22,7 @@ const dialect = {
|
||||
},
|
||||
userDatabaseNamePrefix: 'C##',
|
||||
upperCaseAllDbObjectNames: true,
|
||||
requireStandaloneSelectForScopeIdentity: true,
|
||||
|
||||
createColumn: true,
|
||||
dropColumn: true,
|
||||
|
||||
Reference in New Issue
Block a user