diff --git a/src/ShardingCore/TableExists/GuessTableEnsureManager.cs b/src/ShardingCore/TableExists/GuessTableEnsureManager.cs index a46a7540..83622c8e 100644 --- a/src/ShardingCore/TableExists/GuessTableEnsureManager.cs +++ b/src/ShardingCore/TableExists/GuessTableEnsureManager.cs @@ -12,6 +12,7 @@ namespace ShardingCore.TableExists private readonly SqliteTableEnsureManager _tem_sqlite; private readonly PostgreSqlTableEnsureManager _tem_pgsql; private readonly SqlServerTableEnsureManager _tem_mssql; + private readonly OracleTableEnsureManager _tem_oracle; public GuessTableEnsureManager(IRouteTailFactory routeTailFactory) : base(routeTailFactory) { @@ -19,6 +20,7 @@ namespace ShardingCore.TableExists _tem_sqlite = new SqliteTableEnsureManager(routeTailFactory); _tem_pgsql = new PostgreSqlTableEnsureManager(routeTailFactory); _tem_mssql = new SqlServerTableEnsureManager(routeTailFactory); + _tem_oracle = new OracleTableEnsureManager(routeTailFactory); } public override ISet DoGetExistTables(DbConnection connection, string dataSourceName) @@ -46,6 +48,10 @@ namespace ShardingCore.TableExists result = _tem_mssql.DoGetExistTables(connection, dataSourceName); break; + case "Oracle.ManagedDataAccess.Client.OracleConnection": + result = _tem_oracle.DoGetExistTables(connection, dataSourceName); + break; + default: break; } diff --git a/src/ShardingCore/TableExists/OracleTableEnsureManager.cs b/src/ShardingCore/TableExists/OracleTableEnsureManager.cs new file mode 100644 index 00000000..e3569394 --- /dev/null +++ b/src/ShardingCore/TableExists/OracleTableEnsureManager.cs @@ -0,0 +1,33 @@ +using ShardingCore.Core.VirtualRoutes.TableRoutes.RouteTails.Abstractions; +using ShardingCore.TableExists.Abstractions; +using System; +using System.Collections.Generic; +using System.Data; +using System.Data.Common; + +namespace ShardingCore.TableExists +{ + public class OracleTableEnsureManager : AbstractTableEnsureManager + { + private const string Tables = "Tables"; + private const string TABLE_NAME = "TABLE_NAME"; + + public OracleTableEnsureManager(IRouteTailFactory routeTailFactory) : base(routeTailFactory) + { + } + + public override ISet DoGetExistTables(DbConnection connection, string dataSourceName) + { + ISet result = new HashSet(StringComparer.OrdinalIgnoreCase); + using (DataTable dataTable = connection.GetSchema(Tables)) + { + for (int i = 0; i < dataTable.Rows.Count; i++) + { + string schema = dataTable.Rows[i][TABLE_NAME]?.ToString(); + result.Add(schema); + } + } + return result; + } + } +}