mirror of
https://github.com/nsnail/FreeSql.git
synced 2025-04-22 10:42:52 +08:00
- 增加 IDbFirst.ExistsTable 方法判断表是否存在;
This commit is contained in:
parent
1ab1d16e53
commit
da6effcf52
@ -130,13 +130,6 @@
|
||||
清空状态数据
|
||||
</summary>
|
||||
</member>
|
||||
<member name="M:FreeSql.DbSet`1.RemoveAsync(System.Linq.Expressions.Expression{System.Func{`0,System.Boolean}})">
|
||||
<summary>
|
||||
根据 lambda 条件删除数据
|
||||
</summary>
|
||||
<param name="predicate"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:FreeSql.DbSet`1.Add(`0)">
|
||||
<summary>
|
||||
添加
|
||||
@ -527,14 +520,5 @@
|
||||
<param name="that"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:Microsoft.Extensions.DependencyInjection.FreeSqlRepositoryDependencyInjection.AddFreeRepository(Microsoft.Extensions.DependencyInjection.IServiceCollection,System.Action{FreeSql.FluentDataFilter},System.Reflection.Assembly[])">
|
||||
<summary>
|
||||
批量注入 Repository,可以参考代码自行调整
|
||||
</summary>
|
||||
<param name="services"></param>
|
||||
<param name="globalDataFilter"></param>
|
||||
<param name="assemblies"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
</members>
|
||||
</doc>
|
||||
|
@ -21,5 +21,32 @@ namespace FreeSql.Tests.MySqlConnector
|
||||
var t2 = g.mysql.DbFirst.GetTablesByDatabase(g.mysql.DbFirst.GetDatabases()[0]);
|
||||
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ExistsTable()
|
||||
{
|
||||
var fsql = g.mysql;
|
||||
Assert.False(fsql.DbFirst.ExistsTable("test_existstb01"));
|
||||
Assert.False(fsql.DbFirst.ExistsTable("cccddd_mysqlconnector.test_existstb01"));
|
||||
Assert.False(fsql.DbFirst.ExistsTable("test_existstb01", false));
|
||||
Assert.False(fsql.DbFirst.ExistsTable("cccddd_mysqlconnector.test_existstb01", false));
|
||||
fsql.CodeFirst.SyncStructure(typeof(test_existstb01));
|
||||
Assert.True(fsql.DbFirst.ExistsTable("test_existstb01"));
|
||||
Assert.True(fsql.DbFirst.ExistsTable("cccddd_mysqlconnector.test_existstb01"));
|
||||
Assert.True(fsql.DbFirst.ExistsTable("Test_existstb01", false));
|
||||
Assert.True(fsql.DbFirst.ExistsTable("cccddd_mysqlconnector.Test_existstb01", false));
|
||||
fsql.Ado.ExecuteNonQuery("drop table test_existstb01");
|
||||
|
||||
Assert.False(fsql.DbFirst.ExistsTable("cccddd_mysqlconnector.test_existstb01"));
|
||||
Assert.False(fsql.DbFirst.ExistsTable("cccddd_mysqlconnector.test_existstb01", false));
|
||||
fsql.CodeFirst.SyncStructure(typeof(test_existstb01), "cccddd_mysqlconnector.test_existstb01");
|
||||
Assert.True(fsql.DbFirst.ExistsTable("cccddd_mysqlconnector.test_existstb01"));
|
||||
Assert.True(fsql.DbFirst.ExistsTable("cccddd_mysqlconnector.Test_existstb01", false));
|
||||
fsql.Ado.ExecuteNonQuery("drop table cccddd_mysqlconnector.test_existstb01");
|
||||
}
|
||||
class test_existstb01
|
||||
{
|
||||
public Guid id { get; set; }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -21,5 +21,32 @@ namespace FreeSql.Tests.Odbc.Dameng
|
||||
var t2 = g.dameng.DbFirst.GetTablesByDatabase();
|
||||
//var tb = g.dameng.Ado.ExecuteArray(System.Data.CommandType.Text, "select * from \"tb_dbfirst\"");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ExistsTable()
|
||||
{
|
||||
var fsql = g.dameng;
|
||||
Assert.False(fsql.DbFirst.ExistsTable("test_existstb01"));
|
||||
Assert.False(fsql.DbFirst.ExistsTable("1user.test_existstb01"));
|
||||
Assert.False(fsql.DbFirst.ExistsTable("test_existstb01", false));
|
||||
Assert.False(fsql.DbFirst.ExistsTable("1user.test_existstb01", false));
|
||||
fsql.CodeFirst.SyncStructure(typeof(test_existstb01));
|
||||
Assert.True(fsql.DbFirst.ExistsTable("test_existstb01"));
|
||||
Assert.True(fsql.DbFirst.ExistsTable("1user.test_existstb01"));
|
||||
Assert.False(fsql.DbFirst.ExistsTable("test_existstb01", false));
|
||||
Assert.False(fsql.DbFirst.ExistsTable("1user.test_existstb01", false));
|
||||
fsql.Ado.ExecuteNonQuery("drop table test_existstb01");
|
||||
|
||||
Assert.False(fsql.DbFirst.ExistsTable("1user.test_existstb01"));
|
||||
Assert.False(fsql.DbFirst.ExistsTable("1user.test_existstb01", false));
|
||||
fsql.CodeFirst.SyncStructure(typeof(test_existstb01), "1user.test_existstb01");
|
||||
Assert.True(fsql.DbFirst.ExistsTable("1user.test_existstb01"));
|
||||
Assert.False(fsql.DbFirst.ExistsTable("1user.test_existstb01", false));
|
||||
fsql.Ado.ExecuteNonQuery("drop table \"1USER\".test_existstb01");
|
||||
}
|
||||
class test_existstb01
|
||||
{
|
||||
public Guid id { get; set; }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -18,5 +18,32 @@ namespace FreeSql.Tests.Odbc.KingbaseES
|
||||
var t2 = g.kingbaseES.DbFirst.GetTablesByDatabase();
|
||||
//var tb = g.kingbaseES.Ado.ExecuteArray(System.Data.CommandType.Text, "select * from \"tb_dbfirst\"");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ExistsTable()
|
||||
{
|
||||
var fsql = g.kingbaseES;
|
||||
Assert.False(fsql.DbFirst.ExistsTable("test_existstb01"));
|
||||
Assert.False(fsql.DbFirst.ExistsTable("public.test_existstb01"));
|
||||
Assert.False(fsql.DbFirst.ExistsTable("test_existstb01", false));
|
||||
Assert.False(fsql.DbFirst.ExistsTable("public.test_existstb01", false));
|
||||
fsql.CodeFirst.SyncStructure(typeof(test_existstb01));
|
||||
Assert.True(fsql.DbFirst.ExistsTable("test_existstb01"));
|
||||
Assert.True(fsql.DbFirst.ExistsTable("public.test_existstb01"));
|
||||
Assert.False(fsql.DbFirst.ExistsTable("Test_existstb01", false));
|
||||
Assert.False(fsql.DbFirst.ExistsTable("public.Test_existstb01", false));
|
||||
fsql.Ado.ExecuteNonQuery("drop table test_existstb01");
|
||||
|
||||
Assert.False(fsql.DbFirst.ExistsTable("tbexts.test_existstb01"));
|
||||
Assert.False(fsql.DbFirst.ExistsTable("tbexts.test_existstb01", false));
|
||||
fsql.CodeFirst.SyncStructure(typeof(test_existstb01), "tbexts.test_existstb01");
|
||||
Assert.True(fsql.DbFirst.ExistsTable("tbexts.test_existstb01"));
|
||||
Assert.False(fsql.DbFirst.ExistsTable("tbexts.Test_existstb01", false));
|
||||
fsql.Ado.ExecuteNonQuery("drop table \"TBEXTS\".test_existstb01");
|
||||
}
|
||||
class test_existstb01
|
||||
{
|
||||
public Guid id { get; set; }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -21,5 +21,32 @@ namespace FreeSql.Tests.Odbc.MySql
|
||||
var t2 = g.mysql.DbFirst.GetTablesByDatabase(g.mysql.DbFirst.GetDatabases()[0]);
|
||||
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ExistsTable()
|
||||
{
|
||||
var fsql = g.mysql;
|
||||
Assert.False(fsql.DbFirst.ExistsTable("test_existstb01"));
|
||||
Assert.False(fsql.DbFirst.ExistsTable("cccddd_odbc.test_existstb01"));
|
||||
Assert.False(fsql.DbFirst.ExistsTable("test_existstb01", false));
|
||||
Assert.False(fsql.DbFirst.ExistsTable("cccddd_odbc.test_existstb01", false));
|
||||
fsql.CodeFirst.SyncStructure(typeof(test_existstb01));
|
||||
Assert.True(fsql.DbFirst.ExistsTable("test_existstb01"));
|
||||
Assert.True(fsql.DbFirst.ExistsTable("cccddd_odbc.test_existstb01"));
|
||||
Assert.True(fsql.DbFirst.ExistsTable("Test_existstb01", false));
|
||||
Assert.True(fsql.DbFirst.ExistsTable("cccddd_odbc.Test_existstb01", false));
|
||||
fsql.Ado.ExecuteNonQuery("drop table test_existstb01");
|
||||
|
||||
Assert.False(fsql.DbFirst.ExistsTable("cccddd_odbc.test_existstb01"));
|
||||
Assert.False(fsql.DbFirst.ExistsTable("cccddd_odbc.test_existstb01", false));
|
||||
fsql.CodeFirst.SyncStructure(typeof(test_existstb01), "cccddd_odbc.test_existstb01");
|
||||
Assert.True(fsql.DbFirst.ExistsTable("cccddd_odbc.test_existstb01"));
|
||||
Assert.True(fsql.DbFirst.ExistsTable("cccddd_odbc.Test_existstb01", false));
|
||||
fsql.Ado.ExecuteNonQuery("drop table cccddd_odbc.test_existstb01");
|
||||
}
|
||||
class test_existstb01
|
||||
{
|
||||
public Guid id { get; set; }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -21,5 +21,32 @@ namespace FreeSql.Tests.Odbc.Oracle
|
||||
var t2 = g.oracle.DbFirst.GetTablesByDatabase();
|
||||
//var tb = g.oracle.Ado.ExecuteArray(System.Data.CommandType.Text, "select * from \"tb_dbfirst\"");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ExistsTable()
|
||||
{
|
||||
var fsql = g.oracle;
|
||||
Assert.False(fsql.DbFirst.ExistsTable("test_existstb01"));
|
||||
Assert.False(fsql.DbFirst.ExistsTable("1odbc.test_existstb01"));
|
||||
Assert.False(fsql.DbFirst.ExistsTable("test_existstb01", false));
|
||||
Assert.False(fsql.DbFirst.ExistsTable("1odbc.test_existstb01", false));
|
||||
fsql.CodeFirst.SyncStructure(typeof(test_existstb01));
|
||||
Assert.True(fsql.DbFirst.ExistsTable("test_existstb01"));
|
||||
Assert.True(fsql.DbFirst.ExistsTable("1odbc.test_existstb01"));
|
||||
Assert.False(fsql.DbFirst.ExistsTable("test_existstb01", false));
|
||||
Assert.False(fsql.DbFirst.ExistsTable("11odbcuser.test_existstb01", false));
|
||||
fsql.Ado.ExecuteNonQuery("drop table test_existstb01");
|
||||
|
||||
Assert.False(fsql.DbFirst.ExistsTable("1odbc.test_existstb01"));
|
||||
Assert.False(fsql.DbFirst.ExistsTable("1odbc.test_existstb01", false));
|
||||
fsql.CodeFirst.SyncStructure(typeof(test_existstb01), "1odbc.test_existstb01");
|
||||
Assert.True(fsql.DbFirst.ExistsTable("1odbc.test_existstb01"));
|
||||
Assert.False(fsql.DbFirst.ExistsTable("1odbc.test_existstb01", false));
|
||||
fsql.Ado.ExecuteNonQuery("drop table \"1ODBC\".test_existstb01");
|
||||
}
|
||||
class test_existstb01
|
||||
{
|
||||
public Guid id { get; set; }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -25,5 +25,32 @@ namespace FreeSql.Tests.Odbc.PostgreSQL
|
||||
|
||||
var tb_identity = t2.Where(a => a.Name == "test_new").FirstOrDefault();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ExistsTable()
|
||||
{
|
||||
var fsql = g.pgsql;
|
||||
Assert.False(fsql.DbFirst.ExistsTable("test_existstb01"));
|
||||
Assert.False(fsql.DbFirst.ExistsTable("public.test_existstb01"));
|
||||
Assert.False(fsql.DbFirst.ExistsTable("test_existstb01", false));
|
||||
Assert.False(fsql.DbFirst.ExistsTable("public.test_existstb01", false));
|
||||
fsql.CodeFirst.SyncStructure(typeof(test_existstb01));
|
||||
Assert.True(fsql.DbFirst.ExistsTable("test_existstb01"));
|
||||
Assert.True(fsql.DbFirst.ExistsTable("public.test_existstb01"));
|
||||
Assert.False(fsql.DbFirst.ExistsTable("Test_existstb01", false));
|
||||
Assert.False(fsql.DbFirst.ExistsTable("public.Test_existstb01", false));
|
||||
fsql.Ado.ExecuteNonQuery("drop table test_existstb01");
|
||||
|
||||
Assert.False(fsql.DbFirst.ExistsTable("tbexts.test_existstb01"));
|
||||
Assert.False(fsql.DbFirst.ExistsTable("tbexts.test_existstb01", false));
|
||||
fsql.CodeFirst.SyncStructure(typeof(test_existstb01), "tbexts.test_existstb01");
|
||||
Assert.True(fsql.DbFirst.ExistsTable("tbexts.test_existstb01"));
|
||||
Assert.False(fsql.DbFirst.ExistsTable("tbexts.Test_existstb01", false));
|
||||
fsql.Ado.ExecuteNonQuery("drop table \"tbexts\".test_existstb01");
|
||||
}
|
||||
class test_existstb01
|
||||
{
|
||||
public Guid id { get; set; }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -22,5 +22,32 @@ namespace FreeSql.Tests.Odbc.SqlServer
|
||||
var t2 = g.sqlserver.DbFirst.GetTablesByDatabase();
|
||||
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ExistsTable()
|
||||
{
|
||||
var fsql = g.sqlserver;
|
||||
Assert.False(fsql.DbFirst.ExistsTable("test_existstb01"));
|
||||
Assert.False(fsql.DbFirst.ExistsTable("dbo.test_existstb01"));
|
||||
Assert.False(fsql.DbFirst.ExistsTable("test_existstb01", false));
|
||||
Assert.False(fsql.DbFirst.ExistsTable("dbo.test_existstb01", false));
|
||||
fsql.CodeFirst.SyncStructure(typeof(test_existstb01));
|
||||
Assert.True(fsql.DbFirst.ExistsTable("test_existstb01"));
|
||||
Assert.True(fsql.DbFirst.ExistsTable("dbo.test_existstb01"));
|
||||
Assert.True(fsql.DbFirst.ExistsTable("Test_existstb01", false));
|
||||
Assert.True(fsql.DbFirst.ExistsTable("dbo.Test_existstb01", false));
|
||||
fsql.Ado.ExecuteNonQuery("drop table test_existstb01");
|
||||
|
||||
Assert.False(fsql.DbFirst.ExistsTable("xxxtb.test_existstb01"));
|
||||
Assert.False(fsql.DbFirst.ExistsTable("xxxtb.test_existstb01", false));
|
||||
fsql.CodeFirst.SyncStructure(typeof(test_existstb01), "xxxtb.test_existstb01");
|
||||
Assert.True(fsql.DbFirst.ExistsTable("xxxtb.test_existstb01"));
|
||||
Assert.True(fsql.DbFirst.ExistsTable("xxxtb.Test_existstb01", false));
|
||||
fsql.Ado.ExecuteNonQuery("drop table xxxtb.test_existstb01");
|
||||
}
|
||||
class test_existstb01
|
||||
{
|
||||
public Guid id { get; set; }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -21,5 +21,32 @@ namespace FreeSql.Tests.Dameng
|
||||
var t2 = g.dameng.DbFirst.GetTablesByDatabase();
|
||||
//var tb = g.dameng.Ado.ExecuteArray(System.Data.CommandType.Text, "select * from \"tb_dbfirst\"");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ExistsTable()
|
||||
{
|
||||
var fsql = g.dameng;
|
||||
Assert.False(fsql.DbFirst.ExistsTable("test_existstb01"));
|
||||
Assert.False(fsql.DbFirst.ExistsTable("2user.test_existstb01"));
|
||||
Assert.False(fsql.DbFirst.ExistsTable("test_existstb01", false));
|
||||
Assert.False(fsql.DbFirst.ExistsTable("2user.test_existstb01", false));
|
||||
fsql.CodeFirst.SyncStructure(typeof(test_existstb01));
|
||||
Assert.True(fsql.DbFirst.ExistsTable("test_existstb01"));
|
||||
Assert.True(fsql.DbFirst.ExistsTable("2user.test_existstb01"));
|
||||
Assert.False(fsql.DbFirst.ExistsTable("test_existstb01", false));
|
||||
Assert.False(fsql.DbFirst.ExistsTable("2user.test_existstb01", false));
|
||||
fsql.Ado.ExecuteNonQuery("drop table test_existstb01");
|
||||
|
||||
Assert.False(fsql.DbFirst.ExistsTable("2user.test_existstb01"));
|
||||
Assert.False(fsql.DbFirst.ExistsTable("2user.test_existstb01", false));
|
||||
fsql.CodeFirst.SyncStructure(typeof(test_existstb01), "2user.test_existstb01");
|
||||
Assert.True(fsql.DbFirst.ExistsTable("2user.test_existstb01"));
|
||||
Assert.False(fsql.DbFirst.ExistsTable("2user.test_existstb01", false));
|
||||
fsql.Ado.ExecuteNonQuery("drop table \"2USER\".test_existstb01");
|
||||
}
|
||||
class test_existstb01
|
||||
{
|
||||
public Guid id { get; set; }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -21,5 +21,32 @@ namespace FreeSql.Tests.MySql
|
||||
var t2 = g.mysql.DbFirst.GetTablesByDatabase(g.mysql.DbFirst.GetDatabases()[0]);
|
||||
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ExistsTable()
|
||||
{
|
||||
var fsql = g.mysql;
|
||||
Assert.False(fsql.DbFirst.ExistsTable("test_existstb01"));
|
||||
Assert.False(fsql.DbFirst.ExistsTable("cccddd.test_existstb01"));
|
||||
Assert.False(fsql.DbFirst.ExistsTable("test_existstb01", false));
|
||||
Assert.False(fsql.DbFirst.ExistsTable("cccddd.test_existstb01", false));
|
||||
fsql.CodeFirst.SyncStructure(typeof(test_existstb01));
|
||||
Assert.True(fsql.DbFirst.ExistsTable("test_existstb01"));
|
||||
Assert.True(fsql.DbFirst.ExistsTable("cccddd.test_existstb01"));
|
||||
Assert.True(fsql.DbFirst.ExistsTable("Test_existstb01", false));
|
||||
Assert.True(fsql.DbFirst.ExistsTable("cccddd.Test_existstb01", false));
|
||||
fsql.Ado.ExecuteNonQuery("drop table test_existstb01");
|
||||
|
||||
Assert.False(fsql.DbFirst.ExistsTable("cccddd.test_existstb01"));
|
||||
Assert.False(fsql.DbFirst.ExistsTable("cccddd.test_existstb01", false));
|
||||
fsql.CodeFirst.SyncStructure(typeof(test_existstb01), "cccddd.test_existstb01");
|
||||
Assert.True(fsql.DbFirst.ExistsTable("cccddd.test_existstb01"));
|
||||
Assert.True(fsql.DbFirst.ExistsTable("cccddd.Test_existstb01", false));
|
||||
fsql.Ado.ExecuteNonQuery("drop table cccddd.test_existstb01");
|
||||
}
|
||||
class test_existstb01
|
||||
{
|
||||
public Guid id { get; set; }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -21,5 +21,32 @@ namespace FreeSql.Tests.Oracle
|
||||
var t2 = g.oracle.DbFirst.GetTablesByDatabase();
|
||||
//var tb = g.oracle.Ado.ExecuteArray(System.Data.CommandType.Text, "select * from \"tb_dbfirst\"");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ExistsTable()
|
||||
{
|
||||
var fsql = g.oracle;
|
||||
Assert.False(fsql.DbFirst.ExistsTable("test_existstb01"));
|
||||
Assert.False(fsql.DbFirst.ExistsTable("1user.test_existstb01"));
|
||||
Assert.False(fsql.DbFirst.ExistsTable("test_existstb01", false));
|
||||
Assert.False(fsql.DbFirst.ExistsTable("1user.test_existstb01", false));
|
||||
fsql.CodeFirst.SyncStructure(typeof(test_existstb01));
|
||||
Assert.True(fsql.DbFirst.ExistsTable("test_existstb01"));
|
||||
Assert.True(fsql.DbFirst.ExistsTable("1user.test_existstb01"));
|
||||
Assert.False(fsql.DbFirst.ExistsTable("test_existstb01", false));
|
||||
Assert.False(fsql.DbFirst.ExistsTable("1user.test_existstb01", false));
|
||||
fsql.Ado.ExecuteNonQuery("drop table test_existstb01");
|
||||
|
||||
Assert.False(fsql.DbFirst.ExistsTable("1user.test_existstb01"));
|
||||
Assert.False(fsql.DbFirst.ExistsTable("1user.test_existstb01", false));
|
||||
fsql.CodeFirst.SyncStructure(typeof(test_existstb01), "1user.test_existstb01");
|
||||
Assert.True(fsql.DbFirst.ExistsTable("1user.test_existstb01"));
|
||||
Assert.False(fsql.DbFirst.ExistsTable("1user.test_existstb01", false));
|
||||
fsql.Ado.ExecuteNonQuery("drop table \"1USER\".test_existstb01");
|
||||
}
|
||||
class test_existstb01
|
||||
{
|
||||
public Guid id { get; set; }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -26,5 +26,32 @@ namespace FreeSql.Tests.PostgreSQL
|
||||
var tb_identity = t2.Where(a => a.Name == "test_new").FirstOrDefault();
|
||||
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ExistsTable()
|
||||
{
|
||||
var fsql = g.pgsql;
|
||||
Assert.False(fsql.DbFirst.ExistsTable("test_existstb01"));
|
||||
Assert.False(fsql.DbFirst.ExistsTable("public.test_existstb01"));
|
||||
Assert.False(fsql.DbFirst.ExistsTable("test_existstb01", false));
|
||||
Assert.False(fsql.DbFirst.ExistsTable("public.test_existstb01", false));
|
||||
fsql.CodeFirst.SyncStructure(typeof(test_existstb01));
|
||||
Assert.True(fsql.DbFirst.ExistsTable("test_existstb01"));
|
||||
Assert.True(fsql.DbFirst.ExistsTable("public.test_existstb01"));
|
||||
Assert.False(fsql.DbFirst.ExistsTable("Test_existstb01", false));
|
||||
Assert.False(fsql.DbFirst.ExistsTable("public.Test_existstb01", false));
|
||||
fsql.Ado.ExecuteNonQuery("drop table test_existstb01");
|
||||
|
||||
Assert.False(fsql.DbFirst.ExistsTable("tbexts.test_existstb01"));
|
||||
Assert.False(fsql.DbFirst.ExistsTable("tbexts.test_existstb01", false));
|
||||
fsql.CodeFirst.SyncStructure(typeof(test_existstb01), "tbexts.test_existstb01");
|
||||
Assert.True(fsql.DbFirst.ExistsTable("tbexts.test_existstb01"));
|
||||
Assert.False(fsql.DbFirst.ExistsTable("tbexts.Test_existstb01", false));
|
||||
fsql.Ado.ExecuteNonQuery("drop table \"tbexts\".test_existstb01");
|
||||
}
|
||||
class test_existstb01
|
||||
{
|
||||
public Guid id { get; set; }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -21,5 +21,32 @@ namespace FreeSql.Tests.ShenTong
|
||||
var t2 = g.shentong.DbFirst.GetTablesByDatabase(g.shentong.DbFirst.GetDatabases()[0]);
|
||||
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ExistsTable()
|
||||
{
|
||||
var fsql = g.shentong;
|
||||
Assert.False(fsql.DbFirst.ExistsTable("test_existstb01"));
|
||||
Assert.False(fsql.DbFirst.ExistsTable("public.test_existstb01"));
|
||||
Assert.False(fsql.DbFirst.ExistsTable("test_existstb01", false));
|
||||
Assert.False(fsql.DbFirst.ExistsTable("public.test_existstb01", false));
|
||||
fsql.CodeFirst.SyncStructure(typeof(test_existstb01));
|
||||
Assert.True(fsql.DbFirst.ExistsTable("test_existstb01"));
|
||||
Assert.True(fsql.DbFirst.ExistsTable("public.test_existstb01"));
|
||||
Assert.False(fsql.DbFirst.ExistsTable("Test_existstb01", false));
|
||||
Assert.False(fsql.DbFirst.ExistsTable("public.Test_existstb01", false));
|
||||
fsql.Ado.ExecuteNonQuery("drop table test_existstb01");
|
||||
|
||||
Assert.False(fsql.DbFirst.ExistsTable("tbexts.test_existstb01"));
|
||||
Assert.False(fsql.DbFirst.ExistsTable("tbexts.test_existstb01", false));
|
||||
fsql.CodeFirst.SyncStructure(typeof(test_existstb01), "tbexts.test_existstb01");
|
||||
Assert.True(fsql.DbFirst.ExistsTable("tbexts.test_existstb01"));
|
||||
Assert.False(fsql.DbFirst.ExistsTable("tbexts.Test_existstb01", false));
|
||||
fsql.Ado.ExecuteNonQuery("drop table \"TBEXTS\".test_existstb01");
|
||||
}
|
||||
class test_existstb01
|
||||
{
|
||||
public Guid id { get; set; }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -31,5 +31,32 @@ namespace FreeSql.Tests.SqlServer
|
||||
var t2 = g.sqlserver.DbFirst.GetTablesByDatabase();
|
||||
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ExistsTable()
|
||||
{
|
||||
var fsql = g.sqlserver;
|
||||
Assert.False(fsql.DbFirst.ExistsTable("test_existstb01"));
|
||||
Assert.False(fsql.DbFirst.ExistsTable("dbo.test_existstb01"));
|
||||
Assert.False(fsql.DbFirst.ExistsTable("test_existstb01", false));
|
||||
Assert.False(fsql.DbFirst.ExistsTable("dbo.test_existstb01", false));
|
||||
fsql.CodeFirst.SyncStructure(typeof(test_existstb01));
|
||||
Assert.True(fsql.DbFirst.ExistsTable("test_existstb01"));
|
||||
Assert.True(fsql.DbFirst.ExistsTable("dbo.test_existstb01"));
|
||||
Assert.True(fsql.DbFirst.ExistsTable("Test_existstb01", false));
|
||||
Assert.True(fsql.DbFirst.ExistsTable("dbo.Test_existstb01", false));
|
||||
fsql.Ado.ExecuteNonQuery("drop table test_existstb01");
|
||||
|
||||
Assert.False(fsql.DbFirst.ExistsTable("xxxtb.test_existstb01"));
|
||||
Assert.False(fsql.DbFirst.ExistsTable("xxxtb.test_existstb01", false));
|
||||
fsql.CodeFirst.SyncStructure(typeof(test_existstb01), "xxxtb.test_existstb01");
|
||||
Assert.True(fsql.DbFirst.ExistsTable("xxxtb.test_existstb01"));
|
||||
Assert.True(fsql.DbFirst.ExistsTable("xxxtb.Test_existstb01", false));
|
||||
fsql.Ado.ExecuteNonQuery("drop table xxxtb.test_existstb01");
|
||||
}
|
||||
class test_existstb01
|
||||
{
|
||||
public Guid id { get; set; }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -21,5 +21,32 @@ namespace FreeSql.Tests.Sqlite
|
||||
var t2 = g.sqlite.DbFirst.GetTablesByDatabase();
|
||||
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ExistsTable()
|
||||
{
|
||||
var fsql = g.sqlite;
|
||||
Assert.False(fsql.DbFirst.ExistsTable("test_existstb01"));
|
||||
Assert.False(fsql.DbFirst.ExistsTable("main.test_existstb01"));
|
||||
Assert.False(fsql.DbFirst.ExistsTable("test_existstb01", false));
|
||||
Assert.False(fsql.DbFirst.ExistsTable("main.test_existstb01", false));
|
||||
fsql.CodeFirst.SyncStructure(typeof(test_existstb01));
|
||||
Assert.True(fsql.DbFirst.ExistsTable("test_existstb01"));
|
||||
Assert.True(fsql.DbFirst.ExistsTable("main.test_existstb01"));
|
||||
Assert.False(fsql.DbFirst.ExistsTable("Test_existstb01", false));
|
||||
Assert.False(fsql.DbFirst.ExistsTable("main.Test_existstb01", false));
|
||||
fsql.Ado.ExecuteNonQuery("drop table test_existstb01");
|
||||
|
||||
Assert.False(fsql.DbFirst.ExistsTable("xxxtb.test_existstb01"));
|
||||
Assert.False(fsql.DbFirst.ExistsTable("xxxtb.test_existstb01", false));
|
||||
fsql.CodeFirst.SyncStructure(typeof(test_existstb01), "xxxtb.test_existstb01");
|
||||
Assert.True(fsql.DbFirst.ExistsTable("xxxtb.test_existstb01"));
|
||||
Assert.False(fsql.DbFirst.ExistsTable("xxxtb.Test_existstb01", false));
|
||||
fsql.Ado.ExecuteNonQuery("drop table xxxtb.test_existstb01");
|
||||
}
|
||||
class test_existstb01
|
||||
{
|
||||
public Guid id { get; set; }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -3184,6 +3184,14 @@
|
||||
<param name="database"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:FreeSql.IDbFirst.ExistsTable(System.String,System.Boolean)">
|
||||
<summary>
|
||||
判断表是否存在
|
||||
</summary>
|
||||
<param name="name">表名,如:dbo.table1</param>
|
||||
<param name="ignoreCase">是否忽略大小写</param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:FreeSql.Internal.CommonProvider.InsertOrUpdateProvider`1.SplitSourceByIdentityValueIsNull(System.Collections.Generic.List{`0})">
|
||||
<summary>
|
||||
如果实体类有自增属性,分成两个 List,有值的Item1 merge,无值的Item2 insert
|
||||
|
@ -75,5 +75,15 @@ namespace FreeSql
|
||||
/// <param name="database"></param>
|
||||
/// <returns></returns>
|
||||
List<DbEnumInfo> GetEnumsByDatabase(params string[] database);
|
||||
|
||||
/// <summary>
|
||||
/// 判断表是否存在
|
||||
/// </summary>
|
||||
/// <param name="name">表名,如:dbo.table1</param>
|
||||
/// <param name="ignoreCase">是否忽略大小写</param>
|
||||
/// <returns></returns>
|
||||
bool ExistsTable(string name, bool ignoreCase = true);
|
||||
|
||||
//DbTableInfo GetTableByName(string name);
|
||||
}
|
||||
}
|
||||
|
@ -212,6 +212,25 @@ namespace FreeSql.Dameng
|
||||
return ds.Select(a => a.FirstOrDefault()?.ToString()).ToList();
|
||||
}
|
||||
|
||||
public bool ExistsTable(string name, bool ignoreCase)
|
||||
{
|
||||
if (string.IsNullOrEmpty(name)) return false;
|
||||
var tbname = _commonUtils.SplitTableName(name);
|
||||
if (tbname?.Length == 1)
|
||||
{
|
||||
var userId = (_orm.Ado.MasterPool as DamengConnectionPool)?.UserId;
|
||||
if (string.IsNullOrEmpty(userId))
|
||||
using (var conn = _orm.Ado.MasterPool.Get())
|
||||
{
|
||||
userId = DamengConnectionPool.GetUserId(conn.Value.ConnectionString);
|
||||
}
|
||||
tbname = new[] { userId, tbname[0] };
|
||||
}
|
||||
if (ignoreCase) tbname = tbname.Select(a => a.ToLower()).ToArray();
|
||||
var sql = $" select 1 from all_tab_comments where {(ignoreCase ? "lower(owner)" : "owner")}={_commonUtils.FormatSql("{0}", tbname[0])} and {(ignoreCase ? "lower(table_name)" : "table_name")}={_commonUtils.FormatSql("{0}", tbname[1])}";
|
||||
return string.Concat(_orm.Ado.ExecuteScalar(CommandType.Text, sql)) == "1";
|
||||
}
|
||||
|
||||
public List<DbTableInfo> GetTablesByDatabase(params string[] database2)
|
||||
{
|
||||
var loc1 = new List<DbTableInfo>();
|
||||
|
@ -148,6 +148,24 @@ namespace FreeSql.MySql
|
||||
return ds.Select(a => a.FirstOrDefault()?.ToString()).ToList();
|
||||
}
|
||||
|
||||
public bool ExistsTable(string name, bool ignoreCase)
|
||||
{
|
||||
if (string.IsNullOrEmpty(name)) return false;
|
||||
var tbname = _commonUtils.SplitTableName(name);
|
||||
if (tbname?.Length == 1)
|
||||
{
|
||||
var database = "";
|
||||
using (var conn = _orm.Ado.MasterPool.Get(TimeSpan.FromSeconds(5)))
|
||||
{
|
||||
database = conn.Value.Database;
|
||||
}
|
||||
tbname = new[] { database, tbname[0] };
|
||||
}
|
||||
if (ignoreCase) tbname = tbname.Select(a => a.ToLower()).ToArray();
|
||||
var sql = $" SELECT 1 FROM information_schema.TABLES WHERE {(ignoreCase ? "lower(table_schema)" : "table_schema")} = {_commonUtils.FormatSql("{0}", tbname[0])} and {(ignoreCase ? "lower(table_name)" : "table_name")} = {_commonUtils.FormatSql("{0}", tbname[1])}";
|
||||
return string.Concat(_orm.Ado.ExecuteScalar(CommandType.Text, sql)) == "1";
|
||||
}
|
||||
|
||||
public List<DbTableInfo> GetTablesByDatabase(params string[] database2)
|
||||
{
|
||||
var loc1 = new List<DbTableInfo>();
|
||||
|
@ -212,6 +212,25 @@ namespace FreeSql.Odbc.Dameng
|
||||
return ds.Select(a => a.FirstOrDefault()?.ToString()).ToList();
|
||||
}
|
||||
|
||||
public bool ExistsTable(string name, bool ignoreCase)
|
||||
{
|
||||
if (string.IsNullOrEmpty(name)) return false;
|
||||
var tbname = _commonUtils.SplitTableName(name);
|
||||
if (tbname?.Length == 1)
|
||||
{
|
||||
var userId = (_orm.Ado.MasterPool as OdbcDamengConnectionPool)?.UserId;
|
||||
if (string.IsNullOrEmpty(userId))
|
||||
using (var conn = _orm.Ado.MasterPool.Get())
|
||||
{
|
||||
userId = OdbcDamengConnectionPool.GetUserId(conn.Value.ConnectionString);
|
||||
}
|
||||
tbname = new[] { userId, tbname[0] };
|
||||
}
|
||||
if (ignoreCase) tbname = tbname.Select(a => a.ToLower()).ToArray();
|
||||
var sql = $" select 1 from all_tab_comments where {(ignoreCase ? "lower(owner)" : "owner")}={_commonUtils.FormatSql("{0}", tbname[0])} and {(ignoreCase ? "lower(table_name)" : "table_name")}={_commonUtils.FormatSql("{0}", tbname[1])}";
|
||||
return string.Concat(_orm.Ado.ExecuteScalar(CommandType.Text, sql)) == "1";
|
||||
}
|
||||
|
||||
public List<DbTableInfo> GetTablesByDatabase(params string[] database2)
|
||||
{
|
||||
var loc1 = new List<DbTableInfo>();
|
||||
|
@ -110,6 +110,16 @@ namespace FreeSql.Odbc.KingbaseES
|
||||
return ds.Select(a => a.FirstOrDefault()?.ToString()).ToList();
|
||||
}
|
||||
|
||||
public bool ExistsTable(string name, bool ignoreCase)
|
||||
{
|
||||
if (string.IsNullOrEmpty(name)) return false;
|
||||
var tbname = _commonUtils.SplitTableName(name);
|
||||
if (tbname?.Length == 1) tbname = new[] { "public", tbname[0] };
|
||||
if (ignoreCase) tbname = tbname.Select(a => a.ToLower()).ToArray();
|
||||
var sql = $" select 1 from sys_tables a inner join sys_namespace b on b.nspname = a.schemaname where {(ignoreCase ? "lower(b.nspname)" : "b.nspname")} = {_commonUtils.FormatSql("{0}", tbname[0])} and {(ignoreCase ? "lower(a.tablename)" : "a.tablename")} = {_commonUtils.FormatSql("{0}", tbname[1])}";
|
||||
return string.Concat(_orm.Ado.ExecuteScalar(CommandType.Text, sql)) == "1";
|
||||
}
|
||||
|
||||
public List<DbTableInfo> GetTablesByDatabase(params string[] database)
|
||||
{
|
||||
var olddatabase = "";
|
||||
|
@ -114,6 +114,24 @@ namespace FreeSql.Odbc.MySql
|
||||
return ds.Select(a => a.FirstOrDefault()?.ToString()).ToList();
|
||||
}
|
||||
|
||||
public bool ExistsTable(string name, bool ignoreCase)
|
||||
{
|
||||
if (string.IsNullOrEmpty(name)) return false;
|
||||
var tbname = _commonUtils.SplitTableName(name);
|
||||
if (tbname?.Length == 1)
|
||||
{
|
||||
var database = "";
|
||||
using (var conn = _orm.Ado.MasterPool.Get(TimeSpan.FromSeconds(5)))
|
||||
{
|
||||
database = conn.Value.Database;
|
||||
}
|
||||
tbname = new[] { database, tbname[0] };
|
||||
}
|
||||
if (ignoreCase) tbname = tbname.Select(a => a.ToLower()).ToArray();
|
||||
var sql = $" SELECT 1 FROM information_schema.TABLES WHERE {(ignoreCase ? "lower(table_schema)" : "table_schema")} = {_commonUtils.FormatSql("{0}", tbname[0])} and {(ignoreCase ? "lower(table_name)" : "table_name")} = {_commonUtils.FormatSql("{0}", tbname[1])}";
|
||||
return string.Concat(_orm.Ado.ExecuteScalar(CommandType.Text, sql)) == "1";
|
||||
}
|
||||
|
||||
public List<DbTableInfo> GetTablesByDatabase(params string[] database2)
|
||||
{
|
||||
var loc1 = new List<DbTableInfo>();
|
||||
|
@ -166,6 +166,25 @@ namespace FreeSql.Odbc.Oracle
|
||||
return ds.Select(a => a.FirstOrDefault()?.ToString()).ToList();
|
||||
}
|
||||
|
||||
public bool ExistsTable(string name, bool ignoreCase)
|
||||
{
|
||||
if (string.IsNullOrEmpty(name)) return false;
|
||||
var tbname = _commonUtils.SplitTableName(name);
|
||||
if (tbname?.Length == 1)
|
||||
{
|
||||
var userId = (_orm.Ado.MasterPool as OdbcOracleConnectionPool)?.UserId;
|
||||
if (string.IsNullOrEmpty(userId))
|
||||
using (var conn = _orm.Ado.MasterPool.Get())
|
||||
{
|
||||
userId = OdbcOracleConnectionPool.GetUserId(conn.Value.ConnectionString);
|
||||
}
|
||||
tbname = new[] { userId, tbname[0] };
|
||||
}
|
||||
if (ignoreCase) tbname = tbname.Select(a => a.ToLower()).ToArray();
|
||||
var sql = $" select 1 from all_tab_comments where {(ignoreCase ? "lower(owner)" : "owner")}={_commonUtils.FormatSql("{0}", tbname[0])} and {(ignoreCase ? "lower(table_name)" : "table_name")}={_commonUtils.FormatSql("{0}", tbname[1])}";
|
||||
return string.Concat(_orm.Ado.ExecuteScalar(CommandType.Text, sql)) == "1";
|
||||
}
|
||||
|
||||
public List<DbTableInfo> GetTablesByDatabase(params string[] database2)
|
||||
{
|
||||
var loc1 = new List<DbTableInfo>();
|
||||
|
@ -122,6 +122,16 @@ namespace FreeSql.Odbc.PostgreSQL
|
||||
return ds.Select(a => a.FirstOrDefault()?.ToString()).ToList();
|
||||
}
|
||||
|
||||
public bool ExistsTable(string name, bool ignoreCase)
|
||||
{
|
||||
if (string.IsNullOrEmpty(name)) return false;
|
||||
var tbname = _commonUtils.SplitTableName(name);
|
||||
if (tbname?.Length == 1) tbname = new[] { "public", tbname[0] };
|
||||
if (ignoreCase) tbname = tbname.Select(a => a.ToLower()).ToArray();
|
||||
var sql = $" select 1 from pg_tables a inner join pg_namespace b on b.nspname = a.schemaname where {(ignoreCase ? "lower(b.nspname)" : "b.nspname")} = {_commonUtils.FormatSql("{0}", tbname[0])} and {(ignoreCase ? "lower(a.tablename)" : "a.tablename")} = {_commonUtils.FormatSql("{0}", tbname[1])}";
|
||||
return string.Concat(_orm.Ado.ExecuteScalar(CommandType.Text, sql)) == "1";
|
||||
}
|
||||
|
||||
public List<DbTableInfo> GetTablesByDatabase(params string[] database)
|
||||
{
|
||||
var olddatabase = "";
|
||||
|
@ -107,6 +107,31 @@ namespace FreeSql.Odbc.SqlServer
|
||||
return ds.Select(a => a.FirstOrDefault()?.ToString()).ToList();
|
||||
}
|
||||
|
||||
public bool ExistsTable(string name, bool ignoreCase)
|
||||
{
|
||||
if (string.IsNullOrEmpty(name)) return false;
|
||||
var olddatabase = "";
|
||||
using (var conn = _orm.Ado.MasterPool.Get(TimeSpan.FromSeconds(5)))
|
||||
{
|
||||
olddatabase = conn.Value.Database;
|
||||
}
|
||||
var tbname = _commonUtils.SplitTableName(name);
|
||||
if (tbname?.Length == 1) tbname = new[] { olddatabase, "dbo", tbname[0] };
|
||||
if (tbname?.Length == 2) tbname = new[] { olddatabase, tbname[0], tbname[1] };
|
||||
tbname = tbname.Select(a => a.ToLower()).ToArray();
|
||||
var sql = $@"
|
||||
use [{tbname[0]}];
|
||||
select
|
||||
1
|
||||
from sys.tables a
|
||||
inner join sys.schemas b on b.schema_id = a.schema_id
|
||||
where lower(b.name) = {_commonUtils.FormatSql("{0}", tbname[1])} and lower(a.name) = {_commonUtils.FormatSql("{0}", tbname[2])}
|
||||
;
|
||||
use [{olddatabase}];
|
||||
";
|
||||
return string.Concat(_orm.Ado.ExecuteScalar(CommandType.Text, sql)) == "1";
|
||||
}
|
||||
|
||||
public List<DbTableInfo> GetTablesByDatabase(params string[] database)
|
||||
{
|
||||
var olddatabase = "";
|
||||
|
@ -166,6 +166,25 @@ namespace FreeSql.Oracle
|
||||
return ds.Select(a => a.FirstOrDefault()?.ToString()).ToList();
|
||||
}
|
||||
|
||||
public bool ExistsTable(string name, bool ignoreCase)
|
||||
{
|
||||
if (string.IsNullOrEmpty(name)) return false;
|
||||
var tbname = _commonUtils.SplitTableName(name);
|
||||
if (tbname?.Length == 1)
|
||||
{
|
||||
var userId = (_orm.Ado.MasterPool as OracleConnectionPool)?.UserId;
|
||||
if (string.IsNullOrEmpty(userId))
|
||||
using (var conn = _orm.Ado.MasterPool.Get())
|
||||
{
|
||||
userId = OracleConnectionPool.GetUserId(conn.Value.ConnectionString);
|
||||
}
|
||||
tbname = new[] { userId, tbname[0] };
|
||||
}
|
||||
if (ignoreCase) tbname = tbname.Select(a => a.ToLower()).ToArray();
|
||||
var sql = $" select 1 from all_tab_comments where {(ignoreCase ? "lower(owner)" : "owner")}={_commonUtils.FormatSql("{0}", tbname[0])} and {(ignoreCase ? "lower(table_name)" : "table_name")}={_commonUtils.FormatSql("{0}", tbname[1])}";
|
||||
return string.Concat(_orm.Ado.ExecuteScalar(CommandType.Text, sql)) == "1";
|
||||
}
|
||||
|
||||
public List<DbTableInfo> GetTablesByDatabase(params string[] database2)
|
||||
{
|
||||
var loc1 = new List<DbTableInfo>();
|
||||
|
@ -232,6 +232,16 @@ namespace FreeSql.PostgreSQL
|
||||
return ds.Select(a => a.FirstOrDefault()?.ToString()).ToList();
|
||||
}
|
||||
|
||||
public bool ExistsTable(string name, bool ignoreCase)
|
||||
{
|
||||
if (string.IsNullOrEmpty(name)) return false;
|
||||
var tbname = _commonUtils.SplitTableName(name);
|
||||
if (tbname?.Length == 1) tbname = new[] { "public", tbname[0] };
|
||||
if (ignoreCase) tbname = tbname.Select(a => a.ToLower()).ToArray();
|
||||
var sql = $" select 1 from pg_tables a inner join pg_namespace b on b.nspname = a.schemaname where {(ignoreCase ? "lower(b.nspname)" : "b.nspname")} = {_commonUtils.FormatSql("{0}", tbname[0])} and {(ignoreCase ? "lower(a.tablename)" : "a.tablename")} = {_commonUtils.FormatSql("{0}", tbname[1])}";
|
||||
return string.Concat(_orm.Ado.ExecuteScalar(CommandType.Text, sql)) == "1";
|
||||
}
|
||||
|
||||
public List<DbTableInfo> GetTablesByDatabase(params string[] database)
|
||||
{
|
||||
var olddatabase = "";
|
||||
|
@ -123,6 +123,22 @@ namespace FreeSql.ShenTong
|
||||
return ds.Select(a => a.FirstOrDefault()?.ToString()).ToList();
|
||||
}
|
||||
|
||||
public bool ExistsTable(string name, bool ignoreCase)
|
||||
{
|
||||
if (string.IsNullOrEmpty(name)) return false;
|
||||
var tbname = _commonUtils.SplitTableName(name);
|
||||
if (tbname?.Length == 1) tbname = new[] { "PUBLIC", tbname[0] };
|
||||
if (ignoreCase) tbname = tbname.Select(a => a.ToLower()).ToArray();
|
||||
var sql = $@"
|
||||
select
|
||||
1
|
||||
from sys_class a
|
||||
inner join sys_namespace b on b.oid = a.relnamespace
|
||||
where {(ignoreCase ? "lower(b.nspname)" : "b.nspname")} = {_commonUtils.FormatSql("{0}", tbname[0])} and {(ignoreCase ? "lower(a.relname)" : "a.relname")} = {_commonUtils.FormatSql("{0}", tbname[1])} and a.relkind in ('r')
|
||||
";
|
||||
return string.Concat(_orm.Ado.ExecuteScalar(CommandType.Text, sql)) == "1";
|
||||
}
|
||||
|
||||
public List<DbTableInfo> GetTablesByDatabase(params string[] database)
|
||||
{
|
||||
var olddatabase = "";
|
||||
|
@ -110,6 +110,31 @@ namespace FreeSql.SqlServer
|
||||
return ds.Select(a => a.FirstOrDefault()?.ToString()).ToList();
|
||||
}
|
||||
|
||||
public bool ExistsTable(string name, bool ignoreCase)
|
||||
{
|
||||
if (string.IsNullOrEmpty(name)) return false;
|
||||
var olddatabase = "";
|
||||
using (var conn = _orm.Ado.MasterPool.Get(TimeSpan.FromSeconds(5)))
|
||||
{
|
||||
olddatabase = conn.Value.Database;
|
||||
}
|
||||
var tbname = _commonUtils.SplitTableName(name);
|
||||
if (tbname?.Length == 1) tbname = new[] { olddatabase, "dbo", tbname[0] };
|
||||
if (tbname?.Length == 2) tbname = new[] { olddatabase, tbname[0], tbname[1] };
|
||||
tbname = tbname.Select(a => a.ToLower()).ToArray();
|
||||
var sql = $@"
|
||||
use [{tbname[0]}];
|
||||
select
|
||||
1
|
||||
from sys.tables a
|
||||
inner join sys.schemas b on b.schema_id = a.schema_id
|
||||
where lower(b.name) = {_commonUtils.FormatSql("{0}", tbname[1])} and lower(a.name) = {_commonUtils.FormatSql("{0}", tbname[2])}
|
||||
;
|
||||
use [{olddatabase}];
|
||||
";
|
||||
return string.Concat(_orm.Ado.ExecuteScalar(CommandType.Text, sql)) == "1";
|
||||
}
|
||||
|
||||
public List<DbTableInfo> GetTablesByDatabase(params string[] database)
|
||||
{
|
||||
var olddatabase = "";
|
||||
|
@ -149,6 +149,16 @@ namespace FreeSql.Sqlite
|
||||
return _orm.Ado.ExecuteArray("PRAGMA database_list").Select(a => string.Concat(a[1])).ToList();
|
||||
}
|
||||
|
||||
public bool ExistsTable(string name, bool ignoreCase)
|
||||
{
|
||||
if (string.IsNullOrEmpty(name)) return false;
|
||||
var tbname = _commonUtils.SplitTableName(name);
|
||||
if (tbname?.Length == 1) tbname = new[] { "main", tbname[0] };
|
||||
if (ignoreCase) tbname = tbname.Select(a => a.ToLower()).ToArray();
|
||||
var sql = $@" select 1 from {_commonUtils.QuoteSqlName(tbname[0])}.sqlite_master where type = 'table' and {(ignoreCase ? "lower(tbl_name)" : "tbl_name")} = {_commonUtils.FormatSql("{0}", tbname[1])}";
|
||||
return string.Concat(_orm.Ado.ExecuteScalar(CommandType.Text, sql)) == "1";
|
||||
}
|
||||
|
||||
public List<DbTableInfo> GetTablesByDatabase(params string[] database2)
|
||||
{
|
||||
var loc1 = new List<DbTableInfo>();
|
||||
@ -194,7 +204,8 @@ namespace FreeSql.Sqlite
|
||||
|
||||
foreach (var db in database)
|
||||
{
|
||||
var sql = $@"select
|
||||
var sql = $@"
|
||||
select
|
||||
'{db}.' || tbl_name,
|
||||
'{db}',
|
||||
tbl_name,
|
||||
|
Loading…
x
Reference in New Issue
Block a user