Merge pull request #241 from 54ble/fix/#239

🥳 fix: Oracle分表判断是否存在及示例
This commit is contained in:
xuejmnet 2023-04-27 16:46:32 +08:00 committed by GitHub
commit 25d562e045
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 39 additions and 0 deletions

View File

@ -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<string> 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;
}

View File

@ -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<string> DoGetExistTables(DbConnection connection, string dataSourceName)
{
ISet<string> result = new HashSet<string>(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;
}
}
}