Skip to content

Commit

Permalink
- 增加 人大金仓 Ado.Net 实现 FreeSql.Provider.KingbaseES #325
Browse files Browse the repository at this point in the history
  • Loading branch information
28810 authored and 28810 committed Aug 21, 2020
1 parent 7fcae30 commit f7ce4dc
Show file tree
Hide file tree
Showing 55 changed files with 12,596 additions and 10 deletions.
2 changes: 1 addition & 1 deletion Extensions/FreeSql.Generator/ConsoleApp.cs
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ public ConsoleApp(string[] args, ManualResetEvent wait)
case "oracle": ArgsDbType = DataType.Oracle; break;
case "sqlite": ArgsDbType = DataType.Sqlite; break;
case "dameng": ArgsDbType = DataType.Dameng; break;
case "odbckingbasees": ArgsDbType = DataType.OdbcKingbaseES; break;
case "kingbasees": ArgsDbType = DataType.KingbaseES; break;
case "shentong": ArgsDbType = DataType.ShenTong; break;
default: throw new ArgumentException($"-DB 参数错误,不支持的类型:\"{dbargs[0]}\"");
}
Expand Down
2 changes: 1 addition & 1 deletion Extensions/FreeSql.Generator/FreeSql.Generator.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@

<ItemGroup>
<ProjectReference Include="..\..\Providers\FreeSql.Provider.Dameng\FreeSql.Provider.Dameng.csproj" />
<ProjectReference Include="..\..\Providers\FreeSql.Provider.KingbaseES\FreeSql.Provider.KingbaseES.csproj" />
<ProjectReference Include="..\..\Providers\FreeSql.Provider.MySqlConnector\FreeSql.Provider.MySqlConnector.csproj" />
<ProjectReference Include="..\..\Providers\FreeSql.Provider.Odbc\FreeSql.Provider.Odbc.csproj" />
<ProjectReference Include="..\..\Providers\FreeSql.Provider.Oracle\FreeSql.Provider.Oracle.csproj" />
<ProjectReference Include="..\..\Providers\FreeSql.Provider.PostgreSQL\FreeSql.Provider.PostgreSQL.csproj" />
<ProjectReference Include="..\..\Providers\FreeSql.Provider.ShenTong\FreeSql.Provider.ShenTong.csproj" />
Expand Down
3 changes: 2 additions & 1 deletion Extensions/FreeSql.Generator/RazorModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ public string GetColumnAttribute(DbColumnInfo col, bool isInsertValueSql = false
break;
case DataType.PostgreSQL:
case DataType.OdbcPostgreSQL:
case DataType.KingbaseES:
case DataType.OdbcKingbaseES:
case DataType.ShenTong:
switch (col.DbTypeTextFull.ToLower())
Expand Down Expand Up @@ -220,7 +221,7 @@ public string GetColumnDefaultValue(DbColumnInfo col, bool isInsertValueSql)
else if ((cstype == typeof(string) && defval.StartsWith("'") && defval.EndsWith("'::character varying") ||
cstype == typeof(Guid) && defval.StartsWith("'") && defval.EndsWith("'::uuid")
) && (fsql.Ado.DataType == DataType.PostgreSQL || fsql.Ado.DataType == DataType.OdbcPostgreSQL ||
fsql.Ado.DataType == DataType.OdbcKingbaseES ||
fsql.Ado.DataType == DataType.KingbaseES || fsql.Ado.DataType == DataType.OdbcKingbaseES ||
fsql.Ado.DataType == DataType.ShenTong))
{
defval = defval.Substring(1, defval.LastIndexOf("'::") - 1).Replace("''", "'");
Expand Down
1 change: 1 addition & 0 deletions FreeSql.DbContext/DbSet/DbSet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,7 @@ bool CanAdd(TEntity data, bool isThrow)
case DataType.OdbcSqlServer:
case DataType.PostgreSQL:
case DataType.OdbcPostgreSQL:
case DataType.KingbaseES:
case DataType.OdbcKingbaseES:
case DataType.ShenTong:
return true;
Expand Down
2 changes: 2 additions & 0 deletions FreeSql.DbContext/DbSet/DbSetAsync.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ async Task AddPrivAsync(TEntity data, bool isCheck)
case DataType.OdbcSqlServer:
case DataType.PostgreSQL:
case DataType.OdbcPostgreSQL:
case DataType.KingbaseES:
case DataType.OdbcKingbaseES:
case DataType.ShenTong:
if (_tableIdentitys.Length == 1 && _table.Primarys.Length == 1)
Expand Down Expand Up @@ -104,6 +105,7 @@ async public Task AddRangeAsync(IEnumerable<TEntity> data)
case DataType.OdbcSqlServer:
case DataType.PostgreSQL:
case DataType.OdbcPostgreSQL:
case DataType.KingbaseES:
case DataType.OdbcKingbaseES:
case DataType.ShenTong:
await DbContextFlushCommandAsync();
Expand Down
2 changes: 2 additions & 0 deletions FreeSql.DbContext/DbSet/DbSetSync.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ void AddPriv(TEntity data, bool isCheck)
case DataType.OdbcSqlServer:
case DataType.PostgreSQL:
case DataType.OdbcPostgreSQL:
case DataType.KingbaseES:
case DataType.OdbcKingbaseES:
case DataType.ShenTong:
if (_tableIdentitys.Length == 1)
Expand Down Expand Up @@ -108,6 +109,7 @@ public void AddRange(IEnumerable<TEntity> data)
case DataType.OdbcSqlServer:
case DataType.PostgreSQL:
case DataType.OdbcPostgreSQL:
case DataType.KingbaseES:
case DataType.OdbcKingbaseES:
case DataType.ShenTong:
DbContextFlushCommand();
Expand Down
16 changes: 16 additions & 0 deletions FreeSql.DbContext/FreeSql.DbContext.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 10 additions & 6 deletions FreeSql.Tests/FreeSql.Tests/FreeSql.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
<ProjectReference Include="..\..\FreeSql.DbContext\FreeSql.DbContext.csproj" />
<ProjectReference Include="..\..\FreeSql\FreeSql.csproj" />
<ProjectReference Include="..\..\Providers\FreeSql.Provider.Dameng\FreeSql.Provider.Dameng.csproj" />
<ProjectReference Include="..\..\Providers\FreeSql.Provider.KingbaseES\FreeSql.Provider.KingbaseES.csproj" />
<ProjectReference Include="..\..\Providers\FreeSql.Provider.MsAccess\FreeSql.Provider.MsAccess.csproj" />
<ProjectReference Include="..\..\Providers\FreeSql.Provider.MySql\FreeSql.Provider.MySql.csproj" />
<ProjectReference Include="..\..\Providers\FreeSql.Provider.Oracle\FreeSql.Provider.Oracle.csproj" />
Expand All @@ -51,12 +52,15 @@
<Reference Include="DmProvider">
<HintPath>..\..\Providers\FreeSql.Provider.Dameng\lib\DmProvider\netstandard2.0\DmProvider.dll</HintPath>
</Reference>
<Reference Include="System.Data.OscarClient">
<HintPath>..\..\Providers\FreeSql.Provider.ShenTong\lib\System.Data.OscarClient.dll</HintPath>
</Reference>
<Reference Include="Mono.Security">
<HintPath>..\..\Providers\FreeSql.Provider.ShenTong\lib\Mono.Security.dll</HintPath>
</Reference>
<Reference Include="System.Data.OscarClient">
<HintPath>..\..\Providers\FreeSql.Provider.ShenTong\lib\System.Data.OscarClient.dll</HintPath>
</Reference>
<Reference Include="Mono.Security">
<HintPath>..\..\Providers\FreeSql.Provider.ShenTong\lib\Mono.Security.dll</HintPath>
</Reference>
<Reference Include="Kdbndp">
<HintPath>..\..\Providers\FreeSql.Provider.KingbaseES\lib\Kdbndp.dll</HintPath>
</Reference>
</ItemGroup>

</Project>
106 changes: 106 additions & 0 deletions FreeSql.Tests/FreeSql.Tests/KingbaseES/Curd/KingbaseESDeleteTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
using FreeSql.DataAnnotations;
using System;
using System.Collections.Generic;
using System.Linq;
using Xunit;

namespace FreeSql.Tests.KingbaseES
{
public class KingbaseESDeleteTest
{

IDelete<Topic> delete => g.kingbaseES.Delete<Topic>(); //��������

[Table(Name = "tb_topic22211")]
class Topic
{
[Column(IsIdentity = true, IsPrimary = true)]
public int Id { get; set; }
public int? Clicks { get; set; }
public TestTypeInfo Type { get; set; }
public string Title { get; set; }
public DateTime CreateTime { get; set; }
}

[Fact]
public void Dywhere()
{
Assert.Null(g.kingbaseES.Delete<Topic>().ToSql());
var sql = g.kingbaseES.Delete<Topic>(new[] { 1, 2 }).ToSql();
Assert.Equal("DELETE FROM \"TB_TOPIC22211\" WHERE (\"ID\" IN (1,2))", sql);

sql = g.kingbaseES.Delete<Topic>(new Topic { Id = 1, Title = "test" }).ToSql();
Assert.Equal("DELETE FROM \"TB_TOPIC22211\" WHERE (\"ID\" = 1)", sql);

sql = g.kingbaseES.Delete<Topic>(new[] { new Topic { Id = 1, Title = "test" }, new Topic { Id = 2, Title = "test" } }).ToSql();
Assert.Equal("DELETE FROM \"TB_TOPIC22211\" WHERE (\"ID\" IN (1,2))", sql);

sql = g.kingbaseES.Delete<Topic>(new { id = 1 }).ToSql();
Assert.Equal("DELETE FROM \"TB_TOPIC22211\" WHERE (\"ID\" = 1)", sql);

sql = g.kingbaseES.Delete<MultiPkTopic>(new[] { new { Id1 = 1, Id2 = 10 }, new { Id1 = 2, Id2 = 20 } }).ToSql();
Assert.Equal("DELETE FROM \"MULTIPKTOPIC\" WHERE (\"ID1\" = 1 AND \"ID2\" = 10 OR \"ID1\" = 2 AND \"ID2\" = 20)", sql);
}
class MultiPkTopic
{
[Column(IsPrimary = true)]
public int Id1 { get; set; }
[Column(IsPrimary = true)]
public int Id2 { get; set; }
public int Clicks { get; set; }
public string Title { get; set; }
public DateTime CreateTime { get; set; }
}

[Fact]
public void Where()
{
var sql = delete.Where(a => a.Id == 1).ToSql().Replace("\r\n", "");
Assert.Equal("DELETE FROM \"TB_TOPIC22211\" WHERE (\"ID\" = 1)", sql);

sql = delete.Where("id = :id", new { id = 1 }).ToSql().Replace("\r\n", "");
Assert.Equal("DELETE FROM \"TB_TOPIC22211\" WHERE (id = :id)", sql);

var item = new Topic { Id = 1, Title = "newtitle" };
sql = delete.Where(item).ToSql().Replace("\r\n", "");
Assert.Equal("DELETE FROM \"TB_TOPIC22211\" WHERE (\"ID\" = 1)", sql);

var items = new List<Topic>();
for (var a = 0; a < 10; a++) items.Add(new Topic { Id = a + 1, Title = $"newtitle{a}", Clicks = a * 100 });

sql = delete.Where(items).ToSql().Replace("\r\n", "");
Assert.Equal("DELETE FROM \"TB_TOPIC22211\" WHERE (\"ID\" IN (1,2,3,4,5,6,7,8,9,10))", sql);
}
[Fact]
public void ExecuteAffrows()
{

var id = g.kingbaseES.Insert<Topic>(new Topic { Title = "xxxx", CreateTime = DateTime.Now }).ExecuteIdentity();
Assert.Equal(1, delete.Where(a => a.Id == id).ExecuteAffrows());
}
[Fact]
public void ExecuteDeleted()
{

//var item = g.kingbaseES.Insert<Topic>(new Topic { Title = "xxxx", CreateTime = DateTime.Now }).ExecuteInserted();
//Assert.Equal(item[0].Id, delete.Where(a => a.Id == item[0].Id).ExecuteDeleted()[0].Id);
}

[Fact]
public void AsTable()
{
Assert.Null(g.kingbaseES.Delete<Topic>().ToSql());
var sql = g.kingbaseES.Delete<Topic>(new[] { 1, 2 }).AsTable(a => "TopicAsTable").ToSql();
Assert.Equal("DELETE FROM \"TOPICASTABLE\" WHERE (\"ID\" IN (1,2))", sql);

sql = g.kingbaseES.Delete<Topic>(new Topic { Id = 1, Title = "test" }).AsTable(a => "TopicAsTable").ToSql();
Assert.Equal("DELETE FROM \"TOPICASTABLE\" WHERE (\"ID\" = 1)", sql);

sql = g.kingbaseES.Delete<Topic>(new[] { new Topic { Id = 1, Title = "test" }, new Topic { Id = 2, Title = "test" } }).AsTable(a => "TopicAsTable").ToSql();
Assert.Equal("DELETE FROM \"TOPICASTABLE\" WHERE (\"ID\" IN (1,2))", sql);

sql = g.kingbaseES.Delete<Topic>(new { id = 1 }).AsTable(a => "TopicAsTable").ToSql();
Assert.Equal("DELETE FROM \"TOPICASTABLE\" WHERE (\"ID\" = 1)", sql);
}
}
}
Loading

0 comments on commit f7ce4dc

Please sign in to comment.