🥳 fix: Oracle分表判断是否存在及示例
This commit is contained in:
parent
04237772bf
commit
3bf980a759
|
@ -12,6 +12,7 @@ namespace ShardingCore.TableExists
|
||||||
private readonly SqliteTableEnsureManager _tem_sqlite;
|
private readonly SqliteTableEnsureManager _tem_sqlite;
|
||||||
private readonly PostgreSqlTableEnsureManager _tem_pgsql;
|
private readonly PostgreSqlTableEnsureManager _tem_pgsql;
|
||||||
private readonly SqlServerTableEnsureManager _tem_mssql;
|
private readonly SqlServerTableEnsureManager _tem_mssql;
|
||||||
|
private readonly OracleTableEnsureManager _tem_oracle;
|
||||||
|
|
||||||
public GuessTableEnsureManager(IRouteTailFactory routeTailFactory) : base(routeTailFactory)
|
public GuessTableEnsureManager(IRouteTailFactory routeTailFactory) : base(routeTailFactory)
|
||||||
{
|
{
|
||||||
|
@ -19,6 +20,7 @@ namespace ShardingCore.TableExists
|
||||||
_tem_sqlite = new SqliteTableEnsureManager(routeTailFactory);
|
_tem_sqlite = new SqliteTableEnsureManager(routeTailFactory);
|
||||||
_tem_pgsql = new PostgreSqlTableEnsureManager(routeTailFactory);
|
_tem_pgsql = new PostgreSqlTableEnsureManager(routeTailFactory);
|
||||||
_tem_mssql = new SqlServerTableEnsureManager(routeTailFactory);
|
_tem_mssql = new SqlServerTableEnsureManager(routeTailFactory);
|
||||||
|
_tem_oracle = new OracleTableEnsureManager(routeTailFactory);
|
||||||
}
|
}
|
||||||
|
|
||||||
public override ISet<string> DoGetExistTables(DbConnection connection, string dataSourceName)
|
public override ISet<string> DoGetExistTables(DbConnection connection, string dataSourceName)
|
||||||
|
@ -46,6 +48,10 @@ namespace ShardingCore.TableExists
|
||||||
result = _tem_mssql.DoGetExistTables(connection, dataSourceName);
|
result = _tem_mssql.DoGetExistTables(connection, dataSourceName);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case "Oracle.ManagedDataAccess.Client.OracleConnection":
|
||||||
|
result = _tem_oracle.DoGetExistTables(connection, dataSourceName);
|
||||||
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
|
@ -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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue