From 9017e951bba6fbece2db4de3600bb4e9d46e3922 Mon Sep 17 00:00:00 2001 From: lost__ask Date: Sat, 19 Mar 2022 11:07:32 +0800 Subject: [PATCH] =?UTF-8?q?IDbFirst=E6=8E=A5=E5=8F=A3=E6=B7=BB=E5=8A=A0Get?= =?UTF-8?q?TablesNameByDatabase=E6=96=B9=E6=B3=95,=E8=8E=B7=E5=8F=96?= =?UTF-8?q?=E6=8C=87=E5=AE=9A=E6=95=B0=E6=8D=AE=E5=BA=93=E6=89=80=E6=9C=89?= =?UTF-8?q?=E8=A1=A8=E5=90=8D.=20=E7=9B=AE=E5=89=8D=E5=B7=B2=E6=B5=8B?= =?UTF-8?q?=E8=AF=95mysql,sqlite,sql=20server=20=E7=94=B1=E4=BA=8E?= =?UTF-8?q?=E6=B2=A1=E6=9C=89=20FW=20=E6=B2=A1=E6=9C=89.net=204.0=20?= =?UTF-8?q?=E7=AD=89=E7=AD=89=20=20=E9=A1=B9=E7=9B=AE=E7=9B=AE=E6=A0=87?= =?UTF-8?q?=E6=A1=86=E6=9E=B6:=E6=9B=B4=E6=94=B9=E4=BA=86.=20=E5=90=8E?= =?UTF-8?q?=E7=BB=AD=E8=AF=B7=E4=BF=AE=E6=AD=A3=EF=BC=8C=E8=B0=A2=E8=B0=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Examples/orm_vs_net40/app.config | 3 ++ Examples/orm_vs_net40/orm_vs_net40.csproj | 6 ++- .../FreeSql.Extensions.BaseEntity.csproj | 2 +- .../FreeSql.Extensions.JsonMap.csproj | 2 +- .../FreeSql.Extensions.LazyLoading.csproj | 2 +- .../FreeSql.Extensions.Linq.csproj | 2 +- FreeSql.All/FreeSql.All.csproj | 2 +- FreeSql.DbContext/FreeSql.DbContext.csproj | 2 +- FreeSql.Repository/FreeSql.Repository.csproj | 2 +- FreeSql/FreeSql.csproj | 2 +- FreeSql/FreeSql.xml | 7 +++ FreeSql/Interface/IDbFirst.cs | 7 ++- .../FreeSql.Provider.Custom.csproj | 2 +- .../FreeSql.Provider.Dameng/DamengDbFirst.cs | 28 ++++++++++++ .../FreeSql.Provider.Dameng.csproj | 2 +- .../FirebirdDbFirst.cs | 11 +++++ .../FreeSql.Provider.Firebird.csproj | 2 +- .../FreeSql.Provider.KingbaseES.csproj | 2 +- .../KingbaseESDbFirst.cs | 37 ++++++++++++++++ .../FreeSql.Provider.MsAccess.csproj | 2 +- .../FreeSql.Provider.MySql.csproj | 2 +- .../FreeSql.Provider.MySql/MySqlDbFirst.cs | 23 ++++++++++ .../FreeSql.Provider.MySqlConnector.csproj | 2 +- .../Dameng/OdbcDamengDbFirst.cs | 28 ++++++++++++ .../FreeSql.Provider.Odbc.csproj | 2 +- .../KingbaseES/OdbcKingbaseESDbFirst.cs | 37 ++++++++++++++++ .../MySql/OdbcMySqlDbFirst.cs | 23 ++++++++++ .../Oracle/OdbcOracleDbFirst.cs | 29 +++++++++++++ .../PostgreSQL/OdbcPostgreSQLDbFirst.cs | 42 ++++++++++++++++++ .../SqlServer/OdbcSqlServerDbFirst.cs | 42 ++++++++++++++++++ .../FreeSql.Provider.Oracle.csproj | 2 +- .../FreeSql.Provider.Oracle/OracleDbFirst.cs | 30 +++++++++++++ .../FreeSql.Provider.PostgreSQL.csproj | 2 +- .../PostgreSQLDbFirst.cs | 42 ++++++++++++++++++ .../FreeSql.Provider.ShenTong.csproj | 2 +- .../ShenTongDbFirst.cs | 40 +++++++++++++++++ .../FreeSql.Provider.SqlServer.csproj | 2 +- .../SqlServerDbFirst.cs | 43 +++++++++++++++++++ ...FreeSql.Provider.SqlServerForSystem.csproj | 2 +- .../FreeSql.Provider.Sqlite.csproj | 2 +- .../FreeSql.Provider.Sqlite/SqliteDbFirst.cs | 20 +++++++++ 41 files changed, 518 insertions(+), 24 deletions(-) create mode 100644 Examples/orm_vs_net40/app.config diff --git a/Examples/orm_vs_net40/app.config b/Examples/orm_vs_net40/app.config new file mode 100644 index 000000000..3e0e37cfc --- /dev/null +++ b/Examples/orm_vs_net40/app.config @@ -0,0 +1,3 @@ + + + diff --git a/Examples/orm_vs_net40/orm_vs_net40.csproj b/Examples/orm_vs_net40/orm_vs_net40.csproj index b26d26267..25b379ca1 100644 --- a/Examples/orm_vs_net40/orm_vs_net40.csproj +++ b/Examples/orm_vs_net40/orm_vs_net40.csproj @@ -8,9 +8,10 @@ Exe orm_vs_net40 orm_vs_net40 - v4.0 + v4.8 512 true + AnyCPU @@ -21,6 +22,7 @@ DEBUG;TRACE prompt 4 + false AnyCPU @@ -30,6 +32,7 @@ TRACE prompt 4 + false @@ -70,6 +73,7 @@ .editorconfig + \ No newline at end of file diff --git a/Extensions/FreeSql.Extensions.BaseEntity/FreeSql.Extensions.BaseEntity.csproj b/Extensions/FreeSql.Extensions.BaseEntity/FreeSql.Extensions.BaseEntity.csproj index 5a3010885..f68be27b7 100644 --- a/Extensions/FreeSql.Extensions.BaseEntity/FreeSql.Extensions.BaseEntity.csproj +++ b/Extensions/FreeSql.Extensions.BaseEntity/FreeSql.Extensions.BaseEntity.csproj @@ -1,7 +1,7 @@  - netstandard2.0;net45;net40 + netstandard2.0 2.6.100 true FreeSql;ncc;YeXiangQin diff --git a/Extensions/FreeSql.Extensions.JsonMap/FreeSql.Extensions.JsonMap.csproj b/Extensions/FreeSql.Extensions.JsonMap/FreeSql.Extensions.JsonMap.csproj index 8eb3c10a4..f9258453b 100644 --- a/Extensions/FreeSql.Extensions.JsonMap/FreeSql.Extensions.JsonMap.csproj +++ b/Extensions/FreeSql.Extensions.JsonMap/FreeSql.Extensions.JsonMap.csproj @@ -1,7 +1,7 @@  - netstandard2.0;net45;net40 + netstandard2.0; 2.6.100 true FreeSql;ncc;YeXiangQin diff --git a/Extensions/FreeSql.Extensions.LazyLoading/FreeSql.Extensions.LazyLoading.csproj b/Extensions/FreeSql.Extensions.LazyLoading/FreeSql.Extensions.LazyLoading.csproj index 2fae56b7e..414dc8be7 100644 --- a/Extensions/FreeSql.Extensions.LazyLoading/FreeSql.Extensions.LazyLoading.csproj +++ b/Extensions/FreeSql.Extensions.LazyLoading/FreeSql.Extensions.LazyLoading.csproj @@ -1,7 +1,7 @@  - netstandard2.0;netstandard2.1;net45;net40 + netstandard2.0;netstandard2.1 2.6.100 true FreeSql;ncc;YeXiangQin diff --git a/Extensions/FreeSql.Extensions.Linq/FreeSql.Extensions.Linq.csproj b/Extensions/FreeSql.Extensions.Linq/FreeSql.Extensions.Linq.csproj index f91ba2879..854542a8a 100644 --- a/Extensions/FreeSql.Extensions.Linq/FreeSql.Extensions.Linq.csproj +++ b/Extensions/FreeSql.Extensions.Linq/FreeSql.Extensions.Linq.csproj @@ -1,7 +1,7 @@  - netstandard2.0;net45;net40 + netstandard2.0 2.6.100 true FreeSql;ncc;YeXiangQin diff --git a/FreeSql.All/FreeSql.All.csproj b/FreeSql.All/FreeSql.All.csproj index 0e0b1e379..5dfd63d8c 100644 --- a/FreeSql.All/FreeSql.All.csproj +++ b/FreeSql.All/FreeSql.All.csproj @@ -1,7 +1,7 @@  - netstandard2.0;net45;net40 + netstandard2.0 2.6.100 true FreeSql;ncc;YeXiangQin diff --git a/FreeSql.DbContext/FreeSql.DbContext.csproj b/FreeSql.DbContext/FreeSql.DbContext.csproj index 13b16a691..2c0a60c8f 100644 --- a/FreeSql.DbContext/FreeSql.DbContext.csproj +++ b/FreeSql.DbContext/FreeSql.DbContext.csproj @@ -1,7 +1,7 @@  - netstandard2.0;net50;netcoreapp31;netcoreapp21;net45;net40 + netstandard2.0;net50;netcoreapp31;netcoreapp21 2.6.100 true FreeSql;ncc;YeXiangQin diff --git a/FreeSql.Repository/FreeSql.Repository.csproj b/FreeSql.Repository/FreeSql.Repository.csproj index c3d7db920..502435a50 100644 --- a/FreeSql.Repository/FreeSql.Repository.csproj +++ b/FreeSql.Repository/FreeSql.Repository.csproj @@ -1,7 +1,7 @@  - netstandard2.0;net50;netcoreapp31;netcoreapp21;net45;net40 + netstandard2.0;net50;netcoreapp31;netcoreapp21 2.6.100 FreeSql;ncc;YeXiangQin FreeSql Implementation of General Repository, Support MySql/SqlServer/PostgreSQL/Oracle/Sqlite/Firebird/达梦/人大金仓/神舟通用/翰高/Access, and read/write separation、and split table. diff --git a/FreeSql/FreeSql.csproj b/FreeSql/FreeSql.csproj index 40d582648..bb0227014 100644 --- a/FreeSql/FreeSql.csproj +++ b/FreeSql/FreeSql.csproj @@ -1,7 +1,7 @@  - netstandard2.0;net45;net40 + netstandard2.0 2.6.100 true FreeSql;ncc;YeXiangQin diff --git a/FreeSql/FreeSql.xml b/FreeSql/FreeSql.xml index 9c849a521..c806d072b 100644 --- a/FreeSql/FreeSql.xml +++ b/FreeSql/FreeSql.xml @@ -3774,6 +3774,13 @@ + + + 获取指定数据库的表名 + + + + 获取指定单表信息,包括列详情、主键、唯一键、索引、备注 diff --git a/FreeSql/Interface/IDbFirst.cs b/FreeSql/Interface/IDbFirst.cs index de6144535..ade000143 100644 --- a/FreeSql/Interface/IDbFirst.cs +++ b/FreeSql/Interface/IDbFirst.cs @@ -18,7 +18,12 @@ public interface IDbFirst /// /// List GetTablesByDatabase(params string[] database); - + /// + /// 获取指定数据库的表名 + /// + /// + /// + List GetTablesNameByDatabase(params string[] database); /// /// 获取指定单表信息,包括列详情、主键、唯一键、索引、备注 /// diff --git a/Providers/FreeSql.Provider.Custom/FreeSql.Provider.Custom.csproj b/Providers/FreeSql.Provider.Custom/FreeSql.Provider.Custom.csproj index aa0935a06..7cd81534e 100644 --- a/Providers/FreeSql.Provider.Custom/FreeSql.Provider.Custom.csproj +++ b/Providers/FreeSql.Provider.Custom/FreeSql.Provider.Custom.csproj @@ -1,7 +1,7 @@  - netstandard2.0;net45;net40 + netstandard2.0; 2.6.100 true FreeSql;ncc;YeXiangQin diff --git a/Providers/FreeSql.Provider.Dameng/DamengDbFirst.cs b/Providers/FreeSql.Provider.Dameng/DamengDbFirst.cs index 613dbda5c..5ff858c38 100644 --- a/Providers/FreeSql.Provider.Dameng/DamengDbFirst.cs +++ b/Providers/FreeSql.Provider.Dameng/DamengDbFirst.cs @@ -603,6 +603,34 @@ all_cons_columns d --主键表 return loc1; } + public List GetTablesNameByDatabase(params string[] database) + { + if (database == null || database.Any() == false) + { + var userUsers = _orm.Ado.ExecuteScalar(" select username from user_users")?.ToString(); + if (string.IsNullOrEmpty(userUsers)) return new List(); + database = new[] { userUsers }; + } + + var databaseIn = string.Join(",", database.Select(a => _commonUtils.FormatSql("{0}", a))); + + var sql = $@" +select +a.table_name +from all_tables a +where lower(a.owner) in ({databaseIn}) + +UNION ALL + +select +a.view_name +from all_views a +where lower(a.owner) in ({databaseIn})"; + var ds = _orm.Ado.ExecuteArray(CommandType.Text, sql); + if (ds == null) return new List(); + return ds.Select(x => x[0] as string).ToList(); + + } public List GetEnumsByDatabase(params string[] database) { return new List(); diff --git a/Providers/FreeSql.Provider.Dameng/FreeSql.Provider.Dameng.csproj b/Providers/FreeSql.Provider.Dameng/FreeSql.Provider.Dameng.csproj index d9c0ef8e0..ea53fe9e6 100644 --- a/Providers/FreeSql.Provider.Dameng/FreeSql.Provider.Dameng.csproj +++ b/Providers/FreeSql.Provider.Dameng/FreeSql.Provider.Dameng.csproj @@ -1,7 +1,7 @@  - netstandard2.0;net45;net40 + netstandard2.0 2.6.100 true FreeSql;ncc;YeXiangQin diff --git a/Providers/FreeSql.Provider.Firebird/FirebirdDbFirst.cs b/Providers/FreeSql.Provider.Firebird/FirebirdDbFirst.cs index fa7fb0f0d..e77e12d25 100644 --- a/Providers/FreeSql.Provider.Firebird/FirebirdDbFirst.cs +++ b/Providers/FreeSql.Provider.Firebird/FirebirdDbFirst.cs @@ -383,6 +383,17 @@ from rdb$indices d return loc1; } + public List GetTablesNameByDatabase(params string[] database) + { + var sql = @" + select + trim(rdb$relation_name) as name + from rdb$relations + where rdb$system_flag=0;"; + var ds = _orm.Ado.ExecuteArray(CommandType.Text, sql); + if (ds == null) return new List(); + return ds.Select(z => z[0] as string).ToList(); + } public List GetEnumsByDatabase(params string[] database) { return new List(); diff --git a/Providers/FreeSql.Provider.Firebird/FreeSql.Provider.Firebird.csproj b/Providers/FreeSql.Provider.Firebird/FreeSql.Provider.Firebird.csproj index b06fb41f9..37abfd024 100644 --- a/Providers/FreeSql.Provider.Firebird/FreeSql.Provider.Firebird.csproj +++ b/Providers/FreeSql.Provider.Firebird/FreeSql.Provider.Firebird.csproj @@ -1,7 +1,7 @@  - netstandard2.0;net452 + netstandard2.0 2.6.100 true FreeSql;ncc;YeXiangQin diff --git a/Providers/FreeSql.Provider.KingbaseES/FreeSql.Provider.KingbaseES.csproj b/Providers/FreeSql.Provider.KingbaseES/FreeSql.Provider.KingbaseES.csproj index 11c8e10e4..4e06f3949 100644 --- a/Providers/FreeSql.Provider.KingbaseES/FreeSql.Provider.KingbaseES.csproj +++ b/Providers/FreeSql.Provider.KingbaseES/FreeSql.Provider.KingbaseES.csproj @@ -1,7 +1,7 @@  - netstandard2.0;net461 + netstandard2.0 2.6.100 true FreeSql;ncc;YeXiangQin diff --git a/Providers/FreeSql.Provider.KingbaseES/KingbaseESDbFirst.cs b/Providers/FreeSql.Provider.KingbaseES/KingbaseESDbFirst.cs index bf079acda..c28b464b5 100644 --- a/Providers/FreeSql.Provider.KingbaseES/KingbaseESDbFirst.cs +++ b/Providers/FreeSql.Provider.KingbaseES/KingbaseESDbFirst.cs @@ -493,6 +493,43 @@ from sys_constraint a return tables; } + public List GetTablesNameByDatabase(params string[] database) + { + var olddatabase = ""; + using (var conn = _orm.Ado.MasterPool.Get(TimeSpan.FromSeconds(5))) + { + olddatabase = conn.Value.Database; + } + string[] dbs = database == null || database.Any() == false ? new[] { olddatabase } : database; + + var result = new List(); + foreach (var db in dbs) + { + if (string.IsNullOrEmpty(db) || string.Compare(db, olddatabase, true) != 0) continue; + + var sql = $@"select +a.tablename +from sys_tables a +where +a.schemaname not in ('SYS_CATALOG', 'INFORMATION_SCHEMA', 'TOPOLOGY', 'SYSAUDIT', 'SYSLOGICAL', 'SYS_TEMP_1', 'SYS_TOAST', 'SYS_TOAST_TEMP_1', 'XLOG_RECORD_READ') +and +a.tablename not in ('PUBLIC.SPATIAL_REF_SYS') + +union all + +select +a.relname +from sys_class a +where a.relkind in ('m','v') +and +a.relname not in ('PUBLIC.GEOGRAPHY_COLUMNS','PUBLIC.GEOMETRY_COLUMNS','PUBLIC.RASTER_COLUMNS','PUBLIC.RASTER_OVERVIEWS') +;"; + var ds = _orm.Ado.ExecuteArray(CommandType.Text, sql); + if (ds == null) return result; + result.AddRange(ds.Select(z => z[0] as string)); + } + return result; + } public class GetEnumsByDatabaseQueryInfo { public string name { get; set; } diff --git a/Providers/FreeSql.Provider.MsAccess/FreeSql.Provider.MsAccess.csproj b/Providers/FreeSql.Provider.MsAccess/FreeSql.Provider.MsAccess.csproj index 9bbaca5fc..aa07b2e25 100644 --- a/Providers/FreeSql.Provider.MsAccess/FreeSql.Provider.MsAccess.csproj +++ b/Providers/FreeSql.Provider.MsAccess/FreeSql.Provider.MsAccess.csproj @@ -1,7 +1,7 @@  - netstandard2.0;net45;net40 + netstandard2.0 2.6.100 true FreeSql;ncc;YeXiangQin diff --git a/Providers/FreeSql.Provider.MySql/FreeSql.Provider.MySql.csproj b/Providers/FreeSql.Provider.MySql/FreeSql.Provider.MySql.csproj index a234483ec..74fdd31da 100644 --- a/Providers/FreeSql.Provider.MySql/FreeSql.Provider.MySql.csproj +++ b/Providers/FreeSql.Provider.MySql/FreeSql.Provider.MySql.csproj @@ -1,7 +1,7 @@  - netstandard2.0;net452;net451;net45;net40 + netstandard2.0 2.6.100 true FreeSql;ncc;YeXiangQin diff --git a/Providers/FreeSql.Provider.MySql/MySqlDbFirst.cs b/Providers/FreeSql.Provider.MySql/MySqlDbFirst.cs index 2591ac388..7e8e7045d 100644 --- a/Providers/FreeSql.Provider.MySql/MySqlDbFirst.cs +++ b/Providers/FreeSql.Provider.MySql/MySqlDbFirst.cs @@ -480,6 +480,29 @@ from information_schema.key_column_usage a return loc1; } + public List GetTablesNameByDatabase(params string[] database) + { + if (database == null || database.Any() == false) + { + using (var conn = _orm.Ado.MasterPool.Get()) + { + if (string.IsNullOrEmpty(conn.Value.Database)) return new List(); + database = new[] { conn.Value.Database }; + } + } + + var databaseIn = string.Join(",", database.Select(a => _commonUtils.FormatSql("{0}", a))); + var sql = $@" +select +a.table_name 'table' +from information_schema.tables a +where lower(a.table_schema) in ({databaseIn})"; + var ds = _orm.Ado.ExecuteArray(CommandType.Text, sql); + var result = new List(); + if (ds == null) return result; + result.AddRange(ds.Select(z => z[0] as string)); + return result; + } public List GetEnumsByDatabase(params string[] database) { return new List(); diff --git a/Providers/FreeSql.Provider.MySqlConnector/FreeSql.Provider.MySqlConnector.csproj b/Providers/FreeSql.Provider.MySqlConnector/FreeSql.Provider.MySqlConnector.csproj index 1eecd068c..1f39299b9 100644 --- a/Providers/FreeSql.Provider.MySqlConnector/FreeSql.Provider.MySqlConnector.csproj +++ b/Providers/FreeSql.Provider.MySqlConnector/FreeSql.Provider.MySqlConnector.csproj @@ -1,7 +1,7 @@  - netstandard2.0;net50;net45;netstandard2.1;netcoreapp2.1;netcoreapp3.1; + netstandard2.0;net50;netstandard2.1;netcoreapp2.1;netcoreapp3.1; 2.6.100 true FreeSql;ncc;YeXiangQin diff --git a/Providers/FreeSql.Provider.Odbc/Dameng/OdbcDamengDbFirst.cs b/Providers/FreeSql.Provider.Odbc/Dameng/OdbcDamengDbFirst.cs index 844a5b0ad..85976cad2 100644 --- a/Providers/FreeSql.Provider.Odbc/Dameng/OdbcDamengDbFirst.cs +++ b/Providers/FreeSql.Provider.Odbc/Dameng/OdbcDamengDbFirst.cs @@ -235,6 +235,34 @@ public bool ExistsTable(string name, bool ignoreCase) public DbTableInfo GetTableByName(string name, bool ignoreCase = true) => GetTables(null, name, ignoreCase)?.FirstOrDefault(); public List GetTablesByDatabase(params string[] database) => GetTables(database, null, false); + public List GetTablesNameByDatabase(params string[] database) + { + if (database == null || database.Any() == false) + { + var userUsers = _orm.Ado.ExecuteScalar(" select username from user_users")?.ToString(); + if (string.IsNullOrEmpty(userUsers)) return new List(); + database = new[] { userUsers }; + } + + var databaseIn = string.Join(",", database.Select(a => _commonUtils.FormatSql("{0}", a))); + + var sql = $@" +select +a.table_name +from all_tables a +where lower(a.owner) in ({databaseIn}) + +UNION ALL + +select +a.view_name +from all_views a +where lower(a.owner) in ({databaseIn})"; + var ds = _orm.Ado.ExecuteArray(CommandType.Text, sql); + if (ds == null) return new List(); + return ds.Select(x => x[0] as string).ToList(); + + } public List GetTables(string[] database, string tablename, bool ignoreCase) { var loc1 = new List(); diff --git a/Providers/FreeSql.Provider.Odbc/FreeSql.Provider.Odbc.csproj b/Providers/FreeSql.Provider.Odbc/FreeSql.Provider.Odbc.csproj index 57823b20b..6fe18c684 100644 --- a/Providers/FreeSql.Provider.Odbc/FreeSql.Provider.Odbc.csproj +++ b/Providers/FreeSql.Provider.Odbc/FreeSql.Provider.Odbc.csproj @@ -1,7 +1,7 @@  - netstandard2.0;net45;net40 + netstandard2.0; 2.6.100 true FreeSql;ncc;YeXiangQin diff --git a/Providers/FreeSql.Provider.Odbc/KingbaseES/OdbcKingbaseESDbFirst.cs b/Providers/FreeSql.Provider.Odbc/KingbaseES/OdbcKingbaseESDbFirst.cs index 006d7f34e..2697930be 100644 --- a/Providers/FreeSql.Provider.Odbc/KingbaseES/OdbcKingbaseESDbFirst.cs +++ b/Providers/FreeSql.Provider.Odbc/KingbaseES/OdbcKingbaseESDbFirst.cs @@ -494,6 +494,43 @@ from sys_constraint a return tables; } + public List GetTablesNameByDatabase(params string[] database) + { + var olddatabase = ""; + using (var conn = _orm.Ado.MasterPool.Get(TimeSpan.FromSeconds(5))) + { + olddatabase = conn.Value.Database; + } + string[] dbs = database == null || database.Any() == false ? new[] { olddatabase } : database; + + var result = new List(); + foreach (var db in dbs) + { + if (string.IsNullOrEmpty(db) || string.Compare(db, olddatabase, true) != 0) continue; + + var sql = $@"select +a.tablename +from sys_tables a +where +a.schemaname not in ('SYS_CATALOG', 'INFORMATION_SCHEMA', 'TOPOLOGY', 'SYSAUDIT', 'SYSLOGICAL', 'SYS_TEMP_1', 'SYS_TOAST', 'SYS_TOAST_TEMP_1', 'XLOG_RECORD_READ') +and +a.tablename not in ('PUBLIC.SPATIAL_REF_SYS') + +union all + +select +a.relname +from sys_class a +where a.relkind in ('m','v') +and +a.relname not in ('PUBLIC.GEOGRAPHY_COLUMNS','PUBLIC.GEOMETRY_COLUMNS','PUBLIC.RASTER_COLUMNS','PUBLIC.RASTER_OVERVIEWS') +;"; + var ds = _orm.Ado.ExecuteArray(CommandType.Text, sql); + if (ds == null) return result; + result.AddRange(ds.Select(z => z[0] as string)); + } + return result; + } public class GetEnumsByDatabaseQueryInfo { public string name { get; set; } diff --git a/Providers/FreeSql.Provider.Odbc/MySql/OdbcMySqlDbFirst.cs b/Providers/FreeSql.Provider.Odbc/MySql/OdbcMySqlDbFirst.cs index e3996d910..d96d3ab98 100644 --- a/Providers/FreeSql.Provider.Odbc/MySql/OdbcMySqlDbFirst.cs +++ b/Providers/FreeSql.Provider.Odbc/MySql/OdbcMySqlDbFirst.cs @@ -446,6 +446,29 @@ from information_schema.key_column_usage a return loc1; } + public List GetTablesNameByDatabase(params string[] database) + { + if (database == null || database.Any() == false) + { + using (var conn = _orm.Ado.MasterPool.Get()) + { + if (string.IsNullOrEmpty(conn.Value.Database)) return new List(); + database = new[] { conn.Value.Database }; + } + } + + var databaseIn = string.Join(",", database.Select(a => _commonUtils.FormatSql("{0}", a))); + var sql = $@" +select +a.table_name 'table' +from information_schema.tables a +where lower(a.table_schema) in ({databaseIn})"; + var ds = _orm.Ado.ExecuteArray(CommandType.Text, sql); + var result = new List(); + if (ds == null) return result; + result.AddRange(ds.Select(z => z[0] as string)); + return result; + } public List GetEnumsByDatabase(params string[] database) { return new List(); diff --git a/Providers/FreeSql.Provider.Odbc/Oracle/OdbcOracleDbFirst.cs b/Providers/FreeSql.Provider.Odbc/Oracle/OdbcOracleDbFirst.cs index c77317cf9..72bc55f75 100644 --- a/Providers/FreeSql.Provider.Odbc/Oracle/OdbcOracleDbFirst.cs +++ b/Providers/FreeSql.Provider.Odbc/Oracle/OdbcOracleDbFirst.cs @@ -576,7 +576,36 @@ all_cons_columns d --主键表 loc3.Clear(); return loc1; } + public List GetTablesNameByDatabase(params string[] database) + { + if (database == null || database.Any() == false) + { + var userUsers = _orm.Ado.ExecuteScalar(" select username from user_users")?.ToString(); + if (string.IsNullOrEmpty(userUsers)) return new List(); + database = new[] { userUsers }; + } + + var databaseIn = string.Join(",", database.Select(a => _commonUtils.FormatSql("{0}", a))); + var result = new List(); + var sql = $@" +select +a.table_name +from all_tables a + +where lower(a.owner) in ({databaseIn}) +UNION ALL + +select +a.view_name +from all_views a +where lower(a.owner) in ({databaseIn}) +"; + var ds = _orm.Ado.ExecuteArray(CommandType.Text, sql); + if (ds == null) return result; + result.AddRange(ds.Select(z => z[0] as string)); + return result; + } public List GetEnumsByDatabase(params string[] database) { return new List(); diff --git a/Providers/FreeSql.Provider.Odbc/PostgreSQL/OdbcPostgreSQLDbFirst.cs b/Providers/FreeSql.Provider.Odbc/PostgreSQL/OdbcPostgreSQLDbFirst.cs index ef6fc7bfd..e285e37e6 100644 --- a/Providers/FreeSql.Provider.Odbc/PostgreSQL/OdbcPostgreSQLDbFirst.cs +++ b/Providers/FreeSql.Provider.Odbc/PostgreSQL/OdbcPostgreSQLDbFirst.cs @@ -509,6 +509,48 @@ from pg_constraint a return tables; } + public List GetTablesNameByDatabase(params string[] database) + { + var olddatabase = ""; + var is96 = true; + using (var conn = _orm.Ado.MasterPool.Get(TimeSpan.FromSeconds(5))) + { + olddatabase = conn.Value.Database; + is96 = PgVersionIs96(conn.Value.ServerVersion); + } + + string[] dbs = database == null || database.Any() == false ? new[] { olddatabase } : database; + + + var result = new List(); + foreach (var db in dbs) + { + if (string.IsNullOrEmpty(db) || string.Compare(db, olddatabase, true) != 0) continue; + var sql = $@"select +a.tablename +from pg_tables a +where +a.schemaname not in ('pg_catalog', 'information_schema', 'topology') +and +a.tablename not in ('public.spatial_ref_sys') + +union all + +select +a.relname +from pg_class a +where +a.relkind in ('m','v') +and +a.relname not in ('public.geography_columns','public.geometry_columns','public.raster_columns','public.raster_overviews') +"; + + var ds = _orm.Ado.ExecuteArray(CommandType.Text, sql); + if (ds == null) return result; + result.AddRange(ds.Select(z => z[0] as string)); + } + return result; + } public class GetEnumsByDatabaseQueryInfo { public string name { get; set; } diff --git a/Providers/FreeSql.Provider.Odbc/SqlServer/OdbcSqlServerDbFirst.cs b/Providers/FreeSql.Provider.Odbc/SqlServer/OdbcSqlServerDbFirst.cs index 7c95ad8ef..8c3e8797a 100644 --- a/Providers/FreeSql.Provider.Odbc/SqlServer/OdbcSqlServerDbFirst.cs +++ b/Providers/FreeSql.Provider.Odbc/SqlServer/OdbcSqlServerDbFirst.cs @@ -516,6 +516,48 @@ from sys.foreign_key_columns a return tables; } + public List GetTablesNameByDatabase(params string[] database) + { + var olddatabase = ""; + using (var conn = _orm.Ado.MasterPool.Get(TimeSpan.FromSeconds(5))) + { + olddatabase = conn.Value.Database; + } + + string[] dbs = database == null || database.Any() == false ? new[] { olddatabase } : database; + + var result = new List(); + foreach (var db in dbs) + { + if (string.IsNullOrEmpty(db)) continue; + var sql = $@"use [{db}]; +select * from ( +select +a.name 'name' +from sys.tables a +inner join sys.schemas b on b.schema_id = a.schema_id +where not(b.name = 'dbo' and a.name = 'sysdiagrams') +union all +select +a.name 'name' +from sys.views a +inner join sys.schemas b on b.schema_id = a.schema_id +union all +select +a.name 'name' +from sys.procedures a +inner join sys.schemas b on b.schema_id = a.schema_id +where a.type = 'P' and charindex('diagram', a.name) = 0 +) ft_dbf +order by [name] desc; +use [{olddatabase}]; +"; + var ds = _orm.Ado.ExecuteArray(CommandType.Text, sql); + if (ds == null) return result; + result.AddRange(ds.Select(z => z[0] as string)); + } + return result; + } public List GetEnumsByDatabase(params string[] database) { return new List(); diff --git a/Providers/FreeSql.Provider.Oracle/FreeSql.Provider.Oracle.csproj b/Providers/FreeSql.Provider.Oracle/FreeSql.Provider.Oracle.csproj index d2e753e38..d38883c12 100644 --- a/Providers/FreeSql.Provider.Oracle/FreeSql.Provider.Oracle.csproj +++ b/Providers/FreeSql.Provider.Oracle/FreeSql.Provider.Oracle.csproj @@ -1,7 +1,7 @@  - netstandard2.0;net50;net45;net40 + netstandard2.0;net50 2.6.100 true FreeSql;ncc;YeXiangQin diff --git a/Providers/FreeSql.Provider.Oracle/OracleDbFirst.cs b/Providers/FreeSql.Provider.Oracle/OracleDbFirst.cs index e44f30f49..98f660c0f 100644 --- a/Providers/FreeSql.Provider.Oracle/OracleDbFirst.cs +++ b/Providers/FreeSql.Provider.Oracle/OracleDbFirst.cs @@ -577,6 +577,36 @@ all_cons_columns d --主键表 return loc1; } + public List GetTablesNameByDatabase(params string[] database) + { + if (database == null || database.Any() == false) + { + var userUsers = _orm.Ado.ExecuteScalar(" select username from user_users")?.ToString(); + if (string.IsNullOrEmpty(userUsers)) return new List(); + database = new[] { userUsers }; + } + + var databaseIn = string.Join(",", database.Select(a => _commonUtils.FormatSql("{0}", a))); + var result = new List(); + var sql = $@" +select +a.table_name +from all_tables a + +where lower(a.owner) in ({databaseIn}) + +UNION ALL + +select +a.view_name +from all_views a +where lower(a.owner) in ({databaseIn}) +"; + var ds = _orm.Ado.ExecuteArray(CommandType.Text, sql); + if (ds == null) return result; + result.AddRange(ds.Select(z => z[0] as string)); + return result; + } public List GetEnumsByDatabase(params string[] database) { return new List(); diff --git a/Providers/FreeSql.Provider.PostgreSQL/FreeSql.Provider.PostgreSQL.csproj b/Providers/FreeSql.Provider.PostgreSQL/FreeSql.Provider.PostgreSQL.csproj index ca25c6831..2de549f82 100644 --- a/Providers/FreeSql.Provider.PostgreSQL/FreeSql.Provider.PostgreSQL.csproj +++ b/Providers/FreeSql.Provider.PostgreSQL/FreeSql.Provider.PostgreSQL.csproj @@ -1,7 +1,7 @@  - netstandard2.0;net461;net452;net451;net45 + netstandard2.0 2.6.100 true FreeSql;ncc;YeXiangQin diff --git a/Providers/FreeSql.Provider.PostgreSQL/PostgreSQLDbFirst.cs b/Providers/FreeSql.Provider.PostgreSQL/PostgreSQLDbFirst.cs index 96ebf9bb8..f36e22a8f 100644 --- a/Providers/FreeSql.Provider.PostgreSQL/PostgreSQLDbFirst.cs +++ b/Providers/FreeSql.Provider.PostgreSQL/PostgreSQLDbFirst.cs @@ -619,6 +619,48 @@ from pg_constraint a return tables; } + public List GetTablesNameByDatabase(params string[] database) + { + var olddatabase = ""; + var is96 = true; + using (var conn = _orm.Ado.MasterPool.Get(TimeSpan.FromSeconds(5))) + { + olddatabase = conn.Value.Database; + is96 = PgVersionIs96(conn.Value.ServerVersion); + } + + string[] dbs = database == null || database.Any() == false ? new[] { olddatabase } : database; + + + var result = new List(); + foreach (var db in dbs) + { + if (string.IsNullOrEmpty(db) || string.Compare(db, olddatabase, true) != 0) continue; + var sql = $@"select +a.tablename +from pg_tables a +where +a.schemaname not in ('pg_catalog', 'information_schema', 'topology') +and +a.tablename not in ('public.spatial_ref_sys') + +union all + +select +a.relname +from pg_class a +where +a.relkind in ('m','v') +and +a.relname not in ('public.geography_columns','public.geometry_columns','public.raster_columns','public.raster_overviews') +"; + + var ds = _orm.Ado.ExecuteArray(CommandType.Text, sql); + if (ds == null) return result; + result.AddRange(ds.Select(z => z[0] as string)); + } + return result; + } public List GetEnumsByDatabase(params string[] database) { if (database == null || database.Length == 0) return new List(); diff --git a/Providers/FreeSql.Provider.ShenTong/FreeSql.Provider.ShenTong.csproj b/Providers/FreeSql.Provider.ShenTong/FreeSql.Provider.ShenTong.csproj index 9dfbd3c8a..dad1d6376 100644 --- a/Providers/FreeSql.Provider.ShenTong/FreeSql.Provider.ShenTong.csproj +++ b/Providers/FreeSql.Provider.ShenTong/FreeSql.Provider.ShenTong.csproj @@ -1,7 +1,7 @@  - netstandard2.0;net45;net40 + netstandard2.0 2.6.100 true FreeSql;ncc;YeXiangQin diff --git a/Providers/FreeSql.Provider.ShenTong/ShenTongDbFirst.cs b/Providers/FreeSql.Provider.ShenTong/ShenTongDbFirst.cs index 0f9ce722b..feb16fdf9 100644 --- a/Providers/FreeSql.Provider.ShenTong/ShenTongDbFirst.cs +++ b/Providers/FreeSql.Provider.ShenTong/ShenTongDbFirst.cs @@ -504,6 +504,46 @@ from v_sys_foreign_keys a return tables; } + public List GetTablesNameByDatabase(params string[] database) + { + var olddatabase = ""; + using (var conn = _orm.Ado.MasterPool.Get(TimeSpan.FromSeconds(5))) + { + olddatabase = conn.Value.Database; + } + + string[] dbs = database == null || database.Any() == false ? new[] { olddatabase } : database; + + var result = new List(); + foreach (var db in dbs) + { + if (string.IsNullOrEmpty(db) || string.Compare(db, olddatabase, true) != 0) continue; + var sql = $@" +select +a.relname +from sys_class a + +where +a.relkind in ('r') +and +a.relname not in ('PUBLIC.SPATIAL_REF_SYS') + +union all + +select + +a.relname, +from sys_class a +where +a.relkind in ('m','v') +and a.relname not in ('PUBLIC.GEOGRAPHY_COLUMNS','PUBLIC.GEOMETRY_COLUMNS','PUBLIC.RASTER_COLUMNS','PUBLIC.RASTER_OVERVIEWS','PUBLIC.DBA_JOBS') +"; + var ds = _orm.Ado.ExecuteArray(CommandType.Text, sql); + if (ds == null) return result; + result.AddRange(ds.Select(z => z[0] as string)); + } + return result; + } public List GetEnumsByDatabase(params string[] database) => new List(); } } \ No newline at end of file diff --git a/Providers/FreeSql.Provider.SqlServer/FreeSql.Provider.SqlServer.csproj b/Providers/FreeSql.Provider.SqlServer/FreeSql.Provider.SqlServer.csproj index af9eb9775..b3bd3f531 100644 --- a/Providers/FreeSql.Provider.SqlServer/FreeSql.Provider.SqlServer.csproj +++ b/Providers/FreeSql.Provider.SqlServer/FreeSql.Provider.SqlServer.csproj @@ -1,7 +1,7 @@  - netstandard2.0;net50;net451;net45;net40 + netstandard2.0;net50 2.6.100 true FreeSql;ncc;YeXiangQin diff --git a/Providers/FreeSql.Provider.SqlServer/SqlServerDbFirst.cs b/Providers/FreeSql.Provider.SqlServer/SqlServerDbFirst.cs index 828214f40..011dff1d6 100644 --- a/Providers/FreeSql.Provider.SqlServer/SqlServerDbFirst.cs +++ b/Providers/FreeSql.Provider.SqlServer/SqlServerDbFirst.cs @@ -519,6 +519,49 @@ from sys.foreign_key_columns a return tables; } + + public List GetTablesNameByDatabase(params string[] database) + { + var olddatabase = ""; + using (var conn = _orm.Ado.MasterPool.Get(TimeSpan.FromSeconds(5))) + { + olddatabase = conn.Value.Database; + } + + string[] dbs = database == null || database.Any() == false ? new[] { olddatabase } : database; + + var result = new List(); + foreach (var db in dbs) + { + if (string.IsNullOrEmpty(db)) continue; + var sql = $@"use [{db}]; +select * from ( +select +a.name 'name' +from sys.tables a +inner join sys.schemas b on b.schema_id = a.schema_id +where not(b.name = 'dbo' and a.name = 'sysdiagrams') +union all +select +a.name 'name' +from sys.views a +inner join sys.schemas b on b.schema_id = a.schema_id +union all +select +a.name 'name' +from sys.procedures a +inner join sys.schemas b on b.schema_id = a.schema_id +where a.type = 'P' and charindex('diagram', a.name) = 0 +) ft_dbf +order by [name] desc; +use [{olddatabase}]; +"; + var ds = _orm.Ado.ExecuteArray(CommandType.Text, sql); + if (ds == null) return result; + result.AddRange(ds.Select(z => z[0] as string)); + } + return result; + } public List GetEnumsByDatabase(params string[] database) { return new List(); diff --git a/Providers/FreeSql.Provider.SqlServerForSystem/FreeSql.Provider.SqlServerForSystem.csproj b/Providers/FreeSql.Provider.SqlServerForSystem/FreeSql.Provider.SqlServerForSystem.csproj index 52e8df27a..0528a5038 100644 --- a/Providers/FreeSql.Provider.SqlServerForSystem/FreeSql.Provider.SqlServerForSystem.csproj +++ b/Providers/FreeSql.Provider.SqlServerForSystem/FreeSql.Provider.SqlServerForSystem.csproj @@ -1,7 +1,7 @@  - netstandard2.0;net50;net451;net45;net40 + netstandard2.0;net50 2.6.100 true FreeSql;ncc;YeXiangQin diff --git a/Providers/FreeSql.Provider.Sqlite/FreeSql.Provider.Sqlite.csproj b/Providers/FreeSql.Provider.Sqlite/FreeSql.Provider.Sqlite.csproj index dd7dc5eb0..44d0a2518 100644 --- a/Providers/FreeSql.Provider.Sqlite/FreeSql.Provider.Sqlite.csproj +++ b/Providers/FreeSql.Provider.Sqlite/FreeSql.Provider.Sqlite.csproj @@ -1,7 +1,7 @@  - netstandard2.0;net45;net40 + netstandard2.0 2.6.100 true FreeSql;ncc;YeXiangQin diff --git a/Providers/FreeSql.Provider.Sqlite/SqliteDbFirst.cs b/Providers/FreeSql.Provider.Sqlite/SqliteDbFirst.cs index 2faf42916..4b812c887 100644 --- a/Providers/FreeSql.Provider.Sqlite/SqliteDbFirst.cs +++ b/Providers/FreeSql.Provider.Sqlite/SqliteDbFirst.cs @@ -380,6 +380,26 @@ public List GetTables(string[] database, string tablename, bool ign return loc1; } + public List GetTablesNameByDatabase(params string[] database) + { + if (database == null || database.Any() == false) + database = GetDatabases().ToArray(); + if (database.Any() == false) return new List(); + var result = new List(); + foreach (var db in database) + { + var sql = $@" +select +tbl_name +from {db}.sqlite_master where type='table'"; + var ds = _orm.Ado.ExecuteArray(CommandType.Text, sql); + if (ds == null) continue; + result.AddRange(ds.Select(z => z[0] as string)); + } + return result; + } + + public List GetEnumsByDatabase(params string[] database) { return new List();