From 880b07a3289d78e5f3992377278a6cc842e6e77e Mon Sep 17 00:00:00 2001 From: "SPRINX0\\prochazka" Date: Thu, 5 Sep 2024 13:13:58 +0200 Subject: [PATCH] support range select for oracle <12 --- packages/datalib/src/GridDisplay.ts | 4 ++-- packages/tools/src/driverBase.ts | 1 + packages/types/dialect.d.ts | 1 + plugins/dbgate-plugin-mssql/src/frontend/driver.js | 1 + plugins/dbgate-plugin-oracle/src/backend/driver.js | 2 +- plugins/dbgate-plugin-oracle/src/frontend/driver.js | 12 ++++++++++++ 6 files changed, 18 insertions(+), 3 deletions(-) diff --git a/packages/datalib/src/GridDisplay.ts b/packages/datalib/src/GridDisplay.ts index 3a62d9bf..155397e9 100644 --- a/packages/datalib/src/GridDisplay.ts +++ b/packages/datalib/src/GridDisplay.ts @@ -625,7 +625,7 @@ export abstract class GridDisplay { columns: [ ...select.columns, { - alias: '_rowNumber', + alias: '_RowNumber', exprType: 'rowNumber', orderBy: select.orderBy ? select.orderBy.map(x => @@ -683,7 +683,7 @@ export abstract class GridDisplay { let select = this.createSelect(); if (!select) return null; if (this.dialect.rangeSelect) select.range = { offset: offset, limit: count }; - else if (this.dialect.rowNumberOverPaging && offset > 0) + else if (this.dialect.rowNumberOverPaging && (offset > 0 || !this.dialect.topRecords)) select = this.getRowNumberOverSelect(select, offset, count); else if (this.dialect.limitSelect) select.topRecords = count; return select; diff --git a/packages/tools/src/driverBase.ts b/packages/tools/src/driverBase.ts index 9f9ca069..307146c4 100644 --- a/packages/tools/src/driverBase.ts +++ b/packages/tools/src/driverBase.ts @@ -8,6 +8,7 @@ import { detectSqlFilterBehaviour } from './detectSqlFilterBehaviour'; const dialect = { limitSelect: true, rangeSelect: true, + topRecords: false, offsetFetchRangeSyntax: true, stringEscapeChar: "'", fallbackDataType: 'nvarchar(max)', diff --git a/packages/types/dialect.d.ts b/packages/types/dialect.d.ts index 0db6a110..ffff7f0c 100644 --- a/packages/types/dialect.d.ts +++ b/packages/types/dialect.d.ts @@ -3,6 +3,7 @@ export interface SqlDialect { limitSelect?: boolean; ilike?: boolean; rowNumberOverPaging?: boolean; + topRecords?: boolean; stringEscapeChar: string; offsetFetchRangeSyntax?: boolean; quoteIdentifier(s: string): string; diff --git a/plugins/dbgate-plugin-mssql/src/frontend/driver.js b/plugins/dbgate-plugin-mssql/src/frontend/driver.js index b61f9813..748ad1df 100644 --- a/plugins/dbgate-plugin-mssql/src/frontend/driver.js +++ b/plugins/dbgate-plugin-mssql/src/frontend/driver.js @@ -8,6 +8,7 @@ const spatialTypes = ['GEOGRAPHY']; const dialect = { limitSelect: true, rangeSelect: true, + topRecords: true, offsetFetchRangeSyntax: true, rowNumberOverPaging: true, defaultSchemaName: 'dbo', diff --git a/plugins/dbgate-plugin-oracle/src/backend/driver.js b/plugins/dbgate-plugin-oracle/src/backend/driver.js index 4b975b04..64c9078f 100644 --- a/plugins/dbgate-plugin-oracle/src/backend/driver.js +++ b/plugins/dbgate-plugin-oracle/src/backend/driver.js @@ -255,7 +255,7 @@ const driver = { // const { rows } = await this.query(client, 'SELECT version as "version" FROM v$instance'); const version = await this.getVersionCore(client); - const m = version.match(/(\d+[a-z])\s+(\w+).*(\d+)\.(\d+)/); + const m = version.match(/(\d+[a-z]+)\s+(\w+).*?(\d+)\.(\d+)/); //console.log('M', m); let versionText = null; let versionMajor = null; diff --git a/plugins/dbgate-plugin-oracle/src/frontend/driver.js b/plugins/dbgate-plugin-oracle/src/frontend/driver.js index cfe388c9..4150c310 100644 --- a/plugins/dbgate-plugin-oracle/src/frontend/driver.js +++ b/plugins/dbgate-plugin-oracle/src/frontend/driver.js @@ -9,6 +9,7 @@ const dialect = { rangeSelect: true, limitSelect: false, offsetFetchRangeSyntax: true, + rowNumberOverPaging: true, ilike: true, // stringEscapeChar: '\\', stringEscapeChar: "'", @@ -151,6 +152,17 @@ $$ LANGUAGE plpgsql;`, }, showConnectionTab: field => field == 'sshTunnel', + + dialectByVersion(version) { + if (version && version.versionMajor < 12) { + return { + ...dialect, + rangeSelect: false, + offsetFetchRangeSyntax: false, + }; + } + return dialect; + }, }; module.exports = oracleDriver;