mirror of
https://github.com/nsnail/FreeSql.git
synced 2025-06-17 19:43:21 +08:00
## v0.9.17 (ODBC)
- 增加 FreeSql.Provider.Odbc,实现 Oracle/SqlServer/MySql 的 Odbc 访问提供; - 增加 FreeSqlBuilder.UseConnectionString 参数 providerType,可解决因包版本冲突时,可能无法反射获得 FreeSql.Provider 对应的类型,通常这个参数不需要设置; - 优化 MaxLength 特性,当指定为 -1 时 DbType 会分别映射类型 text/nvarchar(max)/nvarchar2(4000);
This commit is contained in:
parent
8d92ccd751
commit
f434418b2c
@ -1,8 +1,8 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
<TargetFramework>netcoreapp2.2</TargetFramework>
|
||||
<TargetFramework>netcoreapp2.1</TargetFramework>
|
||||
</PropertyGroup>
|
||||
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
|
||||
|
@ -2,7 +2,7 @@
|
||||
|
||||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
<TargetFramework>netcoreapp2.2</TargetFramework>
|
||||
<TargetFramework>netcoreapp2.1</TargetFramework>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
@ -2,7 +2,7 @@
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFrameworks>netstandard2.0</TargetFrameworks>
|
||||
<Version>0.9.16</Version>
|
||||
<Version>0.9.17</Version>
|
||||
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
|
||||
<Authors>YeXiangQin</Authors>
|
||||
<Description>BaseEntity 是一种极简单的 CodeFirst 开发方式,特别对单表或多表CRUD,利用继承节省了每个实体类的重复属性(创建时间、ID等字段),软件删除等功能,进行 crud 操作时不必时常考虑仓储的使用.</Description>
|
||||
|
@ -2,7 +2,7 @@
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFrameworks>netstandard2.0;net45</TargetFrameworks>
|
||||
<Version>0.9.16</Version>
|
||||
<Version>0.9.17</Version>
|
||||
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
|
||||
<Authors>YeXiangQin</Authors>
|
||||
<Description>FreeSql 扩展包,可实现实体类属性为对象时,以JSON形式映射存储.</Description>
|
||||
|
@ -2,7 +2,7 @@
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFrameworks>netstandard2.0;net45</TargetFrameworks>
|
||||
<Version>0.9.16</Version>
|
||||
<Version>0.9.17</Version>
|
||||
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
|
||||
<Authors>YeXiangQin</Authors>
|
||||
<Description>FreeSql 扩展包,可实现【延时加载】属性.</Description>
|
||||
|
@ -2,7 +2,7 @@
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFrameworks>netstandard2.0;net45</TargetFrameworks>
|
||||
<Version>0.9.16</Version>
|
||||
<Version>0.9.17</Version>
|
||||
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
|
||||
<Authors>YeXiangQin</Authors>
|
||||
<Description>FreeSql is the most convenient ORM in dotnet. It supports Mysql, Postgresql, SqlServer, Oracle and Sqlite.</Description>
|
||||
|
@ -2,7 +2,7 @@
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFrameworks>netstandard2.0;net45</TargetFrameworks>
|
||||
<Version>0.9.16</Version>
|
||||
<Version>0.9.17</Version>
|
||||
<Authors>YeXiangQin</Authors>
|
||||
<Description>FreeSql Implementation of General Repository, Support MySql/SqlServer/PostgreSQL/Oracle/Sqlite, and read/write separation、and split table.</Description>
|
||||
<PackageProjectUrl>https://github.com/2881099/FreeSql/wiki/Repository</PackageProjectUrl>
|
||||
|
@ -1,7 +1,7 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>netcoreapp2.2</TargetFramework>
|
||||
<TargetFramework>netcoreapp2.1</TargetFramework>
|
||||
|
||||
<IsPackable>false</IsPackable>
|
||||
</PropertyGroup>
|
||||
|
@ -0,0 +1,22 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>netcoreapp2.1</TargetFramework>
|
||||
|
||||
<IsPackable>false</IsPackable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.9.0" />
|
||||
<PackageReference Include="xunit" Version="2.4.0" />
|
||||
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.0" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\Extensions\FreeSql.Extensions.LazyLoading\FreeSql.Extensions.LazyLoading.csproj" />
|
||||
<ProjectReference Include="..\..\FreeSql.DbContext\FreeSql.DbContext.csproj" />
|
||||
<ProjectReference Include="..\..\FreeSql\FreeSql.csproj" />
|
||||
<ProjectReference Include="..\..\Providers\FreeSql.Provider.Odbc\FreeSql.Provider.Odbc.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
@ -0,0 +1,96 @@
|
||||
using FreeSql.DataAnnotations;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Xunit;
|
||||
|
||||
namespace FreeSql.Tests.Odbc.MySql
|
||||
{
|
||||
public class MySqlDeleteTest
|
||||
{
|
||||
|
||||
IDelete<Topic> delete => g.mysql.Delete<Topic>(); //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
|
||||
[Table(Name = "tb_topic")]
|
||||
class Topic
|
||||
{
|
||||
[Column(IsIdentity = true, IsPrimary = true)]
|
||||
public int Id { get; set; }
|
||||
public int Clicks { get; set; }
|
||||
public string Title { get; set; }
|
||||
public DateTime CreateTime { get; set; }
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Dywhere()
|
||||
{
|
||||
Assert.Null(g.mysql.Delete<Topic>().ToSql());
|
||||
var sql = g.mysql.Delete<Topic>(new[] { 1, 2 }).ToSql();
|
||||
Assert.Equal("DELETE FROM `tb_topic` WHERE (`Id` = 1 OR `Id` = 2)", sql);
|
||||
|
||||
sql = g.mysql.Delete<Topic>(new Topic { Id = 1, Title = "test" }).ToSql();
|
||||
Assert.Equal("DELETE FROM `tb_topic` WHERE (`Id` = 1)", sql);
|
||||
|
||||
sql = g.mysql.Delete<Topic>(new[] { new Topic { Id = 1, Title = "test" }, new Topic { Id = 2, Title = "test" } }).ToSql();
|
||||
Assert.Equal("DELETE FROM `tb_topic` WHERE (`Id` = 1 OR `Id` = 2)", sql);
|
||||
|
||||
sql = g.mysql.Delete<Topic>(new { id = 1 }).ToSql();
|
||||
Assert.Equal("DELETE FROM `tb_topic` WHERE (`Id` = 1)", sql);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Where()
|
||||
{
|
||||
var sql = delete.Where(a => a.Id == 1).ToSql().Replace("\r\n", "");
|
||||
Assert.Equal("DELETE FROM `tb_topic` WHERE (`Id` = 1)", sql);
|
||||
|
||||
sql = delete.Where("id = @id", new { id = 1 }).ToSql().Replace("\r\n", "");
|
||||
Assert.Equal("DELETE FROM `tb_topic` 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_topic` 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_topic` WHERE (`Id` IN (1,2,3,4,5,6,7,8,9,10))", sql);
|
||||
}
|
||||
[Fact]
|
||||
public void WhereExists()
|
||||
{
|
||||
|
||||
}
|
||||
[Fact]
|
||||
public void ExecuteAffrows()
|
||||
{
|
||||
|
||||
var id = g.mysql.Insert<Topic>(new Topic { Title = "xxxx" }).ExecuteIdentity();
|
||||
Assert.Equal(1, delete.Where(a => a.Id == id).ExecuteAffrows());
|
||||
}
|
||||
[Fact]
|
||||
public void ExecuteDeleted()
|
||||
{
|
||||
|
||||
//delete.Where(a => a.Id > 0).ExecuteDeleted();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void AsTable()
|
||||
{
|
||||
Assert.Null(g.mysql.Delete<Topic>().ToSql());
|
||||
var sql = g.mysql.Delete<Topic>(new[] { 1, 2 }).AsTable(a => "TopicAsTable").ToSql();
|
||||
Assert.Equal("DELETE FROM `TopicAsTable` WHERE (`Id` = 1 OR `Id` = 2)", sql);
|
||||
|
||||
sql = g.mysql.Delete<Topic>(new Topic { Id = 1, Title = "test" }).AsTable(a => "TopicAsTable").ToSql();
|
||||
Assert.Equal("DELETE FROM `TopicAsTable` WHERE (`Id` = 1)", sql);
|
||||
|
||||
sql = g.mysql.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` = 1 OR `Id` = 2)", sql);
|
||||
|
||||
sql = g.mysql.Delete<Topic>(new { id = 1 }).AsTable(a => "TopicAsTable").ToSql();
|
||||
Assert.Equal("DELETE FROM `TopicAsTable` WHERE (`Id` = 1)", sql);
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,162 @@
|
||||
using FreeSql.DataAnnotations;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Xunit;
|
||||
|
||||
namespace FreeSql.Tests.Odbc.MySql
|
||||
{
|
||||
public class MySqlInsertTest
|
||||
{
|
||||
|
||||
IInsert<Topic> insert => g.mysql.Insert<Topic>(); //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
|
||||
[Table(Name = "tb_topic")]
|
||||
class Topic
|
||||
{
|
||||
[Column(IsIdentity = true, IsPrimary = true)]
|
||||
public int Id { get; set; }
|
||||
public int Clicks { get; set; }
|
||||
public string Title { get; set; }
|
||||
public DateTime CreateTime { get; set; }
|
||||
}
|
||||
class TestEnumInsertTb
|
||||
{
|
||||
[Column(IsIdentity = true)]
|
||||
public int id { get; set; }
|
||||
public TestEnumInserTbType type { get; set; }
|
||||
public DateTime time { get; set; } = new DateTime();
|
||||
}
|
||||
enum TestEnumInserTbType { str1, biggit, sum211 }
|
||||
|
||||
[Fact]
|
||||
public void AppendData()
|
||||
{
|
||||
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 });
|
||||
|
||||
var sql = insert.AppendData(items.First()).ToSql();
|
||||
Assert.Equal("INSERT INTO `tb_topic`(`Clicks`, `Title`, `CreateTime`) VALUES(0, 'newtitle0', '0001-01-01 00:00:00.000')", sql);
|
||||
|
||||
sql = insert.AppendData(items).ToSql();
|
||||
Assert.Equal("INSERT INTO `tb_topic`(`Clicks`, `Title`, `CreateTime`) VALUES(0, 'newtitle0', '0001-01-01 00:00:00.000'), (100, 'newtitle1', '0001-01-01 00:00:00.000'), (200, 'newtitle2', '0001-01-01 00:00:00.000'), (300, 'newtitle3', '0001-01-01 00:00:00.000'), (400, 'newtitle4', '0001-01-01 00:00:00.000'), (500, 'newtitle5', '0001-01-01 00:00:00.000'), (600, 'newtitle6', '0001-01-01 00:00:00.000'), (700, 'newtitle7', '0001-01-01 00:00:00.000'), (800, 'newtitle8', '0001-01-01 00:00:00.000'), (900, 'newtitle9', '0001-01-01 00:00:00.000')", sql);
|
||||
|
||||
sql = insert.AppendData(items).InsertColumns(a => a.Title).ToSql();
|
||||
Assert.Equal("INSERT INTO `tb_topic`(`Title`) VALUES('newtitle0'), ('newtitle1'), ('newtitle2'), ('newtitle3'), ('newtitle4'), ('newtitle5'), ('newtitle6'), ('newtitle7'), ('newtitle8'), ('newtitle9')", sql);
|
||||
|
||||
sql = insert.AppendData(items).IgnoreColumns(a => a.CreateTime).ToSql();
|
||||
Assert.Equal("INSERT INTO `tb_topic`(`Clicks`, `Title`) VALUES(0, 'newtitle0'), (100, 'newtitle1'), (200, 'newtitle2'), (300, 'newtitle3'), (400, 'newtitle4'), (500, 'newtitle5'), (600, 'newtitle6'), (700, 'newtitle7'), (800, 'newtitle8'), (900, 'newtitle9')", sql);
|
||||
|
||||
sql = g.mysql.Insert<TestEnumInsertTb>().AppendData(new TestEnumInsertTb { type = TestEnumInserTbType.sum211, time = DateTime.Parse("2019-09-19 21:26:51.030") }).ToSql();
|
||||
Assert.Equal("INSERT INTO `TestEnumInsertTb`(`type`, `time`) VALUES('sum211', '2019-09-19 21:26:51.030')", sql);
|
||||
|
||||
sql = g.mysql.Insert<TestEnumInsertTb>().AppendData(new TestEnumInsertTb { type = TestEnumInserTbType.sum211 }).NoneParameter().ToSql();
|
||||
Assert.Equal("INSERT INTO `TestEnumInsertTb`(`type`, `time`) VALUES('sum211', '0001-01-01 00:00:00.000')", sql);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void InsertColumns()
|
||||
{
|
||||
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 });
|
||||
|
||||
var sql = insert.AppendData(items).InsertColumns(a => a.Title).ToSql();
|
||||
Assert.Equal("INSERT INTO `tb_topic`(`Title`) VALUES('newtitle0'), ('newtitle1'), ('newtitle2'), ('newtitle3'), ('newtitle4'), ('newtitle5'), ('newtitle6'), ('newtitle7'), ('newtitle8'), ('newtitle9')", sql);
|
||||
|
||||
sql = insert.AppendData(items).InsertColumns(a => new { a.Title, a.Clicks }).ToSql();
|
||||
Assert.Equal("INSERT INTO `tb_topic`(`Clicks`, `Title`) VALUES(0, 'newtitle0'), (100, 'newtitle1'), (200, 'newtitle2'), (300, 'newtitle3'), (400, 'newtitle4'), (500, 'newtitle5'), (600, 'newtitle6'), (700, 'newtitle7'), (800, 'newtitle8'), (900, 'newtitle9')", sql);
|
||||
}
|
||||
[Fact]
|
||||
public void IgnoreColumns()
|
||||
{
|
||||
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 });
|
||||
|
||||
var sql = insert.AppendData(items).IgnoreColumns(a => a.CreateTime).ToSql();
|
||||
Assert.Equal("INSERT INTO `tb_topic`(`Clicks`, `Title`) VALUES(0, 'newtitle0'), (100, 'newtitle1'), (200, 'newtitle2'), (300, 'newtitle3'), (400, 'newtitle4'), (500, 'newtitle5'), (600, 'newtitle6'), (700, 'newtitle7'), (800, 'newtitle8'), (900, 'newtitle9')", sql);
|
||||
|
||||
sql = insert.AppendData(items).IgnoreColumns(a => new { a.Title, a.CreateTime }).ToSql();
|
||||
Assert.Equal("INSERT INTO `tb_topic`(`Clicks`) VALUES(0), (100), (200), (300), (400), (500), (600), (700), (800), (900)", sql);
|
||||
|
||||
g.mysql.Delete<TopicIgnore>().Where("1=1").ExecuteAffrows();
|
||||
var itemsIgnore = new List<TopicIgnore>();
|
||||
for (var a = 0; a < 2072; a++) itemsIgnore.Add(new TopicIgnore { Id = a + 1, Title = $"newtitle{a}", Clicks = a * 100, CreateTime = DateTime.Now });
|
||||
g.mysql.Insert<TopicIgnore>().AppendData(itemsIgnore).IgnoreColumns(a => new { a.Title }).ExecuteAffrows();
|
||||
Assert.Equal(2072, itemsIgnore.Count);
|
||||
Assert.Equal(2072, g.mysql.Select<TopicIgnore>().Where(a => a.Title == null).Count());
|
||||
}
|
||||
[Table(Name = "tb_topicIgnoreColumns")]
|
||||
class TopicIgnore
|
||||
{
|
||||
[Column(IsIdentity = true, IsPrimary = true)]
|
||||
public int Id { get; set; }
|
||||
public int Clicks { get; set; }
|
||||
public string Title { get; set; }
|
||||
public DateTime CreateTime { get; set; }
|
||||
}
|
||||
[Fact]
|
||||
public void ExecuteAffrows()
|
||||
{
|
||||
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, CreateTime = DateTime.Now });
|
||||
|
||||
Assert.Equal(1, insert.AppendData(items.First()).ExecuteAffrows());
|
||||
Assert.Equal(10, insert.AppendData(items).ExecuteAffrows());
|
||||
|
||||
Assert.Equal(1, g.mysql.Insert<TestEnumInsertTb>().AppendData(new TestEnumInsertTb { type = TestEnumInserTbType.sum211 }).ExecuteAffrows());
|
||||
Assert.Equal(1, g.mysql.Insert<TestEnumInsertTb>().AppendData(new TestEnumInsertTb { type = TestEnumInserTbType.sum211 }).NoneParameter().ExecuteAffrows());
|
||||
}
|
||||
[Fact]
|
||||
public void ExecuteIdentity()
|
||||
{
|
||||
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 });
|
||||
|
||||
Assert.NotEqual(0, insert.AppendData(items.First()).ExecuteIdentity());
|
||||
|
||||
var id = g.mysql.Insert<TestEnumInsertTb>().AppendData(new TestEnumInsertTb { type = TestEnumInserTbType.sum211 }).ExecuteIdentity();
|
||||
Assert.Equal(TestEnumInserTbType.sum211, g.mysql.Select<TestEnumInsertTb>().Where(a => a.id == id).First()?.type);
|
||||
id = g.mysql.Insert<TestEnumInsertTb>().AppendData(new TestEnumInsertTb { type = TestEnumInserTbType.sum211 }).NoneParameter().ExecuteIdentity();
|
||||
Assert.Equal(TestEnumInserTbType.sum211, g.mysql.Select<TestEnumInsertTb>().Where(a => a.id == id).First()?.type);
|
||||
}
|
||||
[Fact]
|
||||
public void ExecuteInserted()
|
||||
{
|
||||
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 });
|
||||
|
||||
//insert.AppendData(items.First()).ExecuteInserted();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void AsTable()
|
||||
{
|
||||
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 });
|
||||
|
||||
var sql = insert.AppendData(items.First()).AsTable(a => "Topic_InsertAsTable").ToSql();
|
||||
Assert.Equal("INSERT INTO `Topic_InsertAsTable`(`Clicks`, `Title`, `CreateTime`) VALUES(0, 'newTitle0', '0001-01-01 00:00:00.000')", sql);
|
||||
|
||||
sql = insert.AppendData(items).AsTable(a => "Topic_InsertAsTable").ToSql();
|
||||
Assert.Equal("INSERT INTO `Topic_InsertAsTable`(`Clicks`, `Title`, `CreateTime`) VALUES(0, 'newTitle0', '0001-01-01 00:00:00.000'), (100, 'newTitle1', '0001-01-01 00:00:00.000'), (200, 'newTitle2', '0001-01-01 00:00:00.000'), (300, 'newTitle3', '0001-01-01 00:00:00.000'), (400, 'newTitle4', '0001-01-01 00:00:00.000'), (500, 'newTitle5', '0001-01-01 00:00:00.000'), (600, 'newTitle6', '0001-01-01 00:00:00.000'), (700, 'newTitle7', '0001-01-01 00:00:00.000'), (800, 'newTitle8', '0001-01-01 00:00:00.000'), (900, 'newTitle9', '0001-01-01 00:00:00.000')", sql);
|
||||
|
||||
sql = insert.AppendData(items).InsertColumns(a => a.Title).AsTable(a => "Topic_InsertAsTable").ToSql();
|
||||
Assert.Equal("INSERT INTO `Topic_InsertAsTable`(`Title`) VALUES('newTitle0'), ('newTitle1'), ('newTitle2'), ('newTitle3'), ('newTitle4'), ('newTitle5'), ('newTitle6'), ('newTitle7'), ('newTitle8'), ('newTitle9')", sql);
|
||||
|
||||
sql = insert.AppendData(items).IgnoreColumns(a => a.CreateTime).AsTable(a => "Topic_InsertAsTable").ToSql();
|
||||
Assert.Equal("INSERT INTO `Topic_InsertAsTable`(`Clicks`, `Title`) VALUES(0, 'newTitle0'), (100, 'newTitle1'), (200, 'newTitle2'), (300, 'newTitle3'), (400, 'newTitle4'), (500, 'newTitle5'), (600, 'newTitle6'), (700, 'newTitle7'), (800, 'newTitle8'), (900, 'newTitle9')", sql);
|
||||
|
||||
sql = insert.AppendData(items).InsertColumns(a => a.Title).AsTable(a => "Topic_InsertAsTable").ToSql();
|
||||
Assert.Equal("INSERT INTO `Topic_InsertAsTable`(`Title`) VALUES('newTitle0'), ('newTitle1'), ('newTitle2'), ('newTitle3'), ('newTitle4'), ('newTitle5'), ('newTitle6'), ('newTitle7'), ('newTitle8'), ('newTitle9')", sql);
|
||||
|
||||
sql = insert.AppendData(items).InsertColumns(a => new { a.Title, a.Clicks }).AsTable(a => "Topic_InsertAsTable").ToSql();
|
||||
Assert.Equal("INSERT INTO `Topic_InsertAsTable`(`Clicks`, `Title`) VALUES(0, 'newTitle0'), (100, 'newTitle1'), (200, 'newTitle2'), (300, 'newTitle3'), (400, 'newTitle4'), (500, 'newTitle5'), (600, 'newTitle6'), (700, 'newTitle7'), (800, 'newTitle8'), (900, 'newTitle9')", sql);
|
||||
|
||||
sql = insert.AppendData(items).IgnoreColumns(a => a.CreateTime).AsTable(a => "Topic_InsertAsTable").ToSql();
|
||||
Assert.Equal("INSERT INTO `Topic_InsertAsTable`(`Clicks`, `Title`) VALUES(0, 'newTitle0'), (100, 'newTitle1'), (200, 'newTitle2'), (300, 'newTitle3'), (400, 'newTitle4'), (500, 'newTitle5'), (600, 'newTitle6'), (700, 'newTitle7'), (800, 'newTitle8'), (900, 'newTitle9')", sql);
|
||||
|
||||
sql = insert.AppendData(items).IgnoreColumns(a => new { a.Title, a.CreateTime }).AsTable(a => "Topic_InsertAsTable").ToSql();
|
||||
Assert.Equal("INSERT INTO `Topic_InsertAsTable`(`Clicks`) VALUES(0), (100), (200), (300), (400), (500), (600), (700), (800), (900)", sql);
|
||||
}
|
||||
}
|
||||
}
|
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,210 @@
|
||||
using FreeSql.DataAnnotations;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Xunit;
|
||||
|
||||
namespace FreeSql.Tests.Odbc.MySql
|
||||
{
|
||||
public class MySqlUpdateTest
|
||||
{
|
||||
IUpdate<Topic> update => g.mysql.Update<Topic>();
|
||||
|
||||
[Table(Name = "tb_topic")]
|
||||
class Topic
|
||||
{
|
||||
[Column(IsIdentity = true, IsPrimary = true)]
|
||||
public int Id { get; set; }
|
||||
public int? Clicks { get; set; }
|
||||
public string Title { get; set; }
|
||||
public DateTime CreateTime { get; set; }
|
||||
}
|
||||
class TestEnumUpdateTb
|
||||
{
|
||||
[Column(IsIdentity = true)]
|
||||
public int id { get; set; }
|
||||
public TestEnumUpdateTbType type { get; set; }
|
||||
public DateTime time { get; set; } = new DateTime();
|
||||
}
|
||||
enum TestEnumUpdateTbType { str1, biggit, sum211 }
|
||||
|
||||
[Fact]
|
||||
public void Dywhere()
|
||||
{
|
||||
Assert.Null(g.mysql.Update<Topic>().ToSql());
|
||||
Assert.Equal("UPDATE `tb_topic` SET title='test' \r\nWHERE (`Id` = 1 OR `Id` = 2)", g.mysql.Update<Topic>(new[] { 1, 2 }).SetRaw("title='test'").ToSql());
|
||||
Assert.Equal("UPDATE `tb_topic` SET title='test1' \r\nWHERE (`Id` = 1)", g.mysql.Update<Topic>(new Topic { Id = 1, Title = "test" }).SetRaw("title='test1'").ToSql());
|
||||
Assert.Equal("UPDATE `tb_topic` SET title='test1' \r\nWHERE (`Id` = 1 OR `Id` = 2)", g.mysql.Update<Topic>(new[] { new Topic { Id = 1, Title = "test" }, new Topic { Id = 2, Title = "test" } }).SetRaw("title='test1'").ToSql());
|
||||
Assert.Equal("UPDATE `tb_topic` SET title='test1' \r\nWHERE (`Id` = 1)", g.mysql.Update<Topic>(new { id = 1 }).SetRaw("title='test1'").ToSql());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void SetSource()
|
||||
{
|
||||
var sql = update.SetSource(new Topic { Id = 1, Title = "newtitle" }).ToSql().Replace("\r\n", "");
|
||||
Assert.Equal("UPDATE `tb_topic` SET `Clicks` = NULL, `Title` = 'newtitle', `CreateTime` = '0001-01-01 00:00:00.000' 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 });
|
||||
items[0].Clicks = null;
|
||||
|
||||
sql = update.SetSource(items).ToSql().Replace("\r\n", "");
|
||||
Assert.Equal("UPDATE `tb_topic` SET `Clicks` = CASE `Id` WHEN 1 THEN NULL WHEN 2 THEN 100 WHEN 3 THEN 200 WHEN 4 THEN 300 WHEN 5 THEN 400 WHEN 6 THEN 500 WHEN 7 THEN 600 WHEN 8 THEN 700 WHEN 9 THEN 800 WHEN 10 THEN 900 END, `Title` = CASE `Id` WHEN 1 THEN 'newtitle0' WHEN 2 THEN 'newtitle1' WHEN 3 THEN 'newtitle2' WHEN 4 THEN 'newtitle3' WHEN 5 THEN 'newtitle4' WHEN 6 THEN 'newtitle5' WHEN 7 THEN 'newtitle6' WHEN 8 THEN 'newtitle7' WHEN 9 THEN 'newtitle8' WHEN 10 THEN 'newtitle9' END, `CreateTime` = CASE `Id` WHEN 1 THEN '0001-01-01 00:00:00.000' WHEN 2 THEN '0001-01-01 00:00:00.000' WHEN 3 THEN '0001-01-01 00:00:00.000' WHEN 4 THEN '0001-01-01 00:00:00.000' WHEN 5 THEN '0001-01-01 00:00:00.000' WHEN 6 THEN '0001-01-01 00:00:00.000' WHEN 7 THEN '0001-01-01 00:00:00.000' WHEN 8 THEN '0001-01-01 00:00:00.000' WHEN 9 THEN '0001-01-01 00:00:00.000' WHEN 10 THEN '0001-01-01 00:00:00.000' END WHERE (`Id` IN (1,2,3,4,5,6,7,8,9,10))", sql);
|
||||
|
||||
sql = update.SetSource(items).IgnoreColumns(a => new { a.Clicks, a.CreateTime }).ToSql().Replace("\r\n", "");
|
||||
Assert.Equal("UPDATE `tb_topic` SET `Title` = CASE `Id` WHEN 1 THEN 'newtitle0' WHEN 2 THEN 'newtitle1' WHEN 3 THEN 'newtitle2' WHEN 4 THEN 'newtitle3' WHEN 5 THEN 'newtitle4' WHEN 6 THEN 'newtitle5' WHEN 7 THEN 'newtitle6' WHEN 8 THEN 'newtitle7' WHEN 9 THEN 'newtitle8' WHEN 10 THEN 'newtitle9' END WHERE (`Id` IN (1,2,3,4,5,6,7,8,9,10))", sql);
|
||||
|
||||
sql = update.SetSource(items).Set(a => a.CreateTime, new DateTime(2020, 1, 1)).ToSql().Replace("\r\n", "");
|
||||
Assert.Equal("UPDATE `tb_topic` SET `CreateTime` = '2020-01-01 00:00:00.000' WHERE (`Id` IN (1,2,3,4,5,6,7,8,9,10))", sql);
|
||||
|
||||
sql = g.mysql.Insert<TestEnumUpdateTb>().AppendData(new TestEnumUpdateTb { type = TestEnumUpdateTbType.sum211 }).ToSql().Replace("\r\n", "");
|
||||
Assert.Equal("INSERT INTO `TestEnumUpdateTb`(`type`, `time`) VALUES('sum211', '0001-01-01 00:00:00.000')", sql);
|
||||
var id = g.mysql.Insert<TestEnumUpdateTb>().AppendData(new TestEnumUpdateTb { type = TestEnumUpdateTbType.sum211 }).ExecuteIdentity();
|
||||
Assert.True(id > 0);
|
||||
Assert.Equal(TestEnumUpdateTbType.sum211, g.mysql.Select<TestEnumUpdateTb>().Where(a => a.id == id).First()?.type);
|
||||
|
||||
sql = g.mysql.Update<TestEnumUpdateTb>().SetSource(new TestEnumUpdateTb { type = TestEnumUpdateTbType.sum211 }).ToSql().Replace("\r\n", "");
|
||||
Assert.Equal("UPDATE `TestEnumUpdateTb` SET `type` = 'sum211', `time` = '0001-01-01 00:00:00.000' WHERE (`id` = 0)", sql);
|
||||
g.mysql.Update<TestEnumUpdateTb>().SetSource(new TestEnumUpdateTb { id = (int)id, type = TestEnumUpdateTbType.biggit }).ExecuteAffrows();
|
||||
Assert.Equal(TestEnumUpdateTbType.biggit, g.mysql.Select<TestEnumUpdateTb>().Where(a => a.id == id).First()?.type);
|
||||
|
||||
sql = g.mysql.Insert<TestEnumUpdateTb>().NoneParameter().AppendData(new TestEnumUpdateTb { type = TestEnumUpdateTbType.sum211 }).ToSql().Replace("\r\n", "");
|
||||
Assert.Equal("INSERT INTO `TestEnumUpdateTb`(`type`, `time`) VALUES('sum211', '0001-01-01 00:00:00.000')", sql);
|
||||
id = g.mysql.Insert<TestEnumUpdateTb>().NoneParameter().AppendData(new TestEnumUpdateTb { type = TestEnumUpdateTbType.sum211 }).ExecuteIdentity();
|
||||
Assert.True(id > 0);
|
||||
Assert.Equal(TestEnumUpdateTbType.sum211, g.mysql.Select<TestEnumUpdateTb>().Where(a => a.id == id).First()?.type);
|
||||
|
||||
sql = g.mysql.Update<TestEnumUpdateTb>().NoneParameter().SetSource(new TestEnumUpdateTb { type = TestEnumUpdateTbType.sum211 }).ToSql().Replace("\r\n", "");
|
||||
Assert.Equal("UPDATE `TestEnumUpdateTb` SET `type` = 'sum211', `time` = '0001-01-01 00:00:00.000' WHERE (`id` = 0)", sql);
|
||||
g.mysql.Update<TestEnumUpdateTb>().NoneParameter().SetSource(new TestEnumUpdateTb { id = (int)id, type = TestEnumUpdateTbType.biggit }).ExecuteAffrows();
|
||||
Assert.Equal(TestEnumUpdateTbType.biggit, g.mysql.Select<TestEnumUpdateTb>().Where(a => a.id == id).First()?.type);
|
||||
}
|
||||
[Fact]
|
||||
public void IgnoreColumns()
|
||||
{
|
||||
var sql = update.SetSource(new Topic { Id = 1, Title = "newtitle" }).IgnoreColumns(a => new { a.Clicks, a.CreateTime }).ToSql().Replace("\r\n", "");
|
||||
Assert.Equal("UPDATE `tb_topic` SET `Title` = 'newtitle' WHERE (`Id` = 1)", sql);
|
||||
|
||||
sql = g.mysql.Update<TestEnumUpdateTb>().SetSource(new TestEnumUpdateTb { type = TestEnumUpdateTbType.sum211 }).IgnoreColumns(a => a.time).ToSql().Replace("\r\n", "");
|
||||
Assert.Equal("UPDATE `TestEnumUpdateTb` SET `type` = 'sum211' WHERE (`id` = 0)", sql);
|
||||
|
||||
sql = g.mysql.Update<TestEnumUpdateTb>().NoneParameter().SetSource(new TestEnumUpdateTb { type = TestEnumUpdateTbType.sum211 }).IgnoreColumns(a => a.time).ToSql().Replace("\r\n", "");
|
||||
Assert.Equal("UPDATE `TestEnumUpdateTb` SET `type` = 'sum211' WHERE (`id` = 0)", sql);
|
||||
}
|
||||
[Fact]
|
||||
public void UpdateColumns()
|
||||
{
|
||||
var sql = update.SetSource(new Topic { Id = 1, Title = "newtitle" }).UpdateColumns(a => a.Title).ToSql().Replace("\r\n", "");
|
||||
Assert.Equal("UPDATE `tb_topic` SET `Title` = 'newtitle' WHERE (`Id` = 1)", sql);
|
||||
|
||||
sql = g.mysql.Update<TestEnumUpdateTb>().SetSource(new TestEnumUpdateTb { type = TestEnumUpdateTbType.sum211 }).UpdateColumns(a => a.type).ToSql().Replace("\r\n", "");
|
||||
Assert.Equal("UPDATE `TestEnumUpdateTb` SET `type` = 'sum211' WHERE (`id` = 0)", sql);
|
||||
|
||||
sql = g.mysql.Update<TestEnumUpdateTb>().NoneParameter().SetSource(new TestEnumUpdateTb { type = TestEnumUpdateTbType.sum211 }).UpdateColumns(a => a.type).ToSql().Replace("\r\n", "");
|
||||
Assert.Equal("UPDATE `TestEnumUpdateTb` SET `type` = 'sum211' WHERE (`id` = 0)", sql);
|
||||
}
|
||||
[Fact]
|
||||
public void Set()
|
||||
{
|
||||
var sql = update.Where(a => a.Id == 1).Set(a => a.Title, "newtitle").ToSql().Replace("\r\n", "");
|
||||
Assert.Equal("UPDATE `tb_topic` SET `Title` = 'newtitle' WHERE (`Id` = 1)", sql);
|
||||
|
||||
sql = update.Where(a => a.Id == 1).Set(a => a.Title, "newtitle").Set(a => a.CreateTime, new DateTime(2020, 1, 1)).ToSql().Replace("\r\n", "");
|
||||
Assert.Equal("UPDATE `tb_topic` SET `Title` = 'newtitle', `CreateTime` = '2020-01-01 00:00:00.000' WHERE (`Id` = 1)", sql);
|
||||
|
||||
sql = update.Set(a => a.Clicks * 10 / 1).Where(a => a.Id == 1).ToSql().Replace("\r\n", "");
|
||||
Assert.Equal("UPDATE `tb_topic` SET `Clicks` = ifnull(`Clicks`, 0) * 10 div 1 WHERE (`Id` = 1)", sql);
|
||||
|
||||
sql = update.Set(a => a.Id - 10).Where(a => a.Id == 1).ToSql().Replace("\r\n", "");
|
||||
Assert.Equal("UPDATE `tb_topic` SET `Id` = (`Id` - 10) WHERE (`Id` = 1)", sql);
|
||||
|
||||
int incrv = 10;
|
||||
sql = update.Set(a => a.Clicks * incrv / 1).Where(a => a.Id == 1).ToSql().Replace("\r\n", "");
|
||||
Assert.Equal("UPDATE `tb_topic` SET `Clicks` = ifnull(`Clicks`, 0) * 10 div 1 WHERE (`Id` = 1)", sql);
|
||||
|
||||
sql = update.Set(a => a.Id - incrv).Where(a => a.Id == 1).ToSql().Replace("\r\n", "");
|
||||
Assert.Equal("UPDATE `tb_topic` SET `Id` = (`Id` - 10) WHERE (`Id` = 1)", sql);
|
||||
|
||||
sql = update.Set(a => a.Clicks == a.Clicks * 10 / 1).Where(a => a.Id == 1).ToSql().Replace("\r\n", "");
|
||||
Assert.Equal("UPDATE `tb_topic` SET `Clicks` = `Clicks` * 10 div 1 WHERE (`Id` = 1)", sql);
|
||||
|
||||
sql = update.Set(a => a.Id == 10).Where(a => a.Id == 1).ToSql().Replace("\r\n", "");
|
||||
Assert.Equal("UPDATE `tb_topic` SET `Id` = 10 WHERE (`Id` = 1)", sql);
|
||||
|
||||
var id = g.mysql.Insert<TestEnumUpdateTb>().AppendData(new TestEnumUpdateTb { type = TestEnumUpdateTbType.sum211 }).ExecuteIdentity();
|
||||
Assert.True(id > 0);
|
||||
sql = g.mysql.Update<TestEnumUpdateTb>().Where(a => a.id == id).Set(a => a.type, TestEnumUpdateTbType.biggit).ToSql().Replace("\r\n", "");
|
||||
Assert.Equal($"UPDATE `TestEnumUpdateTb` SET `type` = 'biggit' WHERE (`id` = {id})", sql);
|
||||
g.mysql.Update<TestEnumUpdateTb>().Where(a => a.id == id).Set(a => a.type, TestEnumUpdateTbType.biggit).ExecuteAffrows();
|
||||
Assert.Equal(TestEnumUpdateTbType.biggit, g.mysql.Select<TestEnumUpdateTb>().Where(a => a.id == id).First()?.type);
|
||||
|
||||
sql = g.mysql.Update<TestEnumUpdateTb>().NoneParameter().Where(a => a.id == id).Set(a => a.type, TestEnumUpdateTbType.str1).ToSql().Replace("\r\n", "");
|
||||
Assert.Equal($"UPDATE `TestEnumUpdateTb` SET `type` = 'str1' WHERE (`id` = {id})", sql);
|
||||
g.mysql.Update<TestEnumUpdateTb>().NoneParameter().Where(a => a.id == id).Set(a => a.type, TestEnumUpdateTbType.str1).ExecuteAffrows();
|
||||
Assert.Equal(TestEnumUpdateTbType.str1, g.mysql.Select<TestEnumUpdateTb>().Where(a => a.id == id).First()?.type);
|
||||
}
|
||||
[Fact]
|
||||
public void SetRaw()
|
||||
{
|
||||
var sql = update.Where(a => a.Id == 1).SetRaw("clicks = clicks + ?", new { incrClick = 1 }).ToSql().Replace("\r\n", "");
|
||||
Assert.Equal("UPDATE `tb_topic` SET clicks = clicks + ? WHERE (`Id` = 1)", sql);
|
||||
|
||||
sql = g.mysql.Update<TestEnumUpdateTb>().NoneParameter().Where(a => a.id == 0).SetRaw("`type` = {0}".FormatOdbcMySql(TestEnumUpdateTbType.sum211)).ToSql().Replace("\r\n", "");
|
||||
Assert.Equal("UPDATE `TestEnumUpdateTb` SET `type` = 'sum211' WHERE (`id` = 0)", sql);
|
||||
}
|
||||
[Fact]
|
||||
public void Where()
|
||||
{
|
||||
var sql = update.Where(a => a.Id == 1).SetRaw("title='newtitle'").ToSql().Replace("\r\n", "");
|
||||
Assert.Equal("UPDATE `tb_topic` SET title='newtitle' WHERE (`Id` = 1)", sql);
|
||||
|
||||
sql = update.Where("id = ?", new { id = 1 }).SetRaw("title='newtitle'").ToSql().Replace("\r\n", "");
|
||||
Assert.Equal("UPDATE `tb_topic` SET title='newtitle' WHERE (id = ?)", sql);
|
||||
|
||||
var item = new Topic { Id = 1, Title = "newtitle" };
|
||||
sql = update.Where(item).SetRaw("title='newtitle'").ToSql().Replace("\r\n", "");
|
||||
Assert.Equal("UPDATE `tb_topic` SET title='newtitle' 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 = update.Where(items).SetRaw("title='newtitle'").ToSql().Replace("\r\n", "");
|
||||
Assert.Equal("UPDATE `tb_topic` SET title='newtitle' WHERE (`Id` IN (1,2,3,4,5,6,7,8,9,10))", sql);
|
||||
|
||||
sql = g.mysql.Update<TestEnumUpdateTb>().NoneParameter().Where(a => a.id == 0 && a.type == TestEnumUpdateTbType.str1)
|
||||
.Set(a => a.type, TestEnumUpdateTbType.sum211).ToSql().Replace("\r\n", "");
|
||||
Assert.Equal("UPDATE `TestEnumUpdateTb` SET `type` = 'sum211' WHERE (`id` = 0 AND `type` = 'str1')", sql);
|
||||
}
|
||||
[Fact]
|
||||
public void WhereExists()
|
||||
{
|
||||
|
||||
}
|
||||
[Fact]
|
||||
public void ExecuteAffrows()
|
||||
{
|
||||
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 });
|
||||
|
||||
var time = DateTime.Now;
|
||||
var items222 = g.mysql.Select<Topic>().Where(a => a.CreateTime > time).Limit(10).ToList();
|
||||
|
||||
update.SetSource(items.First()).NoneParameter().ExecuteAffrows();
|
||||
update.SetSource(items).NoneParameter().ExecuteAffrows();
|
||||
}
|
||||
[Fact]
|
||||
public void ExecuteUpdated()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void AsTable()
|
||||
{
|
||||
Assert.Null(g.mysql.Update<Topic>().ToSql());
|
||||
Assert.Equal("UPDATE `tb_topicAsTable` SET title='test' \r\nWHERE (`Id` = 1 OR `Id` = 2)", g.mysql.Update<Topic>(new[] { 1, 2 }).SetRaw("title='test'").AsTable(a => "tb_topicAsTable").ToSql());
|
||||
Assert.Equal("UPDATE `tb_topicAsTable` SET title='test1' \r\nWHERE (`Id` = 1)", g.mysql.Update<Topic>(new Topic { Id = 1, Title = "test" }).SetRaw("title='test1'").AsTable(a => "tb_topicAsTable").ToSql());
|
||||
Assert.Equal("UPDATE `tb_topicAsTable` SET title='test1' \r\nWHERE (`Id` = 1 OR `Id` = 2)", g.mysql.Update<Topic>(new[] { new Topic { Id = 1, Title = "test" }, new Topic { Id = 2, Title = "test" } }).SetRaw("title='test1'").AsTable(a => "tb_topicAsTable").ToSql());
|
||||
Assert.Equal("UPDATE `tb_topicAsTable` SET title='test1' \r\nWHERE (`Id` = 1)", g.mysql.Update<Topic>(new { id = 1 }).SetRaw("title='test1'").AsTable(a => "tb_topicAsTable").ToSql());
|
||||
}
|
||||
}
|
||||
}
|
File diff suppressed because it is too large
Load Diff
1130
FreeSql.Tests/FreeSql.Tests.Provider.Odbc/MySql/MapType/BoolTest.cs
Normal file
1130
FreeSql.Tests/FreeSql.Tests.Provider.Odbc/MySql/MapType/BoolTest.cs
Normal file
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,62 @@
|
||||
using FreeSql.DataAnnotations;
|
||||
using System;
|
||||
using System.Numerics;
|
||||
using Xunit;
|
||||
|
||||
namespace FreeSql.Tests.Odbc.MySqlMapType
|
||||
{
|
||||
public class DateTimeOffSetTest
|
||||
{
|
||||
class DateTimeOffSetTestMap
|
||||
{
|
||||
public Guid id { get; set; }
|
||||
|
||||
[Column(MapType = typeof(DateTime))]
|
||||
public DateTimeOffset dtos_to_dt { get; set; }
|
||||
[Column(MapType = typeof(DateTime?))]
|
||||
public DateTimeOffset? dtosnullable_to_dt { get; set; }
|
||||
}
|
||||
[Fact]
|
||||
public void DateTimeToDateTimeOffSet()
|
||||
{
|
||||
//insert
|
||||
var orm = g.mysql;
|
||||
var item = new DateTimeOffSetTestMap { dtos_to_dt = DateTimeOffset.Now };
|
||||
Assert.Equal(1, orm.Insert<DateTimeOffSetTestMap>().AppendData(item).ExecuteAffrows());
|
||||
var find = orm.Select<DateTimeOffSetTestMap>().Where(a => a.id == item.id).First();
|
||||
Assert.NotNull(find);
|
||||
Assert.Equal(item.id, find.id);
|
||||
Assert.Equal(item.dtos_to_dt.ToString("g"), find.dtos_to_dt.ToString("g"));
|
||||
Assert.Equal(item.dtosnullable_to_dt, find.dtosnullable_to_dt);
|
||||
|
||||
//update all
|
||||
item.dtos_to_dt = DateTimeOffset.Now;
|
||||
Assert.Equal(1, orm.Update<DateTimeOffSetTestMap>().SetSource(item).ExecuteAffrows());
|
||||
find = orm.Select<DateTimeOffSetTestMap>().Where(a => a.id == item.id).First();
|
||||
Assert.NotNull(find);
|
||||
Assert.Equal(item.id, find.id);
|
||||
Assert.Equal(item.dtos_to_dt.ToString("g"), find.dtos_to_dt.ToString("g"));
|
||||
Assert.Equal(item.dtosnullable_to_dt, find.dtosnullable_to_dt);
|
||||
|
||||
item.dtosnullable_to_dt = DateTimeOffset.Now;
|
||||
Assert.Equal(1, orm.Update<DateTimeOffSetTestMap>().SetSource(item).ExecuteAffrows());
|
||||
find = orm.Select<DateTimeOffSetTestMap>().Where(a => a.id == item.id).First();
|
||||
Assert.NotNull(find);
|
||||
Assert.Equal(item.id, find.id);
|
||||
Assert.Equal(item.dtos_to_dt.ToString("g"), find.dtos_to_dt.ToString("g"));
|
||||
Assert.Equal(item.dtosnullable_to_dt.Value.ToString("g"), find.dtosnullable_to_dt.Value.ToString("g"));
|
||||
|
||||
//update set
|
||||
Assert.Equal(1, orm.Update<DateTimeOffSetTestMap>().Where(a => a.id == item.id).Set(a => a.dtos_to_dt, item.dtos_to_dt = DateTimeOffset.Now).ExecuteAffrows());
|
||||
find = orm.Select<DateTimeOffSetTestMap>().Where(a => a.id == item.id).First();
|
||||
Assert.NotNull(find);
|
||||
Assert.Equal(item.dtos_to_dt.ToString("g"), find.dtos_to_dt.ToString("g"));
|
||||
Assert.Equal(item.dtosnullable_to_dt.Value.ToString("g"), find.dtosnullable_to_dt.Value.ToString("g"));
|
||||
|
||||
//delete
|
||||
Assert.Equal(1, orm.Delete<DateTimeOffSetTestMap>().Where(a => a.id == item.id).ExecuteAffrows());
|
||||
Assert.Null(orm.Select<DateTimeOffSetTestMap>().Where(a => a.id == item.id).First());
|
||||
}
|
||||
|
||||
}
|
||||
}
|
@ -0,0 +1,261 @@
|
||||
using FreeSql.DataAnnotations;
|
||||
using System;
|
||||
using System.Numerics;
|
||||
using Xunit;
|
||||
|
||||
namespace FreeSql.Tests.Odbc.MySqlMapType
|
||||
{
|
||||
public class EnumTest
|
||||
{
|
||||
class EnumTestMap
|
||||
{
|
||||
public Guid id { get; set; }
|
||||
|
||||
[Column(MapType = typeof(string))]
|
||||
public ToStringMapEnum enum_to_string { get; set; }
|
||||
[Column(MapType = typeof(string))]
|
||||
public ToStringMapEnum? enumnullable_to_string { get; set; }
|
||||
|
||||
[Column(MapType = typeof(int))]
|
||||
public ToStringMapEnum enum_to_int { get; set; }
|
||||
[Column(MapType = typeof(int?))]
|
||||
public ToStringMapEnum? enumnullable_to_int { get; set; }
|
||||
}
|
||||
public enum ToStringMapEnum { 中国人, abc, 香港 }
|
||||
[Fact]
|
||||
public void EnumToString()
|
||||
{
|
||||
//insert
|
||||
var orm = g.mysql;
|
||||
var item = new EnumTestMap { };
|
||||
Assert.Equal(1, orm.Insert<EnumTestMap>().AppendData(item).ExecuteAffrows());
|
||||
var find = orm.Select<EnumTestMap>().Where(a => a.id == item.id && a.enum_to_string == ToStringMapEnum.中国人).First();
|
||||
Assert.NotNull(find);
|
||||
Assert.Equal(item.id, find.id);
|
||||
Assert.Equal(item.enum_to_string, find.enum_to_string);
|
||||
Assert.Equal(ToStringMapEnum.中国人, find.enum_to_string);
|
||||
|
||||
item = new EnumTestMap { enum_to_string = ToStringMapEnum.abc };
|
||||
Assert.Equal(1, orm.Insert<EnumTestMap>().AppendData(item).ExecuteAffrows());
|
||||
find = orm.Select<EnumTestMap>().Where(a => a.id == item.id && a.enum_to_string == ToStringMapEnum.abc).First();
|
||||
Assert.NotNull(find);
|
||||
Assert.Equal(item.id, find.id);
|
||||
Assert.Equal(item.enum_to_string, find.enum_to_string);
|
||||
Assert.Equal(ToStringMapEnum.abc, find.enum_to_string);
|
||||
|
||||
//update all
|
||||
item.enum_to_string = ToStringMapEnum.香港;
|
||||
Assert.Equal(1, orm.Update<EnumTestMap>().SetSource(item).ExecuteAffrows());
|
||||
find = orm.Select<EnumTestMap>().Where(a => a.id == item.id && a.enum_to_string == ToStringMapEnum.香港).First();
|
||||
Assert.NotNull(find);
|
||||
Assert.Equal(item.id, find.id);
|
||||
Assert.Equal(item.enum_to_string, find.enum_to_string);
|
||||
Assert.Equal(ToStringMapEnum.香港, find.enum_to_string);
|
||||
|
||||
item.enum_to_string = ToStringMapEnum.中国人;
|
||||
Assert.Equal(1, orm.Update<EnumTestMap>().SetSource(item).ExecuteAffrows());
|
||||
find = orm.Select<EnumTestMap>().Where(a => a.id == item.id && a.enum_to_string == ToStringMapEnum.中国人).First();
|
||||
Assert.NotNull(find);
|
||||
Assert.Equal(item.id, find.id);
|
||||
Assert.Equal(item.enum_to_string, find.enum_to_string);
|
||||
Assert.Equal(ToStringMapEnum.中国人, find.enum_to_string);
|
||||
|
||||
//update set
|
||||
Assert.Equal(1, orm.Update<EnumTestMap>().Where(a => a.id == item.id).Set(a => a.enum_to_string, ToStringMapEnum.香港).ExecuteAffrows());
|
||||
find = orm.Select<EnumTestMap>().Where(a => a.id == item.id && a.enum_to_string == ToStringMapEnum.香港).First();
|
||||
Assert.NotNull(find);
|
||||
Assert.Equal(item.id, find.id);
|
||||
Assert.Equal(ToStringMapEnum.香港, find.enum_to_string);
|
||||
|
||||
Assert.Equal(1, orm.Update<EnumTestMap>().Where(a => a.id == item.id).Set(a => a.enum_to_string, ToStringMapEnum.abc).ExecuteAffrows());
|
||||
find = orm.Select<EnumTestMap>().Where(a => a.id == item.id && a.enum_to_string == ToStringMapEnum.abc).First();
|
||||
Assert.NotNull(find);
|
||||
Assert.Equal(item.id, find.id);
|
||||
Assert.Equal(ToStringMapEnum.abc, find.enum_to_string);
|
||||
|
||||
//delete
|
||||
Assert.Equal(0, orm.Delete<EnumTestMap>().Where(a => a.id == item.id && a.enum_to_string == ToStringMapEnum.中国人).ExecuteAffrows());
|
||||
Assert.Equal(0, orm.Delete<EnumTestMap>().Where(a => a.id == item.id && a.enum_to_string == ToStringMapEnum.香港).ExecuteAffrows());
|
||||
Assert.Equal(1, orm.Delete<EnumTestMap>().Where(a => a.id == item.id && a.enum_to_string == ToStringMapEnum.abc).ExecuteAffrows());
|
||||
Assert.Null(orm.Select<EnumTestMap>().Where(a => a.id == item.id).First());
|
||||
}
|
||||
[Fact]
|
||||
public void EnumNullableToString()
|
||||
{
|
||||
//insert
|
||||
var orm = g.mysql;
|
||||
var item = new EnumTestMap { };
|
||||
Assert.Equal(1, orm.Insert<EnumTestMap>().AppendData(item).ExecuteAffrows());
|
||||
var find = orm.Select<EnumTestMap>().Where(a => a.id == item.id && a.enumnullable_to_string == null).First();
|
||||
Assert.NotNull(find);
|
||||
Assert.Equal(item.id, find.id);
|
||||
Assert.Equal(item.enumnullable_to_string, find.enumnullable_to_string);
|
||||
Assert.Null(find.enumnullable_to_string);
|
||||
|
||||
item = new EnumTestMap { enumnullable_to_string = ToStringMapEnum.中国人 };
|
||||
Assert.Equal(1, orm.Insert<EnumTestMap>().AppendData(item).ExecuteAffrows());
|
||||
find = orm.Select<EnumTestMap>().Where(a => a.id == item.id && a.enumnullable_to_string == ToStringMapEnum.中国人).First();
|
||||
Assert.NotNull(find);
|
||||
Assert.Equal(item.id, find.id);
|
||||
Assert.Equal(item.enumnullable_to_string, find.enumnullable_to_string);
|
||||
Assert.Equal(ToStringMapEnum.中国人, find.enumnullable_to_string);
|
||||
|
||||
//update all
|
||||
item.enumnullable_to_string = ToStringMapEnum.香港;
|
||||
Assert.Equal(1, orm.Update<EnumTestMap>().SetSource(item).ExecuteAffrows());
|
||||
find = orm.Select<EnumTestMap>().Where(a => a.id == item.id && a.enumnullable_to_string == ToStringMapEnum.香港).First();
|
||||
Assert.NotNull(find);
|
||||
Assert.Equal(item.id, find.id);
|
||||
Assert.Equal(item.enumnullable_to_string, find.enumnullable_to_string);
|
||||
Assert.Equal(ToStringMapEnum.香港, find.enumnullable_to_string);
|
||||
|
||||
item.enumnullable_to_string = null;
|
||||
Assert.Equal(1, orm.Update<EnumTestMap>().SetSource(item).ExecuteAffrows());
|
||||
Assert.Null(orm.Select<EnumTestMap>().Where(a => a.id == item.id && a.enumnullable_to_string == ToStringMapEnum.香港).First());
|
||||
find = orm.Select<EnumTestMap>().Where(a => a.id == item.id && a.enumnullable_to_string == null).First();
|
||||
Assert.NotNull(find);
|
||||
Assert.Equal(item.id, find.id);
|
||||
Assert.Equal(item.enumnullable_to_string, find.enumnullable_to_string);
|
||||
Assert.Null(find.enumnullable_to_string);
|
||||
|
||||
//update set
|
||||
Assert.Equal(1, orm.Update<EnumTestMap>().Where(a => a.id == item.id).Set(a => a.enumnullable_to_string, ToStringMapEnum.abc).ExecuteAffrows());
|
||||
find = orm.Select<EnumTestMap>().Where(a => a.id == item.id && a.enumnullable_to_string == ToStringMapEnum.abc).First();
|
||||
Assert.NotNull(find);
|
||||
Assert.Equal(item.id, find.id);
|
||||
Assert.Equal(ToStringMapEnum.abc, find.enumnullable_to_string);
|
||||
|
||||
|
||||
Assert.Equal(1, orm.Update<EnumTestMap>().Where(a => a.id == item.id).Set(a => a.enumnullable_to_string, null).ExecuteAffrows());
|
||||
Assert.Null(orm.Select<EnumTestMap>().Where(a => a.id == item.id && a.enumnullable_to_string == ToStringMapEnum.abc).First());
|
||||
find = orm.Select<EnumTestMap>().Where(a => a.id == item.id && a.enumnullable_to_string == null).First();
|
||||
Assert.NotNull(find);
|
||||
Assert.Equal(item.id, find.id);
|
||||
Assert.Null(find.enumnullable_to_string);
|
||||
|
||||
//delete
|
||||
Assert.Equal(0, orm.Delete<EnumTestMap>().Where(a => a.id == item.id && a.enumnullable_to_string == ToStringMapEnum.中国人).ExecuteAffrows());
|
||||
Assert.Equal(0, orm.Delete<EnumTestMap>().Where(a => a.id == item.id && a.enumnullable_to_string == ToStringMapEnum.香港).ExecuteAffrows());
|
||||
Assert.Equal(1, orm.Delete<EnumTestMap>().Where(a => a.id == item.id && a.enumnullable_to_string == null).ExecuteAffrows());
|
||||
Assert.Null(orm.Select<EnumTestMap>().Where(a => a.id == item.id).First());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void EnumToInt()
|
||||
{
|
||||
//insert
|
||||
var orm = g.mysql;
|
||||
var item = new EnumTestMap { };
|
||||
Assert.Equal(1, orm.Insert<EnumTestMap>().AppendData(item).ExecuteAffrows());
|
||||
var find = orm.Select<EnumTestMap>().Where(a => a.id == item.id && a.enum_to_int == ToStringMapEnum.中国人).First();
|
||||
Assert.NotNull(find);
|
||||
Assert.Equal(item.id, find.id);
|
||||
Assert.Equal(item.enum_to_int, find.enum_to_int);
|
||||
Assert.Equal(ToStringMapEnum.中国人, find.enum_to_int);
|
||||
|
||||
item = new EnumTestMap { enum_to_int = ToStringMapEnum.abc };
|
||||
Assert.Equal(1, orm.Insert<EnumTestMap>().AppendData(item).ExecuteAffrows());
|
||||
find = orm.Select<EnumTestMap>().Where(a => a.id == item.id && a.enum_to_int == ToStringMapEnum.abc).First();
|
||||
Assert.NotNull(find);
|
||||
Assert.Equal(item.id, find.id);
|
||||
Assert.Equal(item.enum_to_int, find.enum_to_int);
|
||||
Assert.Equal(ToStringMapEnum.abc, find.enum_to_int);
|
||||
|
||||
//update all
|
||||
item.enum_to_int = ToStringMapEnum.香港;
|
||||
Assert.Equal(1, orm.Update<EnumTestMap>().SetSource(item).ExecuteAffrows());
|
||||
find = orm.Select<EnumTestMap>().Where(a => a.id == item.id && a.enum_to_int == ToStringMapEnum.香港).First();
|
||||
Assert.NotNull(find);
|
||||
Assert.Equal(item.id, find.id);
|
||||
Assert.Equal(item.enum_to_int, find.enum_to_int);
|
||||
Assert.Equal(ToStringMapEnum.香港, find.enum_to_int);
|
||||
|
||||
item.enum_to_int = ToStringMapEnum.中国人;
|
||||
Assert.Equal(1, orm.Update<EnumTestMap>().SetSource(item).ExecuteAffrows());
|
||||
find = orm.Select<EnumTestMap>().Where(a => a.id == item.id && a.enum_to_int == ToStringMapEnum.中国人).First();
|
||||
Assert.NotNull(find);
|
||||
Assert.Equal(item.id, find.id);
|
||||
Assert.Equal(item.enum_to_int, find.enum_to_int);
|
||||
Assert.Equal(ToStringMapEnum.中国人, find.enum_to_int);
|
||||
|
||||
//update set
|
||||
Assert.Equal(1, orm.Update<EnumTestMap>().Where(a => a.id == item.id).Set(a => a.enum_to_int, ToStringMapEnum.香港).ExecuteAffrows());
|
||||
find = orm.Select<EnumTestMap>().Where(a => a.id == item.id && a.enum_to_int == ToStringMapEnum.香港).First();
|
||||
Assert.NotNull(find);
|
||||
Assert.Equal(item.id, find.id);
|
||||
Assert.Equal(ToStringMapEnum.香港, find.enum_to_int);
|
||||
|
||||
Assert.Equal(1, orm.Update<EnumTestMap>().Where(a => a.id == item.id).Set(a => a.enum_to_int, ToStringMapEnum.abc).ExecuteAffrows());
|
||||
find = orm.Select<EnumTestMap>().Where(a => a.id == item.id && a.enum_to_int == ToStringMapEnum.abc).First();
|
||||
Assert.NotNull(find);
|
||||
Assert.Equal(item.id, find.id);
|
||||
Assert.Equal(ToStringMapEnum.abc, find.enum_to_int);
|
||||
|
||||
//delete
|
||||
Assert.Equal(0, orm.Delete<EnumTestMap>().Where(a => a.id == item.id && a.enum_to_int == ToStringMapEnum.中国人).ExecuteAffrows());
|
||||
Assert.Equal(0, orm.Delete<EnumTestMap>().Where(a => a.id == item.id && a.enum_to_int == ToStringMapEnum.香港).ExecuteAffrows());
|
||||
Assert.Equal(1, orm.Delete<EnumTestMap>().Where(a => a.id == item.id && a.enum_to_int == ToStringMapEnum.abc).ExecuteAffrows());
|
||||
Assert.Null(orm.Select<EnumTestMap>().Where(a => a.id == item.id).First());
|
||||
}
|
||||
[Fact]
|
||||
public void EnumNullableToInt()
|
||||
{
|
||||
//insert
|
||||
var orm = g.mysql;
|
||||
var item = new EnumTestMap { };
|
||||
Assert.Equal(1, orm.Insert<EnumTestMap>().AppendData(item).ExecuteAffrows());
|
||||
var find = orm.Select<EnumTestMap>().Where(a => a.id == item.id && a.enumnullable_to_int == null).First();
|
||||
Assert.NotNull(find);
|
||||
Assert.Equal(item.id, find.id);
|
||||
Assert.Equal(item.enumnullable_to_int, find.enumnullable_to_int);
|
||||
Assert.Null(find.enumnullable_to_int);
|
||||
|
||||
item = new EnumTestMap { enumnullable_to_int = ToStringMapEnum.中国人 };
|
||||
Assert.Equal(1, orm.Insert<EnumTestMap>().AppendData(item).ExecuteAffrows());
|
||||
find = orm.Select<EnumTestMap>().Where(a => a.id == item.id && a.enumnullable_to_int == ToStringMapEnum.中国人).First();
|
||||
Assert.NotNull(find);
|
||||
Assert.Equal(item.id, find.id);
|
||||
Assert.Equal(item.enumnullable_to_int, find.enumnullable_to_int);
|
||||
Assert.Equal(ToStringMapEnum.中国人, find.enumnullable_to_int);
|
||||
|
||||
//update all
|
||||
item.enumnullable_to_int = ToStringMapEnum.香港;
|
||||
Assert.Equal(1, orm.Update<EnumTestMap>().SetSource(item).ExecuteAffrows());
|
||||
find = orm.Select<EnumTestMap>().Where(a => a.id == item.id && a.enumnullable_to_int == ToStringMapEnum.香港).First();
|
||||
Assert.NotNull(find);
|
||||
Assert.Equal(item.id, find.id);
|
||||
Assert.Equal(item.enumnullable_to_int, find.enumnullable_to_int);
|
||||
Assert.Equal(ToStringMapEnum.香港, find.enumnullable_to_int);
|
||||
|
||||
item.enumnullable_to_int = null;
|
||||
Assert.Equal(1, orm.Update<EnumTestMap>().SetSource(item).ExecuteAffrows());
|
||||
Assert.Null(orm.Select<EnumTestMap>().Where(a => a.id == item.id && a.enumnullable_to_int == ToStringMapEnum.香港).First());
|
||||
find = orm.Select<EnumTestMap>().Where(a => a.id == item.id && a.enumnullable_to_int == null).First();
|
||||
Assert.NotNull(find);
|
||||
Assert.Equal(item.id, find.id);
|
||||
Assert.Equal(item.enumnullable_to_int, find.enumnullable_to_int);
|
||||
Assert.Null(find.enumnullable_to_int);
|
||||
|
||||
//update set
|
||||
Assert.Equal(1, orm.Update<EnumTestMap>().Where(a => a.id == item.id).Set(a => a.enumnullable_to_int, ToStringMapEnum.abc).ExecuteAffrows());
|
||||
find = orm.Select<EnumTestMap>().Where(a => a.id == item.id && a.enumnullable_to_int == ToStringMapEnum.abc).First();
|
||||
Assert.NotNull(find);
|
||||
Assert.Equal(item.id, find.id);
|
||||
Assert.Equal(ToStringMapEnum.abc, find.enumnullable_to_int);
|
||||
|
||||
|
||||
Assert.Equal(1, orm.Update<EnumTestMap>().Where(a => a.id == item.id).Set(a => a.enumnullable_to_int, null).ExecuteAffrows());
|
||||
Assert.Null(orm.Select<EnumTestMap>().Where(a => a.id == item.id && a.enumnullable_to_int == ToStringMapEnum.abc).First());
|
||||
find = orm.Select<EnumTestMap>().Where(a => a.id == item.id && a.enumnullable_to_int == null).First();
|
||||
Assert.NotNull(find);
|
||||
Assert.Equal(item.id, find.id);
|
||||
Assert.Null(find.enumnullable_to_int);
|
||||
|
||||
//delete
|
||||
Assert.Equal(0, orm.Delete<EnumTestMap>().Where(a => a.id == item.id && a.enumnullable_to_int == ToStringMapEnum.中国人).ExecuteAffrows());
|
||||
Assert.Equal(0, orm.Delete<EnumTestMap>().Where(a => a.id == item.id && a.enumnullable_to_int == ToStringMapEnum.香港).ExecuteAffrows());
|
||||
Assert.Equal(1, orm.Delete<EnumTestMap>().Where(a => a.id == item.id && a.enumnullable_to_int == null).ExecuteAffrows());
|
||||
Assert.Null(orm.Select<EnumTestMap>().Where(a => a.id == item.id).First());
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,570 @@
|
||||
using FreeSql.DataAnnotations;
|
||||
using System;
|
||||
using System.Numerics;
|
||||
using Xunit;
|
||||
|
||||
namespace FreeSql.Tests.Odbc.MySqlMapType
|
||||
{
|
||||
public class ToStringTest
|
||||
{
|
||||
class ToStringMap
|
||||
{
|
||||
public Guid id { get; set; }
|
||||
|
||||
[Column(MapType = typeof(string))]
|
||||
public TimeSpan timespan_to_string { get; set; }
|
||||
[Column(MapType = typeof(string))]
|
||||
public TimeSpan? timespannullable_to_string { get; set; }
|
||||
|
||||
[Column(MapType = typeof(string))]
|
||||
public DateTime datetime_to_string { get; set; }
|
||||
[Column(MapType = typeof(string))]
|
||||
public DateTime? datetimenullable_to_string { get; set; }
|
||||
|
||||
[Column(MapType = typeof(string))]
|
||||
public Guid guid_to_string { get; set; }
|
||||
[Column(MapType = typeof(string))]
|
||||
public Guid? guidnullable_to_string { get; set; }
|
||||
|
||||
[Column(MapType = typeof(string))]
|
||||
public ToStringMapEnum enum_to_string { get; set; }
|
||||
[Column(MapType = typeof(string))]
|
||||
public ToStringMapEnum? enumnullable_to_string { get; set; }
|
||||
|
||||
[Column(MapType = typeof(string))]
|
||||
public BigInteger biginteger_to_string { get; set; }
|
||||
[Column(MapType = typeof(string))]
|
||||
public BigInteger? bigintegernullable_to_string { get; set; }
|
||||
}
|
||||
public enum ToStringMapEnum { 中国人, abc, 香港 }
|
||||
[Fact]
|
||||
public void Enum1()
|
||||
{
|
||||
//insert
|
||||
var orm = g.mysql;
|
||||
var item = new ToStringMap { };
|
||||
Assert.Equal(1, orm.Insert<ToStringMap>().AppendData(item).ExecuteAffrows());
|
||||
var find = orm.Select<ToStringMap>().Where(a => a.id == item.id && a.enum_to_string == ToStringMapEnum.中国人).First();
|
||||
Assert.NotNull(find);
|
||||
Assert.Equal(item.id, find.id);
|
||||
Assert.Equal(item.enum_to_string, find.enum_to_string);
|
||||
Assert.Equal(ToStringMapEnum.中国人, find.enum_to_string);
|
||||
|
||||
item = new ToStringMap { enum_to_string = ToStringMapEnum.abc };
|
||||
Assert.Equal(1, orm.Insert<ToStringMap>().AppendData(item).ExecuteAffrows());
|
||||
find = orm.Select<ToStringMap>().Where(a => a.id == item.id && a.enum_to_string == ToStringMapEnum.abc).First();
|
||||
Assert.NotNull(find);
|
||||
Assert.Equal(item.id, find.id);
|
||||
Assert.Equal(item.enum_to_string, find.enum_to_string);
|
||||
Assert.Equal(ToStringMapEnum.abc, find.enum_to_string);
|
||||
|
||||
//update all
|
||||
item.enum_to_string = ToStringMapEnum.香港;
|
||||
Assert.Equal(1, orm.Update<ToStringMap>().SetSource(item).ExecuteAffrows());
|
||||
find = orm.Select<ToStringMap>().Where(a => a.id == item.id && a.enum_to_string == ToStringMapEnum.香港).First();
|
||||
Assert.NotNull(find);
|
||||
Assert.Equal(item.id, find.id);
|
||||
Assert.Equal(item.enum_to_string, find.enum_to_string);
|
||||
Assert.Equal(ToStringMapEnum.香港, find.enum_to_string);
|
||||
|
||||
item.enum_to_string = ToStringMapEnum.中国人;
|
||||
Assert.Equal(1, orm.Update<ToStringMap>().SetSource(item).ExecuteAffrows());
|
||||
find = orm.Select<ToStringMap>().Where(a => a.id == item.id && a.enum_to_string == ToStringMapEnum.中国人).First();
|
||||
Assert.NotNull(find);
|
||||
Assert.Equal(item.id, find.id);
|
||||
Assert.Equal(item.enum_to_string, find.enum_to_string);
|
||||
Assert.Equal(ToStringMapEnum.中国人, find.enum_to_string);
|
||||
|
||||
//update set
|
||||
Assert.Equal(1, orm.Update<ToStringMap>().Where(a => a.id == item.id).Set(a => a.enum_to_string, ToStringMapEnum.香港).ExecuteAffrows());
|
||||
find = orm.Select<ToStringMap>().Where(a => a.id == item.id && a.enum_to_string == ToStringMapEnum.香港).First();
|
||||
Assert.NotNull(find);
|
||||
Assert.Equal(item.id, find.id);
|
||||
Assert.Equal(ToStringMapEnum.香港, find.enum_to_string);
|
||||
|
||||
Assert.Equal(1, orm.Update<ToStringMap>().Where(a => a.id == item.id).Set(a => a.enum_to_string, ToStringMapEnum.abc).ExecuteAffrows());
|
||||
find = orm.Select<ToStringMap>().Where(a => a.id == item.id && a.enum_to_string == ToStringMapEnum.abc).First();
|
||||
Assert.NotNull(find);
|
||||
Assert.Equal(item.id, find.id);
|
||||
Assert.Equal(ToStringMapEnum.abc, find.enum_to_string);
|
||||
|
||||
//delete
|
||||
Assert.Equal(0, orm.Delete<ToStringMap>().Where(a => a.id == item.id && a.enum_to_string == ToStringMapEnum.中国人).ExecuteAffrows());
|
||||
Assert.Equal(0, orm.Delete<ToStringMap>().Where(a => a.id == item.id && a.enum_to_string == ToStringMapEnum.香港).ExecuteAffrows());
|
||||
Assert.Equal(1, orm.Delete<ToStringMap>().Where(a => a.id == item.id && a.enum_to_string == ToStringMapEnum.abc).ExecuteAffrows());
|
||||
Assert.Null(orm.Select<ToStringMap>().Where(a => a.id == item.id).First());
|
||||
}
|
||||
[Fact]
|
||||
public void EnumNullable()
|
||||
{
|
||||
//insert
|
||||
var orm = g.mysql;
|
||||
var item = new ToStringMap { };
|
||||
Assert.Equal(1, orm.Insert<ToStringMap>().AppendData(item).ExecuteAffrows());
|
||||
var find = orm.Select<ToStringMap>().Where(a => a.id == item.id && a.enumnullable_to_string == null).First();
|
||||
Assert.NotNull(find);
|
||||
Assert.Equal(item.id, find.id);
|
||||
Assert.Equal(item.enumnullable_to_string, find.enumnullable_to_string);
|
||||
Assert.Null(find.enumnullable_to_string);
|
||||
|
||||
item = new ToStringMap { enumnullable_to_string = ToStringMapEnum.中国人 };
|
||||
Assert.Equal(1, orm.Insert<ToStringMap>().AppendData(item).ExecuteAffrows());
|
||||
find = orm.Select<ToStringMap>().Where(a => a.id == item.id && a.enumnullable_to_string == ToStringMapEnum.中国人).First();
|
||||
Assert.NotNull(find);
|
||||
Assert.Equal(item.id, find.id);
|
||||
Assert.Equal(item.enumnullable_to_string, find.enumnullable_to_string);
|
||||
Assert.Equal(ToStringMapEnum.中国人, find.enumnullable_to_string);
|
||||
|
||||
//update all
|
||||
item.enumnullable_to_string = ToStringMapEnum.香港;
|
||||
Assert.Equal(1, orm.Update<ToStringMap>().SetSource(item).ExecuteAffrows());
|
||||
find = orm.Select<ToStringMap>().Where(a => a.id == item.id && a.enumnullable_to_string == ToStringMapEnum.香港).First();
|
||||
Assert.NotNull(find);
|
||||
Assert.Equal(item.id, find.id);
|
||||
Assert.Equal(item.enumnullable_to_string, find.enumnullable_to_string);
|
||||
Assert.Equal(ToStringMapEnum.香港, find.enumnullable_to_string);
|
||||
|
||||
item.enumnullable_to_string = null;
|
||||
Assert.Equal(1, orm.Update<ToStringMap>().SetSource(item).ExecuteAffrows());
|
||||
Assert.Null(orm.Select<ToStringMap>().Where(a => a.id == item.id && a.enumnullable_to_string == ToStringMapEnum.香港).First());
|
||||
find = orm.Select<ToStringMap>().Where(a => a.id == item.id && a.enumnullable_to_string == null).First();
|
||||
Assert.NotNull(find);
|
||||
Assert.Equal(item.id, find.id);
|
||||
Assert.Equal(item.enumnullable_to_string, find.enumnullable_to_string);
|
||||
Assert.Null(find.enumnullable_to_string);
|
||||
|
||||
//update set
|
||||
Assert.Equal(1, orm.Update<ToStringMap>().Where(a => a.id == item.id).Set(a => a.enumnullable_to_string, ToStringMapEnum.abc).ExecuteAffrows());
|
||||
find = orm.Select<ToStringMap>().Where(a => a.id == item.id && a.enumnullable_to_string == ToStringMapEnum.abc).First();
|
||||
Assert.NotNull(find);
|
||||
Assert.Equal(item.id, find.id);
|
||||
Assert.Equal(ToStringMapEnum.abc, find.enumnullable_to_string);
|
||||
|
||||
|
||||
Assert.Equal(1, orm.Update<ToStringMap>().Where(a => a.id == item.id).Set(a => a.enumnullable_to_string, null).ExecuteAffrows());
|
||||
Assert.Null(orm.Select<ToStringMap>().Where(a => a.id == item.id && a.enumnullable_to_string == ToStringMapEnum.abc).First());
|
||||
find = orm.Select<ToStringMap>().Where(a => a.id == item.id && a.enumnullable_to_string == null).First();
|
||||
Assert.NotNull(find);
|
||||
Assert.Equal(item.id, find.id);
|
||||
Assert.Null(find.enumnullable_to_string);
|
||||
|
||||
//delete
|
||||
Assert.Equal(0, orm.Delete<ToStringMap>().Where(a => a.id == item.id && a.enumnullable_to_string == ToStringMapEnum.中国人).ExecuteAffrows());
|
||||
Assert.Equal(0, orm.Delete<ToStringMap>().Where(a => a.id == item.id && a.enumnullable_to_string == ToStringMapEnum.香港).ExecuteAffrows());
|
||||
Assert.Equal(1, orm.Delete<ToStringMap>().Where(a => a.id == item.id && a.enumnullable_to_string == null).ExecuteAffrows());
|
||||
Assert.Null(orm.Select<ToStringMap>().Where(a => a.id == item.id).First());
|
||||
}
|
||||
[Fact]
|
||||
public void BigInteger1()
|
||||
{
|
||||
//insert
|
||||
var orm = g.mysql;
|
||||
var item = new ToStringMap { };
|
||||
Assert.Equal(1, orm.Insert<ToStringMap>().AppendData(item).ExecuteAffrows());
|
||||
var find = orm.Select<ToStringMap>().Where(a => a.id == item.id && a.biginteger_to_string == 0).First();
|
||||
Assert.NotNull(find);
|
||||
Assert.Equal(item.id, find.id);
|
||||
Assert.Equal(item.biginteger_to_string, find.biginteger_to_string);
|
||||
Assert.Equal(0, find.biginteger_to_string);
|
||||
|
||||
item = new ToStringMap { biginteger_to_string = 100 };
|
||||
Assert.Equal(1, orm.Insert<ToStringMap>().AppendData(item).ExecuteAffrows());
|
||||
find = orm.Select<ToStringMap>().Where(a => a.id == item.id && a.biginteger_to_string == 100).First();
|
||||
Assert.NotNull(find);
|
||||
Assert.Equal(item.id, find.id);
|
||||
Assert.Equal(item.biginteger_to_string, find.biginteger_to_string);
|
||||
Assert.Equal(100, find.biginteger_to_string);
|
||||
|
||||
//update all
|
||||
item.biginteger_to_string = 200;
|
||||
Assert.Equal(1, orm.Update<ToStringMap>().SetSource(item).ExecuteAffrows());
|
||||
find = orm.Select<ToStringMap>().Where(a => a.id == item.id && a.biginteger_to_string == 200).First();
|
||||
Assert.NotNull(find);
|
||||
Assert.Equal(item.id, find.id);
|
||||
Assert.Equal(item.biginteger_to_string, find.biginteger_to_string);
|
||||
Assert.Equal(200, find.biginteger_to_string);
|
||||
|
||||
item.biginteger_to_string = 205;
|
||||
Assert.Equal(1, orm.Update<ToStringMap>().SetSource(item).ExecuteAffrows());
|
||||
find = orm.Select<ToStringMap>().Where(a => a.id == item.id && a.biginteger_to_string == 205).First();
|
||||
Assert.NotNull(find);
|
||||
Assert.Equal(item.id, find.id);
|
||||
Assert.Equal(item.biginteger_to_string, find.biginteger_to_string);
|
||||
Assert.Equal(205, find.biginteger_to_string);
|
||||
|
||||
//update set
|
||||
Assert.Equal(1, orm.Update<ToStringMap>().Where(a => a.id == item.id).Set(a => a.biginteger_to_string, 522).ExecuteAffrows());
|
||||
find = orm.Select<ToStringMap>().Where(a => a.id == item.id && a.biginteger_to_string == 522).First();
|
||||
Assert.NotNull(find);
|
||||
Assert.Equal(item.id, find.id);
|
||||
Assert.Equal(522, find.biginteger_to_string);
|
||||
|
||||
Assert.Equal(1, orm.Update<ToStringMap>().Where(a => a.id == item.id).Set(a => a.biginteger_to_string, 10005).ExecuteAffrows());
|
||||
find = orm.Select<ToStringMap>().Where(a => a.id == item.id && a.biginteger_to_string == 10005).First();
|
||||
Assert.NotNull(find);
|
||||
Assert.Equal(item.id, find.id);
|
||||
Assert.Equal(10005, find.biginteger_to_string);
|
||||
|
||||
//delete
|
||||
Assert.Equal(0, orm.Delete<ToStringMap>().Where(a => a.id == item.id && a.biginteger_to_string == 522).ExecuteAffrows());
|
||||
Assert.Equal(0, orm.Delete<ToStringMap>().Where(a => a.id == item.id && a.biginteger_to_string == 205).ExecuteAffrows());
|
||||
Assert.Equal(1, orm.Delete<ToStringMap>().Where(a => a.id == item.id && a.biginteger_to_string == 10005).ExecuteAffrows());
|
||||
Assert.Null(orm.Select<ToStringMap>().Where(a => a.id == item.id).First());
|
||||
}
|
||||
[Fact]
|
||||
public void BigIntegerNullable()
|
||||
{
|
||||
//insert
|
||||
var orm = g.mysql;
|
||||
var item = new ToStringMap { };
|
||||
Assert.Equal(1, orm.Insert<ToStringMap>().AppendData(item).ExecuteAffrows());
|
||||
var find = orm.Select<ToStringMap>().Where(a => a.id == item.id && a.bigintegernullable_to_string == null).First();
|
||||
Assert.NotNull(find);
|
||||
Assert.Equal(item.id, find.id);
|
||||
Assert.Equal(item.bigintegernullable_to_string, find.bigintegernullable_to_string);
|
||||
Assert.Null(find.bigintegernullable_to_string);
|
||||
|
||||
item = new ToStringMap { bigintegernullable_to_string = 101 };
|
||||
Assert.Equal(1, orm.Insert<ToStringMap>().AppendData(item).ExecuteAffrows());
|
||||
find = orm.Select<ToStringMap>().Where(a => a.id == item.id && a.bigintegernullable_to_string == 101).First();
|
||||
Assert.NotNull(find);
|
||||
Assert.Equal(item.id, find.id);
|
||||
Assert.Equal(item.bigintegernullable_to_string, find.bigintegernullable_to_string);
|
||||
Assert.Equal(101, find.bigintegernullable_to_string);
|
||||
|
||||
//update all
|
||||
item.bigintegernullable_to_string = 2004;
|
||||
Assert.Equal(1, orm.Update<ToStringMap>().SetSource(item).ExecuteAffrows());
|
||||
find = orm.Select<ToStringMap>().Where(a => a.id == item.id && a.bigintegernullable_to_string == 2004).First();
|
||||
Assert.NotNull(find);
|
||||
Assert.Equal(item.id, find.id);
|
||||
Assert.Equal(item.bigintegernullable_to_string, find.bigintegernullable_to_string);
|
||||
Assert.Equal(2004, find.bigintegernullable_to_string);
|
||||
|
||||
item.bigintegernullable_to_string = null;
|
||||
Assert.Equal(1, orm.Update<ToStringMap>().SetSource(item).ExecuteAffrows());
|
||||
Assert.Null(orm.Select<ToStringMap>().Where(a => a.id == item.id && a.bigintegernullable_to_string == 2004).First());
|
||||
find = orm.Select<ToStringMap>().Where(a => a.id == item.id && a.bigintegernullable_to_string == null).First();
|
||||
Assert.NotNull(find);
|
||||
Assert.Equal(item.id, find.id);
|
||||
Assert.Equal(item.bigintegernullable_to_string, find.bigintegernullable_to_string);
|
||||
Assert.Null(find.bigintegernullable_to_string);
|
||||
|
||||
//update set
|
||||
Assert.Equal(1, orm.Update<ToStringMap>().Where(a => a.id == item.id).Set(a => a.bigintegernullable_to_string, 998).ExecuteAffrows());
|
||||
find = orm.Select<ToStringMap>().Where(a => a.id == item.id && a.bigintegernullable_to_string == 998).First();
|
||||
Assert.NotNull(find);
|
||||
Assert.Equal(item.id, find.id);
|
||||
Assert.Equal(998, find.bigintegernullable_to_string);
|
||||
|
||||
|
||||
Assert.Equal(1, orm.Update<ToStringMap>().Where(a => a.id == item.id).Set(a => a.bigintegernullable_to_string, null).ExecuteAffrows());
|
||||
Assert.Null(orm.Select<ToStringMap>().Where(a => a.id == item.id && a.bigintegernullable_to_string == 998).First());
|
||||
find = orm.Select<ToStringMap>().Where(a => a.id == item.id && a.bigintegernullable_to_string == null).First();
|
||||
Assert.NotNull(find);
|
||||
Assert.Equal(item.id, find.id);
|
||||
Assert.Null(find.bigintegernullable_to_string);
|
||||
|
||||
//delete
|
||||
Assert.Equal(0, orm.Delete<ToStringMap>().Where(a => a.id == item.id && a.bigintegernullable_to_string == 998).ExecuteAffrows());
|
||||
Assert.Equal(0, orm.Delete<ToStringMap>().Where(a => a.id == item.id && a.bigintegernullable_to_string == 2004).ExecuteAffrows());
|
||||
Assert.Equal(1, orm.Delete<ToStringMap>().Where(a => a.id == item.id && a.bigintegernullable_to_string == null).ExecuteAffrows());
|
||||
Assert.Null(orm.Select<ToStringMap>().Where(a => a.id == item.id).First());
|
||||
}
|
||||
[Fact]
|
||||
public void TimeSpan1()
|
||||
{
|
||||
//insert
|
||||
var orm = g.mysql;
|
||||
var item = new ToStringMap { };
|
||||
Assert.Equal(1, orm.Insert<ToStringMap>().AppendData(item).ExecuteAffrows());
|
||||
var find = orm.Select<ToStringMap>().Where(a => a.id == item.id).First();
|
||||
Assert.NotNull(find);
|
||||
Assert.Equal(item.id, find.id);
|
||||
Assert.Equal(item.timespan_to_string, find.timespan_to_string);
|
||||
Assert.Equal(TimeSpan.Zero, find.timespan_to_string);
|
||||
|
||||
item = new ToStringMap { timespan_to_string = TimeSpan.FromDays(1) };
|
||||
Assert.Equal(1, orm.Insert<ToStringMap>().AppendData(item).ExecuteAffrows());
|
||||
find = orm.Select<ToStringMap>().Where(a => a.id == item.id).First();
|
||||
Assert.NotNull(find);
|
||||
Assert.Equal(item.id, find.id);
|
||||
Assert.Equal(item.timespan_to_string, find.timespan_to_string);
|
||||
Assert.Equal(TimeSpan.FromDays(1), find.timespan_to_string);
|
||||
|
||||
//update all
|
||||
item.timespan_to_string = TimeSpan.FromHours(10);
|
||||
Assert.Equal(1, orm.Update<ToStringMap>().SetSource(item).ExecuteAffrows());
|
||||
find = orm.Select<ToStringMap>().Where(a => a.id == item.id).First();
|
||||
Assert.NotNull(find);
|
||||
Assert.Equal(item.id, find.id);
|
||||
Assert.Equal(item.timespan_to_string, find.timespan_to_string);
|
||||
Assert.Equal(TimeSpan.FromHours(10), find.timespan_to_string);
|
||||
|
||||
//update set
|
||||
Assert.Equal(1, orm.Update<ToStringMap>().Where(a => a.id == item.id).Set(a => a.timespan_to_string, TimeSpan.FromHours(11)).ExecuteAffrows());
|
||||
find = orm.Select<ToStringMap>().Where(a => a.id == item.id).First();
|
||||
Assert.NotNull(find);
|
||||
Assert.Equal(item.id, find.id);
|
||||
Assert.Equal(TimeSpan.FromHours(11), find.timespan_to_string);
|
||||
|
||||
//delete
|
||||
Assert.Equal(1, orm.Delete<ToStringMap>().Where(a => a.id == item.id).ExecuteAffrows());
|
||||
Assert.Null(orm.Select<ToStringMap>().Where(a => a.id == item.id).First());
|
||||
}
|
||||
[Fact]
|
||||
public void TimeSpanNullable()
|
||||
{
|
||||
//insert
|
||||
var orm = g.mysql;
|
||||
var item = new ToStringMap { };
|
||||
Assert.Equal(1, orm.Insert<ToStringMap>().AppendData(item).ExecuteAffrows());
|
||||
var find = orm.Select<ToStringMap>().Where(a => a.id == item.id).First();
|
||||
Assert.NotNull(find);
|
||||
Assert.Equal(item.id, find.id);
|
||||
Assert.Equal(item.timespannullable_to_string, find.timespannullable_to_string);
|
||||
Assert.Null(find.timespannullable_to_string);
|
||||
|
||||
item = new ToStringMap { timespannullable_to_string = TimeSpan.FromDays(1) };
|
||||
Assert.Equal(1, orm.Insert<ToStringMap>().AppendData(item).ExecuteAffrows());
|
||||
find = orm.Select<ToStringMap>().Where(a => a.id == item.id).First();
|
||||
Assert.NotNull(find);
|
||||
Assert.Equal(item.id, find.id);
|
||||
Assert.Equal(item.timespannullable_to_string, find.timespannullable_to_string);
|
||||
Assert.Equal(TimeSpan.FromDays(1), find.timespannullable_to_string);
|
||||
|
||||
//update all
|
||||
item.timespannullable_to_string = TimeSpan.FromHours(10);
|
||||
Assert.Equal(1, orm.Update<ToStringMap>().SetSource(item).ExecuteAffrows());
|
||||
find = orm.Select<ToStringMap>().Where(a => a.id == item.id).First();
|
||||
Assert.NotNull(find);
|
||||
Assert.Equal(item.id, find.id);
|
||||
Assert.Equal(item.timespannullable_to_string, find.timespannullable_to_string);
|
||||
Assert.Equal(TimeSpan.FromHours(10), find.timespannullable_to_string);
|
||||
|
||||
item.timespannullable_to_string = null;
|
||||
Assert.Equal(1, orm.Update<ToStringMap>().SetSource(item).ExecuteAffrows());
|
||||
find = orm.Select<ToStringMap>().Where(a => a.id == item.id).First();
|
||||
Assert.NotNull(find);
|
||||
Assert.Equal(item.id, find.id);
|
||||
Assert.Equal(item.timespannullable_to_string, find.timespannullable_to_string);
|
||||
Assert.Null(find.timespannullable_to_string);
|
||||
|
||||
//update set
|
||||
Assert.Equal(1, orm.Update<ToStringMap>().Where(a => a.id == item.id).Set(a => a.timespannullable_to_string, TimeSpan.FromHours(11)).ExecuteAffrows());
|
||||
find = orm.Select<ToStringMap>().Where(a => a.id == item.id).First();
|
||||
Assert.NotNull(find);
|
||||
Assert.Equal(item.id, find.id);
|
||||
Assert.Equal(TimeSpan.FromHours(11), find.timespannullable_to_string);
|
||||
|
||||
Assert.Equal(1, orm.Update<ToStringMap>().Where(a => a.id == item.id).Set(a => a.timespannullable_to_string, null).ExecuteAffrows());
|
||||
find = orm.Select<ToStringMap>().Where(a => a.id == item.id).First();
|
||||
Assert.NotNull(find);
|
||||
Assert.Equal(item.id, find.id);
|
||||
Assert.Null(find.timespannullable_to_string);
|
||||
|
||||
//delete
|
||||
Assert.Equal(1, orm.Delete<ToStringMap>().Where(a => a.id == item.id).ExecuteAffrows());
|
||||
Assert.Null(orm.Select<ToStringMap>().Where(a => a.id == item.id).First());
|
||||
}
|
||||
[Fact]
|
||||
public void DateTime1()
|
||||
{
|
||||
//insert
|
||||
var orm = g.mysql;
|
||||
var item = new ToStringMap { };
|
||||
Assert.Equal(1, orm.Insert<ToStringMap>().AppendData(item).ExecuteAffrows());
|
||||
var find = orm.Select<ToStringMap>().Where(a => a.id == item.id).First();
|
||||
Assert.NotNull(find);
|
||||
Assert.Equal(item.id, find.id);
|
||||
Assert.Equal(item.datetime_to_string, find.datetime_to_string);
|
||||
Assert.Equal(DateTime.MinValue, find.datetime_to_string);
|
||||
|
||||
item = new ToStringMap { datetime_to_string = DateTime.Parse("2000-1-1") };
|
||||
Assert.Equal(1, orm.Insert<ToStringMap>().AppendData(item).ExecuteAffrows());
|
||||
find = orm.Select<ToStringMap>().Where(a => a.id == item.id).First();
|
||||
Assert.NotNull(find);
|
||||
Assert.Equal(item.id, find.id);
|
||||
Assert.Equal(item.datetime_to_string, find.datetime_to_string);
|
||||
Assert.Equal(DateTime.Parse("2000-1-1"), find.datetime_to_string);
|
||||
|
||||
//update all
|
||||
item.datetime_to_string = DateTime.Parse("2000-1-11");
|
||||
Assert.Equal(1, orm.Update<ToStringMap>().SetSource(item).ExecuteAffrows());
|
||||
find = orm.Select<ToStringMap>().Where(a => a.id == item.id).First();
|
||||
Assert.NotNull(find);
|
||||
Assert.Equal(item.id, find.id);
|
||||
Assert.Equal(item.datetime_to_string, find.datetime_to_string);
|
||||
Assert.Equal(DateTime.Parse("2000-1-11"), find.datetime_to_string);
|
||||
|
||||
//update set
|
||||
Assert.Equal(1, orm.Update<ToStringMap>().Where(a => a.id == item.id).Set(a => a.datetime_to_string, DateTime.Parse("2000-1-12")).ExecuteAffrows());
|
||||
find = orm.Select<ToStringMap>().Where(a => a.id == item.id).First();
|
||||
Assert.NotNull(find);
|
||||
Assert.Equal(item.id, find.id);
|
||||
Assert.Equal(DateTime.Parse("2000-1-12"), find.datetime_to_string);
|
||||
|
||||
//delete
|
||||
Assert.Equal(1, orm.Delete<ToStringMap>().Where(a => a.id == item.id).ExecuteAffrows());
|
||||
Assert.Null(orm.Select<ToStringMap>().Where(a => a.id == item.id).First());
|
||||
}
|
||||
[Fact]
|
||||
public void DateTimeNullable()
|
||||
{
|
||||
//insert
|
||||
var orm = g.mysql;
|
||||
var item = new ToStringMap { };
|
||||
Assert.Equal(1, orm.Insert<ToStringMap>().AppendData(item).ExecuteAffrows());
|
||||
var find = orm.Select<ToStringMap>().Where(a => a.id == item.id).First();
|
||||
Assert.NotNull(find);
|
||||
Assert.Equal(item.id, find.id);
|
||||
Assert.Equal(item.datetimenullable_to_string, find.datetimenullable_to_string);
|
||||
Assert.Null(find.datetimenullable_to_string);
|
||||
|
||||
item = new ToStringMap { datetimenullable_to_string = DateTime.Parse("2000-1-1") };
|
||||
Assert.Equal(1, orm.Insert<ToStringMap>().AppendData(item).ExecuteAffrows());
|
||||
find = orm.Select<ToStringMap>().Where(a => a.id == item.id).First();
|
||||
Assert.NotNull(find);
|
||||
Assert.Equal(item.id, find.id);
|
||||
Assert.Equal(item.datetimenullable_to_string, find.datetimenullable_to_string);
|
||||
Assert.Equal(DateTime.Parse("2000-1-1"), find.datetimenullable_to_string);
|
||||
|
||||
//update all
|
||||
item.datetimenullable_to_string = DateTime.Parse("2000-1-11");
|
||||
Assert.Equal(1, orm.Update<ToStringMap>().SetSource(item).ExecuteAffrows());
|
||||
find = orm.Select<ToStringMap>().Where(a => a.id == item.id).First();
|
||||
Assert.NotNull(find);
|
||||
Assert.Equal(item.id, find.id);
|
||||
Assert.Equal(item.datetimenullable_to_string, find.datetimenullable_to_string);
|
||||
Assert.Equal(DateTime.Parse("2000-1-11"), find.datetimenullable_to_string);
|
||||
|
||||
item.datetimenullable_to_string = null;
|
||||
Assert.Equal(1, orm.Update<ToStringMap>().SetSource(item).ExecuteAffrows());
|
||||
find = orm.Select<ToStringMap>().Where(a => a.id == item.id).First();
|
||||
Assert.NotNull(find);
|
||||
Assert.Equal(item.id, find.id);
|
||||
Assert.Equal(item.datetimenullable_to_string, find.datetimenullable_to_string);
|
||||
Assert.Null(find.datetimenullable_to_string);
|
||||
|
||||
//update set
|
||||
Assert.Equal(1, orm.Update<ToStringMap>().Where(a => a.id == item.id).Set(a => a.datetimenullable_to_string, DateTime.Parse("2000-1-12")).ExecuteAffrows());
|
||||
find = orm.Select<ToStringMap>().Where(a => a.id == item.id).First();
|
||||
Assert.NotNull(find);
|
||||
Assert.Equal(item.id, find.id);
|
||||
Assert.Equal(DateTime.Parse("2000-1-12"), find.datetimenullable_to_string);
|
||||
|
||||
Assert.Equal(1, orm.Update<ToStringMap>().Where(a => a.id == item.id).Set(a => a.datetimenullable_to_string, null).ExecuteAffrows());
|
||||
find = orm.Select<ToStringMap>().Where(a => a.id == item.id).First();
|
||||
Assert.NotNull(find);
|
||||
Assert.Equal(item.id, find.id);
|
||||
Assert.Null(find.datetimenullable_to_string);
|
||||
|
||||
//delete
|
||||
Assert.Equal(1, orm.Delete<ToStringMap>().Where(a => a.id == item.id).ExecuteAffrows());
|
||||
Assert.Null(orm.Select<ToStringMap>().Where(a => a.id == item.id).First());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Guid1()
|
||||
{
|
||||
//insert
|
||||
var orm = g.mysql;
|
||||
var item = new ToStringMap { };
|
||||
Assert.Equal(1, orm.Insert<ToStringMap>().AppendData(item).ExecuteAffrows());
|
||||
var find = orm.Select<ToStringMap>().Where(a => a.id == item.id && a.guid_to_string == Guid.Empty).First();
|
||||
Assert.NotNull(find);
|
||||
Assert.Equal(item.id, find.id);
|
||||
Assert.Equal(item.guid_to_string, find.guid_to_string);
|
||||
Assert.Equal(Guid.Empty, find.guid_to_string);
|
||||
|
||||
var newid = Guid.NewGuid();
|
||||
item = new ToStringMap { guid_to_string = newid };
|
||||
Assert.Equal(1, orm.Insert<ToStringMap>().AppendData(item).ExecuteAffrows());
|
||||
find = orm.Select<ToStringMap>().Where(a => a.id == item.id && a.guid_to_string == newid).First();
|
||||
Assert.NotNull(find);
|
||||
Assert.Equal(item.id, find.id);
|
||||
Assert.Equal(item.guid_to_string, find.guid_to_string);
|
||||
Assert.Equal(newid, find.guid_to_string);
|
||||
|
||||
//update all
|
||||
newid = Guid.NewGuid();
|
||||
item.guid_to_string = newid;
|
||||
Assert.Equal(1, orm.Update<ToStringMap>().SetSource(item).ExecuteAffrows());
|
||||
find = orm.Select<ToStringMap>().Where(a => a.id == item.id && a.guid_to_string == newid).First();
|
||||
Assert.NotNull(find);
|
||||
Assert.Equal(item.id, find.id);
|
||||
Assert.Equal(item.guid_to_string, find.guid_to_string);
|
||||
Assert.Equal(newid, find.guid_to_string);
|
||||
|
||||
//update set
|
||||
newid = Guid.NewGuid();
|
||||
Assert.Equal(1, orm.Update<ToStringMap>().Where(a => a.id == item.id).Set(a => a.guid_to_string, newid).ExecuteAffrows());
|
||||
find = orm.Select<ToStringMap>().Where(a => a.id == item.id && a.guid_to_string == newid).First();
|
||||
Assert.NotNull(find);
|
||||
Assert.Equal(item.id, find.id);
|
||||
Assert.Equal(newid, find.guid_to_string);
|
||||
|
||||
//delete
|
||||
Assert.Equal(1, orm.Delete<ToStringMap>().Where(a => a.id == item.id && a.guid_to_string == newid).ExecuteAffrows());
|
||||
Assert.Null(orm.Select<ToStringMap>().Where(a => a.id == item.id).First());
|
||||
}
|
||||
[Fact]
|
||||
public void GuidNullable()
|
||||
{
|
||||
//insert
|
||||
var orm = g.mysql;
|
||||
var item = new ToStringMap { };
|
||||
Assert.Equal(1, orm.Insert<ToStringMap>().AppendData(item).ExecuteAffrows());
|
||||
var find = orm.Select<ToStringMap>().Where(a => a.id == item.id && a.guidnullable_to_string == null).First();
|
||||
Assert.NotNull(find);
|
||||
Assert.Equal(item.id, find.id);
|
||||
Assert.Equal(item.guidnullable_to_string, find.guidnullable_to_string);
|
||||
Assert.Null(find.guidnullable_to_string);
|
||||
|
||||
var newid = Guid.NewGuid();
|
||||
item = new ToStringMap { guidnullable_to_string = newid };
|
||||
Assert.Equal(1, orm.Insert<ToStringMap>().AppendData(item).ExecuteAffrows());
|
||||
find = orm.Select<ToStringMap>().Where(a => a.id == item.id && a.guidnullable_to_string == newid).First();
|
||||
Assert.NotNull(find);
|
||||
Assert.Equal(item.id, find.id);
|
||||
Assert.Equal(item.guidnullable_to_string, find.guidnullable_to_string);
|
||||
Assert.Equal(newid, find.guidnullable_to_string);
|
||||
|
||||
//update all
|
||||
newid = Guid.NewGuid();
|
||||
item.guidnullable_to_string = newid;
|
||||
Assert.Equal(1, orm.Update<ToStringMap>().SetSource(item).ExecuteAffrows());
|
||||
find = orm.Select<ToStringMap>().Where(a => a.id == item.id && a.guidnullable_to_string == newid).First();
|
||||
Assert.NotNull(find);
|
||||
Assert.Equal(item.id, find.id);
|
||||
Assert.Equal(item.guidnullable_to_string, find.guidnullable_to_string);
|
||||
Assert.Equal(newid, find.guidnullable_to_string);
|
||||
|
||||
item.guidnullable_to_string = null;
|
||||
Assert.Equal(1, orm.Update<ToStringMap>().SetSource(item).ExecuteAffrows());
|
||||
find = orm.Select<ToStringMap>().Where(a => a.id == item.id && a.guidnullable_to_string == null).First();
|
||||
Assert.NotNull(find);
|
||||
Assert.Equal(item.id, find.id);
|
||||
Assert.Equal(item.guidnullable_to_string, find.guidnullable_to_string);
|
||||
Assert.Null(find.guidnullable_to_string);
|
||||
|
||||
//update set
|
||||
newid = Guid.NewGuid();
|
||||
Assert.Equal(1, orm.Update<ToStringMap>().Where(a => a.id == item.id).Set(a => a.guidnullable_to_string, newid).ExecuteAffrows());
|
||||
find = orm.Select<ToStringMap>().Where(a => a.id == item.id && a.guidnullable_to_string == newid).First();
|
||||
Assert.NotNull(find);
|
||||
Assert.Equal(item.id, find.id);
|
||||
Assert.Equal(newid, find.guidnullable_to_string);
|
||||
|
||||
Assert.Equal(1, orm.Update<ToStringMap>().Where(a => a.id == item.id).Set(a => a.guidnullable_to_string, null).ExecuteAffrows());
|
||||
find = orm.Select<ToStringMap>().Where(a => a.id == item.id && a.guidnullable_to_string == null).First();
|
||||
Assert.NotNull(find);
|
||||
Assert.Equal(item.id, find.id);
|
||||
Assert.Null(find.guidnullable_to_string);
|
||||
|
||||
//delete
|
||||
Assert.Equal(1, orm.Delete<ToStringMap>().Where(a => a.id == item.id && a.guidnullable_to_string == null).ExecuteAffrows());
|
||||
Assert.Null(orm.Select<ToStringMap>().Where(a => a.id == item.id).First());
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,66 @@
|
||||
using FreeSql.DataAnnotations;
|
||||
using System;
|
||||
using System.Data.Odbc;
|
||||
using Xunit;
|
||||
|
||||
namespace FreeSql.Tests.Odbc.MySql
|
||||
{
|
||||
public class MySqlAdoTest
|
||||
{
|
||||
[Fact]
|
||||
public void Pool()
|
||||
{
|
||||
var t1 = g.mysql.Ado.MasterPool.StatisticsFullily;
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void SlavePools()
|
||||
{
|
||||
var t2 = g.mysql.Ado.SlavePools.Count;
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ExecuteReader()
|
||||
{
|
||||
|
||||
}
|
||||
[Fact]
|
||||
public void ExecuteArray()
|
||||
{
|
||||
|
||||
}
|
||||
[Fact]
|
||||
public void ExecuteNonQuery()
|
||||
{
|
||||
|
||||
}
|
||||
[Fact]
|
||||
public void ExecuteScalar()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Query()
|
||||
{
|
||||
var t3 = g.mysql.Ado.Query<xxx>("select * from song");
|
||||
|
||||
var t4 = g.mysql.Ado.Query<(int, string, string)>("select * from song");
|
||||
|
||||
var t5 = g.mysql.Ado.Query<dynamic>("select * from song");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void QueryMultipline()
|
||||
{
|
||||
Assert.Throws<OdbcException>(() => g.mysql.Ado.Query<xxx, (int, string, string), dynamic>("select * from song; select * from song; select * from song"));
|
||||
}
|
||||
|
||||
class xxx
|
||||
{
|
||||
public int Id { get; set; }
|
||||
public string Path { get; set; }
|
||||
public string Title2 { get; set; }
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,40 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Reflection;
|
||||
using System.Text;
|
||||
using Xunit;
|
||||
|
||||
namespace FreeSql.Tests.Odbc.MySql
|
||||
{
|
||||
public class MySqlAopTest
|
||||
{
|
||||
|
||||
class TestAuditValue
|
||||
{
|
||||
public Guid id { get; set; }
|
||||
[Now]
|
||||
public DateTime createtime { get; set; }
|
||||
}
|
||||
class NowAttribute: Attribute { }
|
||||
|
||||
[Fact]
|
||||
public void AuditValue()
|
||||
{
|
||||
var date = DateTime.Now.Date;
|
||||
var item = new TestAuditValue();
|
||||
|
||||
EventHandler<Aop.AuditValueEventArgs> audit = (s, e) =>
|
||||
{
|
||||
if (e.Property.GetCustomAttribute<NowAttribute>(false) != null)
|
||||
e.Value = DateTime.Now.Date;
|
||||
};
|
||||
g.mysql.Aop.AuditValue += audit;
|
||||
|
||||
g.mysql.Insert(item).ExecuteAffrows();
|
||||
|
||||
g.mysql.Aop.AuditValue -= audit;
|
||||
|
||||
Assert.Equal(item.createtime, date);
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,451 @@
|
||||
using FreeSql.DataAnnotations;
|
||||
using Newtonsoft.Json;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using Xunit;
|
||||
|
||||
namespace FreeSql.Tests.Odbc.MySql
|
||||
{
|
||||
public class MySqlCodeFirstTest
|
||||
{
|
||||
|
||||
[Fact]
|
||||
public void 中文表_字段()
|
||||
{
|
||||
var sql = g.mysql.CodeFirst.GetComparisonDDLStatements<测试中文表2>();
|
||||
g.mysql.CodeFirst.SyncStructure<测试中文表2>();
|
||||
|
||||
var item = new 测试中文表2
|
||||
{
|
||||
标题 = "测试标题",
|
||||
创建时间 = DateTime.Now
|
||||
};
|
||||
Assert.Equal(1, g.mysql.Insert<测试中文表2>().AppendData(item).ExecuteAffrows());
|
||||
Assert.NotEqual(Guid.Empty, item.编号);
|
||||
var item2 = g.mysql.Select<测试中文表2>().Where(a => a.编号 == item.编号).First();
|
||||
Assert.NotNull(item2);
|
||||
Assert.Equal(item.编号, item2.编号);
|
||||
Assert.Equal(item.标题, item2.标题);
|
||||
}
|
||||
class 测试中文表2
|
||||
{
|
||||
[Column(IsPrimary = true)]
|
||||
public Guid 编号 { get; set; }
|
||||
|
||||
public string 标题 { get; set; }
|
||||
|
||||
public DateTime 创建时间 { get; set; }
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void AddUniques()
|
||||
{
|
||||
var sql = g.mysql.CodeFirst.GetComparisonDDLStatements<AddUniquesInfo>();
|
||||
g.mysql.CodeFirst.SyncStructure<AddUniquesInfo>();
|
||||
}
|
||||
[Table(Name = "AddUniquesInfo", OldName = "AddUniquesInfo2")]
|
||||
class AddUniquesInfo
|
||||
{
|
||||
public Guid id { get; set; }
|
||||
[Column(Unique = "uk_phone")]
|
||||
public string phone { get; set; }
|
||||
|
||||
[Column(Unique = "uk_group_index, uk_group_index22")]
|
||||
public string group { get; set; }
|
||||
[Column(Unique = "uk_group_index")]
|
||||
public int index { get; set; }
|
||||
[Column(Unique = "uk_group_index22")]
|
||||
public string index22 { get; set; }
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void AddField()
|
||||
{
|
||||
var sql = g.mysql.CodeFirst.GetComparisonDDLStatements<TopicAddField>();
|
||||
|
||||
var id = g.mysql.Insert<TopicAddField>().AppendData(new TopicAddField { }).ExecuteIdentity();
|
||||
}
|
||||
|
||||
[Table(Name = "TopicAddField", OldName = "xxxtb.TopicAddField")]
|
||||
public class TopicAddField
|
||||
{
|
||||
[Column(IsIdentity = true)]
|
||||
public int? Id { get; set; }
|
||||
|
||||
public string name { get; set; }
|
||||
|
||||
[Column(DbType = "varchar(200) not null", OldName = "title")]
|
||||
public string title222 { get; set; } = "10";
|
||||
|
||||
[Column(IsIgnore = true)]
|
||||
public DateTime ct { get; set; } = DateTime.Now;
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void GetComparisonDDLStatements()
|
||||
{
|
||||
|
||||
var sql = g.mysql.CodeFirst.GetComparisonDDLStatements<TableAllType>();
|
||||
if (string.IsNullOrEmpty(sql) == false)
|
||||
{
|
||||
Assert.Equal(@"CREATE TABLE IF NOT EXISTS `cccddd`.`tb_alltype` (
|
||||
`Id` INT(11) NOT NULL AUTO_INCREMENT,
|
||||
`testFieldBool` BIT(1) NOT NULL,
|
||||
`testFieldSByte` TINYINT(3) NOT NULL,
|
||||
`testFieldShort` SMALLINT(6) NOT NULL,
|
||||
`testFieldInt` INT(11) NOT NULL,
|
||||
`testFieldLong` BIGINT(20) NOT NULL,
|
||||
`testFieldByte` TINYINT(3) UNSIGNED NOT NULL,
|
||||
`testFieldUShort` SMALLINT(5) UNSIGNED NOT NULL,
|
||||
`testFieldUInt` INT(10) UNSIGNED NOT NULL,
|
||||
`testFieldULong` BIGINT(20) UNSIGNED NOT NULL,
|
||||
`testFieldDouble` DOUBLE NOT NULL,
|
||||
`testFieldFloat` FLOAT NOT NULL,
|
||||
`testFieldDecimal` DECIMAL(10,2) NOT NULL,
|
||||
`testFieldTimeSpan` TIME NOT NULL,
|
||||
`testFieldDateTime` DATETIME(3) NOT NULL,
|
||||
`testFieldBytes` VARBINARY(255),
|
||||
`testFieldString` VARCHAR(255),
|
||||
`testFieldGuid` VARCHAR(36),
|
||||
`testFieldBoolNullable` BIT(1),
|
||||
`testFieldSByteNullable` TINYINT(3),
|
||||
`testFieldShortNullable` SMALLINT(6),
|
||||
`testFieldIntNullable` INT(11),
|
||||
`testFielLongNullable` BIGINT(20),
|
||||
`testFieldByteNullable` TINYINT(3) UNSIGNED,
|
||||
`testFieldUShortNullable` SMALLINT(5) UNSIGNED,
|
||||
`testFieldUIntNullable` INT(10) UNSIGNED,
|
||||
`testFieldULongNullable` BIGINT(20) UNSIGNED,
|
||||
`testFieldDoubleNullable` DOUBLE,
|
||||
`testFieldFloatNullable` FLOAT,
|
||||
`testFieldDecimalNullable` DECIMAL(10,2),
|
||||
`testFieldTimeSpanNullable` TIME,
|
||||
`testFieldDateTimeNullable` DATETIME(3),
|
||||
`testFieldGuidNullable` VARCHAR(36),
|
||||
`testFieldPoint` POINT,
|
||||
`testFieldLineString` LINESTRING,
|
||||
`testFieldPolygon` POLYGON,
|
||||
`testFieldMultiPoint` MULTIPOINT,
|
||||
`testFieldMultiLineString` MULTILINESTRING,
|
||||
`testFieldMultiPolygon` MULTIPOLYGON,
|
||||
`testFieldEnum1` ENUM('E1','E2','E3') NOT NULL,
|
||||
`testFieldEnum1Nullable` ENUM('E1','E2','E3'),
|
||||
`testFieldEnum2` SET('F1','F2','F3') NOT NULL,
|
||||
`testFieldEnum2Nullable` SET('F1','F2','F3'),
|
||||
PRIMARY KEY (`Id`)
|
||||
) Engine=InnoDB;
|
||||
", sql);
|
||||
}
|
||||
|
||||
sql = g.mysql.CodeFirst.GetComparisonDDLStatements<Tb_alltype>();
|
||||
}
|
||||
|
||||
IInsert<TableAllType> insert => g.mysql.Insert<TableAllType>();
|
||||
ISelect<TableAllType> select => g.mysql.Select<TableAllType>();
|
||||
|
||||
[Fact]
|
||||
public void CurdAllField()
|
||||
{
|
||||
var item = new TableAllType { };
|
||||
item.Id = (int)insert.AppendData(item).ExecuteIdentity();
|
||||
|
||||
var newitem = select.Where(a => a.Id == item.Id).ToOne();
|
||||
|
||||
var item2 = new TableAllType
|
||||
{
|
||||
testFieldBool = true,
|
||||
testFieldBoolNullable = true,
|
||||
testFieldByte = 255,
|
||||
testFieldByteNullable = 127,
|
||||
testFieldBytes = Encoding.UTF8.GetBytes("我是中国人"),
|
||||
testFieldDateTime = DateTime.Now,
|
||||
testFieldDateTimeNullable = DateTime.Now.AddHours(-1),
|
||||
testFieldDecimal = 99.99M,
|
||||
testFieldDecimalNullable = 99.98M,
|
||||
testFieldDouble = 999.99,
|
||||
testFieldDoubleNullable = 999.98,
|
||||
testFieldEnum1 = TableAllTypeEnumType1.e5,
|
||||
testFieldEnum1Nullable = TableAllTypeEnumType1.e3,
|
||||
testFieldEnum2 = TableAllTypeEnumType2.f2,
|
||||
testFieldEnum2Nullable = TableAllTypeEnumType2.f3,
|
||||
testFieldFloat = 19.99F,
|
||||
testFieldFloatNullable = 19.98F,
|
||||
testFieldGuid = Guid.NewGuid(),
|
||||
testFieldGuidNullable = Guid.NewGuid(),
|
||||
testFieldInt = int.MaxValue,
|
||||
testFieldIntNullable = int.MinValue,
|
||||
testFieldSByte = 100,
|
||||
testFieldSByteNullable = 99,
|
||||
testFieldShort = short.MaxValue,
|
||||
testFieldShortNullable = short.MinValue,
|
||||
testFieldString = "我是中国人string",
|
||||
testFieldTimeSpan = TimeSpan.FromSeconds(999),
|
||||
testFieldTimeSpanNullable = TimeSpan.FromSeconds(60),
|
||||
testFieldUInt = uint.MaxValue,
|
||||
testFieldUIntNullable = uint.MinValue,
|
||||
testFieldULong = ulong.MaxValue,
|
||||
testFieldULongNullable = ulong.MinValue,
|
||||
testFieldUShort = ushort.MaxValue,
|
||||
testFieldUShortNullable = ushort.MinValue,
|
||||
testFielLongNullable = long.MinValue
|
||||
};
|
||||
var sqlPar = insert.AppendData(item2).ToSql();
|
||||
var sqlText = insert.AppendData(item2).NoneParameter().ToSql();
|
||||
var item3NP = insert.AppendData(item2).NoneParameter().ExecuteIdentity();
|
||||
|
||||
var enumConvInt = select.Where(a => a.Id == (int)TableAllTypeEnumType1.e1).ToSql();
|
||||
|
||||
item2.Id = (int)insert.AppendData(item2).ExecuteIdentity();
|
||||
var newitem2 = select.Where(a => a.Id == item2.Id).ToOne();
|
||||
|
||||
var items = select.ToList();
|
||||
}
|
||||
|
||||
|
||||
[JsonObject(MemberSerialization.OptIn), Table(Name = "tb_alltype")]
|
||||
public partial class Tb_alltype
|
||||
{
|
||||
|
||||
[JsonProperty, Column(Name = "Id", DbType = "int(11)", IsPrimary = true, IsIdentity = true)]
|
||||
public int Id { get; set; }
|
||||
|
||||
|
||||
[JsonProperty, Column(Name = "testFieldBool", DbType = "bit(1)")]
|
||||
public bool TestFieldBool { get; set; }
|
||||
|
||||
|
||||
[JsonProperty, Column(Name = "testFieldBoolNullable", DbType = "bit(1)", IsNullable = true)]
|
||||
public bool? TestFieldBoolNullable { get; set; }
|
||||
|
||||
|
||||
[JsonProperty, Column(Name = "testFieldByte", DbType = "tinyint(3) unsigned")]
|
||||
public byte TestFieldByte { get; set; }
|
||||
|
||||
|
||||
[JsonProperty, Column(Name = "testFieldByteNullable", DbType = "tinyint(3) unsigned", IsNullable = true)]
|
||||
public byte? TestFieldByteNullable { get; set; }
|
||||
|
||||
|
||||
[JsonProperty, Column(Name = "testFieldBytes", DbType = "varbinary(255)", IsNullable = true)]
|
||||
public byte[] TestFieldBytes { get; set; }
|
||||
|
||||
|
||||
[JsonProperty, Column(Name = "testFieldDateTime", DbType = "datetime")]
|
||||
public DateTime TestFieldDateTime { get; set; }
|
||||
|
||||
|
||||
[JsonProperty, Column(Name = "testFieldDateTimeNullable", DbType = "datetime", IsNullable = true)]
|
||||
public DateTime? TestFieldDateTimeNullable { get; set; }
|
||||
|
||||
|
||||
[JsonProperty, Column(Name = "testFieldDecimal", DbType = "decimal(10,2)")]
|
||||
public decimal TestFieldDecimal { get; set; }
|
||||
|
||||
|
||||
[JsonProperty, Column(Name = "testFieldDecimalNullable", DbType = "decimal(10,2)", IsNullable = true)]
|
||||
public decimal? TestFieldDecimalNullable { get; set; }
|
||||
|
||||
|
||||
[JsonProperty, Column(Name = "testFieldDouble", DbType = "double")]
|
||||
public double TestFieldDouble { get; set; }
|
||||
|
||||
|
||||
[JsonProperty, Column(Name = "testFieldDoubleNullable", DbType = "double", IsNullable = true)]
|
||||
public double? TestFieldDoubleNullable { get; set; }
|
||||
|
||||
|
||||
[JsonProperty, Column(Name = "testFieldEnum1", DbType = "enum('E1','E2','E3','E5')")]
|
||||
public Tb_alltypeTESTFIELDENUM1 TestFieldEnum1 { get; set; }
|
||||
|
||||
|
||||
[JsonProperty, Column(Name = "testFieldEnum1Nullable", DbType = "enum('E1','E2','E3','E5')", IsNullable = true)]
|
||||
public Tb_alltypeTESTFIELDENUM1NULLABLE? TestFieldEnum1Nullable { get; set; }
|
||||
|
||||
|
||||
[JsonProperty, Column(Name = "testFieldEnum2", DbType = "set('F1','F2','F3')")]
|
||||
public Tb_alltypeTESTFIELDENUM2 TestFieldEnum2 { get; set; }
|
||||
|
||||
|
||||
[JsonProperty, Column(Name = "testFieldEnum2Nullable", DbType = "set('F1','F2','F3')", IsNullable = true)]
|
||||
public Tb_alltypeTESTFIELDENUM2NULLABLE? TestFieldEnum2Nullable { get; set; }
|
||||
|
||||
|
||||
[JsonProperty, Column(Name = "testFieldFloat", DbType = "float")]
|
||||
public float TestFieldFloat { get; set; }
|
||||
|
||||
|
||||
[JsonProperty, Column(Name = "testFieldFloatNullable", DbType = "float", IsNullable = true)]
|
||||
public float? TestFieldFloatNullable { get; set; }
|
||||
|
||||
|
||||
[JsonProperty, Column(Name = "testFieldGuid", DbType = "char(36)")]
|
||||
public Guid TestFieldGuid { get; set; }
|
||||
|
||||
|
||||
[JsonProperty, Column(Name = "testFieldGuidNullable", DbType = "char(36)", IsNullable = true)]
|
||||
public Guid? TestFieldGuidNullable { get; set; }
|
||||
|
||||
|
||||
[JsonProperty, Column(Name = "testFieldInt", DbType = "int(11)")]
|
||||
public int TestFieldInt { get; set; }
|
||||
|
||||
|
||||
[JsonProperty, Column(Name = "testFieldIntNullable", DbType = "int(11)", IsNullable = true)]
|
||||
public int? TestFieldIntNullable { get; set; }
|
||||
|
||||
|
||||
[JsonProperty, Column(Name = "testFieldLong", DbType = "bigint(20)")]
|
||||
public long TestFieldLong { get; set; }
|
||||
|
||||
|
||||
[JsonProperty, Column(Name = "testFieldSByte", DbType = "tinyint(3)")]
|
||||
public sbyte TestFieldSByte { get; set; }
|
||||
|
||||
|
||||
[JsonProperty, Column(Name = "testFieldSByteNullable", DbType = "tinyint(3)", IsNullable = true)]
|
||||
public sbyte? TestFieldSByteNullable { get; set; }
|
||||
|
||||
|
||||
[JsonProperty, Column(Name = "testFieldShort", DbType = "smallint(6)")]
|
||||
public short TestFieldShort { get; set; }
|
||||
|
||||
|
||||
[JsonProperty, Column(Name = "testFieldShortNullable", DbType = "smallint(6)", IsNullable = true)]
|
||||
public short? TestFieldShortNullable { get; set; }
|
||||
|
||||
|
||||
[JsonProperty, Column(Name = "testFieldString", DbType = "varchar(255)", IsNullable = true)]
|
||||
public string TestFieldString { get; set; }
|
||||
|
||||
|
||||
[JsonProperty, Column(Name = "testFieldTimeSpan", DbType = "time")]
|
||||
public TimeSpan TestFieldTimeSpan { get; set; }
|
||||
|
||||
|
||||
[JsonProperty, Column(Name = "testFieldTimeSpanNullable", DbType = "time", IsNullable = true)]
|
||||
public TimeSpan? TestFieldTimeSpanNullable { get; set; }
|
||||
|
||||
|
||||
[JsonProperty, Column(Name = "testFieldUInt", DbType = "int(10) unsigned")]
|
||||
public uint TestFieldUInt { get; set; }
|
||||
|
||||
|
||||
[JsonProperty, Column(Name = "testFieldUIntNullable", DbType = "int(10) unsigned", IsNullable = true)]
|
||||
public uint? TestFieldUIntNullable { get; set; }
|
||||
|
||||
|
||||
[JsonProperty, Column(Name = "testFieldULong", DbType = "bigint(20) unsigned")]
|
||||
public ulong TestFieldULong { get; set; }
|
||||
|
||||
|
||||
[JsonProperty, Column(Name = "testFieldULongNullable", DbType = "bigint(20) unsigned", IsNullable = true)]
|
||||
public ulong? TestFieldULongNullable { get; set; }
|
||||
|
||||
|
||||
[JsonProperty, Column(Name = "testFieldUShort", DbType = "smallint(5) unsigned")]
|
||||
public ushort TestFieldUShort { get; set; }
|
||||
|
||||
|
||||
[JsonProperty, Column(Name = "testFieldUShortNullable", DbType = "smallint(5) unsigned", IsNullable = true)]
|
||||
public ushort? TestFieldUShortNullable { get; set; }
|
||||
|
||||
|
||||
[JsonProperty, Column(Name = "testFielLongNullable", DbType = "bigint(20)", IsNullable = true)]
|
||||
public long? TestFielLongNullable { get; set; }
|
||||
|
||||
internal static IFreeSql mysql => null;
|
||||
public static FreeSql.ISelect<Tb_alltype> Select => mysql.Select<Tb_alltype>();
|
||||
|
||||
public static long Delete(int Id)
|
||||
{
|
||||
var affrows = mysql.Delete<Tb_alltype>().Where(a => a.Id == Id).ExecuteAffrows();
|
||||
return affrows;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 保存或添加,如果主键有值则尝试 Update,如果影响的行为 0 则尝试 Insert
|
||||
/// </summary>
|
||||
public void Save()
|
||||
{
|
||||
if (this.Id != default(int))
|
||||
{
|
||||
var affrows = mysql.Update<Tb_alltype>().Where(a => a.Id == Id).ExecuteAffrows();
|
||||
if (affrows > 0) return;
|
||||
}
|
||||
this.Id = (int)mysql.Insert<Tb_alltype>().AppendData(this).ExecuteIdentity();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public enum Tb_alltypeTESTFIELDENUM1
|
||||
{
|
||||
E1 = 1, E2, E3, E5
|
||||
}
|
||||
public enum Tb_alltypeTESTFIELDENUM1NULLABLE
|
||||
{
|
||||
E1 = 1, E2, E3, E5
|
||||
}
|
||||
[Flags]
|
||||
public enum Tb_alltypeTESTFIELDENUM2 : long
|
||||
{
|
||||
F1 = 1, F2 = 2, F3 = 4
|
||||
}
|
||||
[Flags]
|
||||
public enum Tb_alltypeTESTFIELDENUM2NULLABLE : long
|
||||
{
|
||||
F1 = 1, F2 = 2, F3 = 4
|
||||
}
|
||||
|
||||
|
||||
[Table(Name = "tb_alltype")]
|
||||
class TableAllType
|
||||
{
|
||||
[Column(IsIdentity = true, IsPrimary = true)]
|
||||
public int Id { get; set; }
|
||||
|
||||
public bool testFieldBool { get; set; }
|
||||
public sbyte testFieldSByte { get; set; }
|
||||
public short testFieldShort { get; set; }
|
||||
public int testFieldInt { get; set; }
|
||||
public long testFieldLong { get; set; }
|
||||
public byte testFieldByte { get; set; }
|
||||
public ushort testFieldUShort { get; set; }
|
||||
public uint testFieldUInt { get; set; }
|
||||
public ulong testFieldULong { get; set; }
|
||||
public double testFieldDouble { get; set; }
|
||||
public float testFieldFloat { get; set; }
|
||||
public decimal testFieldDecimal { get; set; }
|
||||
public TimeSpan testFieldTimeSpan { get; set; }
|
||||
public DateTime testFieldDateTime { get; set; }
|
||||
public byte[] testFieldBytes { get; set; }
|
||||
public string testFieldString { get; set; }
|
||||
public Guid testFieldGuid { get; set; }
|
||||
|
||||
public bool? testFieldBoolNullable { get; set; }
|
||||
public sbyte? testFieldSByteNullable { get; set; }
|
||||
public short? testFieldShortNullable { get; set; }
|
||||
public int? testFieldIntNullable { get; set; }
|
||||
public long? testFielLongNullable { get; set; }
|
||||
public byte? testFieldByteNullable { get; set; }
|
||||
public ushort? testFieldUShortNullable { get; set; }
|
||||
public uint? testFieldUIntNullable { get; set; }
|
||||
public ulong? testFieldULongNullable { get; set; }
|
||||
public double? testFieldDoubleNullable { get; set; }
|
||||
public float? testFieldFloatNullable { get; set; }
|
||||
public decimal? testFieldDecimalNullable { get; set; }
|
||||
public TimeSpan? testFieldTimeSpanNullable { get; set; }
|
||||
public DateTime? testFieldDateTimeNullable { get; set; }
|
||||
public Guid? testFieldGuidNullable { get; set; }
|
||||
|
||||
public TableAllTypeEnumType1 testFieldEnum1 { get; set; }
|
||||
public TableAllTypeEnumType1? testFieldEnum1Nullable { get; set; }
|
||||
public TableAllTypeEnumType2 testFieldEnum2 { get; set; }
|
||||
public TableAllTypeEnumType2? testFieldEnum2Nullable { get; set; }
|
||||
}
|
||||
|
||||
public enum TableAllTypeEnumType1 { e1, e2, e3, e5 }
|
||||
[Flags] public enum TableAllTypeEnumType2 { f1, f2, f3 }
|
||||
}
|
||||
}
|
@ -0,0 +1,25 @@
|
||||
using FreeSql.DataAnnotations;
|
||||
using System;
|
||||
using Xunit;
|
||||
|
||||
namespace FreeSql.Tests.Odbc.MySql
|
||||
{
|
||||
public class MySqlDbFirstTest
|
||||
{
|
||||
[Fact]
|
||||
public void GetDatabases()
|
||||
{
|
||||
|
||||
var t1 = g.mysql.DbFirst.GetDatabases();
|
||||
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void GetTablesByDatabase()
|
||||
{
|
||||
|
||||
var t2 = g.mysql.DbFirst.GetTablesByDatabase(g.mysql.DbFirst.GetDatabases()[0]);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,169 @@
|
||||
using FreeSql.DataAnnotations;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Xunit;
|
||||
|
||||
namespace FreeSql.Tests.Odbc.MySqlExpression
|
||||
{
|
||||
public class ConvertTest
|
||||
{
|
||||
|
||||
ISelect<Topic> select => g.mysql.Select<Topic>();
|
||||
|
||||
[Table(Name = "tb_topic")]
|
||||
class Topic
|
||||
{
|
||||
[Column(IsIdentity = true, IsPrimary = true)]
|
||||
public int Id { get; set; }
|
||||
public int Clicks { get; set; }
|
||||
public int TypeGuid { get; set; }
|
||||
public TestTypeInfo Type { get; set; }
|
||||
public string Title { get; set; }
|
||||
public DateTime CreateTime { get; set; }
|
||||
}
|
||||
class TestTypeInfo
|
||||
{
|
||||
public int Guid { get; set; }
|
||||
public int ParentId { get; set; }
|
||||
public TestTypeParentInfo Parent { get; set; }
|
||||
public string Name { get; set; }
|
||||
}
|
||||
class TestTypeParentInfo
|
||||
{
|
||||
public int Id { get; set; }
|
||||
public string Name { get; set; }
|
||||
|
||||
public List<TestTypeInfo> Types { get; set; }
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ToBoolean()
|
||||
{
|
||||
var data = new List<object>();
|
||||
data.Add(select.Where(a => (Convert.ToBoolean(a.Clicks) ? 1 : 0) > 0).ToList());
|
||||
data.Add(select.Where(a => (bool.Parse(a.Clicks.ToString()) ? 1 : 0) > 0).ToList());
|
||||
}
|
||||
[Fact]
|
||||
public void ToByte()
|
||||
{
|
||||
var data = new List<object>();
|
||||
data.Add(select.Where(a => Convert.ToByte(a.Clicks % 255) > 0).ToList());
|
||||
data.Add(select.Where(a => byte.Parse((a.Clicks % 255).ToString()) > 0).ToList());
|
||||
}
|
||||
[Fact]
|
||||
public void ToChar()
|
||||
{
|
||||
var data = new List<object>();
|
||||
data.Add(select.Where(a => Convert.ToChar(a.Clicks) == '1').ToList());
|
||||
data.Add(select.Where(a => char.Parse(a.Clicks.ToString()) == '1').ToList());
|
||||
}
|
||||
[Fact]
|
||||
public void ToDateTime()
|
||||
{
|
||||
var data = new List<object>();
|
||||
data.Add(select.Where(a => Convert.ToDateTime(a.CreateTime.ToString()).Year > 0).ToList());
|
||||
data.Add(select.Where(a => DateTime.Parse(a.CreateTime.ToString()).Year > 0).ToList());
|
||||
}
|
||||
[Fact]
|
||||
public void ToDecimal()
|
||||
{
|
||||
var data = new List<object>();
|
||||
data.Add(select.Where(a => Convert.ToDecimal(a.Clicks) > 0).ToList());
|
||||
data.Add(select.Where(a => decimal.Parse(a.Clicks.ToString()) > 0).ToList());
|
||||
}
|
||||
[Fact]
|
||||
public void ToDouble()
|
||||
{
|
||||
var data = new List<object>();
|
||||
data.Add(select.Where(a => Convert.ToDouble(a.Clicks) > 0).ToList());
|
||||
data.Add(select.Where(a => double.Parse(a.Clicks.ToString()) > 0).ToList());
|
||||
}
|
||||
[Fact]
|
||||
public void ToInt16()
|
||||
{
|
||||
var data = new List<object>();
|
||||
data.Add(select.Where(a => Convert.ToInt16(a.Clicks) > 0).ToList());
|
||||
data.Add(select.Where(a => short.Parse(a.Clicks.ToString()) > 0).ToList());
|
||||
}
|
||||
[Fact]
|
||||
public void ToInt32()
|
||||
{
|
||||
var data = new List<object>();
|
||||
data.Add(select.Where(a => (int)a.Clicks > 0).ToList());
|
||||
data.Add(select.Where(a => Convert.ToInt32(a.Clicks) > 0).ToList());
|
||||
data.Add(select.Where(a => int.Parse(a.Clicks.ToString()) > 0).ToList());
|
||||
}
|
||||
[Fact]
|
||||
public void ToInt64()
|
||||
{
|
||||
var data = new List<object>();
|
||||
data.Add(select.Where(a => Convert.ToInt64(a.Clicks) > 0).ToList());
|
||||
data.Add(select.Where(a => long.Parse(a.Clicks.ToString()) > 0).ToList());
|
||||
}
|
||||
[Fact]
|
||||
public void ToSByte()
|
||||
{
|
||||
var data = new List<object>();
|
||||
data.Add(select.Where(a => Convert.ToSByte(a.Clicks % 128) > 0).ToList());
|
||||
data.Add(select.Where(a => sbyte.Parse((a.Clicks % 128).ToString()) > 0).ToList());
|
||||
}
|
||||
[Fact]
|
||||
public void ToSingle()
|
||||
{
|
||||
var data = new List<object>();
|
||||
data.Add(select.Where(a => Convert.ToSingle(a.Clicks) > 0).ToList());
|
||||
data.Add(select.Where(a => float.Parse(a.Clicks.ToString()) > 0).ToList());
|
||||
}
|
||||
[Fact]
|
||||
public void this_ToString()
|
||||
{
|
||||
var data = new List<object>();
|
||||
data.Add(select.Where(a => Convert.ToString(a.Clicks).Equals("")).ToList());
|
||||
data.Add(select.Where(a => a.Clicks.ToString().Equals("")).ToList());
|
||||
}
|
||||
[Fact]
|
||||
public void ToUInt16()
|
||||
{
|
||||
var data = new List<object>();
|
||||
data.Add(select.Where(a => Convert.ToUInt16(a.Clicks) > 0).ToList());
|
||||
data.Add(select.Where(a => ushort.Parse(a.Clicks.ToString()) > 0).ToList());
|
||||
}
|
||||
[Fact]
|
||||
public void ToUInt32()
|
||||
{
|
||||
var data = new List<object>();
|
||||
data.Add(select.Where(a => Convert.ToUInt32(a.Clicks) > 0).ToList());
|
||||
data.Add(select.Where(a => uint.Parse(a.Clicks.ToString()) > 0).ToList());
|
||||
}
|
||||
[Fact]
|
||||
public void ToUInt64()
|
||||
{
|
||||
var data = new List<object>();
|
||||
data.Add(select.Where(a => Convert.ToUInt64(a.Clicks) > 0).ToList());
|
||||
data.Add(select.Where(a => ulong.Parse(a.Clicks.ToString()) > 0).ToList());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Guid_Parse()
|
||||
{
|
||||
var data = new List<object>();
|
||||
data.Add(select.Where(a => Guid.Parse(Guid.Empty.ToString()) == Guid.Empty).ToList());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Guid_NewGuid()
|
||||
{
|
||||
var data = new List<object>();
|
||||
//data.Add(select.OrderBy(a => Guid.NewGuid()).Limit(10).ToList());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Random()
|
||||
{
|
||||
var data = new List<object>();
|
||||
data.Add(select.Where(a => new Random().Next() > a.Clicks).Limit(10).ToList());
|
||||
data.Add(select.Where(a => new Random().NextDouble() > a.Clicks).Limit(10).ToList());
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,694 @@
|
||||
using FreeSql.DataAnnotations;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Xunit;
|
||||
|
||||
namespace FreeSql.Tests.Odbc.MySqlExpression
|
||||
{
|
||||
public class DateTimeTest
|
||||
{
|
||||
|
||||
ISelect<Topic> select => g.mysql.Select<Topic>();
|
||||
|
||||
[Table(Name = "tb_topic111333")]
|
||||
class Topic
|
||||
{
|
||||
[Column(IsIdentity = true, IsPrimary = true)]
|
||||
public int Id { get; set; }
|
||||
public int Clicks { get; set; }
|
||||
public int TypeGuid { get; set; }
|
||||
public TestTypeInfo Type { get; set; }
|
||||
public string Title { get; set; }
|
||||
public DateTime CreateTime { get; set; }
|
||||
}
|
||||
[Table(Name = "TestTypeInfo333")]
|
||||
class TestTypeInfo
|
||||
{
|
||||
[Column(IsIdentity = true)]
|
||||
public int Guid { get; set; }
|
||||
public int ParentId { get; set; }
|
||||
public TestTypeParentInfo Parent { get; set; }
|
||||
public string Name { get; set; }
|
||||
public DateTime Time { get; set; }
|
||||
}
|
||||
[Table(Name = "TestTypeParentInfo23123")]
|
||||
class TestTypeParentInfo
|
||||
{
|
||||
public int Id { get; set; }
|
||||
public string Name { get; set; }
|
||||
|
||||
public List<TestTypeInfo> Types { get; set; }
|
||||
public DateTime Time2 { get; set; }
|
||||
}
|
||||
[Fact]
|
||||
public void Now()
|
||||
{
|
||||
var data = new List<object>();
|
||||
data.Add(select.Where(a => a.CreateTime.Date == DateTime.Now.Date).ToList());
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5
|
||||
//FROM `tb_topic111333` a
|
||||
//WHERE (cast(date_format(a.`CreateTime`, '%Y-%m-%d') as datetime) = cast(date_format(now(), '%Y-%m-%d') as datetime))
|
||||
}
|
||||
[Fact]
|
||||
public void UtcNow()
|
||||
{
|
||||
var data = new List<object>();
|
||||
data.Add(select.Where(a => a.CreateTime.Date == DateTime.UtcNow.Date).ToList());
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5
|
||||
//FROM `tb_topic111333` a
|
||||
//WHERE (cast(date_format(a.`CreateTime`, '%Y-%m-%d') as datetime) = cast(date_format(utc_timestamp(), '%Y-%m-%d') as datetime))
|
||||
}
|
||||
[Fact]
|
||||
public void MinValue()
|
||||
{
|
||||
var data = new List<object>();
|
||||
data.Add(select.Where(a => a.CreateTime.Date == DateTime.MinValue.Date).ToList());
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5
|
||||
//FROM `tb_topic111333` a
|
||||
//WHERE (cast(date_format(a.`CreateTime`, '%Y-%m-%d') as datetime) = cast(date_format(cast('0001/1/1 0:00:00' as datetime), '%Y-%m-%d') as datetime))
|
||||
}
|
||||
[Fact]
|
||||
public void MaxValue()
|
||||
{
|
||||
var data = new List<object>();
|
||||
data.Add(select.Where(a => a.CreateTime.Date == DateTime.MaxValue.Date).ToList());
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5
|
||||
//FROM `tb_topic111333` a
|
||||
//WHERE (cast(date_format(a.`CreateTime`, '%Y-%m-%d') as datetime) = cast(date_format(cast('9999/12/31 23:59:59' as datetime), '%Y-%m-%d') as datetime))
|
||||
}
|
||||
[Fact]
|
||||
public void Date()
|
||||
{
|
||||
var data = new List<object>();
|
||||
data.Add(select.Where(a => a.CreateTime.Date == DateTime.Now.Date).ToList());
|
||||
data.Add(select.Where(a => a.Type.Time.Date > DateTime.Now.Date).ToList());
|
||||
data.Add(select.Where(a => a.Type.Parent.Time2.Date > DateTime.Now.Date).ToList());
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5
|
||||
//FROM `tb_topic111333` a
|
||||
//WHERE (cast(date_format(a.`CreateTime`, '%Y-%m-%d') as datetime) = cast(date_format(now(), '%Y-%m-%d') as datetime));
|
||||
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a__Type.`Time` as7, a.`Title` as8, a.`CreateTime` as9
|
||||
//FROM `tb_topic111333` a, `TestTypeInfo333` a__Type
|
||||
//WHERE (cast(date_format(a__Type.`Time`, '%Y-%m-%d') as datetime) > cast(date_format(now(), '%Y-%m-%d') as datetime));
|
||||
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a__Type.`Time` as7, a.`Title` as8, a.`CreateTime` as9
|
||||
//FROM `tb_topic111333` a, `TestTypeInfo333` a__Type, `TestTypeParentInfo23123` a__Type__Parent
|
||||
//WHERE (cast(date_format(a__Type__Parent.`Time2`, '%Y-%m-%d') as datetime) > cast(date_format(now(), '%Y-%m-%d') as datetime));
|
||||
data.Add(select.Where(a => DateTime.Now.Subtract(a.CreateTime.Date).TotalSeconds > 0).ToList());
|
||||
data.Add(select.Where(a => DateTime.Now.Subtract(a.Type.Time.Date).TotalSeconds > 0).ToList());
|
||||
data.Add(select.Where(a => DateTime.Now.Subtract(a.Type.Parent.Time2.Date).TotalSeconds > 0).ToList());
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5
|
||||
//FROM `tb_topic111333` a
|
||||
//WHERE (((timestampdiff(microsecond, cast(date_format(a.`CreateTime`, '%Y-%m-%d') as datetime), now())) / 1000000) > 0);
|
||||
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a__Type.`Time` as7, a.`Title` as8, a.`CreateTime` as9
|
||||
//FROM `tb_topic111333` a, `TestTypeInfo333` a__Type
|
||||
//WHERE (((timestampdiff(microsecond, cast(date_format(a__Type.`Time`, '%Y-%m-%d') as datetime), now())) / 1000000) > 0);
|
||||
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a__Type.`Time` as7, a.`Title` as8, a.`CreateTime` as9
|
||||
//FROM `tb_topic111333` a, `TestTypeInfo333` a__Type, `TestTypeParentInfo23123` a__Type__Parent
|
||||
//WHERE (((timestampdiff(microsecond, cast(date_format(a__Type__Parent.`Time2`, '%Y-%m-%d') as datetime), now())) / 1000000) > 0)
|
||||
}
|
||||
[Fact]
|
||||
public void TimeOfDay()
|
||||
{
|
||||
var data = new List<object>();
|
||||
data.Add(select.Where(a => a.CreateTime.TimeOfDay == DateTime.Now.TimeOfDay).ToList());
|
||||
data.Add(select.Where(a => a.Type.Time.TimeOfDay > DateTime.Now.TimeOfDay).ToList());
|
||||
data.Add(select.Where(a => a.Type.Parent.Time2.TimeOfDay > DateTime.Now.TimeOfDay).ToList());
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5
|
||||
//FROM `tb_topic111333` a
|
||||
//WHERE ((timestampdiff(microsecond, date_format(a.`CreateTime`, '1970-1-1 %H:%i:%s.%f'), a.`CreateTime`) + 62135596800000000) = (timestampdiff(microsecond, date_format(now(), '1970-1-1 %H:%i:%s.%f'), now()) + 62135596800000000));
|
||||
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a__Type.`Time` as7, a.`Title` as8, a.`CreateTime` as9
|
||||
//FROM `tb_topic111333` a, `TestTypeInfo333` a__Type
|
||||
//WHERE ((timestampdiff(microsecond, date_format(a__Type.`Time`, '1970-1-1 %H:%i:%s.%f'), a__Type.`Time`) + 62135596800000000) > (timestampdiff(microsecond, date_format(now(), '1970-1-1 %H:%i:%s.%f'), now()) + 62135596800000000));
|
||||
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a__Type.`Time` as7, a.`Title` as8, a.`CreateTime` as9
|
||||
//FROM `tb_topic111333` a, `TestTypeInfo333` a__Type, `TestTypeParentInfo23123` a__Type__Parent
|
||||
//WHERE ((timestampdiff(microsecond, date_format(a__Type__Parent.`Time2`, '1970-1-1 %H:%i:%s.%f'), a__Type__Parent.`Time2`) + 62135596800000000) > (timestampdiff(microsecond, date_format(now(), '1970-1-1 %H:%i:%s.%f'), now()) + 62135596800000000))
|
||||
}
|
||||
[Fact]
|
||||
public void DayOfWeek()
|
||||
{
|
||||
var data = new List<object>();
|
||||
data.Add(select.Where(a => a.CreateTime.DayOfWeek > DateTime.Now.DayOfWeek).ToList());
|
||||
data.Add(select.Where(a => a.Type.Time.DayOfWeek > DateTime.Now.DayOfWeek).ToList());
|
||||
data.Add(select.Where(a => a.Type.Parent.Time2.DayOfWeek > DateTime.Now.DayOfWeek).ToList());
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5
|
||||
//FROM `tb_topic111333` a
|
||||
//WHERE ((dayofweek(a.`CreateTime`) - 1) > (dayofweek(now()) - 1));
|
||||
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a__Type.`Time` as7, a.`Title` as8, a.`CreateTime` as9
|
||||
//FROM `tb_topic111333` a, `TestTypeInfo333` a__Type
|
||||
//WHERE ((dayofweek(a__Type.`Time`) - 1) > (dayofweek(now()) - 1));
|
||||
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a__Type.`Time` as7, a.`Title` as8, a.`CreateTime` as9
|
||||
//FROM `tb_topic111333` a, `TestTypeInfo333` a__Type, `TestTypeParentInfo23123` a__Type__Parent
|
||||
//WHERE ((dayofweek(a__Type__Parent.`Time2`) - 1) > (dayofweek(now()) - 1))
|
||||
}
|
||||
[Fact]
|
||||
public void Day()
|
||||
{
|
||||
var data = new List<object>();
|
||||
data.Add(select.Where(a => a.CreateTime.Day > DateTime.Now.Day).ToList());
|
||||
data.Add(select.Where(a => a.Type.Time.Day > DateTime.Now.Day).ToList());
|
||||
data.Add(select.Where(a => a.Type.Parent.Time2.Day > DateTime.Now.Day).ToList());
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5
|
||||
//FROM `tb_topic111333` a
|
||||
//WHERE (dayofmonth(a.`CreateTime`) > dayofmonth(now()));
|
||||
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a__Type.`Time` as7, a.`Title` as8, a.`CreateTime` as9
|
||||
//FROM `tb_topic111333` a, `TestTypeInfo333` a__Type
|
||||
//WHERE (dayofmonth(a__Type.`Time`) > dayofmonth(now()));
|
||||
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a__Type.`Time` as7, a.`Title` as8, a.`CreateTime` as9
|
||||
//FROM `tb_topic111333` a, `TestTypeInfo333` a__Type, `TestTypeParentInfo23123` a__Type__Parent
|
||||
//WHERE (dayofmonth(a__Type__Parent.`Time2`) > dayofmonth(now()))
|
||||
}
|
||||
[Fact]
|
||||
public void DayOfYear()
|
||||
{
|
||||
var data = new List<object>();
|
||||
data.Add(select.Where(a => a.CreateTime.DayOfYear > DateTime.Now.DayOfYear).ToList());
|
||||
data.Add(select.Where(a => a.Type.Time.DayOfYear > DateTime.Now.DayOfYear).ToList());
|
||||
data.Add(select.Where(a => a.Type.Parent.Time2.DayOfYear > DateTime.Now.DayOfYear).ToList());
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5
|
||||
//FROM `tb_topic111333` a
|
||||
//WHERE (dayofyear(a.`CreateTime`) > dayofyear(now()));
|
||||
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a__Type.`Time` as7, a.`Title` as8, a.`CreateTime` as9
|
||||
//FROM `tb_topic111333` a, `TestTypeInfo333` a__Type
|
||||
//WHERE (dayofyear(a__Type.`Time`) > dayofyear(now()));
|
||||
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a__Type.`Time` as7, a.`Title` as8, a.`CreateTime` as9
|
||||
//FROM `tb_topic111333` a, `TestTypeInfo333` a__Type, `TestTypeParentInfo23123` a__Type__Parent
|
||||
//WHERE (dayofyear(a__Type__Parent.`Time2`) > dayofyear(now()))
|
||||
}
|
||||
[Fact]
|
||||
public void Month()
|
||||
{
|
||||
var data = new List<object>();
|
||||
data.Add(select.Where(a => a.CreateTime.Month > DateTime.Now.Month).ToList());
|
||||
data.Add(select.Where(a => a.Type.Time.Month > DateTime.Now.Month).ToList());
|
||||
data.Add(select.Where(a => a.Type.Parent.Time2.Month > DateTime.Now.Month).ToList());
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5
|
||||
//FROM `tb_topic111333` a
|
||||
//WHERE (month(a.`CreateTime`) > month(now()));
|
||||
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a__Type.`Time` as7, a.`Title` as8, a.`CreateTime` as9
|
||||
//FROM `tb_topic111333` a, `TestTypeInfo333` a__Type
|
||||
//WHERE (month(a__Type.`Time`) > month(now()));
|
||||
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a__Type.`Time` as7, a.`Title` as8, a.`CreateTime` as9
|
||||
//FROM `tb_topic111333` a, `TestTypeInfo333` a__Type, `TestTypeParentInfo23123` a__Type__Parent
|
||||
//WHERE (month(a__Type__Parent.`Time2`) > month(now()))
|
||||
}
|
||||
[Fact]
|
||||
public void Year()
|
||||
{
|
||||
var data = new List<object>();
|
||||
data.Add(select.Where(a => a.CreateTime.Year > DateTime.Now.Year).ToList());
|
||||
data.Add(select.Where(a => a.Type.Time.Year > DateTime.Now.Year).ToList());
|
||||
data.Add(select.Where(a => a.Type.Parent.Time2.Year > DateTime.Now.Year).ToList());
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5
|
||||
//FROM `tb_topic111333` a
|
||||
//WHERE (year(a.`CreateTime`) > year(now()));
|
||||
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a__Type.`Time` as7, a.`Title` as8, a.`CreateTime` as9
|
||||
//FROM `tb_topic111333` a, `TestTypeInfo333` a__Type
|
||||
//WHERE (year(a__Type.`Time`) > year(now()));
|
||||
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a__Type.`Time` as7, a.`Title` as8, a.`CreateTime` as9
|
||||
//FROM `tb_topic111333` a, `TestTypeInfo333` a__Type, `TestTypeParentInfo23123` a__Type__Parent
|
||||
//WHERE (year(a__Type__Parent.`Time2`) > year(now()))
|
||||
}
|
||||
[Fact]
|
||||
public void Hour()
|
||||
{
|
||||
var data = new List<object>();
|
||||
data.Add(select.Where(a => a.CreateTime.Hour > DateTime.Now.Hour).ToList());
|
||||
data.Add(select.Where(a => a.Type.Time.Hour > DateTime.Now.Hour).ToList());
|
||||
data.Add(select.Where(a => a.Type.Parent.Time2.Hour > DateTime.Now.Hour).ToList());
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5
|
||||
//FROM `tb_topic111333` a
|
||||
//WHERE (hour(a.`CreateTime`) > hour(now()));
|
||||
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a__Type.`Time` as7, a.`Title` as8, a.`CreateTime` as9
|
||||
//FROM `tb_topic111333` a, `TestTypeInfo333` a__Type
|
||||
//WHERE (hour(a__Type.`Time`) > hour(now()));
|
||||
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a__Type.`Time` as7, a.`Title` as8, a.`CreateTime` as9
|
||||
//FROM `tb_topic111333` a, `TestTypeInfo333` a__Type, `TestTypeParentInfo23123` a__Type__Parent
|
||||
//WHERE (hour(a__Type__Parent.`Time2`) > hour(now()))
|
||||
}
|
||||
[Fact]
|
||||
public void Minute()
|
||||
{
|
||||
var data = new List<object>();
|
||||
data.Add(select.Where(a => a.CreateTime.Minute > DateTime.Now.Minute).ToList());
|
||||
data.Add(select.Where(a => a.Type.Time.Minute > DateTime.Now.Minute).ToList());
|
||||
data.Add(select.Where(a => a.Type.Parent.Time2.Minute > DateTime.Now.Minute).ToList());
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5
|
||||
//FROM `tb_topic111333` a
|
||||
//WHERE (minute(a.`CreateTime`) > minute(now()));
|
||||
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a__Type.`Time` as7, a.`Title` as8, a.`CreateTime` as9
|
||||
//FROM `tb_topic111333` a, `TestTypeInfo333` a__Type
|
||||
//WHERE (minute(a__Type.`Time`) > minute(now()));
|
||||
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a__Type.`Time` as7, a.`Title` as8, a.`CreateTime` as9
|
||||
//FROM `tb_topic111333` a, `TestTypeInfo333` a__Type, `TestTypeParentInfo23123` a__Type__Parent
|
||||
//WHERE (minute(a__Type__Parent.`Time2`) > minute(now()))
|
||||
}
|
||||
[Fact]
|
||||
public void Second()
|
||||
{
|
||||
var data = new List<object>();
|
||||
data.Add(select.Where(a => a.CreateTime.Second > DateTime.Now.Second).ToList());
|
||||
data.Add(select.Where(a => a.Type.Time.Second > DateTime.Now.Second).ToList());
|
||||
data.Add(select.Where(a => a.Type.Parent.Time2.Second > DateTime.Now.Second).ToList());
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5
|
||||
//FROM `tb_topic111333` a
|
||||
//WHERE (second(a.`CreateTime`) > second(now()));
|
||||
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a__Type.`Time` as7, a.`Title` as8, a.`CreateTime` as9
|
||||
//FROM `tb_topic111333` a, `TestTypeInfo333` a__Type
|
||||
//WHERE (second(a__Type.`Time`) > second(now()));
|
||||
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a__Type.`Time` as7, a.`Title` as8, a.`CreateTime` as9
|
||||
//FROM `tb_topic111333` a, `TestTypeInfo333` a__Type, `TestTypeParentInfo23123` a__Type__Parent
|
||||
//WHERE (second(a__Type__Parent.`Time2`) > second(now()))
|
||||
}
|
||||
[Fact]
|
||||
public void Millisecond()
|
||||
{
|
||||
var data = new List<object>();
|
||||
data.Add(select.Where(a => a.CreateTime.Millisecond > DateTime.Now.Millisecond).ToList());
|
||||
data.Add(select.Where(a => a.Type.Time.Millisecond > DateTime.Now.Millisecond).ToList());
|
||||
data.Add(select.Where(a => a.Type.Parent.Time2.Millisecond > DateTime.Now.Millisecond).ToList());
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5
|
||||
//FROM `tb_topic111333` a
|
||||
//WHERE (floor(microsecond(a.`CreateTime`) / 1000) > floor(microsecond(now()) / 1000));
|
||||
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a__Type.`Time` as7, a.`Title` as8, a.`CreateTime` as9
|
||||
//FROM `tb_topic111333` a, `TestTypeInfo333` a__Type
|
||||
//WHERE (floor(microsecond(a__Type.`Time`) / 1000) > floor(microsecond(now()) / 1000));
|
||||
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a__Type.`Time` as7, a.`Title` as8, a.`CreateTime` as9
|
||||
//FROM `tb_topic111333` a, `TestTypeInfo333` a__Type, `TestTypeParentInfo23123` a__Type__Parent
|
||||
//WHERE (floor(microsecond(a__Type__Parent.`Time2`) / 1000) > floor(microsecond(now()) / 1000))
|
||||
}
|
||||
[Fact]
|
||||
public void Ticks()
|
||||
{
|
||||
var data = new List<object>();
|
||||
data.Add(select.Where(a => a.CreateTime.Ticks > DateTime.Now.Ticks).ToList());
|
||||
data.Add(select.Where(a => a.Type.Time.Ticks > DateTime.Now.Ticks).ToList());
|
||||
data.Add(select.Where(a => a.Type.Parent.Time2.Ticks > DateTime.Now.Ticks).ToList());
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5
|
||||
//FROM `tb_topic111333` a
|
||||
//WHERE ((timestampdiff(microsecond, '1970-1-1', a.`CreateTime`) * 10 + 621355968000000000) > (timestampdiff(microsecond, '1970-1-1', now()) * 10 + 621355968000000000));
|
||||
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a__Type.`Time` as7, a.`Title` as8, a.`CreateTime` as9
|
||||
//FROM `tb_topic111333` a, `TestTypeInfo333` a__Type
|
||||
//WHERE ((timestampdiff(microsecond, '1970-1-1', a__Type.`Time`) * 10 + 621355968000000000) > (timestampdiff(microsecond, '1970-1-1', now()) * 10 + 621355968000000000));
|
||||
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a__Type.`Time` as7, a.`Title` as8, a.`CreateTime` as9
|
||||
//FROM `tb_topic111333` a, `TestTypeInfo333` a__Type, `TestTypeParentInfo23123` a__Type__Parent
|
||||
//WHERE ((timestampdiff(microsecond, '1970-1-1', a__Type__Parent.`Time2`) * 10 + 621355968000000000) > (timestampdiff(microsecond, '1970-1-1', now()) * 10 + 621355968000000000))
|
||||
}
|
||||
[Fact]
|
||||
public void Add()
|
||||
{
|
||||
var data = new List<object>();
|
||||
data.Add(select.Where(a => a.CreateTime.Add(TimeSpan.FromDays(1)) > DateTime.Now).ToList());
|
||||
data.Add(select.Where(a => a.Type.Time.Add(TimeSpan.FromDays(1)) > DateTime.Now).ToList());
|
||||
data.Add(select.Where(a => a.Type.Parent.Time2.Add(TimeSpan.FromDays(1)) > DateTime.Now).ToList());
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5
|
||||
//FROM `tb_topic111333` a
|
||||
//WHERE (date_add(a.`CreateTime`, interval ((1 * 86400000000)) microsecond) > now());
|
||||
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a__Type.`Time` as7, a.`Title` as8, a.`CreateTime` as9
|
||||
//FROM `tb_topic111333` a, `TestTypeInfo333` a__Type
|
||||
//WHERE (date_add(a__Type.`Time`, interval ((1 * 86400000000)) microsecond) > now());
|
||||
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a__Type.`Time` as7, a.`Title` as8, a.`CreateTime` as9
|
||||
//FROM `tb_topic111333` a, `TestTypeInfo333` a__Type, `TestTypeParentInfo23123` a__Type__Parent
|
||||
//WHERE (date_add(a__Type__Parent.`Time2`, interval ((1 * 86400000000)) microsecond) > now())
|
||||
}
|
||||
[Fact]
|
||||
public void AddDays()
|
||||
{
|
||||
var data = new List<object>();
|
||||
data.Add(select.Where(a => a.CreateTime.AddDays(1) > DateTime.Now).ToList());
|
||||
data.Add(select.Where(a => a.Type.Time.AddDays(1) > DateTime.Now).ToList());
|
||||
data.Add(select.Where(a => a.Type.Parent.Time2.AddDays(1) > DateTime.Now).ToList());
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5
|
||||
//FROM `tb_topic111333` a
|
||||
//WHERE (date_add(a.`CreateTime`, interval (1) day) > now());
|
||||
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a__Type.`Time` as7, a.`Title` as8, a.`CreateTime` as9
|
||||
//FROM `tb_topic111333` a, `TestTypeInfo333` a__Type
|
||||
//WHERE (date_add(a__Type.`Time`, interval (1) day) > now());
|
||||
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a__Type.`Time` as7, a.`Title` as8, a.`CreateTime` as9
|
||||
//FROM `tb_topic111333` a, `TestTypeInfo333` a__Type, `TestTypeParentInfo23123` a__Type__Parent
|
||||
//WHERE (date_add(a__Type__Parent.`Time2`, interval (1) day) > now())
|
||||
}
|
||||
[Fact]
|
||||
public void AddHours()
|
||||
{
|
||||
var data = new List<object>();
|
||||
data.Add(select.Where(a => a.CreateTime.AddHours(1) > DateTime.Now).ToList());
|
||||
data.Add(select.Where(a => a.Type.Time.AddHours(1) > DateTime.Now).ToList());
|
||||
data.Add(select.Where(a => a.Type.Parent.Time2.AddHours(1) > DateTime.Now).ToList());
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5
|
||||
//FROM `tb_topic111333` a
|
||||
//WHERE (date_add(a.`CreateTime`, interval (1) hour) > now());
|
||||
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a__Type.`Time` as7, a.`Title` as8, a.`CreateTime` as9
|
||||
//FROM `tb_topic111333` a, `TestTypeInfo333` a__Type
|
||||
//WHERE (date_add(a__Type.`Time`, interval (1) hour) > now());
|
||||
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a__Type.`Time` as7, a.`Title` as8, a.`CreateTime` as9
|
||||
//FROM `tb_topic111333` a, `TestTypeInfo333` a__Type, `TestTypeParentInfo23123` a__Type__Parent
|
||||
//WHERE (date_add(a__Type__Parent.`Time2`, interval (1) hour) > now())
|
||||
}
|
||||
[Fact]
|
||||
public void AddMilliseconds()
|
||||
{
|
||||
var data = new List<object>();
|
||||
data.Add(select.Where(a => a.CreateTime.AddMilliseconds(1) > DateTime.Now).ToList());
|
||||
data.Add(select.Where(a => a.Type.Time.AddMilliseconds(1) > DateTime.Now).ToList());
|
||||
data.Add(select.Where(a => a.Type.Parent.Time2.AddMilliseconds(1) > DateTime.Now).ToList());
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5
|
||||
//FROM `tb_topic111333` a
|
||||
//WHERE (date_add(a.`CreateTime`, interval (1) * 1000 microsecond) > now());
|
||||
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a__Type.`Time` as7, a.`Title` as8, a.`CreateTime` as9
|
||||
//FROM `tb_topic111333` a, `TestTypeInfo333` a__Type
|
||||
//WHERE (date_add(a__Type.`Time`, interval (1) * 1000 microsecond) > now());
|
||||
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a__Type.`Time` as7, a.`Title` as8, a.`CreateTime` as9
|
||||
//FROM `tb_topic111333` a, `TestTypeInfo333` a__Type, `TestTypeParentInfo23123` a__Type__Parent
|
||||
//WHERE (date_add(a__Type__Parent.`Time2`, interval (1) * 1000 microsecond) > now())
|
||||
}
|
||||
[Fact]
|
||||
public void AddMinutes()
|
||||
{
|
||||
var data = new List<object>();
|
||||
data.Add(select.Where(a => a.CreateTime.AddMinutes(1) > DateTime.Now).ToList());
|
||||
data.Add(select.Where(a => a.Type.Time.AddMinutes(1) > DateTime.Now).ToList());
|
||||
data.Add(select.Where(a => a.Type.Parent.Time2.AddMinutes(1) > DateTime.Now).ToList());
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5
|
||||
//FROM `tb_topic111333` a
|
||||
//WHERE (date_add(a.`CreateTime`, interval (1) minute) > now());
|
||||
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a__Type.`Time` as7, a.`Title` as8, a.`CreateTime` as9
|
||||
//FROM `tb_topic111333` a, `TestTypeInfo333` a__Type
|
||||
//WHERE (date_add(a__Type.`Time`, interval (1) minute) > now());
|
||||
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a__Type.`Time` as7, a.`Title` as8, a.`CreateTime` as9
|
||||
//FROM `tb_topic111333` a, `TestTypeInfo333` a__Type, `TestTypeParentInfo23123` a__Type__Parent
|
||||
//WHERE (date_add(a__Type__Parent.`Time2`, interval (1) minute) > now())
|
||||
}
|
||||
[Fact]
|
||||
public void AddMonths()
|
||||
{
|
||||
var data = new List<object>();
|
||||
data.Add(select.Where(a => a.CreateTime.AddMonths(1) > DateTime.Now).ToList());
|
||||
data.Add(select.Where(a => a.Type.Time.AddMonths(1) > DateTime.Now).ToList());
|
||||
data.Add(select.Where(a => a.Type.Parent.Time2.AddMonths(1) > DateTime.Now).ToList());
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5
|
||||
//FROM `tb_topic111333` a
|
||||
//WHERE (date_add(a.`CreateTime`, interval (1) month) > now());
|
||||
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a__Type.`Time` as7, a.`Title` as8, a.`CreateTime` as9
|
||||
//FROM `tb_topic111333` a, `TestTypeInfo333` a__Type
|
||||
//WHERE (date_add(a__Type.`Time`, interval (1) month) > now());
|
||||
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a__Type.`Time` as7, a.`Title` as8, a.`CreateTime` as9
|
||||
//FROM `tb_topic111333` a, `TestTypeInfo333` a__Type, `TestTypeParentInfo23123` a__Type__Parent
|
||||
//WHERE (date_add(a__Type__Parent.`Time2`, interval (1) month) > now())
|
||||
}
|
||||
[Fact]
|
||||
public void AddSeconds()
|
||||
{
|
||||
var data = new List<object>();
|
||||
data.Add(select.Where(a => a.CreateTime.AddSeconds(1) > DateTime.Now).ToList());
|
||||
data.Add(select.Where(a => a.Type.Time.AddSeconds(1) > DateTime.Now).ToList());
|
||||
data.Add(select.Where(a => a.Type.Parent.Time2.AddSeconds(1) > DateTime.Now).ToList());
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5
|
||||
//FROM `tb_topic111333` a
|
||||
//WHERE (date_add(a.`CreateTime`, interval (1) second) > now());
|
||||
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a__Type.`Time` as7, a.`Title` as8, a.`CreateTime` as9
|
||||
//FROM `tb_topic111333` a, `TestTypeInfo333` a__Type
|
||||
//WHERE (date_add(a__Type.`Time`, interval (1) second) > now());
|
||||
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a__Type.`Time` as7, a.`Title` as8, a.`CreateTime` as9
|
||||
//FROM `tb_topic111333` a, `TestTypeInfo333` a__Type, `TestTypeParentInfo23123` a__Type__Parent
|
||||
//WHERE (date_add(a__Type__Parent.`Time2`, interval (1) second) > now())
|
||||
}
|
||||
[Fact]
|
||||
public void AddTicks()
|
||||
{
|
||||
var data = new List<object>();
|
||||
data.Add(select.Where(a => a.CreateTime.AddTicks(1) > DateTime.Now).ToList());
|
||||
data.Add(select.Where(a => a.Type.Time.AddTicks(1) > DateTime.Now).ToList());
|
||||
data.Add(select.Where(a => a.Type.Parent.Time2.AddTicks(1) > DateTime.Now).ToList());
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5
|
||||
//FROM `tb_topic111333` a
|
||||
//WHERE (date_add(a.`CreateTime`, interval (1) / 10 microsecond) > now());
|
||||
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a__Type.`Time` as7, a.`Title` as8, a.`CreateTime` as9
|
||||
//FROM `tb_topic111333` a, `TestTypeInfo333` a__Type
|
||||
//WHERE (date_add(a__Type.`Time`, interval (1) / 10 microsecond) > now());
|
||||
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a__Type.`Time` as7, a.`Title` as8, a.`CreateTime` as9
|
||||
//FROM `tb_topic111333` a, `TestTypeInfo333` a__Type, `TestTypeParentInfo23123` a__Type__Parent
|
||||
//WHERE (date_add(a__Type__Parent.`Time2`, interval (1) / 10 microsecond) > now())
|
||||
}
|
||||
[Fact]
|
||||
public void AddYears()
|
||||
{
|
||||
var data = new List<object>();
|
||||
data.Add(select.Where(a => a.CreateTime.AddYears(1) > DateTime.Now).ToList());
|
||||
data.Add(select.Where(a => a.Type.Time.AddYears(1) > DateTime.Now).ToList());
|
||||
data.Add(select.Where(a => a.Type.Parent.Time2.AddYears(1) > DateTime.Now).ToList());
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5
|
||||
//FROM `tb_topic111333` a
|
||||
//WHERE (date_add(a.`CreateTime`, interval (1) year) > now());
|
||||
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a__Type.`Time` as7, a.`Title` as8, a.`CreateTime` as9
|
||||
//FROM `tb_topic111333` a, `TestTypeInfo333` a__Type
|
||||
//WHERE (date_add(a__Type.`Time`, interval (1) year) > now());
|
||||
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a__Type.`Time` as7, a.`Title` as8, a.`CreateTime` as9
|
||||
//FROM `tb_topic111333` a, `TestTypeInfo333` a__Type, `TestTypeParentInfo23123` a__Type__Parent
|
||||
//WHERE (date_add(a__Type__Parent.`Time2`, interval (1) year) > now())
|
||||
}
|
||||
[Fact]
|
||||
public void Subtract()
|
||||
{
|
||||
var data = new List<object>();
|
||||
data.Add(select.Where(a => a.CreateTime.Subtract(DateTime.Now).TotalSeconds > 0).ToList());
|
||||
data.Add(select.Where(a => a.Type.Time.Subtract(DateTime.Now).TotalSeconds > 0).ToList());
|
||||
data.Add(select.Where(a => a.Type.Parent.Time2.Subtract(DateTime.Now).TotalSeconds > 0).ToList());
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5
|
||||
//FROM `tb_topic111333` a
|
||||
//WHERE (((timestampdiff(microsecond, now(), a.`CreateTime`)) / 1000000) > 0);
|
||||
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a__Type.`Time` as7, a.`Title` as8, a.`CreateTime` as9
|
||||
//FROM `tb_topic111333` a, `TestTypeInfo333` a__Type
|
||||
//WHERE (((timestampdiff(microsecond, now(), a__Type.`Time`)) / 1000000) > 0);
|
||||
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a__Type.`Time` as7, a.`Title` as8, a.`CreateTime` as9
|
||||
//FROM `tb_topic111333` a, `TestTypeInfo333` a__Type, `TestTypeParentInfo23123` a__Type__Parent
|
||||
//WHERE (((timestampdiff(microsecond, now(), a__Type__Parent.`Time2`)) / 1000000) > 0);
|
||||
data.Add(select.Where(a => a.CreateTime.Subtract(TimeSpan.FromDays(1)) > a.CreateTime).ToList());
|
||||
data.Add(select.Where(a => a.Type.Time.Subtract(TimeSpan.FromDays(1)) > a.CreateTime).ToList());
|
||||
data.Add(select.Where(a => a.Type.Parent.Time2.Subtract(TimeSpan.FromDays(1)) > a.CreateTime).ToList());
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5
|
||||
//FROM `tb_topic111333` a
|
||||
//WHERE (date_sub(a.`CreateTime`, interval ((1 * 86400000000)) microsecond) > a.`CreateTime`);
|
||||
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a__Type.`Time` as7, a.`Title` as8, a.`CreateTime` as9
|
||||
//FROM `tb_topic111333` a, `TestTypeInfo333` a__Type
|
||||
//WHERE (date_sub(a__Type.`Time`, interval ((1 * 86400000000)) microsecond) > a.`CreateTime`);
|
||||
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a__Type.`Time` as7, a.`Title` as8, a.`CreateTime` as9
|
||||
//FROM `tb_topic111333` a, `TestTypeInfo333` a__Type, `TestTypeParentInfo23123` a__Type__Parent
|
||||
//WHERE (date_sub(a__Type__Parent.`Time2`, interval ((1 * 86400000000)) microsecond) > a.`CreateTime`)
|
||||
}
|
||||
[Fact]
|
||||
public void Á½¸öÈÕÆÚÏà¼õ_Ч¹ûͬSubtract()
|
||||
{
|
||||
var data = new List<object>();
|
||||
data.Add(select.Where(a => (a.CreateTime - DateTime.Now).TotalSeconds > 0).ToList());
|
||||
data.Add(select.Where(a => (a.Type.Time - DateTime.Now).TotalSeconds > 0).ToList());
|
||||
data.Add(select.Where(a => (a.Type.Parent.Time2 - DateTime.Now).TotalSeconds > 0).ToList());
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5
|
||||
//FROM `tb_topic111333` a
|
||||
//WHERE (((timestampdiff(microsecond, now(), a.`CreateTime`)) / 1000000) > 0);
|
||||
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a__Type.`Time` as7, a.`Title` as8, a.`CreateTime` as9
|
||||
//FROM `tb_topic111333` a, `TestTypeInfo333` a__Type
|
||||
//WHERE (((timestampdiff(microsecond, now(), a__Type.`Time`)) / 1000000) > 0);
|
||||
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a__Type.`Time` as7, a.`Title` as8, a.`CreateTime` as9
|
||||
//FROM `tb_topic111333` a, `TestTypeInfo333` a__Type, `TestTypeParentInfo23123` a__Type__Parent
|
||||
//WHERE (((timestampdiff(microsecond, now(), a__Type__Parent.`Time2`)) / 1000000) > 0);
|
||||
data.Add(select.Where(a => (a.CreateTime - TimeSpan.FromDays(1)) > a.CreateTime).ToList());
|
||||
data.Add(select.Where(a => (a.Type.Time - TimeSpan.FromDays(1)) > a.CreateTime).ToList());
|
||||
data.Add(select.Where(a => (a.Type.Parent.Time2 - TimeSpan.FromDays(1)) > a.CreateTime).ToList());
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5
|
||||
//FROM `tb_topic111333` a
|
||||
//WHERE (date_sub(a.`CreateTime`, interval ((1 * 86400000000)) microsecond) > a.`CreateTime`);
|
||||
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a__Type.`Time` as7, a.`Title` as8, a.`CreateTime` as9
|
||||
//FROM `tb_topic111333` a, `TestTypeInfo333` a__Type
|
||||
//WHERE (date_sub(a__Type.`Time`, interval ((1 * 86400000000)) microsecond) > a.`CreateTime`);
|
||||
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a__Type.`Time` as7, a.`Title` as8, a.`CreateTime` as9
|
||||
//FROM `tb_topic111333` a, `TestTypeInfo333` a__Type, `TestTypeParentInfo23123` a__Type__Parent
|
||||
//WHERE (date_sub(a__Type__Parent.`Time2`, interval ((1 * 86400000000)) microsecond) > a.`CreateTime`)
|
||||
}
|
||||
[Fact]
|
||||
public void this_Equals()
|
||||
{
|
||||
var data = new List<object>();
|
||||
data.Add(select.Where(a => a.CreateTime.AddYears(1).Equals(DateTime.Now)).ToList());
|
||||
data.Add(select.Where(a => a.Type.Time.AddYears(1).Equals(DateTime.Now)).ToList());
|
||||
data.Add(select.Where(a => a.Type.Parent.Time2.AddYears(1).Equals(DateTime.Now)).ToList());
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5
|
||||
//FROM `tb_topic111333` a
|
||||
//WHERE ((date_add(a.`CreateTime`, interval (1) year) = now()));
|
||||
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a__Type.`Time` as7, a.`Title` as8, a.`CreateTime` as9
|
||||
//FROM `tb_topic111333` a, `TestTypeInfo333` a__Type
|
||||
//WHERE ((date_add(a__Type.`Time`, interval (1) year) = now()));
|
||||
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a__Type.`Time` as7, a.`Title` as8, a.`CreateTime` as9
|
||||
//FROM `tb_topic111333` a, `TestTypeInfo333` a__Type, `TestTypeParentInfo23123` a__Type__Parent
|
||||
//WHERE ((date_add(a__Type__Parent.`Time2`, interval (1) year) = now()))
|
||||
}
|
||||
[Fact]
|
||||
public void this_ToString()
|
||||
{
|
||||
var data = new List<object>();
|
||||
data.Add(select.Where(a => a.CreateTime.ToString().Equals(DateTime.Now)).ToList());
|
||||
data.Add(select.Where(a => a.Type.Time.AddYears(1).ToString().Equals(DateTime.Now)).ToList());
|
||||
data.Add(select.Where(a => a.Type.Parent.Time2.AddYears(1).ToString().Equals(DateTime.Now)).ToList());
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5
|
||||
//FROM `tb_topic111333` a
|
||||
//WHERE ((date_format(a.`CreateTime`, '%Y-%m-%d %H:%i:%s.%f') = now()));
|
||||
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a__Type.`Time` as7, a.`Title` as8, a.`CreateTime` as9
|
||||
//FROM `tb_topic111333` a, `TestTypeInfo333` a__Type
|
||||
//WHERE ((date_format(date_add(a__Type.`Time`, interval (1) year), '%Y-%m-%d %H:%i:%s.%f') = now()));
|
||||
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a__Type.`Time` as7, a.`Title` as8, a.`CreateTime` as9
|
||||
//FROM `tb_topic111333` a, `TestTypeInfo333` a__Type, `TestTypeParentInfo23123` a__Type__Parent
|
||||
//WHERE ((date_format(date_add(a__Type__Parent.`Time2`, interval (1) year), '%Y-%m-%d %H:%i:%s.%f') = now()))
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void DateTime_Compare()
|
||||
{
|
||||
var data = new List<object>();
|
||||
data.Add(select.Where(a => a.CreateTime.CompareTo(DateTime.Now) == 0).ToList());
|
||||
data.Add(select.Where(a => a.Type.Time.AddYears(1).CompareTo(DateTime.Now) == 0).ToList());
|
||||
data.Add(select.Where(a => a.Type.Parent.Time2.AddYears(1).CompareTo(DateTime.Now) == 0).ToList());
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5
|
||||
//FROM `tb_topic111333` a
|
||||
//WHERE (((a.`CreateTime`) - (now())) = 0);
|
||||
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a__Type.`Time` as7, a.`Title` as8, a.`CreateTime` as9
|
||||
//FROM `tb_topic111333` a, `TestTypeInfo333` a__Type
|
||||
//WHERE (((date_add(a__Type.`Time`, interval (1) year)) - (now())) = 0);
|
||||
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a__Type.`Time` as7, a.`Title` as8, a.`CreateTime` as9
|
||||
//FROM `tb_topic111333` a, `TestTypeInfo333` a__Type, `TestTypeParentInfo23123` a__Type__Parent
|
||||
//WHERE (((date_add(a__Type__Parent.`Time2`, interval (1) year)) - (now())) = 0)
|
||||
}
|
||||
[Fact]
|
||||
public void DateTime_DaysInMonth()
|
||||
{
|
||||
var data = new List<object>();
|
||||
data.Add(select.Where(a => DateTime.DaysInMonth(a.CreateTime.Year, a.CreateTime.Month) > 30).ToList());
|
||||
data.Add(select.Where(a => DateTime.DaysInMonth(a.Type.Time.Year, a.Type.Time.Month) > 30).ToList());
|
||||
data.Add(select.Where(a => DateTime.DaysInMonth(a.Type.Parent.Time2.Year, a.Type.Parent.Time2.Month) > 30).ToList());
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5
|
||||
//FROM `tb_topic111333` a
|
||||
//WHERE (dayofmonth(last_day(concat(year(a.`CreateTime`), month(a.`CreateTime`), '-01'))) > 30);
|
||||
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a__Type.`Time` as7, a.`Title` as8, a.`CreateTime` as9
|
||||
//FROM `tb_topic111333` a, `TestTypeInfo333` a__Type
|
||||
//WHERE (dayofmonth(last_day(concat(year(a__Type.`Time`), month(a__Type.`Time`), '-01'))) > 30);
|
||||
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a__Type.`Time` as7, a.`Title` as8, a.`CreateTime` as9
|
||||
//FROM `tb_topic111333` a, `TestTypeInfo333` a__Type, `TestTypeParentInfo23123` a__Type__Parent
|
||||
//WHERE (dayofmonth(last_day(concat(year(a__Type__Parent.`Time2`), month(a__Type__Parent.`Time2`), '-01'))) > 30)
|
||||
}
|
||||
[Fact]
|
||||
public void DateTime_Equals()
|
||||
{
|
||||
var data = new List<object>();
|
||||
data.Add(select.Where(a => DateTime.Equals(a.CreateTime.AddYears(1), DateTime.Now)).ToList());
|
||||
data.Add(select.Where(a => DateTime.Equals(a.Type.Time.AddYears(1), DateTime.Now)).ToList());
|
||||
data.Add(select.Where(a => DateTime.Equals(a.Type.Parent.Time2.AddYears(1), DateTime.Now)).ToList());
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5
|
||||
//FROM `tb_topic111333` a
|
||||
//WHERE ((date_add(a.`CreateTime`, interval (1) year) = now()));
|
||||
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a__Type.`Time` as7, a.`Title` as8, a.`CreateTime` as9
|
||||
//FROM `tb_topic111333` a, `TestTypeInfo333` a__Type
|
||||
//WHERE ((date_add(a__Type.`Time`, interval (1) year) = now()));
|
||||
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a__Type.`Time` as7, a.`Title` as8, a.`CreateTime` as9
|
||||
//FROM `tb_topic111333` a, `TestTypeInfo333` a__Type, `TestTypeParentInfo23123` a__Type__Parent
|
||||
//WHERE ((date_add(a__Type__Parent.`Time2`, interval (1) year) = now()))
|
||||
}
|
||||
[Fact]
|
||||
public void DateTime_IsLeapYear()
|
||||
{
|
||||
var data = new List<object>();
|
||||
data.Add(select.Where(a => DateTime.IsLeapYear(a.CreateTime.Year)).ToList());
|
||||
data.Add(select.Where(a => DateTime.IsLeapYear(a.Type.Time.AddYears(1).Year)).ToList());
|
||||
data.Add(select.Where(a => DateTime.IsLeapYear(a.Type.Parent.Time2.AddYears(1).Year)).ToList());
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5
|
||||
//FROM `tb_topic111333` a
|
||||
//WHERE (((year(a.`CreateTime`)) % 4 = 0 AND (year(a.`CreateTime`)) % 100 <> 0 OR (year(a.`CreateTime`)) % 400 = 0));
|
||||
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a__Type.`Time` as7, a.`Title` as8, a.`CreateTime` as9
|
||||
//FROM `tb_topic111333` a, `TestTypeInfo333` a__Type
|
||||
//WHERE (((year(date_add(a__Type.`Time`, interval (1) year))) % 4 = 0 AND (year(date_add(a__Type.`Time`, interval (1) year))) % 100 <> 0 OR (year(date_add(a__Type.`Time`, interval (1) year))) % 400 = 0));
|
||||
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a__Type.`Time` as7, a.`Title` as8, a.`CreateTime` as9
|
||||
//FROM `tb_topic111333` a, `TestTypeInfo333` a__Type, `TestTypeParentInfo23123` a__Type__Parent
|
||||
//WHERE (((year(date_add(a__Type__Parent.`Time2`, interval (1) year))) % 4 = 0 AND (year(date_add(a__Type__Parent.`Time2`, interval (1) year))) % 100 <> 0 OR (year(date_add(a__Type__Parent.`Time2`, interval (1) year))) % 400 = 0))
|
||||
}
|
||||
[Fact]
|
||||
public void DateTime_Parse()
|
||||
{
|
||||
var data = new List<object>();
|
||||
data.Add(select.Where(a => DateTime.Parse(a.CreateTime.ToString()) > DateTime.Now).ToList());
|
||||
data.Add(select.Where(a => DateTime.Parse(a.Type.Time.AddYears(1).ToString()) > DateTime.Now).ToList());
|
||||
data.Add(select.Where(a => DateTime.Parse(a.Type.Parent.Time2.AddYears(1).ToString()) > DateTime.Now).ToList());
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5
|
||||
//FROM `tb_topic111333` a
|
||||
//WHERE (cast(date_format(a.`CreateTime`, '%Y-%m-%d %H:%i:%s.%f') as datetime) > now());
|
||||
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a__Type.`Time` as7, a.`Title` as8, a.`CreateTime` as9
|
||||
//FROM `tb_topic111333` a, `TestTypeInfo333` a__Type
|
||||
//WHERE (cast(date_format(date_add(a__Type.`Time`, interval (1) year), '%Y-%m-%d %H:%i:%s.%f') as datetime) > now());
|
||||
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a__Type.`Time` as7, a.`Title` as8, a.`CreateTime` as9
|
||||
//FROM `tb_topic111333` a, `TestTypeInfo333` a__Type, `TestTypeParentInfo23123` a__Type__Parent
|
||||
//WHERE (cast(date_format(date_add(a__Type__Parent.`Time2`, interval (1) year), '%Y-%m-%d %H:%i:%s.%f') as datetime) > now())
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,156 @@
|
||||
using FreeSql.DataAnnotations;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Xunit;
|
||||
|
||||
namespace FreeSql.Tests.Odbc.MySqlExpression
|
||||
{
|
||||
public class MathTest
|
||||
{
|
||||
|
||||
ISelect<Topic> select => g.mysql.Select<Topic>();
|
||||
|
||||
[Table(Name = "tb_topic")]
|
||||
class Topic
|
||||
{
|
||||
[Column(IsIdentity = true, IsPrimary = true)]
|
||||
public int Id { get; set; }
|
||||
public int Clicks { get; set; }
|
||||
public int TypeGuid { get; set; }
|
||||
public TestTypeInfo Type { get; set; }
|
||||
public string Title { get; set; }
|
||||
public DateTime CreateTime { get; set; }
|
||||
}
|
||||
class TestTypeInfo
|
||||
{
|
||||
public int Guid { get; set; }
|
||||
public int ParentId { get; set; }
|
||||
public TestTypeParentInfo Parent { get; set; }
|
||||
public string Name { get; set; }
|
||||
}
|
||||
class TestTypeParentInfo
|
||||
{
|
||||
public int Id { get; set; }
|
||||
public string Name { get; set; }
|
||||
|
||||
public List<TestTypeInfo> Types { get; set; }
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void PI()
|
||||
{
|
||||
var data = new List<object>();
|
||||
data.Add(select.Where(a => Math.PI + a.Clicks > 0).ToList());
|
||||
}
|
||||
[Fact]
|
||||
public void Abs()
|
||||
{
|
||||
var data = new List<object>();
|
||||
data.Add(select.Where(a => Math.Abs(-a.Clicks) > 0).ToList());
|
||||
}
|
||||
[Fact]
|
||||
public void Sign()
|
||||
{
|
||||
var data = new List<object>();
|
||||
data.Add(select.Where(a => Math.Sign(-a.Clicks) > 0).ToList());
|
||||
}
|
||||
[Fact]
|
||||
public void Floor()
|
||||
{
|
||||
var data = new List<object>();
|
||||
data.Add(select.Where(a => Math.Floor(a.Clicks + 0.5) == a.Clicks).ToList());
|
||||
}
|
||||
[Fact]
|
||||
public void Ceiling()
|
||||
{
|
||||
var data = new List<object>();
|
||||
data.Add(select.Where(a => Math.Ceiling(a.Clicks + 0.5) == a.Clicks + 1).ToList());
|
||||
}
|
||||
[Fact]
|
||||
public void Round()
|
||||
{
|
||||
var data = new List<object>();
|
||||
data.Add(select.Where(a => Math.Round(a.Clicks + 0.5) == a.Clicks).ToList());
|
||||
data.Add(select.Where(a => Math.Round(a.Clicks + 0.5, 1) > a.Clicks).ToList());
|
||||
}
|
||||
[Fact]
|
||||
public void Exp()
|
||||
{
|
||||
var data = new List<object>();
|
||||
data.Add(select.Where(a => Math.Exp(1) == a.Clicks + 1).ToList());
|
||||
}
|
||||
[Fact]
|
||||
public void Log()
|
||||
{
|
||||
var data = new List<object>();
|
||||
data.Add(select.Where(a => Math.Log(a.Clicks + 0.5) == a.Clicks + 1).ToList());
|
||||
}
|
||||
[Fact]
|
||||
public void Log10()
|
||||
{
|
||||
var data = new List<object>();
|
||||
data.Add(select.Where(a => Math.Log10(a.Clicks + 0.5) == a.Clicks + 1).ToList());
|
||||
}
|
||||
[Fact]
|
||||
public void Pow()
|
||||
{
|
||||
var data = new List<object>();
|
||||
data.Add(select.Where(a => Math.Pow(2, a.Clicks) == a.Clicks + 1).ToList());
|
||||
}
|
||||
[Fact]
|
||||
public void Sqrt()
|
||||
{
|
||||
var data = new List<object>();
|
||||
data.Add(select.Where(a => Math.Sqrt(Math.Pow(2, a.Clicks)) == a.Clicks + 1).ToList());
|
||||
}
|
||||
[Fact]
|
||||
public void Cos()
|
||||
{
|
||||
var data = new List<object>();
|
||||
data.Add(select.Where(a => Math.Cos(Math.Pow(2, a.Clicks)) == a.Clicks + 1).ToList());
|
||||
}
|
||||
[Fact]
|
||||
public void Sin()
|
||||
{
|
||||
var data = new List<object>();
|
||||
data.Add(select.Where(a => Math.Sin(Math.Pow(2, a.Clicks)) == a.Clicks + 1).ToList());
|
||||
}
|
||||
[Fact]
|
||||
public void Tan()
|
||||
{
|
||||
var data = new List<object>();
|
||||
data.Add(select.Where(a => Math.Tan(Math.Pow(2, a.Clicks)) == a.Clicks + 1).ToList());
|
||||
}
|
||||
[Fact]
|
||||
public void Acos()
|
||||
{
|
||||
var data = new List<object>();
|
||||
data.Add(select.Where(a => Math.Acos(Math.Pow(2, a.Clicks)) == a.Clicks + 1).ToList());
|
||||
}
|
||||
[Fact]
|
||||
public void Asin()
|
||||
{
|
||||
var data = new List<object>();
|
||||
data.Add(select.Where(a => Math.Asin(Math.Pow(2, a.Clicks)) == a.Clicks + 1).ToList());
|
||||
}
|
||||
[Fact]
|
||||
public void Atan()
|
||||
{
|
||||
var data = new List<object>();
|
||||
data.Add(select.Where(a => Math.Atan(Math.Pow(2, a.Clicks)) == a.Clicks + 1).ToList());
|
||||
}
|
||||
[Fact]
|
||||
public void Atan2()
|
||||
{
|
||||
var data = new List<object>();
|
||||
data.Add(select.Where(a => Math.Atan2(2, a.Clicks) == a.Clicks + 1).ToList());
|
||||
}
|
||||
[Fact]
|
||||
public void Truncate()
|
||||
{
|
||||
var data = new List<object>();
|
||||
data.Add(select.Where(a => Math.Truncate(a.Clicks * 1.0 / 3) == a.Clicks + 1).ToList());
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,136 @@
|
||||
using FreeSql.DataAnnotations;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data.Odbc;
|
||||
using System.Linq;
|
||||
using Xunit;
|
||||
|
||||
namespace FreeSql.Tests.Odbc.MySqlExpression
|
||||
{
|
||||
public class OtherTest
|
||||
{
|
||||
|
||||
ISelect<TableAllType> select => g.mysql.Select<TableAllType>();
|
||||
|
||||
public OtherTest()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Div()
|
||||
{
|
||||
var t1 = select.Where(a => a.testFieldInt / 3 > 3).Limit(10).ToList();
|
||||
var t2 = select.Where(a => a.testFieldLong / 3 > 3).Limit(10).ToList();
|
||||
var t3 = select.Where(a => a.testFieldShort / 3 > 3).Limit(10).ToList();
|
||||
|
||||
var t4 = select.Where(a => a.testFieldInt / 3.0 > 3).Limit(10).ToList();
|
||||
var t5 = select.Where(a => a.testFieldLong / 3.0 > 3).Limit(10).ToList();
|
||||
var t6 = select.Where(a => a.testFieldShort / 3.0 > 3).Limit(10).ToList();
|
||||
|
||||
var t7 = select.Where(a => a.testFieldDouble / 3 > 3).Limit(10).ToList();
|
||||
var t8 = select.Where(a => a.testFieldDecimal / 3 > 3).Limit(10).ToList();
|
||||
var t9 = select.Where(a => a.testFieldFloat / 3 > 3).Limit(10).ToList();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Boolean()
|
||||
{
|
||||
var t1 = select.Where(a => a.testFieldBool == true).ToList();
|
||||
var t2 = select.Where(a => a.testFieldBool != true).ToList();
|
||||
var t3 = select.Where(a => a.testFieldBool == false).ToList();
|
||||
var t4 = select.Where(a => !a.testFieldBool).ToList();
|
||||
var t5 = select.Where(a => a.testFieldBool).ToList();
|
||||
|
||||
var t11 = select.Where(a => a.testFieldBoolNullable == true).ToList();
|
||||
var t22 = select.Where(a => a.testFieldBoolNullable != true).ToList();
|
||||
var t33 = select.Where(a => a.testFieldBoolNullable == false).ToList();
|
||||
var t44 = select.Where(a => !a.testFieldBoolNullable.Value).ToList();
|
||||
var t55 = select.Where(a => a.testFieldBoolNullable.Value).ToList();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Array()
|
||||
{
|
||||
int[] nullarr = null;
|
||||
Assert.Throws<OdbcException>(() => { select.Where(a => nullarr.Contains(a.testFieldInt)).ToList(); });
|
||||
Assert.Throws<OdbcException>(() => { select.Where(a => new int[0].Contains(a.testFieldInt)).ToList(); });
|
||||
|
||||
IEnumerable<int> testlinqlist = new List<int>(new[] { 1, 2, 3 });
|
||||
var testlinq = select.Where(a => testlinqlist.Contains(a.testFieldInt)).ToList();
|
||||
|
||||
//in not in
|
||||
var sql111 = select.Where(a => new[] { 1, 2, 3 }.Contains(a.testFieldInt)).ToList();
|
||||
var sql112 = select.Where(a => new[] { 1, 2, 3 }.Contains(a.testFieldInt) == false).ToList();
|
||||
var sql113 = select.Where(a => !new[] { 1, 2, 3 }.Contains(a.testFieldInt)).ToList();
|
||||
|
||||
var inarray = new[] { 1, 2, 3 };
|
||||
var sql1111 = select.Where(a => inarray.Contains(a.testFieldInt)).ToList();
|
||||
var sql1122 = select.Where(a => inarray.Contains(a.testFieldInt) == false).ToList();
|
||||
var sql1133 = select.Where(a => !inarray.Contains(a.testFieldInt)).ToList();
|
||||
|
||||
//in not in
|
||||
var sql11111 = select.Where(a => new List<int>() { 1, 2, 3 }.Contains(a.testFieldInt)).ToList();
|
||||
var sql11222 = select.Where(a => new List<int>() { 1, 2, 3 }.Contains(a.testFieldInt) == false).ToList();
|
||||
var sql11333 = select.Where(a => !new List<int>() { 1, 2, 3 }.Contains(a.testFieldInt)).ToList();
|
||||
|
||||
var sql11111a = select.Where(a => new List<int>(new[] { 1, 2, 3 }).Contains(a.testFieldInt)).ToList();
|
||||
var sql11222b = select.Where(a => new List<int>(new[] { 1, 2, 3 }).Contains(a.testFieldInt) == false).ToList();
|
||||
var sql11333c = select.Where(a => !new List<int>(new[] { 1, 2, 3 }).Contains(a.testFieldInt)).ToList();
|
||||
|
||||
var inarray2 = new List<int>() { 1, 2, 3 };
|
||||
var sql111111 = select.Where(a => inarray.Contains(a.testFieldInt)).ToList();
|
||||
var sql112222 = select.Where(a => inarray.Contains(a.testFieldInt) == false).ToList();
|
||||
var sql113333 = select.Where(a => !inarray.Contains(a.testFieldInt)).ToList();
|
||||
}
|
||||
|
||||
[Table(Name = "tb_alltype")]
|
||||
class TableAllType
|
||||
{
|
||||
[Column(IsIdentity = true, IsPrimary = true)]
|
||||
public int Id { get; set; }
|
||||
|
||||
public bool testFieldBool { get; set; }
|
||||
public sbyte testFieldSByte { get; set; }
|
||||
public short testFieldShort { get; set; }
|
||||
public int testFieldInt { get; set; }
|
||||
public long testFieldLong { get; set; }
|
||||
public byte testFieldByte { get; set; }
|
||||
public ushort testFieldUShort { get; set; }
|
||||
public uint testFieldUInt { get; set; }
|
||||
public ulong testFieldULong { get; set; }
|
||||
public double testFieldDouble { get; set; }
|
||||
public float testFieldFloat { get; set; }
|
||||
public decimal testFieldDecimal { get; set; }
|
||||
public TimeSpan testFieldTimeSpan { get; set; }
|
||||
public DateTime testFieldDateTime { get; set; }
|
||||
public byte[] testFieldBytes { get; set; }
|
||||
public string testFieldString { get; set; }
|
||||
public Guid testFieldGuid { get; set; }
|
||||
|
||||
public bool? testFieldBoolNullable { get; set; }
|
||||
public sbyte? testFieldSByteNullable { get; set; }
|
||||
public short? testFieldShortNullable { get; set; }
|
||||
public int? testFieldIntNullable { get; set; }
|
||||
public long? testFielLongNullable { get; set; }
|
||||
public byte? testFieldByteNullable { get; set; }
|
||||
public ushort? testFieldUShortNullable { get; set; }
|
||||
public uint? testFieldUIntNullable { get; set; }
|
||||
public ulong? testFieldULongNullable { get; set; }
|
||||
public double? testFieldDoubleNullable { get; set; }
|
||||
public float? testFieldFloatNullable { get; set; }
|
||||
public decimal? testFieldDecimalNullable { get; set; }
|
||||
public TimeSpan? testFieldTimeSpanNullable { get; set; }
|
||||
public DateTime? testFieldDateTimeNullable { get; set; }
|
||||
public Guid? testFieldGuidNullable { get; set; }
|
||||
|
||||
public TableAllTypeEnumType1 testFieldEnum1 { get; set; }
|
||||
public TableAllTypeEnumType1? testFieldEnum1Nullable { get; set; }
|
||||
public TableAllTypeEnumType2 testFieldEnum2 { get; set; }
|
||||
public TableAllTypeEnumType2? testFieldEnum2Nullable { get; set; }
|
||||
}
|
||||
|
||||
public enum TableAllTypeEnumType1 { e1, e2, e3, e5 }
|
||||
[Flags] public enum TableAllTypeEnumType2 { f1, f2, f3 }
|
||||
}
|
||||
}
|
@ -0,0 +1,729 @@
|
||||
using FreeSql.DataAnnotations;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Xunit;
|
||||
|
||||
namespace FreeSql.Tests.Odbc.MySqlExpression
|
||||
{
|
||||
public class StringTest
|
||||
{
|
||||
|
||||
ISelect<Topic> select => g.mysql.Select<Topic>();
|
||||
|
||||
[Table(Name = "tb_topic")]
|
||||
class Topic
|
||||
{
|
||||
[Column(IsIdentity = true, IsPrimary = true)]
|
||||
public int Id { get; set; }
|
||||
public int Clicks { get; set; }
|
||||
public int TypeGuid { get; set; }
|
||||
public TestTypeInfo Type { get; set; }
|
||||
public string Title { get; set; }
|
||||
public DateTime CreateTime { get; set; }
|
||||
}
|
||||
class TestTypeInfo
|
||||
{
|
||||
[Column(IsIdentity = true)]
|
||||
public int Guid { get; set; }
|
||||
public int ParentId { get; set; }
|
||||
public TestTypeParentInfo Parent { get; set; }
|
||||
public string Name { get; set; }
|
||||
}
|
||||
class TestTypeParentInfo
|
||||
{
|
||||
public int Id { get; set; }
|
||||
public string Name { get; set; }
|
||||
|
||||
public List<TestTypeInfo> Types { get; set; }
|
||||
}
|
||||
class TestEqualsGuid
|
||||
{
|
||||
public Guid id { get; set; }
|
||||
public bool IsDeleted { get; set; }
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Equals__()
|
||||
{
|
||||
var list = new List<object>();
|
||||
list.Add(select.Where(a => a.Title.Equals("aaa")).ToList());
|
||||
list.Add(g.mysql.Select<TestEqualsGuid>().Where(a => a.id.Equals(Guid.Empty)).ToList());
|
||||
list.Add(g.mysql.Select<TestEqualsGuid>().Where(a => a.IsDeleted.Equals(false)).ToList());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Empty()
|
||||
{
|
||||
var data = new List<object>();
|
||||
data.Add(select.Where(a => (a.Title ?? "") == string.Empty).ToSql());
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5
|
||||
//FROM `tb_topic` a
|
||||
//WHERE (ifnull(a.`Title`, '') = '')
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void StartsWith()
|
||||
{
|
||||
var list = new List<object>();
|
||||
list.Add(select.Where(a => a.Title.StartsWith("aaa")).ToList());
|
||||
list.Add(select.Where(a => a.Title.StartsWith(a.Title)).ToList());
|
||||
list.Add(select.Where(a => a.Title.StartsWith(a.Title + 1)).ToList());
|
||||
list.Add(select.Where(a => a.Title.StartsWith(a.Type.Name)).ToList());
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5
|
||||
//FROM `tb_topic` a
|
||||
//WHERE((a.`Title`) LIKE '%aaa')
|
||||
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5
|
||||
//FROM `tb_topic` a
|
||||
//WHERE((a.`Title`) LIKE concat('%', a.`Title`))
|
||||
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5
|
||||
//FROM `tb_topic` a
|
||||
//WHERE((a.`Title`) LIKE concat('%', concat(a.`Title`, 1)))
|
||||
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a.`Title` as7, a.`CreateTime` as8
|
||||
//FROM `tb_topic` a, `TestTypeInfo` a__Type
|
||||
//WHERE((a.`Title`) LIKE concat('%', a__Type.`Name`))
|
||||
list.Add(select.Where(a => (a.Title + "aaa").StartsWith("aaa")).ToList());
|
||||
list.Add(select.Where(a => (a.Title + "aaa").StartsWith(a.Title)).ToList());
|
||||
list.Add(select.Where(a => (a.Title + "aaa").StartsWith(a.Title + 1)).ToList());
|
||||
list.Add(select.Where(a => (a.Title + "aaa").StartsWith(a.Type.Name)).ToList());
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5
|
||||
//FROM `tb_topic` a
|
||||
//WHERE((concat(a.`Title`, 'aaa')) LIKE '%aaa')
|
||||
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5
|
||||
//FROM `tb_topic` a
|
||||
//WHERE((concat(a.`Title`, 'aaa')) LIKE concat('%', a.`Title`))
|
||||
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5
|
||||
//FROM `tb_topic` a
|
||||
//WHERE((concat(a.`Title`, 'aaa')) LIKE concat('%', concat(a.`Title`, 1)))
|
||||
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a.`Title` as7, a.`CreateTime` as8
|
||||
//FROM `tb_topic` a, `TestTypeInfo` a__Type
|
||||
//WHERE((concat(a.`Title`, 'aaa')) LIKE concat('%', a__Type.`Name`))
|
||||
}
|
||||
[Fact]
|
||||
public void EndsWith()
|
||||
{
|
||||
var list = new List<object>();
|
||||
list.Add(select.Where(a => a.Title.EndsWith("aaa")).ToList());
|
||||
list.Add(select.Where(a => a.Title.EndsWith(a.Title)).ToList());
|
||||
list.Add(select.Where(a => a.Title.EndsWith(a.Title + 1)).ToList());
|
||||
list.Add(select.Where(a => a.Title.EndsWith(a.Type.Name)).ToList());
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5
|
||||
//FROM `tb_topic` a
|
||||
//WHERE((a.`Title`) LIKE 'aaa%')
|
||||
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5
|
||||
//FROM `tb_topic` a
|
||||
//WHERE((a.`Title`) LIKE concat(a.`Title`, '%'))
|
||||
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5
|
||||
//FROM `tb_topic` a
|
||||
//WHERE((a.`Title`) LIKE concat(concat(a.`Title`, 1), '%'))
|
||||
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a.`Title` as7, a.`CreateTime` as8
|
||||
//FROM `tb_topic` a, `TestTypeInfo` a__Type
|
||||
//WHERE((a.`Title`) LIKE concat(a__Type.`Name`, '%'))
|
||||
list.Add(select.Where(a => (a.Title + "aaa").EndsWith("aaa")).ToList());
|
||||
list.Add(select.Where(a => (a.Title + "aaa").EndsWith(a.Title)).ToList());
|
||||
list.Add(select.Where(a => (a.Title + "aaa").EndsWith(a.Title + 1)).ToList());
|
||||
list.Add(select.Where(a => (a.Title + "aaa").EndsWith(a.Type.Name)).ToList());
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5
|
||||
//FROM `tb_topic` a
|
||||
//WHERE((concat(a.`Title`, 'aaa')) LIKE 'aaa%')
|
||||
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5
|
||||
//FROM `tb_topic` a
|
||||
//WHERE((concat(a.`Title`, 'aaa')) LIKE concat(a.`Title`, '%'))
|
||||
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5
|
||||
//FROM `tb_topic` a
|
||||
//WHERE((concat(a.`Title`, 'aaa')) LIKE concat(concat(a.`Title`, 1), '%'))
|
||||
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a.`Title` as7, a.`CreateTime` as8
|
||||
//FROM `tb_topic` a, `TestTypeInfo` a__Type
|
||||
//WHERE((concat(a.`Title`, 'aaa')) LIKE concat(a__Type.`Name`, '%'))
|
||||
}
|
||||
[Fact]
|
||||
public void Contains()
|
||||
{
|
||||
var list = new List<object>();
|
||||
list.Add(select.Where(a => a.Title.Contains("aaa")).ToList());
|
||||
list.Add(select.Where(a => a.Title.Contains(a.Title)).ToList());
|
||||
list.Add(select.Where(a => a.Title.Contains(a.Title + 1)).ToList());
|
||||
list.Add(select.Where(a => a.Title.Contains(a.Type.Name)).ToList());
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5
|
||||
//FROM `tb_topic` a
|
||||
//WHERE((a.`Title`) LIKE '%aaa%')
|
||||
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5
|
||||
//FROM `tb_topic` a
|
||||
//WHERE((a.`Title`) LIKE concat('%', a.`Title`, '%'))
|
||||
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5
|
||||
//FROM `tb_topic` a
|
||||
//WHERE((a.`Title`) LIKE concat('%', a.`Title` +1, '%'))
|
||||
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a.`Title` as7, a.`CreateTime` as8
|
||||
//FROM `tb_topic` a, `TestTypeInfo` a__Type
|
||||
//WHERE((a.`Title`) LIKE concat('%', a__Type.`Name`, '%'))
|
||||
list.Add(select.Where(a => (a.Title + "aaa").Contains("aaa")).ToList());
|
||||
list.Add(select.Where(a => (a.Title + "aaa").Contains(a.Title)).ToList());
|
||||
list.Add(select.Where(a => (a.Title + "aaa").Contains(a.Title + 1)).ToList());
|
||||
list.Add(select.Where(a => (a.Title + "aaa").Contains(a.Type.Name)).ToList());
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5
|
||||
//FROM `tb_topic` a
|
||||
//WHERE((concat(a.`Title`, 'aaa')) LIKE '%aaa%')
|
||||
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5
|
||||
//FROM `tb_topic` a
|
||||
//WHERE((concat(a.`Title`, 'aaa')) LIKE concat('%', a.`Title`, '%'))
|
||||
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5
|
||||
//FROM `tb_topic` a
|
||||
//WHERE((concat(a.`Title`, 'aaa')) LIKE concat('%', concat(a.`Title`, 1), '%'))
|
||||
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a.`Title` as7, a.`CreateTime` as8
|
||||
//FROM `tb_topic` a, `TestTypeInfo` a__Type
|
||||
//WHERE((concat(a.`Title`, 'aaa')) LIKE concat('%', a__Type.`Name`, '%'))
|
||||
}
|
||||
[Fact]
|
||||
public void ToLower()
|
||||
{
|
||||
var data = new List<object>();
|
||||
data.Add(select.Where(a => a.Title.ToLower() == "aaa").ToList());
|
||||
data.Add(select.Where(a => a.Title.ToLower() == a.Title).ToList());
|
||||
data.Add(select.Where(a => a.Title.ToLower() == (a.Title + 1)).ToList());
|
||||
data.Add(select.Where(a => a.Title.ToLower() == a.Type.Name).ToList());
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5
|
||||
//FROM `tb_topic` a
|
||||
//WHERE(lower(a.`Title`) = 'aaa');
|
||||
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5
|
||||
//FROM `tb_topic` a
|
||||
//WHERE(lower(a.`Title`) = a.`Title`);
|
||||
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5
|
||||
//FROM `tb_topic` a
|
||||
//WHERE(lower(a.`Title`) = concat(a.`Title`, 1));
|
||||
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a.`Title` as7, a.`CreateTime` as8
|
||||
//FROM `tb_topic` a, `TestTypeInfo` a__Type
|
||||
//WHERE(lower(a.`Title`) = a__Type.`Name`);
|
||||
data.Add(select.Where(a => (a.Title.ToLower() + "aaa").ToLower() == "aaa").ToList());
|
||||
data.Add(select.Where(a => (a.Title.ToLower() + "aaa").ToLower() == a.Title).ToList());
|
||||
data.Add(select.Where(a => (a.Title.ToLower() + "aaa").ToLower() == (a.Title + 1)).ToList());
|
||||
data.Add(select.Where(a => (a.Title.ToLower() + "aaa").ToLower() == a.Type.Name).ToList());
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5
|
||||
//FROM `tb_topic` a
|
||||
//WHERE(lower(concat(lower(a.`Title`), 'aaa')) = 'aaa');
|
||||
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5
|
||||
//FROM `tb_topic` a
|
||||
//WHERE(lower(concat(lower(a.`Title`), 'aaa')) = a.`Title`);
|
||||
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5
|
||||
//FROM `tb_topic` a
|
||||
//WHERE(lower(concat(lower(a.`Title`), 'aaa')) = concat(a.`Title`, 1));
|
||||
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a.`Title` as7, a.`CreateTime` as8
|
||||
//FROM `tb_topic` a, `TestTypeInfo` a__Type
|
||||
//WHERE(lower(concat(lower(a.`Title`), 'aaa')) = a__Type.`Name`)
|
||||
}
|
||||
[Fact]
|
||||
public void ToUpper()
|
||||
{
|
||||
var data = new List<object>();
|
||||
data.Add(select.Where(a => a.Title.ToUpper() == "aaa").ToList());
|
||||
data.Add(select.Where(a => a.Title.ToUpper() == a.Title).ToList());
|
||||
data.Add(select.Where(a => a.Title.ToUpper() == (a.Title + 1)).ToList());
|
||||
data.Add(select.Where(a => a.Title.ToUpper() == a.Type.Name).ToList());
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5
|
||||
//FROM `tb_topic` a
|
||||
//WHERE (upper(a.`Title`) = 'aaa');
|
||||
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5
|
||||
//FROM `tb_topic` a
|
||||
//WHERE (upper(a.`Title`) = a.`Title`);
|
||||
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5
|
||||
//FROM `tb_topic` a
|
||||
//WHERE (upper(a.`Title`) = concat(a.`Title`, 1));
|
||||
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a.`Title` as7, a.`CreateTime` as8
|
||||
//FROM `tb_topic` a, `TestTypeInfo` a__Type
|
||||
//WHERE (upper(a.`Title`) = a__Type.`Name`);
|
||||
data.Add(select.Where(a => (a.Title.ToUpper() + "aaa").ToUpper() == "aaa").ToList());
|
||||
data.Add(select.Where(a => (a.Title.ToUpper() + "aaa").ToUpper() == a.Title).ToList());
|
||||
data.Add(select.Where(a => (a.Title.ToUpper() + "aaa").ToUpper() == (a.Title + 1)).ToList());
|
||||
data.Add(select.Where(a => (a.Title.ToUpper() + "aaa").ToUpper() == a.Type.Name).ToList());
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5
|
||||
//FROM `tb_topic` a
|
||||
//WHERE (upper(concat(upper(a.`Title`), 'aaa')) = 'aaa');
|
||||
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5
|
||||
//FROM `tb_topic` a
|
||||
//WHERE (upper(concat(upper(a.`Title`), 'aaa')) = a.`Title`);
|
||||
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5
|
||||
//FROM `tb_topic` a
|
||||
//WHERE (upper(concat(upper(a.`Title`), 'aaa')) = concat(a.`Title`, 1));
|
||||
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a.`Title` as7, a.`CreateTime` as8
|
||||
//FROM `tb_topic` a, `TestTypeInfo` a__Type
|
||||
//WHERE (upper(concat(upper(a.`Title`), 'aaa')) = a__Type.`Name`)
|
||||
}
|
||||
[Fact]
|
||||
public void Substring()
|
||||
{
|
||||
var data = new List<object>();
|
||||
data.Add(select.Where(a => a.Title.Substring(0) == "aaa").ToList());
|
||||
data.Add(select.Where(a => a.Title.Substring(0) == a.Title).ToList());
|
||||
data.Add(select.Where(a => a.Title.Substring(0) == (a.Title + 1)).ToList());
|
||||
data.Add(select.Where(a => a.Title.Substring(0) == a.Type.Name).ToList());
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5
|
||||
//FROM `tb_topic` a
|
||||
//WHERE (substr(a.`Title`, 1) = 'aaa');
|
||||
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5
|
||||
//FROM `tb_topic` a
|
||||
//WHERE (substr(a.`Title`, 1) = a.`Title`);
|
||||
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5
|
||||
//FROM `tb_topic` a
|
||||
//WHERE (substr(a.`Title`, 1) = concat(a.`Title`, 1));
|
||||
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a.`Title` as7, a.`CreateTime` as8
|
||||
//FROM `tb_topic` a, `TestTypeInfo` a__Type
|
||||
//WHERE (substr(a.`Title`, 1) = a__Type.`Name`);
|
||||
data.Add(select.Where(a => (a.Title.Substring(0) + "aaa").Substring(a.Title.Length) == "aaa").ToList());
|
||||
data.Add(select.Where(a => (a.Title.Substring(0) + "aaa").Substring(0, a.Title.Length) == a.Title).ToList());
|
||||
data.Add(select.Where(a => (a.Title.Substring(0) + "aaa").Substring(0, 3) == (a.Title + 1)).ToList());
|
||||
data.Add(select.Where(a => (a.Title.Substring(0) + "aaa").Substring(1, 2) == a.Type.Name).ToList());
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5
|
||||
//FROM `tb_topic` a
|
||||
//WHERE (substr(concat(substr(a.`Title`, 1), 'aaa'), char_length(a.`Title`) + 1) = 'aaa');
|
||||
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5
|
||||
//FROM `tb_topic` a
|
||||
//WHERE (substr(concat(substr(a.`Title`, 1), 'aaa'), 1, char_length(a.`Title`)) = a.`Title`);
|
||||
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5
|
||||
//FROM `tb_topic` a
|
||||
//WHERE (substr(concat(substr(a.`Title`, 1), 'aaa'), 1, 3) = concat(a.`Title`, 1));
|
||||
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a.`Title` as7, a.`CreateTime` as8
|
||||
//FROM `tb_topic` a, `TestTypeInfo` a__Type
|
||||
//WHERE (substr(concat(substr(a.`Title`, 1), 'aaa'), 2, 2) = a__Type.`Name`)
|
||||
}
|
||||
[Fact]
|
||||
public void Length()
|
||||
{
|
||||
var data = new List<object>();
|
||||
data.Add(select.Where(a => a.Title.Length == 0).ToList());
|
||||
data.Add(select.Where(a => a.Title.Length == 1).ToList());
|
||||
data.Add(select.Where(a => a.Title.Length == a.Title.Length + 1).ToList());
|
||||
data.Add(select.Where(a => a.Title.Length == a.Type.Name.Length).ToList());
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5
|
||||
//FROM `tb_topic` a
|
||||
//WHERE (char_length(a.`Title`) = 0);
|
||||
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5
|
||||
//FROM `tb_topic` a
|
||||
//WHERE (char_length(a.`Title`) = 1);
|
||||
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5
|
||||
//FROM `tb_topic` a
|
||||
//WHERE (char_length(a.`Title`) = char_length(a.`Title`) + 1);
|
||||
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a.`Title` as7, a.`CreateTime` as8
|
||||
//FROM `tb_topic` a, `TestTypeInfo` a__Type
|
||||
//WHERE (char_length(a.`Title`) = char_length(a__Type.`Name`));
|
||||
data.Add(select.Where(a => (a.Title + "aaa").Length == 0).ToList());
|
||||
data.Add(select.Where(a => (a.Title + "aaa").Length == 1).ToList());
|
||||
data.Add(select.Where(a => (a.Title + "aaa").Length == a.Title.Length + 1).ToList());
|
||||
data.Add(select.Where(a => (a.Title + "aaa").Length == a.Type.Name.Length).ToList());
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5
|
||||
//FROM `tb_topic` a
|
||||
//WHERE (char_length(concat(a.`Title`, 'aaa')) = 0);
|
||||
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5
|
||||
//FROM `tb_topic` a
|
||||
//WHERE (char_length(concat(a.`Title`, 'aaa')) = 1);
|
||||
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5
|
||||
//FROM `tb_topic` a
|
||||
//WHERE (char_length(concat(a.`Title`, 'aaa')) = char_length(a.`Title`) + 1);
|
||||
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a.`Title` as7, a.`CreateTime` as8
|
||||
//FROM `tb_topic` a, `TestTypeInfo` a__Type
|
||||
//WHERE (char_length(concat(a.`Title`, 'aaa')) = char_length(a__Type.`Name`))
|
||||
}
|
||||
[Fact]
|
||||
public void IndexOf()
|
||||
{
|
||||
var data = new List<object>();
|
||||
data.Add(select.Where(a => a.Title.IndexOf("aaa") == -1).ToList());
|
||||
data.Add(select.Where(a => a.Title.IndexOf("aaa", 2) == -1).ToList());
|
||||
data.Add(select.Where(a => a.Title.IndexOf("aaa", 2) == (a.Title.Length + 1)).ToList());
|
||||
data.Add(select.Where(a => a.Title.IndexOf("aaa", 2) == a.Type.Name.Length + 1).ToList());
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5
|
||||
//FROM `tb_topic` a
|
||||
//WHERE ((locate(a.`Title`, 'aaa') - 1) = -1);
|
||||
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5
|
||||
//FROM `tb_topic` a
|
||||
//WHERE ((locate(a.`Title`, 'aaa', 3) - 1) = -1);
|
||||
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5
|
||||
//FROM `tb_topic` a
|
||||
//WHERE ((locate(a.`Title`, 'aaa', 3) - 1) = char_length(a.`Title`) + 1);
|
||||
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a.`Title` as7, a.`CreateTime` as8
|
||||
//FROM `tb_topic` a, `TestTypeInfo` a__Type
|
||||
//WHERE ((locate(a.`Title`, 'aaa', 3) - 1) = char_length(a__Type.`Name`) + 1);
|
||||
data.Add(select.Where(a => (a.Title + "aaa").IndexOf("aaa") == -1).ToList());
|
||||
data.Add(select.Where(a => (a.Title + "aaa").IndexOf("aaa", 2) == -1).ToList());
|
||||
data.Add(select.Where(a => (a.Title + "aaa").IndexOf("aaa", 2) == (a.Title.Length + 1)).ToList());
|
||||
data.Add(select.Where(a => (a.Title + "aaa").IndexOf("aaa", 2) == a.Type.Name.Length + 1).ToList());
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5
|
||||
//FROM `tb_topic` a
|
||||
//WHERE ((locate(concat(a.`Title`, 'aaa'), 'aaa') - 1) = -1);
|
||||
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5
|
||||
//FROM `tb_topic` a
|
||||
//WHERE ((locate(concat(a.`Title`, 'aaa'), 'aaa', 3) - 1) = -1);
|
||||
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5
|
||||
//FROM `tb_topic` a
|
||||
//WHERE ((locate(concat(a.`Title`, 'aaa'), 'aaa', 3) - 1) = char_length(a.`Title`) + 1);
|
||||
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a.`Title` as7, a.`CreateTime` as8
|
||||
//FROM `tb_topic` a, `TestTypeInfo` a__Type
|
||||
//WHERE ((locate(concat(a.`Title`, 'aaa'), 'aaa', 3) - 1) = char_length(a__Type.`Name`) + 1)
|
||||
}
|
||||
[Fact]
|
||||
public void PadLeft()
|
||||
{
|
||||
var data = new List<object>();
|
||||
data.Add(select.Where(a => a.Title.PadLeft(10, 'a') == "aaa").ToList());
|
||||
data.Add(select.Where(a => a.Title.PadLeft(10, 'a') == a.Title).ToList());
|
||||
data.Add(select.Where(a => a.Title.PadLeft(10, 'a') == (a.Title + 1)).ToList());
|
||||
data.Add(select.Where(a => a.Title.PadLeft(10, 'a') == a.Type.Name).ToList());
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5
|
||||
//FROM `tb_topic` a
|
||||
//WHERE (lpad(a.`Title`, 10, 'a') = 'aaa');
|
||||
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5
|
||||
//FROM `tb_topic` a
|
||||
//WHERE (lpad(a.`Title`, 10, 'a') = a.`Title`);
|
||||
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5
|
||||
//FROM `tb_topic` a
|
||||
//WHERE (lpad(a.`Title`, 10, 'a') = concat(a.`Title`, 1));
|
||||
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a.`Title` as7, a.`CreateTime` as8
|
||||
//FROM `tb_topic` a, `TestTypeInfo` a__Type
|
||||
//WHERE (lpad(a.`Title`, 10, 'a') = a__Type.`Name`);
|
||||
data.Add(select.Where(a => (a.Title.PadLeft(10, 'a') + "aaa").PadLeft(20, 'b') == "aaa").ToList());
|
||||
data.Add(select.Where(a => (a.Title.PadLeft(10, 'a') + "aaa").PadLeft(20, 'b') == a.Title).ToList());
|
||||
data.Add(select.Where(a => (a.Title.PadLeft(10, 'a') + "aaa").PadLeft(20, 'b') == (a.Title + 1)).ToList());
|
||||
data.Add(select.Where(a => (a.Title.PadLeft(10, 'a') + "aaa").PadLeft(20, 'b') == a.Type.Name).ToList());
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5
|
||||
//FROM `tb_topic` a
|
||||
//WHERE (lpad(concat(lpad(a.`Title`, 10, 'a'), 'aaa'), 20, 'b') = 'aaa');
|
||||
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5
|
||||
//FROM `tb_topic` a
|
||||
//WHERE (lpad(concat(lpad(a.`Title`, 10, 'a'), 'aaa'), 20, 'b') = a.`Title`);
|
||||
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5
|
||||
//FROM `tb_topic` a
|
||||
//WHERE (lpad(concat(lpad(a.`Title`, 10, 'a'), 'aaa'), 20, 'b') = concat(a.`Title`, 1));
|
||||
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a.`Title` as7, a.`CreateTime` as8
|
||||
//FROM `tb_topic` a, `TestTypeInfo` a__Type
|
||||
//WHERE (lpad(concat(lpad(a.`Title`, 10, 'a'), 'aaa'), 20, 'b') = a__Type.`Name`)
|
||||
}
|
||||
[Fact]
|
||||
public void PadRight()
|
||||
{
|
||||
var data = new List<object>();
|
||||
data.Add(select.Where(a => a.Title.PadRight(10, 'a') == "aaa").ToList());
|
||||
data.Add(select.Where(a => a.Title.PadRight(10, 'a') == a.Title).ToList());
|
||||
data.Add(select.Where(a => a.Title.PadRight(10, 'a') == (a.Title + 1)).ToList());
|
||||
data.Add(select.Where(a => a.Title.PadRight(10, 'a') == a.Type.Name).ToList());
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5
|
||||
//FROM `tb_topic` a
|
||||
//WHERE (rpad(a.`Title`, 10, 'a') = 'aaa');
|
||||
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5
|
||||
//FROM `tb_topic` a
|
||||
//WHERE (rpad(a.`Title`, 10, 'a') = a.`Title`);
|
||||
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5
|
||||
//FROM `tb_topic` a
|
||||
//WHERE (rpad(a.`Title`, 10, 'a') = concat(a.`Title`, 1));
|
||||
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a.`Title` as7, a.`CreateTime` as8
|
||||
//FROM `tb_topic` a, `TestTypeInfo` a__Type
|
||||
//WHERE (rpad(a.`Title`, 10, 'a') = a__Type.`Name`);
|
||||
data.Add(select.Where(a => (a.Title.PadRight(10, 'a') + "aaa").PadRight(20, 'b') == "aaa").ToList());
|
||||
data.Add(select.Where(a => (a.Title.PadRight(10, 'a') + "aaa").PadRight(20, 'b') == a.Title).ToList());
|
||||
data.Add(select.Where(a => (a.Title.PadRight(10, 'a') + "aaa").PadRight(20, 'b') == (a.Title + 1)).ToList());
|
||||
data.Add(select.Where(a => (a.Title.PadRight(10, 'a') + "aaa").PadRight(20, 'b') == a.Type.Name).ToList());
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5
|
||||
//FROM `tb_topic` a
|
||||
//WHERE (rpad(concat(rpad(a.`Title`, 10, 'a'), 'aaa'), 20, 'b') = 'aaa');
|
||||
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5
|
||||
//FROM `tb_topic` a
|
||||
//WHERE (rpad(concat(rpad(a.`Title`, 10, 'a'), 'aaa'), 20, 'b') = a.`Title`);
|
||||
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5
|
||||
//FROM `tb_topic` a
|
||||
//WHERE (rpad(concat(rpad(a.`Title`, 10, 'a'), 'aaa'), 20, 'b') = concat(a.`Title`, 1));
|
||||
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a.`Title` as7, a.`CreateTime` as8
|
||||
//FROM `tb_topic` a, `TestTypeInfo` a__Type
|
||||
//WHERE (rpad(concat(rpad(a.`Title`, 10, 'a'), 'aaa'), 20, 'b') = a__Type.`Name`)
|
||||
}
|
||||
[Fact]
|
||||
public void Trim()
|
||||
{
|
||||
var data = new List<object>();
|
||||
data.Add(select.Where(a => a.Title.Trim() == "aaa").ToList());
|
||||
data.Add(select.Where(a => a.Title.Trim('a') == a.Title).ToList());
|
||||
data.Add(select.Where(a => a.Title.Trim('a', 'b') == (a.Title + 1)).ToList());
|
||||
data.Add(select.Where(a => a.Title.Trim('a', 'b', 'c') == a.Type.Name).ToList());
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5
|
||||
//FROM `tb_topic` a
|
||||
//WHERE (trim(a.`Title`) = 'aaa');
|
||||
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5
|
||||
//FROM `tb_topic` a
|
||||
//WHERE (trim('a' from a.`Title`) = a.`Title`);
|
||||
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5
|
||||
//FROM `tb_topic` a
|
||||
//WHERE (trim('b' from trim('a' from a.`Title`)) = concat(a.`Title`, 1));
|
||||
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a.`Title` as7, a.`CreateTime` as8
|
||||
//FROM `tb_topic` a, `TestTypeInfo` a__Type
|
||||
//WHERE (trim('c' from trim('b' from trim('a' from a.`Title`))) = a__Type.`Name`);
|
||||
data.Add(select.Where(a => (a.Title.Trim() + "aaa").Trim() == "aaa").ToList());
|
||||
data.Add(select.Where(a => (a.Title.Trim('a') + "aaa").Trim('a') == a.Title).ToList());
|
||||
data.Add(select.Where(a => (a.Title.Trim('a', 'b') + "aaa").Trim('a', 'b') == (a.Title + 1)).ToList());
|
||||
data.Add(select.Where(a => (a.Title.Trim('a', 'b', 'c') + "aaa").Trim('a', 'b', 'c') == a.Type.Name).ToList());
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5
|
||||
//FROM `tb_topic` a
|
||||
//WHERE (trim(concat(trim(a.`Title`), 'aaa')) = 'aaa');
|
||||
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5
|
||||
//FROM `tb_topic` a
|
||||
//WHERE (trim('a' from concat(trim('a' from a.`Title`), 'aaa')) = a.`Title`);
|
||||
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5
|
||||
//FROM `tb_topic` a
|
||||
//WHERE (trim('b' from trim('a' from concat(trim('b' from trim('a' from a.`Title`)), 'aaa'))) = concat(a.`Title`, 1));
|
||||
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a.`Title` as7, a.`CreateTime` as8
|
||||
//FROM `tb_topic` a, `TestTypeInfo` a__Type
|
||||
//WHERE (trim('c' from trim('b' from trim('a' from concat(trim('c' from trim('b' from trim('a' from a.`Title`))), 'aaa')))) = a__Type.`Name`)
|
||||
}
|
||||
[Fact]
|
||||
public void TrimStart()
|
||||
{
|
||||
var data = new List<object>();
|
||||
data.Add(select.Where(a => a.Title.TrimStart() == "aaa").ToList());
|
||||
data.Add(select.Where(a => a.Title.TrimStart('a') == a.Title).ToList());
|
||||
data.Add(select.Where(a => a.Title.TrimStart('a', 'b') == (a.Title + 1)).ToList());
|
||||
data.Add(select.Where(a => a.Title.TrimStart('a', 'b', 'c') == a.Type.Name).ToList());
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5
|
||||
//FROM `tb_topic` a
|
||||
//WHERE (ltrim(a.`Title`) = 'aaa');
|
||||
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5
|
||||
//FROM `tb_topic` a
|
||||
//WHERE (trim(trailing 'a' from trim(leading 'a' from a.`Title`)) = a.`Title`);
|
||||
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5
|
||||
//FROM `tb_topic` a
|
||||
//WHERE (trim(trailing 'b' from trim(leading 'b' from trim(trailing 'a' from trim(leading 'a' from a.`Title`)))) = concat(a.`Title`, 1));
|
||||
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a.`Title` as7, a.`CreateTime` as8
|
||||
//FROM `tb_topic` a, `TestTypeInfo` a__Type
|
||||
//WHERE (trim(trailing 'c' from trim(leading 'c' from trim(trailing 'b' from trim(leading 'b' from trim(trailing 'a' from trim(leading 'a' from a.`Title`)))))) = a__Type.`Name`);
|
||||
data.Add(select.Where(a => (a.Title.TrimStart() + "aaa").TrimStart() == "aaa").ToList());
|
||||
data.Add(select.Where(a => (a.Title.TrimStart('a') + "aaa").TrimStart('a') == a.Title).ToList());
|
||||
data.Add(select.Where(a => (a.Title.TrimStart('a', 'b') + "aaa").TrimStart('a', 'b') == (a.Title + 1)).ToList());
|
||||
data.Add(select.Where(a => (a.Title.TrimStart('a', 'b', 'c') + "aaa").TrimStart('a', 'b', 'c') == a.Type.Name).ToList());
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5
|
||||
//FROM `tb_topic` a
|
||||
//WHERE (ltrim(concat(ltrim(a.`Title`), 'aaa')) = 'aaa');
|
||||
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5
|
||||
//FROM `tb_topic` a
|
||||
//WHERE (trim(trailing 'a' from trim(leading 'a' from concat(trim(trailing 'a' from trim(leading 'a' from a.`Title`)), 'aaa'))) = a.`Title`);
|
||||
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5
|
||||
//FROM `tb_topic` a
|
||||
//WHERE (trim(trailing 'b' from trim(leading 'b' from trim(trailing 'a' from trim(leading 'a' from concat(trim(trailing 'b' from trim(leading 'b' from trim(trailing 'a' from trim(leading 'a' from a.`Title`)))), 'aaa'))))) = concat(a.`Title`, 1));
|
||||
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a.`Title` as7, a.`CreateTime` as8
|
||||
//FROM `tb_topic` a, `TestTypeInfo` a__Type
|
||||
//WHERE (trim(trailing 'c' from trim(leading 'c' from trim(trailing 'b' from trim(leading 'b' from trim(trailing 'a' from trim(leading 'a' from concat(trim(trailing 'c' from trim(leading 'c' from trim(trailing 'b' from trim(leading 'b' from trim(trailing 'a' from trim(leading 'a' from a.`Title`)))))), 'aaa'))))))) = a__Type.`Name`)
|
||||
}
|
||||
[Fact]
|
||||
public void TrimEnd()
|
||||
{
|
||||
var data = new List<object>();
|
||||
data.Add(select.Where(a => a.Title.TrimEnd() == "aaa").ToList());
|
||||
data.Add(select.Where(a => a.Title.TrimEnd('a') == a.Title).ToList());
|
||||
data.Add(select.Where(a => a.Title.TrimEnd('a', 'b') == (a.Title + 1)).ToList());
|
||||
data.Add(select.Where(a => a.Title.TrimEnd('a', 'b', 'c') == a.Type.Name).ToList());
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5
|
||||
//FROM `tb_topic` a
|
||||
//WHERE (rtrim(a.`Title`) = 'aaa');
|
||||
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5
|
||||
//FROM `tb_topic` a
|
||||
//WHERE (trim(trailing 'a' from a.`Title`) = a.`Title`);
|
||||
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5
|
||||
//FROM `tb_topic` a
|
||||
//WHERE (trim(trailing 'b' from trim(trailing 'a' from a.`Title`)) = concat(a.`Title`, 1));
|
||||
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a.`Title` as7, a.`CreateTime` as8
|
||||
//FROM `tb_topic` a, `TestTypeInfo` a__Type
|
||||
//WHERE (trim(trailing 'c' from trim(trailing 'b' from trim(trailing 'a' from a.`Title`))) = a__Type.`Name`);
|
||||
data.Add(select.Where(a => (a.Title.TrimEnd() + "aaa").TrimEnd() == "aaa").ToList());
|
||||
data.Add(select.Where(a => (a.Title.TrimEnd('a') + "aaa").TrimEnd('a') == a.Title).ToList());
|
||||
data.Add(select.Where(a => (a.Title.TrimEnd('a', 'b') + "aaa").TrimEnd('a', 'b') == (a.Title + 1)).ToList());
|
||||
data.Add(select.Where(a => (a.Title.TrimEnd('a', 'b', 'c') + "aaa").TrimEnd('a', 'b', 'c') == a.Type.Name).ToList());
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5
|
||||
//FROM `tb_topic` a
|
||||
//WHERE (rtrim(concat(rtrim(a.`Title`), 'aaa')) = 'aaa');
|
||||
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5
|
||||
//FROM `tb_topic` a
|
||||
//WHERE (trim(trailing 'a' from concat(trim(trailing 'a' from a.`Title`), 'aaa')) = a.`Title`);
|
||||
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5
|
||||
//FROM `tb_topic` a
|
||||
//WHERE (trim(trailing 'b' from trim(trailing 'a' from concat(trim(trailing 'b' from trim(trailing 'a' from a.`Title`)), 'aaa'))) = concat(a.`Title`, 1));
|
||||
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a.`Title` as7, a.`CreateTime` as8
|
||||
//FROM `tb_topic` a, `TestTypeInfo` a__Type
|
||||
//WHERE (trim(trailing 'c' from trim(trailing 'b' from trim(trailing 'a' from concat(trim(trailing 'c' from trim(trailing 'b' from trim(trailing 'a' from a.`Title`))), 'aaa')))) = a__Type.`Name`)
|
||||
}
|
||||
[Fact]
|
||||
public void Replace()
|
||||
{
|
||||
var data = new List<object>();
|
||||
data.Add(select.Where(a => a.Title.Replace("a", "b") == "aaa").ToList());
|
||||
data.Add(select.Where(a => a.Title.Replace("a", "b").Replace("b", "c") == a.Title).ToList());
|
||||
data.Add(select.Where(a => a.Title.Replace("a", "b").Replace("b", "c").Replace("c", "a") == (a.Title + 1)).ToList());
|
||||
data.Add(select.Where(a => a.Title.Replace("a", "b").Replace("b", "c").Replace(a.Type.Name, "a") == a.Type.Name).ToList());
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5
|
||||
//FROM `tb_topic` a
|
||||
//WHERE (replace(a.`Title`, 'a', 'b') = 'aaa');
|
||||
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5
|
||||
//FROM `tb_topic` a
|
||||
//WHERE (replace(replace(a.`Title`, 'a', 'b'), 'b', 'c') = a.`Title`);
|
||||
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5
|
||||
//FROM `tb_topic` a
|
||||
//WHERE (replace(replace(replace(a.`Title`, 'a', 'b'), 'b', 'c'), 'c', 'a') = concat(a.`Title`, 1));
|
||||
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a.`Title` as7, a.`CreateTime` as8
|
||||
//FROM `tb_topic` a, `TestTypeInfo` a__Type
|
||||
//WHERE (replace(replace(replace(a.`Title`, 'a', 'b'), 'b', 'c'), a__Type.`Name`, 'a') = a__Type.`Name`);
|
||||
data.Add(select.Where(a => (a.Title.Replace("a", "b") + "aaa").TrimEnd() == "aaa").ToList());
|
||||
data.Add(select.Where(a => (a.Title.Replace("a", "b").Replace("b", "c") + "aaa").TrimEnd('a') == a.Title).ToList());
|
||||
data.Add(select.Where(a => (a.Title.Replace("a", "b").Replace("b", "c").Replace("c", "a") + "aaa").TrimEnd('a', 'b') == (a.Title + 1)).ToList());
|
||||
data.Add(select.Where(a => (a.Title.Replace("a", "b").Replace("b", "c").Replace(a.Type.Name, "a") + "aaa").TrimEnd('a', 'b', 'c') == a.Type.Name).ToList());
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5
|
||||
//FROM `tb_topic` a
|
||||
//WHERE (concat(replace(a.`Title`, 'a', 'b'), 'aaa') = 'aaa');
|
||||
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5
|
||||
//FROM `tb_topic` a
|
||||
//WHERE (concat(replace(replace(a.`Title`, 'a', 'b'), 'b', 'c'), 'aaa') = a.`Title`);
|
||||
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5
|
||||
//FROM `tb_topic` a
|
||||
//WHERE (concat(replace(replace(replace(a.`Title`, 'a', 'b'), 'b', 'c'), 'c', 'a'), 'aaa') = concat(a.`Title`, 1));
|
||||
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a.`Title` as7, a.`CreateTime` as8
|
||||
//FROM `tb_topic` a, `TestTypeInfo` a__Type
|
||||
//WHERE (concat(replace(replace(replace(a.`Title`, 'a', 'b'), 'b', 'c'), a__Type.`Name`, 'a'), 'aaa') = a__Type.`Name`)
|
||||
}
|
||||
[Fact]
|
||||
public void CompareTo()
|
||||
{
|
||||
var data = new List<object>();
|
||||
data.Add(select.Where(a => a.Title.CompareTo(a.Title) == 0).ToList());
|
||||
data.Add(select.Where(a => a.Title.CompareTo(a.Title) > 0).ToList());
|
||||
data.Add(select.Where(a => a.Title.CompareTo(a.Title + 1) == 0).ToList());
|
||||
data.Add(select.Where(a => a.Title.CompareTo(a.Title + a.Type.Name) == 0).ToList());
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5
|
||||
//FROM `tb_topic` a
|
||||
//WHERE (strcmp(a.`Title`, a.`Title`) = 0);
|
||||
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5
|
||||
//FROM `tb_topic` a
|
||||
//WHERE (strcmp(a.`Title`, a.`Title`) > 0);
|
||||
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5
|
||||
//FROM `tb_topic` a
|
||||
//WHERE (strcmp(a.`Title`, concat(a.`Title`, 1)) = 0);
|
||||
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a.`Title` as7, a.`CreateTime` as8
|
||||
//FROM `tb_topic` a, `TestTypeInfo` a__Type
|
||||
//WHERE (strcmp(a.`Title`, concat(a.`Title`, a__Type.`Name`)) = 0);
|
||||
data.Add(select.Where(a => (a.Title + "aaa").CompareTo("aaa") == 0).ToList());
|
||||
data.Add(select.Where(a => (a.Title + "aaa").CompareTo(a.Title) > 0).ToList());
|
||||
data.Add(select.Where(a => (a.Title + "aaa").CompareTo(a.Title + 1) == 0).ToList());
|
||||
data.Add(select.Where(a => (a.Title + "aaa").CompareTo(a.Type.Name) == 0).ToList());
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5
|
||||
//FROM `tb_topic` a
|
||||
//WHERE (strcmp(concat(a.`Title`, 'aaa'), 'aaa') = 0);
|
||||
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5
|
||||
//FROM `tb_topic` a
|
||||
//WHERE (strcmp(concat(a.`Title`, 'aaa'), a.`Title`) > 0);
|
||||
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5
|
||||
//FROM `tb_topic` a
|
||||
//WHERE (strcmp(concat(a.`Title`, 'aaa'), concat(a.`Title`, 1)) = 0);
|
||||
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a.`Title` as7, a.`CreateTime` as8
|
||||
//FROM `tb_topic` a, `TestTypeInfo` a__Type
|
||||
//WHERE (strcmp(concat(a.`Title`, 'aaa'), a__Type.`Name`) = 0)
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void string_IsNullOrEmpty()
|
||||
{
|
||||
var data = new List<object>();
|
||||
data.Add(select.Where(a => string.IsNullOrEmpty(a.Title)).ToList());
|
||||
data.Add(select.Where(a => string.IsNullOrEmpty(a.Title) == false).ToList());
|
||||
data.Add(select.Where(a => !string.IsNullOrEmpty(a.Title)).ToList());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void string_IsNullOrWhiteSpace()
|
||||
{
|
||||
var data = new List<object>();
|
||||
data.Add(select.Where(a => string.IsNullOrWhiteSpace(a.Title)).ToList());
|
||||
data.Add(select.Where(a => string.IsNullOrWhiteSpace(a.Title) == false).ToList());
|
||||
data.Add(select.Where(a => !string.IsNullOrWhiteSpace(a.Title)).ToList());
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,293 @@
|
||||
using FreeSql.DataAnnotations;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Xunit;
|
||||
|
||||
namespace FreeSql.Tests.Odbc.MySqlExpression
|
||||
{
|
||||
public class TimeSpanTest
|
||||
{
|
||||
|
||||
ISelect<Topic> select => g.mysql.Select<Topic>();
|
||||
|
||||
[Table(Name = "tb_topic")]
|
||||
class Topic
|
||||
{
|
||||
[Column(IsIdentity = true, IsPrimary = true)]
|
||||
public int Id { get; set; }
|
||||
public int Clicks { get; set; }
|
||||
public int TypeGuid { get; set; }
|
||||
public TestTypeInfo Type { get; set; }
|
||||
public string Title { get; set; }
|
||||
public DateTime CreateTime { get; set; }
|
||||
}
|
||||
class TestTypeInfo
|
||||
{
|
||||
public int Guid { get; set; }
|
||||
public int ParentId { get; set; }
|
||||
public TestTypeParentInfo Parent { get; set; }
|
||||
public string Name { get; set; }
|
||||
}
|
||||
class TestTypeParentInfo
|
||||
{
|
||||
public int Id { get; set; }
|
||||
public string Name { get; set; }
|
||||
|
||||
public List<TestTypeInfo> Types { get; set; }
|
||||
}
|
||||
[Fact]
|
||||
public void Zero()
|
||||
{
|
||||
var data = new List<object>();
|
||||
data.Add(select.Where(a => a.CreateTime.TimeOfDay > TimeSpan.Zero).ToList());
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5
|
||||
//FROM `tb_topic` a
|
||||
//WHERE (timestampdiff(microsecond, date_format(a.`CreateTime`, '1970-1-1 %H:%i:%s.%f'), a.`CreateTime`) + 62135596800000000) > 0)
|
||||
}
|
||||
[Fact]
|
||||
public void MinValue()
|
||||
{
|
||||
var data = new List<object>();
|
||||
data.Add(select.Where(a => a.CreateTime.TimeOfDay > TimeSpan.MinValue).ToList());
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5
|
||||
//FROM `tb_topic` a
|
||||
//WHERE (timestampdiff(microsecond, date_format(a.`CreateTime`, '1970-1-1 %H:%i:%s.%f'), a.`CreateTime`) + 62135596800000000) > -922337203685477580)
|
||||
}
|
||||
[Fact]
|
||||
public void MaxValue()
|
||||
{
|
||||
var data = new List<object>();
|
||||
data.Add(select.Where(a => a.CreateTime.TimeOfDay < TimeSpan.MaxValue).ToList());
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5
|
||||
//FROM `tb_topic` a
|
||||
//WHERE (timestampdiff(microsecond, date_format(a.`CreateTime`, '1970-1-1 %H:%i:%s.%f'), a.`CreateTime`) + 62135596800000000) < 922337203685477580)
|
||||
}
|
||||
[Fact]
|
||||
public void Days()
|
||||
{
|
||||
var data = new List<object>();
|
||||
data.Add(select.Where(a => a.CreateTime.TimeOfDay.Days == 0).ToList());
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5
|
||||
//FROM `tb_topic` a
|
||||
//WHERE (((timestampdiff(microsecond, date_format(a.`CreateTime`, '1970-1-1 %H:%i:%s.%f'), a.`CreateTime`) + 62135596800000000)) div 86400000000) = 0)
|
||||
}
|
||||
[Fact]
|
||||
public void Hours()
|
||||
{
|
||||
var data = new List<object>();
|
||||
data.Add(select.Where(a => a.CreateTime.TimeOfDay.Hours > 0).ToSql());
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5
|
||||
//FROM `tb_topic` a
|
||||
//WHERE (((timestampdiff(microsecond, date_format(a.`CreateTime`, '1970-1-1 %H:%i:%s.%f'), a.`CreateTime`) + 62135596800000000)) div 3600000000) mod 24 > 0)
|
||||
}
|
||||
[Fact]
|
||||
public void Milliseconds()
|
||||
{
|
||||
var data = new List<object>();
|
||||
data.Add(select.Where(a => a.CreateTime.TimeOfDay.Milliseconds > 0).ToList());
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5
|
||||
//FROM `tb_topic` a
|
||||
//WHERE (((timestampdiff(microsecond, date_format(a.`CreateTime`, '1970-1-1 %H:%i:%s.%f'), a.`CreateTime`) + 62135596800000000)) div 1000 mod 1000) > 0)
|
||||
}
|
||||
[Fact]
|
||||
public void Minutes()
|
||||
{
|
||||
var data = new List<object>();
|
||||
data.Add(select.Where(a => a.CreateTime.TimeOfDay.Minutes > 0).ToList());
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5
|
||||
//FROM `tb_topic` a
|
||||
//WHERE (((timestampdiff(microsecond, date_format(a.`CreateTime`, '1970-1-1 %H:%i:%s.%f'), a.`CreateTime`) + 62135596800000000)) div 60000000 mod 60) > 0)
|
||||
}
|
||||
[Fact]
|
||||
public void Seconds()
|
||||
{
|
||||
var data = new List<object>();
|
||||
data.Add(select.Where(a => a.CreateTime.TimeOfDay.Seconds > 0).ToList());
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5
|
||||
//FROM `tb_topic` a
|
||||
//WHERE (((timestampdiff(microsecond, date_format(a.`CreateTime`, '1970-1-1 %H:%i:%s.%f'), a.`CreateTime`) + 62135596800000000)) div 1000000 mod 60) > 0)
|
||||
}
|
||||
[Fact]
|
||||
public void Ticks()
|
||||
{
|
||||
var data = new List<object>();
|
||||
data.Add(select.Where(a => a.CreateTime.TimeOfDay.Ticks > 0).ToList());
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5
|
||||
//FROM `tb_topic` a
|
||||
//WHERE (((timestampdiff(microsecond, date_format(a.`CreateTime`, '1970-1-1 %H:%i:%s.%f'), a.`CreateTime`) + 62135596800000000)) * 10) > 0)
|
||||
}
|
||||
[Fact]
|
||||
public void TotalDays()
|
||||
{
|
||||
var data = new List<object>();
|
||||
data.Add(select.Where(a => a.CreateTime.TimeOfDay.TotalDays > 0).ToList());
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5
|
||||
//FROM `tb_topic` a
|
||||
//WHERE (((timestampdiff(microsecond, date_format(a.`CreateTime`, '1970-1-1 %H:%i:%s.%f'), a.`CreateTime`) + 62135596800000000)) / 86400000000) > 0)
|
||||
}
|
||||
[Fact]
|
||||
public void TotalHours()
|
||||
{
|
||||
var data = new List<object>();
|
||||
data.Add(select.Where(a => a.CreateTime.TimeOfDay.TotalHours > 0).ToList());
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5
|
||||
//FROM `tb_topic` a
|
||||
//WHERE (((timestampdiff(microsecond, date_format(a.`CreateTime`, '1970-1-1 %H:%i:%s.%f'), a.`CreateTime`) + 62135596800000000)) / 3600000000) > 0)
|
||||
}
|
||||
[Fact]
|
||||
public void TotalMilliseconds()
|
||||
{
|
||||
var data = new List<object>();
|
||||
data.Add(select.Where(a => a.CreateTime.TimeOfDay.TotalMilliseconds > 0).ToList());
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5
|
||||
//FROM `tb_topic` a
|
||||
//WHERE (((timestampdiff(microsecond, date_format(a.`CreateTime`, '1970-1-1 %H:%i:%s.%f'), a.`CreateTime`) + 62135596800000000)) / 1000) > 0)
|
||||
}
|
||||
[Fact]
|
||||
public void TotalMinutes()
|
||||
{
|
||||
var data = new List<object>();
|
||||
data.Add(select.Where(a => a.CreateTime.TimeOfDay.TotalMinutes > 0).ToSql());
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5
|
||||
//FROM `tb_topic` a
|
||||
//WHERE (((timestampdiff(microsecond, date_format(a.`CreateTime`, '1970-1-1 %H:%i:%s.%f'), a.`CreateTime`) + 62135596800000000)) / 60000000) > 0)
|
||||
}
|
||||
[Fact]
|
||||
public void TotalSeconds()
|
||||
{
|
||||
var data = new List<object>();
|
||||
data.Add(select.Where(a => a.CreateTime.TimeOfDay.TotalSeconds > 0).ToList());
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5
|
||||
//FROM `tb_topic` a
|
||||
//WHERE (((timestampdiff(microsecond, date_format(a.`CreateTime`, '1970-1-1 %H:%i:%s.%f'), a.`CreateTime`) + 62135596800000000)) / 1000000) > 0)
|
||||
}
|
||||
[Fact]
|
||||
public void Add()
|
||||
{
|
||||
var data = new List<object>();
|
||||
data.Add(select.Where(a => a.CreateTime.TimeOfDay.Add(TimeSpan.FromDays(1)) > TimeSpan.Zero).ToList());
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5
|
||||
//FROM `tb_topic` a
|
||||
//WHERE ((timestampdiff(microsecond, date_format(a.`CreateTime`, '1970-1-1 %H:%i:%s.%f'), a.`CreateTime`) + 62135596800000000) + (1 * 86400000000)) > 0)
|
||||
}
|
||||
[Fact]
|
||||
public void Subtract()
|
||||
{
|
||||
var data = new List<object>();
|
||||
data.Add(select.Where(a => a.CreateTime.TimeOfDay.Subtract(TimeSpan.FromDays(1)) > TimeSpan.Zero).ToList());
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5
|
||||
//FROM `tb_topic` a
|
||||
//WHERE ((timestampdiff(microsecond, date_format(a.`CreateTime`, '1970-1-1 %H:%i:%s.%f'), a.`CreateTime`) + 62135596800000000) - (1 * 86400000000)) > 0)
|
||||
}
|
||||
[Fact]
|
||||
public void CompareTo()
|
||||
{
|
||||
var data = new List<object>();
|
||||
data.Add(select.Where(a => a.CreateTime.TimeOfDay.CompareTo(TimeSpan.FromDays(1)) > 0).ToList());
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5
|
||||
//FROM `tb_topic` a
|
||||
//WHERE (((timestampdiff(microsecond, date_format(a.`CreateTime`, '1970-1-1 %H:%i:%s.%f'), a.`CreateTime`) + 62135596800000000)) - ((1 * 86400000000))) > 0)
|
||||
}
|
||||
[Fact]
|
||||
public void this_Equals()
|
||||
{
|
||||
var data = new List<object>();
|
||||
data.Add(select.Where(a => a.CreateTime.TimeOfDay.Equals(TimeSpan.FromDays(1))).ToList());
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5
|
||||
//FROM `tb_topic` a
|
||||
//WHERE ((timestampdiff(microsecond, date_format(a.`CreateTime`, '1970-1-1 %H:%i:%s.%f'), a.`CreateTime`) + 62135596800000000) = (1 * 86400000000)))
|
||||
}
|
||||
[Fact]
|
||||
public void this_ToString()
|
||||
{
|
||||
var data = new List<object>();
|
||||
data.Add(select.Where(a => a.CreateTime.TimeOfDay.ToString() == "ssss").ToList());
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5
|
||||
//FROM `tb_topic` a
|
||||
//WHERE (date_format(date_add(cast('0001/1/1 0:00:00' as datetime), interval (timestampdiff(microsecond, date_format(a.`CreateTime`, '1970-1-1 %H:%i:%s.%f'), a.`CreateTime`) + 62135596800000000)) microsecond), '%Y-%m-%d %H:%i:%s.%f') = 'ssss')
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TimeSpan_Compare()
|
||||
{
|
||||
var data = new List<object>();
|
||||
data.Add(select.Where(a => TimeSpan.Compare(a.CreateTime.TimeOfDay, TimeSpan.FromDays(1)) > 0).ToList());
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5
|
||||
//FROM `tb_topic` a
|
||||
//WHERE (((timestampdiff(microsecond, date_format(a.`CreateTime`, '1970-1-1 %H:%i:%s.%f'), a.`CreateTime`) + 62135596800000000)) - ((1 * 86400000000))) > 0)
|
||||
}
|
||||
[Fact]
|
||||
public void TimeSpan_Equals()
|
||||
{
|
||||
var data = new List<object>();
|
||||
data.Add(select.Where(a => TimeSpan.Equals(a.CreateTime.TimeOfDay, TimeSpan.FromDays(1))).ToList());
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5
|
||||
//FROM `tb_topic` a
|
||||
//WHERE ((timestampdiff(microsecond, date_format(a.`CreateTime`, '1970-1-1 %H:%i:%s.%f'), a.`CreateTime`) + 62135596800000000) = (1 * 86400000000)))
|
||||
}
|
||||
[Fact]
|
||||
public void TimeSpan_FromDays()
|
||||
{
|
||||
var data = new List<object>();
|
||||
data.Add(select.Where(a => TimeSpan.Equals(a.CreateTime.TimeOfDay, TimeSpan.FromDays(1))).ToList());
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5
|
||||
//FROM `tb_topic` a
|
||||
//WHERE ((timestampdiff(microsecond, date_format(a.`CreateTime`, '1970-1-1 %H:%i:%s.%f'), a.`CreateTime`) + 62135596800000000) = (1 * 86400000000)))
|
||||
}
|
||||
[Fact]
|
||||
public void TimeSpan_FromHours()
|
||||
{
|
||||
var data = new List<object>();
|
||||
data.Add(select.Where(a => TimeSpan.Equals(a.CreateTime.TimeOfDay, TimeSpan.FromHours(1))).ToList());
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5
|
||||
//FROM `tb_topic` a
|
||||
//WHERE ((timestampdiff(microsecond, date_format(a.`CreateTime`, '1970-1-1 %H:%i:%s.%f'), a.`CreateTime`) + 62135596800000000) = (1 * 3600000000)))
|
||||
}
|
||||
[Fact]
|
||||
public void TimeSpan_FromMilliseconds()
|
||||
{
|
||||
var data = new List<object>();
|
||||
data.Add(select.Where(a => TimeSpan.Equals(a.CreateTime.TimeOfDay, TimeSpan.FromMilliseconds(1))).ToList());
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5
|
||||
//FROM `tb_topic` a
|
||||
//WHERE ((timestampdiff(microsecond, date_format(a.`CreateTime`, '1970-1-1 %H:%i:%s.%f'), a.`CreateTime`) + 62135596800000000) = (1 * 1000)))
|
||||
}
|
||||
[Fact]
|
||||
public void TimeSpan_FromMinutes()
|
||||
{
|
||||
var data = new List<object>();
|
||||
data.Add(select.Where(a => TimeSpan.Equals(a.CreateTime.TimeOfDay, TimeSpan.FromMinutes(1))).ToList());
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5
|
||||
//FROM `tb_topic` a
|
||||
//WHERE ((timestampdiff(microsecond, date_format(a.`CreateTime`, '1970-1-1 %H:%i:%s.%f'), a.`CreateTime`) + 62135596800000000) = (1 * 60000000)))
|
||||
}
|
||||
[Fact]
|
||||
public void TimeSpan_FromSeconds()
|
||||
{
|
||||
var data = new List<object>();
|
||||
data.Add(select.Where(a => TimeSpan.Equals(a.CreateTime.TimeOfDay, TimeSpan.FromSeconds(1))).ToList());
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5
|
||||
//FROM `tb_topic` a
|
||||
//WHERE ((timestampdiff(microsecond, date_format(a.`CreateTime`, '1970-1-1 %H:%i:%s.%f'), a.`CreateTime`) + 62135596800000000) = (1 * 1000000)))
|
||||
}
|
||||
[Fact]
|
||||
public void TimeSpan_FromTicks()
|
||||
{
|
||||
var data = new List<object>();
|
||||
data.Add(select.Where(a => TimeSpan.Equals(a.CreateTime.TimeOfDay, TimeSpan.FromTicks(1))).ToList());
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5
|
||||
//FROM `tb_topic` a
|
||||
//WHERE ((timestampdiff(microsecond, date_format(a.`CreateTime`, '1970-1-1 %H:%i:%s.%f'), a.`CreateTime`) + 62135596800000000) = (1 / 10)))
|
||||
}
|
||||
[Fact]
|
||||
public void TimeSpan_Parse()
|
||||
{
|
||||
var data = new List<object>();
|
||||
data.Add(select.Where(a => TimeSpan.Parse(a.CreateTime.TimeOfDay.ToString()) > TimeSpan.Zero).ToList());
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5
|
||||
//FROM `tb_topic` a
|
||||
//WHERE (cast(date_format(date_add(cast('0001/1/1 0:00:00' as datetime), interval (timestampdiff(microsecond, date_format(a.`CreateTime`, '1970-1-1 %H:%i:%s.%f'), a.`CreateTime`) + 62135596800000000)) microsecond), '%Y-%m-%d %H:%i:%s.%f') as signed) > 0)
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,98 @@
|
||||
using FreeSql.DataAnnotations;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Xunit;
|
||||
|
||||
namespace FreeSql.Tests.Odbc.Oracle
|
||||
{
|
||||
public class OracleDeleteTest
|
||||
{
|
||||
|
||||
IDelete<Topic> delete => g.oracle.Delete<Topic>(); //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
|
||||
[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.oracle.Delete<Topic>().ToSql());
|
||||
var sql = g.oracle.Delete<Topic>(new[] { 1, 2 }).ToSql();
|
||||
Assert.Equal("DELETE FROM \"TB_TOPIC22211\" WHERE (\"ID\" = 1 OR \"ID\" = 2)", sql);
|
||||
|
||||
sql = g.oracle.Delete<Topic>(new Topic { Id = 1, Title = "test" }).ToSql();
|
||||
Assert.Equal("DELETE FROM \"TB_TOPIC22211\" WHERE (\"ID\" = 1)", sql);
|
||||
|
||||
sql = g.oracle.Delete<Topic>(new[] { new Topic { Id = 1, Title = "test" }, new Topic { Id = 2, Title = "test" } }).ToSql();
|
||||
Assert.Equal("DELETE FROM \"TB_TOPIC22211\" WHERE (\"ID\" = 1 OR \"ID\" = 2)", sql);
|
||||
|
||||
sql = g.oracle.Delete<Topic>(new { id = 1 }).ToSql();
|
||||
Assert.Equal("DELETE FROM \"TB_TOPIC22211\" WHERE (\"ID\" = 1)", sql);
|
||||
}
|
||||
|
||||
[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 WhereExists()
|
||||
{
|
||||
|
||||
}
|
||||
[Fact]
|
||||
public void ExecuteAffrows()
|
||||
{
|
||||
|
||||
var id = g.oracle.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.oracle.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.oracle.Delete<Topic>().ToSql());
|
||||
var sql = g.oracle.Delete<Topic>(new[] { 1, 2 }).AsTable(a => "TopicAsTable").ToSql();
|
||||
Assert.Equal("DELETE FROM \"TOPICASTABLE\" WHERE (\"ID\" = 1 OR \"ID\" = 2)", sql);
|
||||
|
||||
sql = g.oracle.Delete<Topic>(new Topic { Id = 1, Title = "test" }).AsTable(a => "TopicAsTable").ToSql();
|
||||
Assert.Equal("DELETE FROM \"TOPICASTABLE\" WHERE (\"ID\" = 1)", sql);
|
||||
|
||||
sql = g.oracle.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\" = 1 OR \"ID\" = 2)", sql);
|
||||
|
||||
sql = g.oracle.Delete<Topic>(new { id = 1 }).AsTable(a => "TopicAsTable").ToSql();
|
||||
Assert.Equal("DELETE FROM \"TOPICASTABLE\" WHERE (\"ID\" = 1)", sql);
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,278 @@
|
||||
using FreeSql.DataAnnotations;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Xunit;
|
||||
|
||||
namespace FreeSql.Tests.Odbc.Oracle
|
||||
{
|
||||
public class OracleInsertTest
|
||||
{
|
||||
|
||||
IInsert<Topic> insert => g.oracle.Insert<Topic>(); //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
|
||||
[Table(Name = "tb_topic_insert")]
|
||||
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 AppendData()
|
||||
{
|
||||
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, CreateTime = DateTime.Parse("2019-09-19 22:25:38.697071") });
|
||||
|
||||
var data = new List<object>();
|
||||
var sql = insert.AppendData(items.First()).ToSql();
|
||||
Assert.Equal("INSERT INTO \"TB_TOPIC_INSERT\"(\"CLICKS\", \"TITLE\", \"CREATETIME\") VALUES(0, 'newtitle0', to_timestamp('2019-09-19 22:25:38.697071','YYYY-MM-DD HH24:MI:SS.FF6'))", sql);
|
||||
data.Add(insert.AppendData(items.First()).ExecuteIdentity());
|
||||
|
||||
sql = insert.AppendData(items).ToSql();
|
||||
Assert.Equal(@"INSERT ALL
|
||||
INTO ""TB_TOPIC_INSERT""(""CLICKS"", ""TITLE"", ""CREATETIME"") VALUES(0, 'newtitle0', to_timestamp('2019-09-19 22:25:38.697071','YYYY-MM-DD HH24:MI:SS.FF6'))
|
||||
INTO ""TB_TOPIC_INSERT""(""CLICKS"", ""TITLE"", ""CREATETIME"") VALUES(100, 'newtitle1', to_timestamp('2019-09-19 22:25:38.697071','YYYY-MM-DD HH24:MI:SS.FF6'))
|
||||
INTO ""TB_TOPIC_INSERT""(""CLICKS"", ""TITLE"", ""CREATETIME"") VALUES(200, 'newtitle2', to_timestamp('2019-09-19 22:25:38.697071','YYYY-MM-DD HH24:MI:SS.FF6'))
|
||||
INTO ""TB_TOPIC_INSERT""(""CLICKS"", ""TITLE"", ""CREATETIME"") VALUES(300, 'newtitle3', to_timestamp('2019-09-19 22:25:38.697071','YYYY-MM-DD HH24:MI:SS.FF6'))
|
||||
INTO ""TB_TOPIC_INSERT""(""CLICKS"", ""TITLE"", ""CREATETIME"") VALUES(400, 'newtitle4', to_timestamp('2019-09-19 22:25:38.697071','YYYY-MM-DD HH24:MI:SS.FF6'))
|
||||
INTO ""TB_TOPIC_INSERT""(""CLICKS"", ""TITLE"", ""CREATETIME"") VALUES(500, 'newtitle5', to_timestamp('2019-09-19 22:25:38.697071','YYYY-MM-DD HH24:MI:SS.FF6'))
|
||||
INTO ""TB_TOPIC_INSERT""(""CLICKS"", ""TITLE"", ""CREATETIME"") VALUES(600, 'newtitle6', to_timestamp('2019-09-19 22:25:38.697071','YYYY-MM-DD HH24:MI:SS.FF6'))
|
||||
INTO ""TB_TOPIC_INSERT""(""CLICKS"", ""TITLE"", ""CREATETIME"") VALUES(700, 'newtitle7', to_timestamp('2019-09-19 22:25:38.697071','YYYY-MM-DD HH24:MI:SS.FF6'))
|
||||
INTO ""TB_TOPIC_INSERT""(""CLICKS"", ""TITLE"", ""CREATETIME"") VALUES(800, 'newtitle8', to_timestamp('2019-09-19 22:25:38.697071','YYYY-MM-DD HH24:MI:SS.FF6'))
|
||||
INTO ""TB_TOPIC_INSERT""(""CLICKS"", ""TITLE"", ""CREATETIME"") VALUES(900, 'newtitle9', to_timestamp('2019-09-19 22:25:38.697071','YYYY-MM-DD HH24:MI:SS.FF6'))
|
||||
SELECT 1 FROM DUAL", sql);
|
||||
data.Add(insert.AppendData(items.First()).ExecuteIdentity());
|
||||
|
||||
sql = insert.AppendData(items).InsertColumns(a => a.Title).ToSql();
|
||||
Assert.Equal(@"INSERT ALL
|
||||
INTO ""TB_TOPIC_INSERT""(""TITLE"") VALUES('newtitle0')
|
||||
INTO ""TB_TOPIC_INSERT""(""TITLE"") VALUES('newtitle1')
|
||||
INTO ""TB_TOPIC_INSERT""(""TITLE"") VALUES('newtitle2')
|
||||
INTO ""TB_TOPIC_INSERT""(""TITLE"") VALUES('newtitle3')
|
||||
INTO ""TB_TOPIC_INSERT""(""TITLE"") VALUES('newtitle4')
|
||||
INTO ""TB_TOPIC_INSERT""(""TITLE"") VALUES('newtitle5')
|
||||
INTO ""TB_TOPIC_INSERT""(""TITLE"") VALUES('newtitle6')
|
||||
INTO ""TB_TOPIC_INSERT""(""TITLE"") VALUES('newtitle7')
|
||||
INTO ""TB_TOPIC_INSERT""(""TITLE"") VALUES('newtitle8')
|
||||
INTO ""TB_TOPIC_INSERT""(""TITLE"") VALUES('newtitle9')
|
||||
SELECT 1 FROM DUAL", sql);
|
||||
data.Add(insert.AppendData(items.First()).ExecuteIdentity());
|
||||
|
||||
sql = insert.AppendData(items).IgnoreColumns(a => a.CreateTime).ToSql();
|
||||
Assert.Equal(@"INSERT ALL
|
||||
INTO ""TB_TOPIC_INSERT""(""CLICKS"", ""TITLE"") VALUES(0, 'newtitle0')
|
||||
INTO ""TB_TOPIC_INSERT""(""CLICKS"", ""TITLE"") VALUES(100, 'newtitle1')
|
||||
INTO ""TB_TOPIC_INSERT""(""CLICKS"", ""TITLE"") VALUES(200, 'newtitle2')
|
||||
INTO ""TB_TOPIC_INSERT""(""CLICKS"", ""TITLE"") VALUES(300, 'newtitle3')
|
||||
INTO ""TB_TOPIC_INSERT""(""CLICKS"", ""TITLE"") VALUES(400, 'newtitle4')
|
||||
INTO ""TB_TOPIC_INSERT""(""CLICKS"", ""TITLE"") VALUES(500, 'newtitle5')
|
||||
INTO ""TB_TOPIC_INSERT""(""CLICKS"", ""TITLE"") VALUES(600, 'newtitle6')
|
||||
INTO ""TB_TOPIC_INSERT""(""CLICKS"", ""TITLE"") VALUES(700, 'newtitle7')
|
||||
INTO ""TB_TOPIC_INSERT""(""CLICKS"", ""TITLE"") VALUES(800, 'newtitle8')
|
||||
INTO ""TB_TOPIC_INSERT""(""CLICKS"", ""TITLE"") VALUES(900, 'newtitle9')
|
||||
SELECT 1 FROM DUAL", sql);
|
||||
data.Add(insert.AppendData(items.First()).ExecuteIdentity());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void InsertColumns()
|
||||
{
|
||||
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, CreateTime = DateTime.Now });
|
||||
|
||||
var data = new List<object>();
|
||||
var sql = insert.AppendData(items).InsertColumns(a => a.Title).ToSql();
|
||||
Assert.Equal(@"INSERT ALL
|
||||
INTO ""TB_TOPIC_INSERT""(""TITLE"") VALUES('newtitle0')
|
||||
INTO ""TB_TOPIC_INSERT""(""TITLE"") VALUES('newtitle1')
|
||||
INTO ""TB_TOPIC_INSERT""(""TITLE"") VALUES('newtitle2')
|
||||
INTO ""TB_TOPIC_INSERT""(""TITLE"") VALUES('newtitle3')
|
||||
INTO ""TB_TOPIC_INSERT""(""TITLE"") VALUES('newtitle4')
|
||||
INTO ""TB_TOPIC_INSERT""(""TITLE"") VALUES('newtitle5')
|
||||
INTO ""TB_TOPIC_INSERT""(""TITLE"") VALUES('newtitle6')
|
||||
INTO ""TB_TOPIC_INSERT""(""TITLE"") VALUES('newtitle7')
|
||||
INTO ""TB_TOPIC_INSERT""(""TITLE"") VALUES('newtitle8')
|
||||
INTO ""TB_TOPIC_INSERT""(""TITLE"") VALUES('newtitle9')
|
||||
SELECT 1 FROM DUAL", sql);
|
||||
data.Add(insert.AppendData(items.First()).ExecuteIdentity());
|
||||
|
||||
sql = insert.AppendData(items).InsertColumns(a => new { a.Title, a.Clicks }).ToSql();
|
||||
Assert.Equal(@"INSERT ALL
|
||||
INTO ""TB_TOPIC_INSERT""(""CLICKS"", ""TITLE"") VALUES(0, 'newtitle0')
|
||||
INTO ""TB_TOPIC_INSERT""(""CLICKS"", ""TITLE"") VALUES(100, 'newtitle1')
|
||||
INTO ""TB_TOPIC_INSERT""(""CLICKS"", ""TITLE"") VALUES(200, 'newtitle2')
|
||||
INTO ""TB_TOPIC_INSERT""(""CLICKS"", ""TITLE"") VALUES(300, 'newtitle3')
|
||||
INTO ""TB_TOPIC_INSERT""(""CLICKS"", ""TITLE"") VALUES(400, 'newtitle4')
|
||||
INTO ""TB_TOPIC_INSERT""(""CLICKS"", ""TITLE"") VALUES(500, 'newtitle5')
|
||||
INTO ""TB_TOPIC_INSERT""(""CLICKS"", ""TITLE"") VALUES(600, 'newtitle6')
|
||||
INTO ""TB_TOPIC_INSERT""(""CLICKS"", ""TITLE"") VALUES(700, 'newtitle7')
|
||||
INTO ""TB_TOPIC_INSERT""(""CLICKS"", ""TITLE"") VALUES(800, 'newtitle8')
|
||||
INTO ""TB_TOPIC_INSERT""(""CLICKS"", ""TITLE"") VALUES(900, 'newtitle9')
|
||||
SELECT 1 FROM DUAL", sql);
|
||||
data.Add(insert.AppendData(items.First()).ExecuteIdentity());
|
||||
}
|
||||
[Fact]
|
||||
public void IgnoreColumns()
|
||||
{
|
||||
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, CreateTime = DateTime.Now });
|
||||
|
||||
var data = new List<object>();
|
||||
var sql = insert.AppendData(items).IgnoreColumns(a => a.CreateTime).ToSql();
|
||||
Assert.Equal(@"INSERT ALL
|
||||
INTO ""TB_TOPIC_INSERT""(""CLICKS"", ""TITLE"") VALUES(0, 'newtitle0')
|
||||
INTO ""TB_TOPIC_INSERT""(""CLICKS"", ""TITLE"") VALUES(100, 'newtitle1')
|
||||
INTO ""TB_TOPIC_INSERT""(""CLICKS"", ""TITLE"") VALUES(200, 'newtitle2')
|
||||
INTO ""TB_TOPIC_INSERT""(""CLICKS"", ""TITLE"") VALUES(300, 'newtitle3')
|
||||
INTO ""TB_TOPIC_INSERT""(""CLICKS"", ""TITLE"") VALUES(400, 'newtitle4')
|
||||
INTO ""TB_TOPIC_INSERT""(""CLICKS"", ""TITLE"") VALUES(500, 'newtitle5')
|
||||
INTO ""TB_TOPIC_INSERT""(""CLICKS"", ""TITLE"") VALUES(600, 'newtitle6')
|
||||
INTO ""TB_TOPIC_INSERT""(""CLICKS"", ""TITLE"") VALUES(700, 'newtitle7')
|
||||
INTO ""TB_TOPIC_INSERT""(""CLICKS"", ""TITLE"") VALUES(800, 'newtitle8')
|
||||
INTO ""TB_TOPIC_INSERT""(""CLICKS"", ""TITLE"") VALUES(900, 'newtitle9')
|
||||
SELECT 1 FROM DUAL", sql);
|
||||
data.Add(insert.AppendData(items.First()).ExecuteIdentity());
|
||||
|
||||
sql = insert.AppendData(items).IgnoreColumns(a => new { a.Title, a.CreateTime }).ToSql();
|
||||
Assert.Equal(@"INSERT ALL
|
||||
INTO ""TB_TOPIC_INSERT""(""CLICKS"") VALUES(0)
|
||||
INTO ""TB_TOPIC_INSERT""(""CLICKS"") VALUES(100)
|
||||
INTO ""TB_TOPIC_INSERT""(""CLICKS"") VALUES(200)
|
||||
INTO ""TB_TOPIC_INSERT""(""CLICKS"") VALUES(300)
|
||||
INTO ""TB_TOPIC_INSERT""(""CLICKS"") VALUES(400)
|
||||
INTO ""TB_TOPIC_INSERT""(""CLICKS"") VALUES(500)
|
||||
INTO ""TB_TOPIC_INSERT""(""CLICKS"") VALUES(600)
|
||||
INTO ""TB_TOPIC_INSERT""(""CLICKS"") VALUES(700)
|
||||
INTO ""TB_TOPIC_INSERT""(""CLICKS"") VALUES(800)
|
||||
INTO ""TB_TOPIC_INSERT""(""CLICKS"") VALUES(900)
|
||||
SELECT 1 FROM DUAL", sql);
|
||||
data.Add(insert.AppendData(items.First()).ExecuteIdentity());
|
||||
|
||||
g.oracle.Delete<TopicIgnore>().Where("1=1").ExecuteAffrows();
|
||||
var itemsIgnore = new List<TopicIgnore>();
|
||||
for (var a = 0; a < 2072; a++) itemsIgnore.Add(new TopicIgnore { Id = a + 1, Title = $"newtitle{a}", Clicks = a * 100, CreateTime = DateTime.Now });
|
||||
g.oracle.Insert<TopicIgnore>().AppendData(itemsIgnore).IgnoreColumns(a => new { a.Title }).ExecuteAffrows();
|
||||
Assert.Equal(2072, itemsIgnore.Count);
|
||||
Assert.Equal(2072, g.oracle.Select<TopicIgnore>().Where(a => a.Title == null).Count());
|
||||
}
|
||||
[Table(Name = "tb_topicICs")]
|
||||
class TopicIgnore
|
||||
{
|
||||
[Column(IsIdentity = true, IsPrimary = true)]
|
||||
public int Id { get; set; }
|
||||
public int Clicks { get; set; }
|
||||
public string Title { get; set; }
|
||||
public DateTime CreateTime { get; set; }
|
||||
}
|
||||
[Fact]
|
||||
public void ExecuteAffrows()
|
||||
{
|
||||
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, CreateTime = DateTime.Now });
|
||||
|
||||
Assert.Equal(1, insert.AppendData(items.First()).ExecuteAffrows());
|
||||
Assert.Equal(10, insert.AppendData(items).ExecuteAffrows());
|
||||
}
|
||||
[Fact]
|
||||
public void ExecuteIdentity()
|
||||
{
|
||||
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, CreateTime = DateTime.Now });
|
||||
|
||||
Assert.NotEqual(0, insert.AppendData(items.First()).ExecuteIdentity());
|
||||
}
|
||||
[Fact]
|
||||
public void ExecuteInserted()
|
||||
{
|
||||
//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, CreateTime = DateTime.Now });
|
||||
|
||||
//var items2 = insert.AppendData(items).ExecuteInserted();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void AsTable()
|
||||
{
|
||||
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 });
|
||||
|
||||
var sql = insert.AppendData(items.First()).AsTable(a => "Topic_InsertAsTable").ToSql();
|
||||
Assert.Equal("INSERT INTO \"TOPIC_INSERTASTABLE\"(\"CLICKS\", \"TITLE\", \"CREATETIME\") VALUES(0, 'newTitle0', to_timestamp('0001-01-01 00:00:00.000000','YYYY-MM-DD HH24:MI:SS.FF6'))", sql);
|
||||
|
||||
sql = insert.AppendData(items).AsTable(a => "Topic_InsertAsTable").ToSql();
|
||||
Assert.Equal(@"INSERT ALL
|
||||
INTO ""TOPIC_INSERTASTABLE""(""CLICKS"", ""TITLE"", ""CREATETIME"") VALUES(0, 'newTitle0', to_timestamp('0001-01-01 00:00:00.000000','YYYY-MM-DD HH24:MI:SS.FF6'))
|
||||
INTO ""TOPIC_INSERTASTABLE""(""CLICKS"", ""TITLE"", ""CREATETIME"") VALUES(100, 'newTitle1', to_timestamp('0001-01-01 00:00:00.000000','YYYY-MM-DD HH24:MI:SS.FF6'))
|
||||
INTO ""TOPIC_INSERTASTABLE""(""CLICKS"", ""TITLE"", ""CREATETIME"") VALUES(200, 'newTitle2', to_timestamp('0001-01-01 00:00:00.000000','YYYY-MM-DD HH24:MI:SS.FF6'))
|
||||
INTO ""TOPIC_INSERTASTABLE""(""CLICKS"", ""TITLE"", ""CREATETIME"") VALUES(300, 'newTitle3', to_timestamp('0001-01-01 00:00:00.000000','YYYY-MM-DD HH24:MI:SS.FF6'))
|
||||
INTO ""TOPIC_INSERTASTABLE""(""CLICKS"", ""TITLE"", ""CREATETIME"") VALUES(400, 'newTitle4', to_timestamp('0001-01-01 00:00:00.000000','YYYY-MM-DD HH24:MI:SS.FF6'))
|
||||
INTO ""TOPIC_INSERTASTABLE""(""CLICKS"", ""TITLE"", ""CREATETIME"") VALUES(500, 'newTitle5', to_timestamp('0001-01-01 00:00:00.000000','YYYY-MM-DD HH24:MI:SS.FF6'))
|
||||
INTO ""TOPIC_INSERTASTABLE""(""CLICKS"", ""TITLE"", ""CREATETIME"") VALUES(600, 'newTitle6', to_timestamp('0001-01-01 00:00:00.000000','YYYY-MM-DD HH24:MI:SS.FF6'))
|
||||
INTO ""TOPIC_INSERTASTABLE""(""CLICKS"", ""TITLE"", ""CREATETIME"") VALUES(700, 'newTitle7', to_timestamp('0001-01-01 00:00:00.000000','YYYY-MM-DD HH24:MI:SS.FF6'))
|
||||
INTO ""TOPIC_INSERTASTABLE""(""CLICKS"", ""TITLE"", ""CREATETIME"") VALUES(800, 'newTitle8', to_timestamp('0001-01-01 00:00:00.000000','YYYY-MM-DD HH24:MI:SS.FF6'))
|
||||
INTO ""TOPIC_INSERTASTABLE""(""CLICKS"", ""TITLE"", ""CREATETIME"") VALUES(900, 'newTitle9', to_timestamp('0001-01-01 00:00:00.000000','YYYY-MM-DD HH24:MI:SS.FF6'))
|
||||
SELECT 1 FROM DUAL", sql);
|
||||
|
||||
sql = insert.AppendData(items).IgnoreColumns(a => a.Title).AsTable(a => "Topic_InsertAsTable").ToSql();
|
||||
Assert.Equal(@"INSERT ALL
|
||||
INTO ""TOPIC_INSERTASTABLE""(""CLICKS"", ""CREATETIME"") VALUES(0, to_timestamp('0001-01-01 00:00:00.000000','YYYY-MM-DD HH24:MI:SS.FF6'))
|
||||
INTO ""TOPIC_INSERTASTABLE""(""CLICKS"", ""CREATETIME"") VALUES(100, to_timestamp('0001-01-01 00:00:00.000000','YYYY-MM-DD HH24:MI:SS.FF6'))
|
||||
INTO ""TOPIC_INSERTASTABLE""(""CLICKS"", ""CREATETIME"") VALUES(200, to_timestamp('0001-01-01 00:00:00.000000','YYYY-MM-DD HH24:MI:SS.FF6'))
|
||||
INTO ""TOPIC_INSERTASTABLE""(""CLICKS"", ""CREATETIME"") VALUES(300, to_timestamp('0001-01-01 00:00:00.000000','YYYY-MM-DD HH24:MI:SS.FF6'))
|
||||
INTO ""TOPIC_INSERTASTABLE""(""CLICKS"", ""CREATETIME"") VALUES(400, to_timestamp('0001-01-01 00:00:00.000000','YYYY-MM-DD HH24:MI:SS.FF6'))
|
||||
INTO ""TOPIC_INSERTASTABLE""(""CLICKS"", ""CREATETIME"") VALUES(500, to_timestamp('0001-01-01 00:00:00.000000','YYYY-MM-DD HH24:MI:SS.FF6'))
|
||||
INTO ""TOPIC_INSERTASTABLE""(""CLICKS"", ""CREATETIME"") VALUES(600, to_timestamp('0001-01-01 00:00:00.000000','YYYY-MM-DD HH24:MI:SS.FF6'))
|
||||
INTO ""TOPIC_INSERTASTABLE""(""CLICKS"", ""CREATETIME"") VALUES(700, to_timestamp('0001-01-01 00:00:00.000000','YYYY-MM-DD HH24:MI:SS.FF6'))
|
||||
INTO ""TOPIC_INSERTASTABLE""(""CLICKS"", ""CREATETIME"") VALUES(800, to_timestamp('0001-01-01 00:00:00.000000','YYYY-MM-DD HH24:MI:SS.FF6'))
|
||||
INTO ""TOPIC_INSERTASTABLE""(""CLICKS"", ""CREATETIME"") VALUES(900, to_timestamp('0001-01-01 00:00:00.000000','YYYY-MM-DD HH24:MI:SS.FF6'))
|
||||
SELECT 1 FROM DUAL", sql);
|
||||
|
||||
sql = insert.AppendData(items).IgnoreColumns(a => new { a.Clicks, a.CreateTime }).AsTable(a => "Topic_InsertAsTable").ToSql();
|
||||
Assert.Equal(@"INSERT ALL
|
||||
INTO ""TOPIC_INSERTASTABLE""(""TITLE"") VALUES('newTitle0')
|
||||
INTO ""TOPIC_INSERTASTABLE""(""TITLE"") VALUES('newTitle1')
|
||||
INTO ""TOPIC_INSERTASTABLE""(""TITLE"") VALUES('newTitle2')
|
||||
INTO ""TOPIC_INSERTASTABLE""(""TITLE"") VALUES('newTitle3')
|
||||
INTO ""TOPIC_INSERTASTABLE""(""TITLE"") VALUES('newTitle4')
|
||||
INTO ""TOPIC_INSERTASTABLE""(""TITLE"") VALUES('newTitle5')
|
||||
INTO ""TOPIC_INSERTASTABLE""(""TITLE"") VALUES('newTitle6')
|
||||
INTO ""TOPIC_INSERTASTABLE""(""TITLE"") VALUES('newTitle7')
|
||||
INTO ""TOPIC_INSERTASTABLE""(""TITLE"") VALUES('newTitle8')
|
||||
INTO ""TOPIC_INSERTASTABLE""(""TITLE"") VALUES('newTitle9')
|
||||
SELECT 1 FROM DUAL", sql);
|
||||
|
||||
sql = insert.AppendData(items).InsertColumns(a => a.Title).AsTable(a => "Topic_InsertAsTable").ToSql();
|
||||
Assert.Equal(@"INSERT ALL
|
||||
INTO ""TOPIC_INSERTASTABLE""(""TITLE"") VALUES('newTitle0')
|
||||
INTO ""TOPIC_INSERTASTABLE""(""TITLE"") VALUES('newTitle1')
|
||||
INTO ""TOPIC_INSERTASTABLE""(""TITLE"") VALUES('newTitle2')
|
||||
INTO ""TOPIC_INSERTASTABLE""(""TITLE"") VALUES('newTitle3')
|
||||
INTO ""TOPIC_INSERTASTABLE""(""TITLE"") VALUES('newTitle4')
|
||||
INTO ""TOPIC_INSERTASTABLE""(""TITLE"") VALUES('newTitle5')
|
||||
INTO ""TOPIC_INSERTASTABLE""(""TITLE"") VALUES('newTitle6')
|
||||
INTO ""TOPIC_INSERTASTABLE""(""TITLE"") VALUES('newTitle7')
|
||||
INTO ""TOPIC_INSERTASTABLE""(""TITLE"") VALUES('newTitle8')
|
||||
INTO ""TOPIC_INSERTASTABLE""(""TITLE"") VALUES('newTitle9')
|
||||
SELECT 1 FROM DUAL", sql);
|
||||
|
||||
sql = insert.AppendData(items).InsertColumns(a => new { a.Title, a.Clicks }).AsTable(a => "Topic_InsertAsTable").ToSql();
|
||||
Assert.Equal(@"INSERT ALL
|
||||
INTO ""TOPIC_INSERTASTABLE""(""CLICKS"", ""TITLE"") VALUES(0, 'newTitle0')
|
||||
INTO ""TOPIC_INSERTASTABLE""(""CLICKS"", ""TITLE"") VALUES(100, 'newTitle1')
|
||||
INTO ""TOPIC_INSERTASTABLE""(""CLICKS"", ""TITLE"") VALUES(200, 'newTitle2')
|
||||
INTO ""TOPIC_INSERTASTABLE""(""CLICKS"", ""TITLE"") VALUES(300, 'newTitle3')
|
||||
INTO ""TOPIC_INSERTASTABLE""(""CLICKS"", ""TITLE"") VALUES(400, 'newTitle4')
|
||||
INTO ""TOPIC_INSERTASTABLE""(""CLICKS"", ""TITLE"") VALUES(500, 'newTitle5')
|
||||
INTO ""TOPIC_INSERTASTABLE""(""CLICKS"", ""TITLE"") VALUES(600, 'newTitle6')
|
||||
INTO ""TOPIC_INSERTASTABLE""(""CLICKS"", ""TITLE"") VALUES(700, 'newTitle7')
|
||||
INTO ""TOPIC_INSERTASTABLE""(""CLICKS"", ""TITLE"") VALUES(800, 'newTitle8')
|
||||
INTO ""TOPIC_INSERTASTABLE""(""CLICKS"", ""TITLE"") VALUES(900, 'newTitle9')
|
||||
SELECT 1 FROM DUAL", sql);
|
||||
}
|
||||
}
|
||||
}
|
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,142 @@
|
||||
using FreeSql.DataAnnotations;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Xunit;
|
||||
|
||||
namespace FreeSql.Tests.Odbc.Oracle
|
||||
{
|
||||
public class OracleUpdateTest
|
||||
{
|
||||
IUpdate<Topic> update => g.oracle.Update<Topic>();
|
||||
|
||||
[Table(Name = "tb_topic")]
|
||||
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.oracle.Update<Topic>().ToSql());
|
||||
Assert.Equal("UPDATE \"TB_TOPIC\" SET title='test' \r\nWHERE (\"ID\" = 1 OR \"ID\" = 2)", g.oracle.Update<Topic>(new[] { 1, 2 }).SetRaw("title='test'").ToSql());
|
||||
Assert.Equal("UPDATE \"TB_TOPIC\" SET title='test1' \r\nWHERE (\"ID\" = 1)", g.oracle.Update<Topic>(new Topic { Id = 1, Title = "test" }).SetRaw("title='test1'").ToSql());
|
||||
Assert.Equal("UPDATE \"TB_TOPIC\" SET title='test1' \r\nWHERE (\"ID\" = 1 OR \"ID\" = 2)", g.oracle.Update<Topic>(new[] { new Topic { Id = 1, Title = "test" }, new Topic { Id = 2, Title = "test" } }).SetRaw("title='test1'").ToSql());
|
||||
Assert.Equal("UPDATE \"TB_TOPIC\" SET title='test1' \r\nWHERE (\"ID\" = 1)", g.oracle.Update<Topic>(new { id = 1 }).SetRaw("title='test1'").ToSql());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void SetSource()
|
||||
{
|
||||
var sql = update.SetSource(new Topic { Id = 1, Title = "newtitle" }).ToSql().Replace("\r\n", "");
|
||||
Assert.Equal("UPDATE \"TB_TOPIC\" SET \"CLICKS\" = NULL, \"TITLE\" = 'newtitle', \"CREATETIME\" = to_timestamp('0001-01-01 00:00:00.000000','YYYY-MM-DD HH24:MI:SS.FF6') 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 });
|
||||
items[0].Clicks = null;
|
||||
|
||||
sql = update.SetSource(items).ToSql().Replace("\r\n", "");
|
||||
Assert.Equal("UPDATE \"TB_TOPIC\" SET \"CLICKS\" = CASE \"ID\" WHEN 1 THEN NULL WHEN 2 THEN 100 WHEN 3 THEN 200 WHEN 4 THEN 300 WHEN 5 THEN 400 WHEN 6 THEN 500 WHEN 7 THEN 600 WHEN 8 THEN 700 WHEN 9 THEN 800 WHEN 10 THEN 900 END, \"TITLE\" = CASE \"ID\" WHEN 1 THEN 'newtitle0' WHEN 2 THEN 'newtitle1' WHEN 3 THEN 'newtitle2' WHEN 4 THEN 'newtitle3' WHEN 5 THEN 'newtitle4' WHEN 6 THEN 'newtitle5' WHEN 7 THEN 'newtitle6' WHEN 8 THEN 'newtitle7' WHEN 9 THEN 'newtitle8' WHEN 10 THEN 'newtitle9' END, \"CREATETIME\" = CASE \"ID\" WHEN 1 THEN to_timestamp('0001-01-01 00:00:00.000000','YYYY-MM-DD HH24:MI:SS.FF6') WHEN 2 THEN to_timestamp('0001-01-01 00:00:00.000000','YYYY-MM-DD HH24:MI:SS.FF6') WHEN 3 THEN to_timestamp('0001-01-01 00:00:00.000000','YYYY-MM-DD HH24:MI:SS.FF6') WHEN 4 THEN to_timestamp('0001-01-01 00:00:00.000000','YYYY-MM-DD HH24:MI:SS.FF6') WHEN 5 THEN to_timestamp('0001-01-01 00:00:00.000000','YYYY-MM-DD HH24:MI:SS.FF6') WHEN 6 THEN to_timestamp('0001-01-01 00:00:00.000000','YYYY-MM-DD HH24:MI:SS.FF6') WHEN 7 THEN to_timestamp('0001-01-01 00:00:00.000000','YYYY-MM-DD HH24:MI:SS.FF6') WHEN 8 THEN to_timestamp('0001-01-01 00:00:00.000000','YYYY-MM-DD HH24:MI:SS.FF6') WHEN 9 THEN to_timestamp('0001-01-01 00:00:00.000000','YYYY-MM-DD HH24:MI:SS.FF6') WHEN 10 THEN to_timestamp('0001-01-01 00:00:00.000000','YYYY-MM-DD HH24:MI:SS.FF6') END WHERE (\"ID\" IN (1,2,3,4,5,6,7,8,9,10))", sql);
|
||||
|
||||
sql = update.SetSource(items).IgnoreColumns(a => new { a.Clicks, a.CreateTime }).ToSql().Replace("\r\n", "");
|
||||
Assert.Equal("UPDATE \"TB_TOPIC\" SET \"TITLE\" = CASE \"ID\" WHEN 1 THEN 'newtitle0' WHEN 2 THEN 'newtitle1' WHEN 3 THEN 'newtitle2' WHEN 4 THEN 'newtitle3' WHEN 5 THEN 'newtitle4' WHEN 6 THEN 'newtitle5' WHEN 7 THEN 'newtitle6' WHEN 8 THEN 'newtitle7' WHEN 9 THEN 'newtitle8' WHEN 10 THEN 'newtitle9' END WHERE (\"ID\" IN (1,2,3,4,5,6,7,8,9,10))", sql);
|
||||
|
||||
sql = update.SetSource(items).Set(a => a.CreateTime, new DateTime(2020, 1, 1)).ToSql().Replace("\r\n", "");
|
||||
Assert.Equal("UPDATE \"TB_TOPIC\" SET \"CREATETIME\" = to_timestamp('2020-01-01 00:00:00.000000','YYYY-MM-DD HH24:MI:SS.FF6') WHERE (\"ID\" IN (1,2,3,4,5,6,7,8,9,10))", sql);
|
||||
}
|
||||
[Fact]
|
||||
public void IgnoreColumns()
|
||||
{
|
||||
var sql = update.SetSource(new Topic { Id = 1, Title = "newtitle" }).IgnoreColumns(a => new { a.Clicks, a.CreateTime }).ToSql().Replace("\r\n", "");
|
||||
Assert.Equal("UPDATE \"TB_TOPIC\" SET \"TITLE\" = 'newtitle' WHERE (\"ID\" = 1)", sql);
|
||||
}
|
||||
[Fact]
|
||||
public void UpdateColumns()
|
||||
{
|
||||
var sql = update.SetSource(new Topic { Id = 1, Title = "newtitle" }).UpdateColumns(a => a.Title).ToSql().Replace("\r\n", "");
|
||||
Assert.Equal("UPDATE \"TB_TOPIC\" SET \"TITLE\" = 'newtitle' WHERE (\"ID\" = 1)", sql);
|
||||
}
|
||||
[Fact]
|
||||
public void Set()
|
||||
{
|
||||
var sql = update.Where(a => a.Id == 1).Set(a => a.Title, "newtitle").ToSql().Replace("\r\n", "");
|
||||
Assert.Equal("UPDATE \"TB_TOPIC\" SET \"TITLE\" = 'newtitle' WHERE (\"ID\" = 1)", sql);
|
||||
|
||||
sql = update.Where(a => a.Id == 1).Set(a => a.Title, "newtitle").Set(a => a.CreateTime, new DateTime(2020, 1, 1)).ToSql().Replace("\r\n", "");
|
||||
Assert.Equal("UPDATE \"TB_TOPIC\" SET \"TITLE\" = 'newtitle', \"CREATETIME\" = to_timestamp('2020-01-01 00:00:00.000000','YYYY-MM-DD HH24:MI:SS.FF6') WHERE (\"ID\" = 1)", sql);
|
||||
|
||||
sql = update.Set(a => a.Clicks * 10 / 1).Where(a => a.Id == 1).ToSql().Replace("\r\n", "");
|
||||
Assert.Equal("UPDATE \"TB_TOPIC\" SET \"CLICKS\" = trunc(nvl(\"CLICKS\", 0) * 10 / 1) WHERE (\"ID\" = 1)", sql);
|
||||
|
||||
sql = update.Set(a => a.Id - 10).Where(a => a.Id == 1).ToSql().Replace("\r\n", "");
|
||||
Assert.Equal("UPDATE \"TB_TOPIC\" SET \"ID\" = (\"ID\" - 10) WHERE (\"ID\" = 1)", sql);
|
||||
|
||||
int incrv = 10;
|
||||
sql = update.Set(a => a.Clicks * incrv / 1).Where(a => a.Id == 1).ToSql().Replace("\r\n", "");
|
||||
Assert.Equal("UPDATE \"TB_TOPIC\" SET \"CLICKS\" = trunc(nvl(\"CLICKS\", 0) * 10 / 1) WHERE (\"ID\" = 1)", sql);
|
||||
|
||||
sql = update.Set(a => a.Id - incrv).Where(a => a.Id == 1).ToSql().Replace("\r\n", "");
|
||||
Assert.Equal("UPDATE \"TB_TOPIC\" SET \"ID\" = (\"ID\" - 10) WHERE (\"ID\" = 1)", sql);
|
||||
|
||||
sql = update.Set(a => a.Clicks == a.Clicks * 10 / 1).Where(a => a.Id == 1).ToSql().Replace("\r\n", "");
|
||||
Assert.Equal("UPDATE \"TB_TOPIC\" SET \"CLICKS\" = trunc(\"CLICKS\" * 10 / 1) WHERE (\"ID\" = 1)", sql);
|
||||
|
||||
sql = update.Set(a => a.Id == 10).Where(a => a.Id == 1).ToSql().Replace("\r\n", "");
|
||||
Assert.Equal("UPDATE \"TB_TOPIC\" SET \"ID\" = 10 WHERE (\"ID\" = 1)", sql);
|
||||
}
|
||||
[Fact]
|
||||
public void SetRaw()
|
||||
{
|
||||
var sql = update.Where(a => a.Id == 1).SetRaw("clicks = clicks + ?", new { incrClick = 1 }).ToSql().Replace("\r\n", "");
|
||||
Assert.Equal("UPDATE \"TB_TOPIC\" SET clicks = clicks + ? WHERE (\"ID\" = 1)", sql);
|
||||
}
|
||||
[Fact]
|
||||
public void Where()
|
||||
{
|
||||
var sql = update.Where(a => a.Id == 1).SetRaw("title='newtitle'").ToSql().Replace("\r\n", "");
|
||||
Assert.Equal("UPDATE \"TB_TOPIC\" SET title='newtitle' WHERE (\"ID\" = 1)", sql);
|
||||
|
||||
sql = update.Where("id = ?", new { id = 1 }).SetRaw("title='newtitle'").ToSql().Replace("\r\n", "");
|
||||
Assert.Equal("UPDATE \"TB_TOPIC\" SET title='newtitle' WHERE (id = ?)", sql);
|
||||
|
||||
var item = new Topic { Id = 1, Title = "newtitle" };
|
||||
sql = update.Where(item).SetRaw("title='newtitle'").ToSql().Replace("\r\n", "");
|
||||
Assert.Equal("UPDATE \"TB_TOPIC\" SET title='newtitle' 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 = update.Where(items).SetRaw("title='newtitle'").ToSql().Replace("\r\n", "");
|
||||
Assert.Equal("UPDATE \"TB_TOPIC\" SET title='newtitle' WHERE (\"ID\" IN (1,2,3,4,5,6,7,8,9,10))", sql);
|
||||
}
|
||||
[Fact]
|
||||
public void WhereExists()
|
||||
{
|
||||
|
||||
}
|
||||
[Fact]
|
||||
public void ExecuteAffrows()
|
||||
{
|
||||
|
||||
}
|
||||
[Fact]
|
||||
public void ExecuteUpdated()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void AsTable()
|
||||
{
|
||||
Assert.Null(g.oracle.Update<Topic>().ToSql());
|
||||
Assert.Equal("UPDATE \"TB_TOPICASTABLE\" SET title='test' \r\nWHERE (\"ID\" = 1 OR \"ID\" = 2)", g.oracle.Update<Topic>(new[] { 1, 2 }).SetRaw("title='test'").AsTable(a => "tb_topicAsTable").ToSql());
|
||||
Assert.Equal("UPDATE \"TB_TOPICASTABLE\" SET title='test1' \r\nWHERE (\"ID\" = 1)", g.oracle.Update<Topic>(new Topic { Id = 1, Title = "test" }).SetRaw("title='test1'").AsTable(a => "tb_topicAsTable").ToSql());
|
||||
Assert.Equal("UPDATE \"TB_TOPICASTABLE\" SET title='test1' \r\nWHERE (\"ID\" = 1 OR \"ID\" = 2)", g.oracle.Update<Topic>(new[] { new Topic { Id = 1, Title = "test" }, new Topic { Id = 2, Title = "test" } }).SetRaw("title='test1'").AsTable(a => "tb_topicAsTable").ToSql());
|
||||
Assert.Equal("UPDATE \"TB_TOPICASTABLE\" SET title='test1' \r\nWHERE (\"ID\" = 1)", g.oracle.Update<Topic>(new { id = 1 }).SetRaw("title='test1'").AsTable(a => "tb_topicAsTable").ToSql());
|
||||
}
|
||||
}
|
||||
}
|
File diff suppressed because it is too large
Load Diff
1130
FreeSql.Tests/FreeSql.Tests.Provider.Odbc/Oracle/MapType/BoolTest.cs
Normal file
1130
FreeSql.Tests/FreeSql.Tests.Provider.Odbc/Oracle/MapType/BoolTest.cs
Normal file
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,54 @@
|
||||
using FreeSql.DataAnnotations;
|
||||
using System;
|
||||
using System.Numerics;
|
||||
using Xunit;
|
||||
|
||||
namespace FreeSql.Tests.Odbc.OracleMapType
|
||||
{
|
||||
public class DateTimeOffSetTest
|
||||
{
|
||||
class Dtos_dt
|
||||
{
|
||||
public Guid id { get; set; }
|
||||
|
||||
[Column(MapType = typeof(DateTime))]
|
||||
public DateTimeOffset dtos_to_dt { get; set; }
|
||||
[Column(MapType = typeof(DateTime))]
|
||||
public DateTimeOffset? dtofnil_to_dt { get; set; }
|
||||
}
|
||||
[Fact]
|
||||
public void DateTimeToDateTimeOffSet()
|
||||
{
|
||||
//insert
|
||||
var orm = g.oracle;
|
||||
var item = new Dtos_dt { dtos_to_dt = DateTimeOffset.Now, dtofnil_to_dt = DateTimeOffset.Now };
|
||||
Assert.Equal(1, orm.Insert<Dtos_dt>().AppendData(item).ExecuteAffrows());
|
||||
var find = orm.Select<Dtos_dt>().Where(a => a.id == item.id).First();
|
||||
Assert.NotNull(find);
|
||||
Assert.Equal(item.id, find.id);
|
||||
Assert.Equal(item.dtos_to_dt.ToString("g"), find.dtos_to_dt.ToString("g"));
|
||||
Assert.Equal(item.dtofnil_to_dt.Value.ToString("g"), find.dtofnil_to_dt.Value.ToString("g"));
|
||||
|
||||
//update all
|
||||
item.dtos_to_dt = DateTimeOffset.Now;
|
||||
Assert.Equal(1, orm.Update<Dtos_dt>().SetSource(item).ExecuteAffrows());
|
||||
find = orm.Select<Dtos_dt>().Where(a => a.id == item.id).First();
|
||||
Assert.NotNull(find);
|
||||
Assert.Equal(item.id, find.id);
|
||||
Assert.Equal(item.dtos_to_dt.ToString("g"), find.dtos_to_dt.ToString("g"));
|
||||
Assert.Equal(item.dtofnil_to_dt.Value.ToString("g"), find.dtofnil_to_dt.Value.ToString("g"));
|
||||
|
||||
//update set
|
||||
Assert.Equal(1, orm.Update<Dtos_dt>().Where(a => a.id == item.id).Set(a => a.dtos_to_dt, item.dtos_to_dt = DateTimeOffset.Now).ExecuteAffrows());
|
||||
find = orm.Select<Dtos_dt>().Where(a => a.id == item.id).First();
|
||||
Assert.NotNull(find);
|
||||
Assert.Equal(item.dtos_to_dt.ToString("g"), find.dtos_to_dt.ToString("g"));
|
||||
Assert.Equal(item.dtofnil_to_dt.Value.ToString("g"), find.dtofnil_to_dt.Value.ToString("g"));
|
||||
|
||||
//delete
|
||||
Assert.Equal(1, orm.Delete<Dtos_dt>().Where(a => a.id == item.id).ExecuteAffrows());
|
||||
Assert.Null(orm.Select<Dtos_dt>().Where(a => a.id == item.id).First());
|
||||
}
|
||||
|
||||
}
|
||||
}
|
@ -0,0 +1,261 @@
|
||||
using FreeSql.DataAnnotations;
|
||||
using System;
|
||||
using System.Numerics;
|
||||
using Xunit;
|
||||
|
||||
namespace FreeSql.Tests.Odbc.OracleMapType
|
||||
{
|
||||
public class EnumTest
|
||||
{
|
||||
class EnumTestMap
|
||||
{
|
||||
public Guid id { get; set; }
|
||||
|
||||
[Column(MapType = typeof(string))]
|
||||
public ToStringMapEnum enum_to_string { get; set; }
|
||||
[Column(MapType = typeof(string))]
|
||||
public ToStringMapEnum? enumnullable_to_string { get; set; }
|
||||
|
||||
[Column(MapType = typeof(int))]
|
||||
public ToStringMapEnum enum_to_int { get; set; }
|
||||
[Column(MapType = typeof(int?))]
|
||||
public ToStringMapEnum? enumnullable_to_int { get; set; }
|
||||
}
|
||||
public enum ToStringMapEnum { 中国人, abc, 香港 }
|
||||
[Fact]
|
||||
public void EnumToString()
|
||||
{
|
||||
//insert
|
||||
var orm = g.oracle;
|
||||
var item = new EnumTestMap { };
|
||||
Assert.Equal(1, orm.Insert<EnumTestMap>().AppendData(item).ExecuteAffrows());
|
||||
var find = orm.Select<EnumTestMap>().Where(a => a.id == item.id && a.enum_to_string == ToStringMapEnum.中国人).First();
|
||||
Assert.NotNull(find);
|
||||
Assert.Equal(item.id, find.id);
|
||||
Assert.Equal(item.enum_to_string, find.enum_to_string);
|
||||
Assert.Equal(ToStringMapEnum.中国人, find.enum_to_string);
|
||||
|
||||
item = new EnumTestMap { enum_to_string = ToStringMapEnum.abc };
|
||||
Assert.Equal(1, orm.Insert<EnumTestMap>().AppendData(item).ExecuteAffrows());
|
||||
find = orm.Select<EnumTestMap>().Where(a => a.id == item.id && a.enum_to_string == ToStringMapEnum.abc).First();
|
||||
Assert.NotNull(find);
|
||||
Assert.Equal(item.id, find.id);
|
||||
Assert.Equal(item.enum_to_string, find.enum_to_string);
|
||||
Assert.Equal(ToStringMapEnum.abc, find.enum_to_string);
|
||||
|
||||
//update all
|
||||
item.enum_to_string = ToStringMapEnum.香港;
|
||||
Assert.Equal(1, orm.Update<EnumTestMap>().SetSource(item).ExecuteAffrows());
|
||||
find = orm.Select<EnumTestMap>().Where(a => a.id == item.id && a.enum_to_string == ToStringMapEnum.香港).First();
|
||||
Assert.NotNull(find);
|
||||
Assert.Equal(item.id, find.id);
|
||||
Assert.Equal(item.enum_to_string, find.enum_to_string);
|
||||
Assert.Equal(ToStringMapEnum.香港, find.enum_to_string);
|
||||
|
||||
item.enum_to_string = ToStringMapEnum.中国人;
|
||||
Assert.Equal(1, orm.Update<EnumTestMap>().SetSource(item).ExecuteAffrows());
|
||||
find = orm.Select<EnumTestMap>().Where(a => a.id == item.id && a.enum_to_string == ToStringMapEnum.中国人).First();
|
||||
Assert.NotNull(find);
|
||||
Assert.Equal(item.id, find.id);
|
||||
Assert.Equal(item.enum_to_string, find.enum_to_string);
|
||||
Assert.Equal(ToStringMapEnum.中国人, find.enum_to_string);
|
||||
|
||||
//update set
|
||||
Assert.Equal(1, orm.Update<EnumTestMap>().Where(a => a.id == item.id).Set(a => a.enum_to_string, ToStringMapEnum.香港).ExecuteAffrows());
|
||||
find = orm.Select<EnumTestMap>().Where(a => a.id == item.id && a.enum_to_string == ToStringMapEnum.香港).First();
|
||||
Assert.NotNull(find);
|
||||
Assert.Equal(item.id, find.id);
|
||||
Assert.Equal(ToStringMapEnum.香港, find.enum_to_string);
|
||||
|
||||
Assert.Equal(1, orm.Update<EnumTestMap>().Where(a => a.id == item.id).Set(a => a.enum_to_string, ToStringMapEnum.abc).ExecuteAffrows());
|
||||
find = orm.Select<EnumTestMap>().Where(a => a.id == item.id && a.enum_to_string == ToStringMapEnum.abc).First();
|
||||
Assert.NotNull(find);
|
||||
Assert.Equal(item.id, find.id);
|
||||
Assert.Equal(ToStringMapEnum.abc, find.enum_to_string);
|
||||
|
||||
//delete
|
||||
Assert.Equal(0, orm.Delete<EnumTestMap>().Where(a => a.id == item.id && a.enum_to_string == ToStringMapEnum.中国人).ExecuteAffrows());
|
||||
Assert.Equal(0, orm.Delete<EnumTestMap>().Where(a => a.id == item.id && a.enum_to_string == ToStringMapEnum.香港).ExecuteAffrows());
|
||||
Assert.Equal(1, orm.Delete<EnumTestMap>().Where(a => a.id == item.id && a.enum_to_string == ToStringMapEnum.abc).ExecuteAffrows());
|
||||
Assert.Null(orm.Select<EnumTestMap>().Where(a => a.id == item.id).First());
|
||||
}
|
||||
[Fact]
|
||||
public void EnumNullableToString()
|
||||
{
|
||||
//insert
|
||||
var orm = g.oracle;
|
||||
var item = new EnumTestMap { };
|
||||
Assert.Equal(1, orm.Insert<EnumTestMap>().AppendData(item).ExecuteAffrows());
|
||||
var find = orm.Select<EnumTestMap>().Where(a => a.id == item.id && a.enumnullable_to_string == null).First();
|
||||
Assert.NotNull(find);
|
||||
Assert.Equal(item.id, find.id);
|
||||
Assert.Equal(item.enumnullable_to_string, find.enumnullable_to_string);
|
||||
Assert.Null(find.enumnullable_to_string);
|
||||
|
||||
item = new EnumTestMap { enumnullable_to_string = ToStringMapEnum.中国人 };
|
||||
Assert.Equal(1, orm.Insert<EnumTestMap>().AppendData(item).ExecuteAffrows());
|
||||
find = orm.Select<EnumTestMap>().Where(a => a.id == item.id && a.enumnullable_to_string == ToStringMapEnum.中国人).First();
|
||||
Assert.NotNull(find);
|
||||
Assert.Equal(item.id, find.id);
|
||||
Assert.Equal(item.enumnullable_to_string, find.enumnullable_to_string);
|
||||
Assert.Equal(ToStringMapEnum.中国人, find.enumnullable_to_string);
|
||||
|
||||
//update all
|
||||
item.enumnullable_to_string = ToStringMapEnum.香港;
|
||||
Assert.Equal(1, orm.Update<EnumTestMap>().SetSource(item).ExecuteAffrows());
|
||||
find = orm.Select<EnumTestMap>().Where(a => a.id == item.id && a.enumnullable_to_string == ToStringMapEnum.香港).First();
|
||||
Assert.NotNull(find);
|
||||
Assert.Equal(item.id, find.id);
|
||||
Assert.Equal(item.enumnullable_to_string, find.enumnullable_to_string);
|
||||
Assert.Equal(ToStringMapEnum.香港, find.enumnullable_to_string);
|
||||
|
||||
item.enumnullable_to_string = null;
|
||||
Assert.Equal(1, orm.Update<EnumTestMap>().SetSource(item).ExecuteAffrows());
|
||||
Assert.Null(orm.Select<EnumTestMap>().Where(a => a.id == item.id && a.enumnullable_to_string == ToStringMapEnum.香港).First());
|
||||
find = orm.Select<EnumTestMap>().Where(a => a.id == item.id && a.enumnullable_to_string == null).First();
|
||||
Assert.NotNull(find);
|
||||
Assert.Equal(item.id, find.id);
|
||||
Assert.Equal(item.enumnullable_to_string, find.enumnullable_to_string);
|
||||
Assert.Null(find.enumnullable_to_string);
|
||||
|
||||
//update set
|
||||
Assert.Equal(1, orm.Update<EnumTestMap>().Where(a => a.id == item.id).Set(a => a.enumnullable_to_string, ToStringMapEnum.abc).ExecuteAffrows());
|
||||
find = orm.Select<EnumTestMap>().Where(a => a.id == item.id && a.enumnullable_to_string == ToStringMapEnum.abc).First();
|
||||
Assert.NotNull(find);
|
||||
Assert.Equal(item.id, find.id);
|
||||
Assert.Equal(ToStringMapEnum.abc, find.enumnullable_to_string);
|
||||
|
||||
|
||||
Assert.Equal(1, orm.Update<EnumTestMap>().Where(a => a.id == item.id).Set(a => a.enumnullable_to_string, null).ExecuteAffrows());
|
||||
Assert.Null(orm.Select<EnumTestMap>().Where(a => a.id == item.id && a.enumnullable_to_string == ToStringMapEnum.abc).First());
|
||||
find = orm.Select<EnumTestMap>().Where(a => a.id == item.id && a.enumnullable_to_string == null).First();
|
||||
Assert.NotNull(find);
|
||||
Assert.Equal(item.id, find.id);
|
||||
Assert.Null(find.enumnullable_to_string);
|
||||
|
||||
//delete
|
||||
Assert.Equal(0, orm.Delete<EnumTestMap>().Where(a => a.id == item.id && a.enumnullable_to_string == ToStringMapEnum.中国人).ExecuteAffrows());
|
||||
Assert.Equal(0, orm.Delete<EnumTestMap>().Where(a => a.id == item.id && a.enumnullable_to_string == ToStringMapEnum.香港).ExecuteAffrows());
|
||||
Assert.Equal(1, orm.Delete<EnumTestMap>().Where(a => a.id == item.id && a.enumnullable_to_string == null).ExecuteAffrows());
|
||||
Assert.Null(orm.Select<EnumTestMap>().Where(a => a.id == item.id).First());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void EnumToInt()
|
||||
{
|
||||
//insert
|
||||
var orm = g.oracle;
|
||||
var item = new EnumTestMap { };
|
||||
Assert.Equal(1, orm.Insert<EnumTestMap>().AppendData(item).ExecuteAffrows());
|
||||
var find = orm.Select<EnumTestMap>().Where(a => a.id == item.id && a.enum_to_int == ToStringMapEnum.中国人).First();
|
||||
Assert.NotNull(find);
|
||||
Assert.Equal(item.id, find.id);
|
||||
Assert.Equal(item.enum_to_int, find.enum_to_int);
|
||||
Assert.Equal(ToStringMapEnum.中国人, find.enum_to_int);
|
||||
|
||||
item = new EnumTestMap { enum_to_int = ToStringMapEnum.abc };
|
||||
Assert.Equal(1, orm.Insert<EnumTestMap>().AppendData(item).ExecuteAffrows());
|
||||
find = orm.Select<EnumTestMap>().Where(a => a.id == item.id && a.enum_to_int == ToStringMapEnum.abc).First();
|
||||
Assert.NotNull(find);
|
||||
Assert.Equal(item.id, find.id);
|
||||
Assert.Equal(item.enum_to_int, find.enum_to_int);
|
||||
Assert.Equal(ToStringMapEnum.abc, find.enum_to_int);
|
||||
|
||||
//update all
|
||||
item.enum_to_int = ToStringMapEnum.香港;
|
||||
Assert.Equal(1, orm.Update<EnumTestMap>().SetSource(item).ExecuteAffrows());
|
||||
find = orm.Select<EnumTestMap>().Where(a => a.id == item.id && a.enum_to_int == ToStringMapEnum.香港).First();
|
||||
Assert.NotNull(find);
|
||||
Assert.Equal(item.id, find.id);
|
||||
Assert.Equal(item.enum_to_int, find.enum_to_int);
|
||||
Assert.Equal(ToStringMapEnum.香港, find.enum_to_int);
|
||||
|
||||
item.enum_to_int = ToStringMapEnum.中国人;
|
||||
Assert.Equal(1, orm.Update<EnumTestMap>().SetSource(item).ExecuteAffrows());
|
||||
find = orm.Select<EnumTestMap>().Where(a => a.id == item.id && a.enum_to_int == ToStringMapEnum.中国人).First();
|
||||
Assert.NotNull(find);
|
||||
Assert.Equal(item.id, find.id);
|
||||
Assert.Equal(item.enum_to_int, find.enum_to_int);
|
||||
Assert.Equal(ToStringMapEnum.中国人, find.enum_to_int);
|
||||
|
||||
//update set
|
||||
Assert.Equal(1, orm.Update<EnumTestMap>().Where(a => a.id == item.id).Set(a => a.enum_to_int, ToStringMapEnum.香港).ExecuteAffrows());
|
||||
find = orm.Select<EnumTestMap>().Where(a => a.id == item.id && a.enum_to_int == ToStringMapEnum.香港).First();
|
||||
Assert.NotNull(find);
|
||||
Assert.Equal(item.id, find.id);
|
||||
Assert.Equal(ToStringMapEnum.香港, find.enum_to_int);
|
||||
|
||||
Assert.Equal(1, orm.Update<EnumTestMap>().Where(a => a.id == item.id).Set(a => a.enum_to_int, ToStringMapEnum.abc).ExecuteAffrows());
|
||||
find = orm.Select<EnumTestMap>().Where(a => a.id == item.id && a.enum_to_int == ToStringMapEnum.abc).First();
|
||||
Assert.NotNull(find);
|
||||
Assert.Equal(item.id, find.id);
|
||||
Assert.Equal(ToStringMapEnum.abc, find.enum_to_int);
|
||||
|
||||
//delete
|
||||
Assert.Equal(0, orm.Delete<EnumTestMap>().Where(a => a.id == item.id && a.enum_to_int == ToStringMapEnum.中国人).ExecuteAffrows());
|
||||
Assert.Equal(0, orm.Delete<EnumTestMap>().Where(a => a.id == item.id && a.enum_to_int == ToStringMapEnum.香港).ExecuteAffrows());
|
||||
Assert.Equal(1, orm.Delete<EnumTestMap>().Where(a => a.id == item.id && a.enum_to_int == ToStringMapEnum.abc).ExecuteAffrows());
|
||||
Assert.Null(orm.Select<EnumTestMap>().Where(a => a.id == item.id).First());
|
||||
}
|
||||
[Fact]
|
||||
public void EnumNullableToInt()
|
||||
{
|
||||
//insert
|
||||
var orm = g.oracle;
|
||||
var item = new EnumTestMap { };
|
||||
Assert.Equal(1, orm.Insert<EnumTestMap>().AppendData(item).ExecuteAffrows());
|
||||
var find = orm.Select<EnumTestMap>().Where(a => a.id == item.id && a.enumnullable_to_int == null).First();
|
||||
Assert.NotNull(find);
|
||||
Assert.Equal(item.id, find.id);
|
||||
Assert.Equal(item.enumnullable_to_int, find.enumnullable_to_int);
|
||||
Assert.Null(find.enumnullable_to_int);
|
||||
|
||||
item = new EnumTestMap { enumnullable_to_int = ToStringMapEnum.中国人 };
|
||||
Assert.Equal(1, orm.Insert<EnumTestMap>().AppendData(item).ExecuteAffrows());
|
||||
find = orm.Select<EnumTestMap>().Where(a => a.id == item.id && a.enumnullable_to_int == ToStringMapEnum.中国人).First();
|
||||
Assert.NotNull(find);
|
||||
Assert.Equal(item.id, find.id);
|
||||
Assert.Equal(item.enumnullable_to_int, find.enumnullable_to_int);
|
||||
Assert.Equal(ToStringMapEnum.中国人, find.enumnullable_to_int);
|
||||
|
||||
//update all
|
||||
item.enumnullable_to_int = ToStringMapEnum.香港;
|
||||
Assert.Equal(1, orm.Update<EnumTestMap>().SetSource(item).ExecuteAffrows());
|
||||
find = orm.Select<EnumTestMap>().Where(a => a.id == item.id && a.enumnullable_to_int == ToStringMapEnum.香港).First();
|
||||
Assert.NotNull(find);
|
||||
Assert.Equal(item.id, find.id);
|
||||
Assert.Equal(item.enumnullable_to_int, find.enumnullable_to_int);
|
||||
Assert.Equal(ToStringMapEnum.香港, find.enumnullable_to_int);
|
||||
|
||||
item.enumnullable_to_int = null;
|
||||
Assert.Equal(1, orm.Update<EnumTestMap>().SetSource(item).ExecuteAffrows());
|
||||
Assert.Null(orm.Select<EnumTestMap>().Where(a => a.id == item.id && a.enumnullable_to_int == ToStringMapEnum.香港).First());
|
||||
find = orm.Select<EnumTestMap>().Where(a => a.id == item.id && a.enumnullable_to_int == null).First();
|
||||
Assert.NotNull(find);
|
||||
Assert.Equal(item.id, find.id);
|
||||
Assert.Equal(item.enumnullable_to_int, find.enumnullable_to_int);
|
||||
Assert.Null(find.enumnullable_to_int);
|
||||
|
||||
//update set
|
||||
Assert.Equal(1, orm.Update<EnumTestMap>().Where(a => a.id == item.id).Set(a => a.enumnullable_to_int, ToStringMapEnum.abc).ExecuteAffrows());
|
||||
find = orm.Select<EnumTestMap>().Where(a => a.id == item.id && a.enumnullable_to_int == ToStringMapEnum.abc).First();
|
||||
Assert.NotNull(find);
|
||||
Assert.Equal(item.id, find.id);
|
||||
Assert.Equal(ToStringMapEnum.abc, find.enumnullable_to_int);
|
||||
|
||||
|
||||
Assert.Equal(1, orm.Update<EnumTestMap>().Where(a => a.id == item.id).Set(a => a.enumnullable_to_int, null).ExecuteAffrows());
|
||||
Assert.Null(orm.Select<EnumTestMap>().Where(a => a.id == item.id && a.enumnullable_to_int == ToStringMapEnum.abc).First());
|
||||
find = orm.Select<EnumTestMap>().Where(a => a.id == item.id && a.enumnullable_to_int == null).First();
|
||||
Assert.NotNull(find);
|
||||
Assert.Equal(item.id, find.id);
|
||||
Assert.Null(find.enumnullable_to_int);
|
||||
|
||||
//delete
|
||||
Assert.Equal(0, orm.Delete<EnumTestMap>().Where(a => a.id == item.id && a.enumnullable_to_int == ToStringMapEnum.中国人).ExecuteAffrows());
|
||||
Assert.Equal(0, orm.Delete<EnumTestMap>().Where(a => a.id == item.id && a.enumnullable_to_int == ToStringMapEnum.香港).ExecuteAffrows());
|
||||
Assert.Equal(1, orm.Delete<EnumTestMap>().Where(a => a.id == item.id && a.enumnullable_to_int == null).ExecuteAffrows());
|
||||
Assert.Null(orm.Select<EnumTestMap>().Where(a => a.id == item.id).First());
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,570 @@
|
||||
using FreeSql.DataAnnotations;
|
||||
using System;
|
||||
using System.Numerics;
|
||||
using Xunit;
|
||||
|
||||
namespace FreeSql.Tests.Odbc.OracleMapType
|
||||
{
|
||||
public class ToStringTest
|
||||
{
|
||||
class ToStringMap
|
||||
{
|
||||
public Guid id { get; set; }
|
||||
|
||||
[Column(MapType = typeof(string))]
|
||||
public TimeSpan timespan_to_string { get; set; }
|
||||
[Column(MapType = typeof(string))]
|
||||
public TimeSpan? timespannullable_to_string { get; set; }
|
||||
|
||||
[Column(MapType = typeof(string))]
|
||||
public DateTime datetime_to_string { get; set; }
|
||||
[Column(MapType = typeof(string))]
|
||||
public DateTime? datetimenullable_to_string { get; set; }
|
||||
|
||||
[Column(MapType = typeof(string))]
|
||||
public Guid guid_to_string { get; set; }
|
||||
[Column(MapType = typeof(string))]
|
||||
public Guid? guidnullable_to_string { get; set; }
|
||||
|
||||
[Column(MapType = typeof(string))]
|
||||
public ToStringMapEnum enum_to_string { get; set; }
|
||||
[Column(MapType = typeof(string))]
|
||||
public ToStringMapEnum? enumnullable_to_string { get; set; }
|
||||
|
||||
[Column(MapType = typeof(string))]
|
||||
public BigInteger biginteger_to_string { get; set; }
|
||||
[Column(MapType = typeof(string))]
|
||||
public BigInteger? bigintegernullable_to_string { get; set; }
|
||||
}
|
||||
public enum ToStringMapEnum { 中国人, abc, 香港 }
|
||||
[Fact]
|
||||
public void Enum1()
|
||||
{
|
||||
//insert
|
||||
var orm = g.oracle;
|
||||
var item = new ToStringMap { };
|
||||
Assert.Equal(1, orm.Insert<ToStringMap>().AppendData(item).ExecuteAffrows());
|
||||
var find = orm.Select<ToStringMap>().Where(a => a.id == item.id && a.enum_to_string == ToStringMapEnum.中国人).First();
|
||||
Assert.NotNull(find);
|
||||
Assert.Equal(item.id, find.id);
|
||||
Assert.Equal(item.enum_to_string, find.enum_to_string);
|
||||
Assert.Equal(ToStringMapEnum.中国人, find.enum_to_string);
|
||||
|
||||
item = new ToStringMap { enum_to_string = ToStringMapEnum.abc };
|
||||
Assert.Equal(1, orm.Insert<ToStringMap>().AppendData(item).ExecuteAffrows());
|
||||
find = orm.Select<ToStringMap>().Where(a => a.id == item.id && a.enum_to_string == ToStringMapEnum.abc).First();
|
||||
Assert.NotNull(find);
|
||||
Assert.Equal(item.id, find.id);
|
||||
Assert.Equal(item.enum_to_string, find.enum_to_string);
|
||||
Assert.Equal(ToStringMapEnum.abc, find.enum_to_string);
|
||||
|
||||
//update all
|
||||
item.enum_to_string = ToStringMapEnum.香港;
|
||||
Assert.Equal(1, orm.Update<ToStringMap>().SetSource(item).ExecuteAffrows());
|
||||
find = orm.Select<ToStringMap>().Where(a => a.id == item.id && a.enum_to_string == ToStringMapEnum.香港).First();
|
||||
Assert.NotNull(find);
|
||||
Assert.Equal(item.id, find.id);
|
||||
Assert.Equal(item.enum_to_string, find.enum_to_string);
|
||||
Assert.Equal(ToStringMapEnum.香港, find.enum_to_string);
|
||||
|
||||
item.enum_to_string = ToStringMapEnum.中国人;
|
||||
Assert.Equal(1, orm.Update<ToStringMap>().SetSource(item).ExecuteAffrows());
|
||||
find = orm.Select<ToStringMap>().Where(a => a.id == item.id && a.enum_to_string == ToStringMapEnum.中国人).First();
|
||||
Assert.NotNull(find);
|
||||
Assert.Equal(item.id, find.id);
|
||||
Assert.Equal(item.enum_to_string, find.enum_to_string);
|
||||
Assert.Equal(ToStringMapEnum.中国人, find.enum_to_string);
|
||||
|
||||
//update set
|
||||
Assert.Equal(1, orm.Update<ToStringMap>().Where(a => a.id == item.id).Set(a => a.enum_to_string, ToStringMapEnum.香港).ExecuteAffrows());
|
||||
find = orm.Select<ToStringMap>().Where(a => a.id == item.id && a.enum_to_string == ToStringMapEnum.香港).First();
|
||||
Assert.NotNull(find);
|
||||
Assert.Equal(item.id, find.id);
|
||||
Assert.Equal(ToStringMapEnum.香港, find.enum_to_string);
|
||||
|
||||
Assert.Equal(1, orm.Update<ToStringMap>().Where(a => a.id == item.id).Set(a => a.enum_to_string, ToStringMapEnum.abc).ExecuteAffrows());
|
||||
find = orm.Select<ToStringMap>().Where(a => a.id == item.id && a.enum_to_string == ToStringMapEnum.abc).First();
|
||||
Assert.NotNull(find);
|
||||
Assert.Equal(item.id, find.id);
|
||||
Assert.Equal(ToStringMapEnum.abc, find.enum_to_string);
|
||||
|
||||
//delete
|
||||
Assert.Equal(0, orm.Delete<ToStringMap>().Where(a => a.id == item.id && a.enum_to_string == ToStringMapEnum.中国人).ExecuteAffrows());
|
||||
Assert.Equal(0, orm.Delete<ToStringMap>().Where(a => a.id == item.id && a.enum_to_string == ToStringMapEnum.香港).ExecuteAffrows());
|
||||
Assert.Equal(1, orm.Delete<ToStringMap>().Where(a => a.id == item.id && a.enum_to_string == ToStringMapEnum.abc).ExecuteAffrows());
|
||||
Assert.Null(orm.Select<ToStringMap>().Where(a => a.id == item.id).First());
|
||||
}
|
||||
[Fact]
|
||||
public void EnumNullable()
|
||||
{
|
||||
//insert
|
||||
var orm = g.oracle;
|
||||
var item = new ToStringMap { };
|
||||
Assert.Equal(1, orm.Insert<ToStringMap>().AppendData(item).ExecuteAffrows());
|
||||
var find = orm.Select<ToStringMap>().Where(a => a.id == item.id && a.enumnullable_to_string == null).First();
|
||||
Assert.NotNull(find);
|
||||
Assert.Equal(item.id, find.id);
|
||||
Assert.Equal(item.enumnullable_to_string, find.enumnullable_to_string);
|
||||
Assert.Null(find.enumnullable_to_string);
|
||||
|
||||
item = new ToStringMap { enumnullable_to_string = ToStringMapEnum.中国人 };
|
||||
Assert.Equal(1, orm.Insert<ToStringMap>().AppendData(item).ExecuteAffrows());
|
||||
find = orm.Select<ToStringMap>().Where(a => a.id == item.id && a.enumnullable_to_string == ToStringMapEnum.中国人).First();
|
||||
Assert.NotNull(find);
|
||||
Assert.Equal(item.id, find.id);
|
||||
Assert.Equal(item.enumnullable_to_string, find.enumnullable_to_string);
|
||||
Assert.Equal(ToStringMapEnum.中国人, find.enumnullable_to_string);
|
||||
|
||||
//update all
|
||||
item.enumnullable_to_string = ToStringMapEnum.香港;
|
||||
Assert.Equal(1, orm.Update<ToStringMap>().SetSource(item).ExecuteAffrows());
|
||||
find = orm.Select<ToStringMap>().Where(a => a.id == item.id && a.enumnullable_to_string == ToStringMapEnum.香港).First();
|
||||
Assert.NotNull(find);
|
||||
Assert.Equal(item.id, find.id);
|
||||
Assert.Equal(item.enumnullable_to_string, find.enumnullable_to_string);
|
||||
Assert.Equal(ToStringMapEnum.香港, find.enumnullable_to_string);
|
||||
|
||||
item.enumnullable_to_string = null;
|
||||
Assert.Equal(1, orm.Update<ToStringMap>().SetSource(item).ExecuteAffrows());
|
||||
Assert.Null(orm.Select<ToStringMap>().Where(a => a.id == item.id && a.enumnullable_to_string == ToStringMapEnum.香港).First());
|
||||
find = orm.Select<ToStringMap>().Where(a => a.id == item.id && a.enumnullable_to_string == null).First();
|
||||
Assert.NotNull(find);
|
||||
Assert.Equal(item.id, find.id);
|
||||
Assert.Equal(item.enumnullable_to_string, find.enumnullable_to_string);
|
||||
Assert.Null(find.enumnullable_to_string);
|
||||
|
||||
//update set
|
||||
Assert.Equal(1, orm.Update<ToStringMap>().Where(a => a.id == item.id).Set(a => a.enumnullable_to_string, ToStringMapEnum.abc).ExecuteAffrows());
|
||||
find = orm.Select<ToStringMap>().Where(a => a.id == item.id && a.enumnullable_to_string == ToStringMapEnum.abc).First();
|
||||
Assert.NotNull(find);
|
||||
Assert.Equal(item.id, find.id);
|
||||
Assert.Equal(ToStringMapEnum.abc, find.enumnullable_to_string);
|
||||
|
||||
|
||||
Assert.Equal(1, orm.Update<ToStringMap>().Where(a => a.id == item.id).Set(a => a.enumnullable_to_string, null).ExecuteAffrows());
|
||||
Assert.Null(orm.Select<ToStringMap>().Where(a => a.id == item.id && a.enumnullable_to_string == ToStringMapEnum.abc).First());
|
||||
find = orm.Select<ToStringMap>().Where(a => a.id == item.id && a.enumnullable_to_string == null).First();
|
||||
Assert.NotNull(find);
|
||||
Assert.Equal(item.id, find.id);
|
||||
Assert.Null(find.enumnullable_to_string);
|
||||
|
||||
//delete
|
||||
Assert.Equal(0, orm.Delete<ToStringMap>().Where(a => a.id == item.id && a.enumnullable_to_string == ToStringMapEnum.中国人).ExecuteAffrows());
|
||||
Assert.Equal(0, orm.Delete<ToStringMap>().Where(a => a.id == item.id && a.enumnullable_to_string == ToStringMapEnum.香港).ExecuteAffrows());
|
||||
Assert.Equal(1, orm.Delete<ToStringMap>().Where(a => a.id == item.id && a.enumnullable_to_string == null).ExecuteAffrows());
|
||||
Assert.Null(orm.Select<ToStringMap>().Where(a => a.id == item.id).First());
|
||||
}
|
||||
[Fact]
|
||||
public void BigInteger1()
|
||||
{
|
||||
//insert
|
||||
var orm = g.oracle;
|
||||
var item = new ToStringMap { };
|
||||
Assert.Equal(1, orm.Insert<ToStringMap>().AppendData(item).ExecuteAffrows());
|
||||
var find = orm.Select<ToStringMap>().Where(a => a.id == item.id && a.biginteger_to_string == 0).First();
|
||||
Assert.NotNull(find);
|
||||
Assert.Equal(item.id, find.id);
|
||||
Assert.Equal(item.biginteger_to_string, find.biginteger_to_string);
|
||||
Assert.Equal(0, find.biginteger_to_string);
|
||||
|
||||
item = new ToStringMap { biginteger_to_string = 100 };
|
||||
Assert.Equal(1, orm.Insert<ToStringMap>().AppendData(item).ExecuteAffrows());
|
||||
find = orm.Select<ToStringMap>().Where(a => a.id == item.id && a.biginteger_to_string == 100).First();
|
||||
Assert.NotNull(find);
|
||||
Assert.Equal(item.id, find.id);
|
||||
Assert.Equal(item.biginteger_to_string, find.biginteger_to_string);
|
||||
Assert.Equal(100, find.biginteger_to_string);
|
||||
|
||||
//update all
|
||||
item.biginteger_to_string = 200;
|
||||
Assert.Equal(1, orm.Update<ToStringMap>().SetSource(item).ExecuteAffrows());
|
||||
find = orm.Select<ToStringMap>().Where(a => a.id == item.id && a.biginteger_to_string == 200).First();
|
||||
Assert.NotNull(find);
|
||||
Assert.Equal(item.id, find.id);
|
||||
Assert.Equal(item.biginteger_to_string, find.biginteger_to_string);
|
||||
Assert.Equal(200, find.biginteger_to_string);
|
||||
|
||||
item.biginteger_to_string = 205;
|
||||
Assert.Equal(1, orm.Update<ToStringMap>().SetSource(item).ExecuteAffrows());
|
||||
find = orm.Select<ToStringMap>().Where(a => a.id == item.id && a.biginteger_to_string == 205).First();
|
||||
Assert.NotNull(find);
|
||||
Assert.Equal(item.id, find.id);
|
||||
Assert.Equal(item.biginteger_to_string, find.biginteger_to_string);
|
||||
Assert.Equal(205, find.biginteger_to_string);
|
||||
|
||||
//update set
|
||||
Assert.Equal(1, orm.Update<ToStringMap>().Where(a => a.id == item.id).Set(a => a.biginteger_to_string, 522).ExecuteAffrows());
|
||||
find = orm.Select<ToStringMap>().Where(a => a.id == item.id && a.biginteger_to_string == 522).First();
|
||||
Assert.NotNull(find);
|
||||
Assert.Equal(item.id, find.id);
|
||||
Assert.Equal(522, find.biginteger_to_string);
|
||||
|
||||
Assert.Equal(1, orm.Update<ToStringMap>().Where(a => a.id == item.id).Set(a => a.biginteger_to_string, 10005).ExecuteAffrows());
|
||||
find = orm.Select<ToStringMap>().Where(a => a.id == item.id && a.biginteger_to_string == 10005).First();
|
||||
Assert.NotNull(find);
|
||||
Assert.Equal(item.id, find.id);
|
||||
Assert.Equal(10005, find.biginteger_to_string);
|
||||
|
||||
//delete
|
||||
Assert.Equal(0, orm.Delete<ToStringMap>().Where(a => a.id == item.id && a.biginteger_to_string == 522).ExecuteAffrows());
|
||||
Assert.Equal(0, orm.Delete<ToStringMap>().Where(a => a.id == item.id && a.biginteger_to_string == 205).ExecuteAffrows());
|
||||
Assert.Equal(1, orm.Delete<ToStringMap>().Where(a => a.id == item.id && a.biginteger_to_string == 10005).ExecuteAffrows());
|
||||
Assert.Null(orm.Select<ToStringMap>().Where(a => a.id == item.id).First());
|
||||
}
|
||||
[Fact]
|
||||
public void BigIntegerNullable()
|
||||
{
|
||||
//insert
|
||||
var orm = g.oracle;
|
||||
var item = new ToStringMap { };
|
||||
Assert.Equal(1, orm.Insert<ToStringMap>().AppendData(item).ExecuteAffrows());
|
||||
var find = orm.Select<ToStringMap>().Where(a => a.id == item.id && a.bigintegernullable_to_string == null).First();
|
||||
Assert.NotNull(find);
|
||||
Assert.Equal(item.id, find.id);
|
||||
Assert.Equal(item.bigintegernullable_to_string, find.bigintegernullable_to_string);
|
||||
Assert.Null(find.bigintegernullable_to_string);
|
||||
|
||||
item = new ToStringMap { bigintegernullable_to_string = 101 };
|
||||
Assert.Equal(1, orm.Insert<ToStringMap>().AppendData(item).ExecuteAffrows());
|
||||
find = orm.Select<ToStringMap>().Where(a => a.id == item.id && a.bigintegernullable_to_string == 101).First();
|
||||
Assert.NotNull(find);
|
||||
Assert.Equal(item.id, find.id);
|
||||
Assert.Equal(item.bigintegernullable_to_string, find.bigintegernullable_to_string);
|
||||
Assert.Equal(101, find.bigintegernullable_to_string);
|
||||
|
||||
//update all
|
||||
item.bigintegernullable_to_string = 2004;
|
||||
Assert.Equal(1, orm.Update<ToStringMap>().SetSource(item).ExecuteAffrows());
|
||||
find = orm.Select<ToStringMap>().Where(a => a.id == item.id && a.bigintegernullable_to_string == 2004).First();
|
||||
Assert.NotNull(find);
|
||||
Assert.Equal(item.id, find.id);
|
||||
Assert.Equal(item.bigintegernullable_to_string, find.bigintegernullable_to_string);
|
||||
Assert.Equal(2004, find.bigintegernullable_to_string);
|
||||
|
||||
item.bigintegernullable_to_string = null;
|
||||
Assert.Equal(1, orm.Update<ToStringMap>().SetSource(item).ExecuteAffrows());
|
||||
Assert.Null(orm.Select<ToStringMap>().Where(a => a.id == item.id && a.bigintegernullable_to_string == 2004).First());
|
||||
find = orm.Select<ToStringMap>().Where(a => a.id == item.id && a.bigintegernullable_to_string == null).First();
|
||||
Assert.NotNull(find);
|
||||
Assert.Equal(item.id, find.id);
|
||||
Assert.Equal(item.bigintegernullable_to_string, find.bigintegernullable_to_string);
|
||||
Assert.Null(find.bigintegernullable_to_string);
|
||||
|
||||
//update set
|
||||
Assert.Equal(1, orm.Update<ToStringMap>().Where(a => a.id == item.id).Set(a => a.bigintegernullable_to_string, 998).ExecuteAffrows());
|
||||
find = orm.Select<ToStringMap>().Where(a => a.id == item.id && a.bigintegernullable_to_string == 998).First();
|
||||
Assert.NotNull(find);
|
||||
Assert.Equal(item.id, find.id);
|
||||
Assert.Equal(998, find.bigintegernullable_to_string);
|
||||
|
||||
|
||||
Assert.Equal(1, orm.Update<ToStringMap>().Where(a => a.id == item.id).Set(a => a.bigintegernullable_to_string, null).ExecuteAffrows());
|
||||
Assert.Null(orm.Select<ToStringMap>().Where(a => a.id == item.id && a.bigintegernullable_to_string == 998).First());
|
||||
find = orm.Select<ToStringMap>().Where(a => a.id == item.id && a.bigintegernullable_to_string == null).First();
|
||||
Assert.NotNull(find);
|
||||
Assert.Equal(item.id, find.id);
|
||||
Assert.Null(find.bigintegernullable_to_string);
|
||||
|
||||
//delete
|
||||
Assert.Equal(0, orm.Delete<ToStringMap>().Where(a => a.id == item.id && a.bigintegernullable_to_string == 998).ExecuteAffrows());
|
||||
Assert.Equal(0, orm.Delete<ToStringMap>().Where(a => a.id == item.id && a.bigintegernullable_to_string == 2004).ExecuteAffrows());
|
||||
Assert.Equal(1, orm.Delete<ToStringMap>().Where(a => a.id == item.id && a.bigintegernullable_to_string == null).ExecuteAffrows());
|
||||
Assert.Null(orm.Select<ToStringMap>().Where(a => a.id == item.id).First());
|
||||
}
|
||||
[Fact]
|
||||
public void TimeSpan1()
|
||||
{
|
||||
//insert
|
||||
var orm = g.oracle;
|
||||
var item = new ToStringMap { };
|
||||
Assert.Equal(1, orm.Insert<ToStringMap>().AppendData(item).ExecuteAffrows());
|
||||
var find = orm.Select<ToStringMap>().Where(a => a.id == item.id).First();
|
||||
Assert.NotNull(find);
|
||||
Assert.Equal(item.id, find.id);
|
||||
Assert.Equal(item.timespan_to_string, find.timespan_to_string);
|
||||
Assert.Equal(TimeSpan.Zero, find.timespan_to_string);
|
||||
|
||||
item = new ToStringMap { timespan_to_string = TimeSpan.FromDays(1) };
|
||||
Assert.Equal(1, orm.Insert<ToStringMap>().AppendData(item).ExecuteAffrows());
|
||||
find = orm.Select<ToStringMap>().Where(a => a.id == item.id).First();
|
||||
Assert.NotNull(find);
|
||||
Assert.Equal(item.id, find.id);
|
||||
Assert.Equal(item.timespan_to_string, find.timespan_to_string);
|
||||
Assert.Equal(TimeSpan.FromDays(1), find.timespan_to_string);
|
||||
|
||||
//update all
|
||||
item.timespan_to_string = TimeSpan.FromHours(10);
|
||||
Assert.Equal(1, orm.Update<ToStringMap>().SetSource(item).ExecuteAffrows());
|
||||
find = orm.Select<ToStringMap>().Where(a => a.id == item.id).First();
|
||||
Assert.NotNull(find);
|
||||
Assert.Equal(item.id, find.id);
|
||||
Assert.Equal(item.timespan_to_string, find.timespan_to_string);
|
||||
Assert.Equal(TimeSpan.FromHours(10), find.timespan_to_string);
|
||||
|
||||
//update set
|
||||
Assert.Equal(1, orm.Update<ToStringMap>().Where(a => a.id == item.id).Set(a => a.timespan_to_string, TimeSpan.FromHours(11)).ExecuteAffrows());
|
||||
find = orm.Select<ToStringMap>().Where(a => a.id == item.id).First();
|
||||
Assert.NotNull(find);
|
||||
Assert.Equal(item.id, find.id);
|
||||
Assert.Equal(TimeSpan.FromHours(11), find.timespan_to_string);
|
||||
|
||||
//delete
|
||||
Assert.Equal(1, orm.Delete<ToStringMap>().Where(a => a.id == item.id).ExecuteAffrows());
|
||||
Assert.Null(orm.Select<ToStringMap>().Where(a => a.id == item.id).First());
|
||||
}
|
||||
[Fact]
|
||||
public void TimeSpanNullable()
|
||||
{
|
||||
//insert
|
||||
var orm = g.oracle;
|
||||
var item = new ToStringMap { };
|
||||
Assert.Equal(1, orm.Insert<ToStringMap>().AppendData(item).ExecuteAffrows());
|
||||
var find = orm.Select<ToStringMap>().Where(a => a.id == item.id).First();
|
||||
Assert.NotNull(find);
|
||||
Assert.Equal(item.id, find.id);
|
||||
Assert.Equal(item.timespannullable_to_string, find.timespannullable_to_string);
|
||||
Assert.Null(find.timespannullable_to_string);
|
||||
|
||||
item = new ToStringMap { timespannullable_to_string = TimeSpan.FromDays(1) };
|
||||
Assert.Equal(1, orm.Insert<ToStringMap>().AppendData(item).ExecuteAffrows());
|
||||
find = orm.Select<ToStringMap>().Where(a => a.id == item.id).First();
|
||||
Assert.NotNull(find);
|
||||
Assert.Equal(item.id, find.id);
|
||||
Assert.Equal(item.timespannullable_to_string, find.timespannullable_to_string);
|
||||
Assert.Equal(TimeSpan.FromDays(1), find.timespannullable_to_string);
|
||||
|
||||
//update all
|
||||
item.timespannullable_to_string = TimeSpan.FromHours(10);
|
||||
Assert.Equal(1, orm.Update<ToStringMap>().SetSource(item).ExecuteAffrows());
|
||||
find = orm.Select<ToStringMap>().Where(a => a.id == item.id).First();
|
||||
Assert.NotNull(find);
|
||||
Assert.Equal(item.id, find.id);
|
||||
Assert.Equal(item.timespannullable_to_string, find.timespannullable_to_string);
|
||||
Assert.Equal(TimeSpan.FromHours(10), find.timespannullable_to_string);
|
||||
|
||||
item.timespannullable_to_string = null;
|
||||
Assert.Equal(1, orm.Update<ToStringMap>().SetSource(item).ExecuteAffrows());
|
||||
find = orm.Select<ToStringMap>().Where(a => a.id == item.id).First();
|
||||
Assert.NotNull(find);
|
||||
Assert.Equal(item.id, find.id);
|
||||
Assert.Equal(item.timespannullable_to_string, find.timespannullable_to_string);
|
||||
Assert.Null(find.timespannullable_to_string);
|
||||
|
||||
//update set
|
||||
Assert.Equal(1, orm.Update<ToStringMap>().Where(a => a.id == item.id).Set(a => a.timespannullable_to_string, TimeSpan.FromHours(11)).ExecuteAffrows());
|
||||
find = orm.Select<ToStringMap>().Where(a => a.id == item.id).First();
|
||||
Assert.NotNull(find);
|
||||
Assert.Equal(item.id, find.id);
|
||||
Assert.Equal(TimeSpan.FromHours(11), find.timespannullable_to_string);
|
||||
|
||||
Assert.Equal(1, orm.Update<ToStringMap>().Where(a => a.id == item.id).Set(a => a.timespannullable_to_string, null).ExecuteAffrows());
|
||||
find = orm.Select<ToStringMap>().Where(a => a.id == item.id).First();
|
||||
Assert.NotNull(find);
|
||||
Assert.Equal(item.id, find.id);
|
||||
Assert.Null(find.timespannullable_to_string);
|
||||
|
||||
//delete
|
||||
Assert.Equal(1, orm.Delete<ToStringMap>().Where(a => a.id == item.id).ExecuteAffrows());
|
||||
Assert.Null(orm.Select<ToStringMap>().Where(a => a.id == item.id).First());
|
||||
}
|
||||
[Fact]
|
||||
public void DateTime1()
|
||||
{
|
||||
//insert
|
||||
var orm = g.oracle;
|
||||
var item = new ToStringMap { };
|
||||
Assert.Equal(1, orm.Insert<ToStringMap>().AppendData(item).ExecuteAffrows());
|
||||
var find = orm.Select<ToStringMap>().Where(a => a.id == item.id).First();
|
||||
Assert.NotNull(find);
|
||||
Assert.Equal(item.id, find.id);
|
||||
Assert.Equal(item.datetime_to_string, find.datetime_to_string);
|
||||
Assert.Equal(DateTime.MinValue, find.datetime_to_string);
|
||||
|
||||
item = new ToStringMap { datetime_to_string = DateTime.Parse("2000-1-1") };
|
||||
Assert.Equal(1, orm.Insert<ToStringMap>().AppendData(item).ExecuteAffrows());
|
||||
find = orm.Select<ToStringMap>().Where(a => a.id == item.id).First();
|
||||
Assert.NotNull(find);
|
||||
Assert.Equal(item.id, find.id);
|
||||
Assert.Equal(item.datetime_to_string, find.datetime_to_string);
|
||||
Assert.Equal(DateTime.Parse("2000-1-1"), find.datetime_to_string);
|
||||
|
||||
//update all
|
||||
item.datetime_to_string = DateTime.Parse("2000-1-11");
|
||||
Assert.Equal(1, orm.Update<ToStringMap>().SetSource(item).ExecuteAffrows());
|
||||
find = orm.Select<ToStringMap>().Where(a => a.id == item.id).First();
|
||||
Assert.NotNull(find);
|
||||
Assert.Equal(item.id, find.id);
|
||||
Assert.Equal(item.datetime_to_string, find.datetime_to_string);
|
||||
Assert.Equal(DateTime.Parse("2000-1-11"), find.datetime_to_string);
|
||||
|
||||
//update set
|
||||
Assert.Equal(1, orm.Update<ToStringMap>().Where(a => a.id == item.id).Set(a => a.datetime_to_string, DateTime.Parse("2000-1-12")).ExecuteAffrows());
|
||||
find = orm.Select<ToStringMap>().Where(a => a.id == item.id).First();
|
||||
Assert.NotNull(find);
|
||||
Assert.Equal(item.id, find.id);
|
||||
Assert.Equal(DateTime.Parse("2000-1-12"), find.datetime_to_string);
|
||||
|
||||
//delete
|
||||
Assert.Equal(1, orm.Delete<ToStringMap>().Where(a => a.id == item.id).ExecuteAffrows());
|
||||
Assert.Null(orm.Select<ToStringMap>().Where(a => a.id == item.id).First());
|
||||
}
|
||||
[Fact]
|
||||
public void DateTimeNullable()
|
||||
{
|
||||
//insert
|
||||
var orm = g.oracle;
|
||||
var item = new ToStringMap { };
|
||||
Assert.Equal(1, orm.Insert<ToStringMap>().AppendData(item).ExecuteAffrows());
|
||||
var find = orm.Select<ToStringMap>().Where(a => a.id == item.id).First();
|
||||
Assert.NotNull(find);
|
||||
Assert.Equal(item.id, find.id);
|
||||
Assert.Equal(item.datetimenullable_to_string, find.datetimenullable_to_string);
|
||||
Assert.Null(find.datetimenullable_to_string);
|
||||
|
||||
item = new ToStringMap { datetimenullable_to_string = DateTime.Parse("2000-1-1") };
|
||||
Assert.Equal(1, orm.Insert<ToStringMap>().AppendData(item).ExecuteAffrows());
|
||||
find = orm.Select<ToStringMap>().Where(a => a.id == item.id).First();
|
||||
Assert.NotNull(find);
|
||||
Assert.Equal(item.id, find.id);
|
||||
Assert.Equal(item.datetimenullable_to_string, find.datetimenullable_to_string);
|
||||
Assert.Equal(DateTime.Parse("2000-1-1"), find.datetimenullable_to_string);
|
||||
|
||||
//update all
|
||||
item.datetimenullable_to_string = DateTime.Parse("2000-1-11");
|
||||
Assert.Equal(1, orm.Update<ToStringMap>().SetSource(item).ExecuteAffrows());
|
||||
find = orm.Select<ToStringMap>().Where(a => a.id == item.id).First();
|
||||
Assert.NotNull(find);
|
||||
Assert.Equal(item.id, find.id);
|
||||
Assert.Equal(item.datetimenullable_to_string, find.datetimenullable_to_string);
|
||||
Assert.Equal(DateTime.Parse("2000-1-11"), find.datetimenullable_to_string);
|
||||
|
||||
item.datetimenullable_to_string = null;
|
||||
Assert.Equal(1, orm.Update<ToStringMap>().SetSource(item).ExecuteAffrows());
|
||||
find = orm.Select<ToStringMap>().Where(a => a.id == item.id).First();
|
||||
Assert.NotNull(find);
|
||||
Assert.Equal(item.id, find.id);
|
||||
Assert.Equal(item.datetimenullable_to_string, find.datetimenullable_to_string);
|
||||
Assert.Null(find.datetimenullable_to_string);
|
||||
|
||||
//update set
|
||||
Assert.Equal(1, orm.Update<ToStringMap>().Where(a => a.id == item.id).Set(a => a.datetimenullable_to_string, DateTime.Parse("2000-1-12")).ExecuteAffrows());
|
||||
find = orm.Select<ToStringMap>().Where(a => a.id == item.id).First();
|
||||
Assert.NotNull(find);
|
||||
Assert.Equal(item.id, find.id);
|
||||
Assert.Equal(DateTime.Parse("2000-1-12"), find.datetimenullable_to_string);
|
||||
|
||||
Assert.Equal(1, orm.Update<ToStringMap>().Where(a => a.id == item.id).Set(a => a.datetimenullable_to_string, null).ExecuteAffrows());
|
||||
find = orm.Select<ToStringMap>().Where(a => a.id == item.id).First();
|
||||
Assert.NotNull(find);
|
||||
Assert.Equal(item.id, find.id);
|
||||
Assert.Null(find.datetimenullable_to_string);
|
||||
|
||||
//delete
|
||||
Assert.Equal(1, orm.Delete<ToStringMap>().Where(a => a.id == item.id).ExecuteAffrows());
|
||||
Assert.Null(orm.Select<ToStringMap>().Where(a => a.id == item.id).First());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Guid1()
|
||||
{
|
||||
//insert
|
||||
var orm = g.oracle;
|
||||
var item = new ToStringMap { };
|
||||
Assert.Equal(1, orm.Insert<ToStringMap>().AppendData(item).ExecuteAffrows());
|
||||
var find = orm.Select<ToStringMap>().Where(a => a.id == item.id && a.guid_to_string == Guid.Empty).First();
|
||||
Assert.NotNull(find);
|
||||
Assert.Equal(item.id, find.id);
|
||||
Assert.Equal(item.guid_to_string, find.guid_to_string);
|
||||
Assert.Equal(Guid.Empty, find.guid_to_string);
|
||||
|
||||
var newid = Guid.NewGuid();
|
||||
item = new ToStringMap { guid_to_string = newid };
|
||||
Assert.Equal(1, orm.Insert<ToStringMap>().AppendData(item).ExecuteAffrows());
|
||||
find = orm.Select<ToStringMap>().Where(a => a.id == item.id && a.guid_to_string == newid).First();
|
||||
Assert.NotNull(find);
|
||||
Assert.Equal(item.id, find.id);
|
||||
Assert.Equal(item.guid_to_string, find.guid_to_string);
|
||||
Assert.Equal(newid, find.guid_to_string);
|
||||
|
||||
//update all
|
||||
newid = Guid.NewGuid();
|
||||
item.guid_to_string = newid;
|
||||
Assert.Equal(1, orm.Update<ToStringMap>().SetSource(item).ExecuteAffrows());
|
||||
find = orm.Select<ToStringMap>().Where(a => a.id == item.id && a.guid_to_string == newid).First();
|
||||
Assert.NotNull(find);
|
||||
Assert.Equal(item.id, find.id);
|
||||
Assert.Equal(item.guid_to_string, find.guid_to_string);
|
||||
Assert.Equal(newid, find.guid_to_string);
|
||||
|
||||
//update set
|
||||
newid = Guid.NewGuid();
|
||||
Assert.Equal(1, orm.Update<ToStringMap>().Where(a => a.id == item.id).Set(a => a.guid_to_string, newid).ExecuteAffrows());
|
||||
find = orm.Select<ToStringMap>().Where(a => a.id == item.id && a.guid_to_string == newid).First();
|
||||
Assert.NotNull(find);
|
||||
Assert.Equal(item.id, find.id);
|
||||
Assert.Equal(newid, find.guid_to_string);
|
||||
|
||||
//delete
|
||||
Assert.Equal(1, orm.Delete<ToStringMap>().Where(a => a.id == item.id && a.guid_to_string == newid).ExecuteAffrows());
|
||||
Assert.Null(orm.Select<ToStringMap>().Where(a => a.id == item.id).First());
|
||||
}
|
||||
[Fact]
|
||||
public void GuidNullable()
|
||||
{
|
||||
//insert
|
||||
var orm = g.oracle;
|
||||
var item = new ToStringMap { };
|
||||
Assert.Equal(1, orm.Insert<ToStringMap>().AppendData(item).ExecuteAffrows());
|
||||
var find = orm.Select<ToStringMap>().Where(a => a.id == item.id && a.guidnullable_to_string == null).First();
|
||||
Assert.NotNull(find);
|
||||
Assert.Equal(item.id, find.id);
|
||||
Assert.Equal(item.guidnullable_to_string, find.guidnullable_to_string);
|
||||
Assert.Null(find.guidnullable_to_string);
|
||||
|
||||
var newid = Guid.NewGuid();
|
||||
item = new ToStringMap { guidnullable_to_string = newid };
|
||||
Assert.Equal(1, orm.Insert<ToStringMap>().AppendData(item).ExecuteAffrows());
|
||||
find = orm.Select<ToStringMap>().Where(a => a.id == item.id && a.guidnullable_to_string == newid).First();
|
||||
Assert.NotNull(find);
|
||||
Assert.Equal(item.id, find.id);
|
||||
Assert.Equal(item.guidnullable_to_string, find.guidnullable_to_string);
|
||||
Assert.Equal(newid, find.guidnullable_to_string);
|
||||
|
||||
//update all
|
||||
newid = Guid.NewGuid();
|
||||
item.guidnullable_to_string = newid;
|
||||
Assert.Equal(1, orm.Update<ToStringMap>().SetSource(item).ExecuteAffrows());
|
||||
find = orm.Select<ToStringMap>().Where(a => a.id == item.id && a.guidnullable_to_string == newid).First();
|
||||
Assert.NotNull(find);
|
||||
Assert.Equal(item.id, find.id);
|
||||
Assert.Equal(item.guidnullable_to_string, find.guidnullable_to_string);
|
||||
Assert.Equal(newid, find.guidnullable_to_string);
|
||||
|
||||
item.guidnullable_to_string = null;
|
||||
Assert.Equal(1, orm.Update<ToStringMap>().SetSource(item).ExecuteAffrows());
|
||||
find = orm.Select<ToStringMap>().Where(a => a.id == item.id && a.guidnullable_to_string == null).First();
|
||||
Assert.NotNull(find);
|
||||
Assert.Equal(item.id, find.id);
|
||||
Assert.Equal(item.guidnullable_to_string, find.guidnullable_to_string);
|
||||
Assert.Null(find.guidnullable_to_string);
|
||||
|
||||
//update set
|
||||
newid = Guid.NewGuid();
|
||||
Assert.Equal(1, orm.Update<ToStringMap>().Where(a => a.id == item.id).Set(a => a.guidnullable_to_string, newid).ExecuteAffrows());
|
||||
find = orm.Select<ToStringMap>().Where(a => a.id == item.id && a.guidnullable_to_string == newid).First();
|
||||
Assert.NotNull(find);
|
||||
Assert.Equal(item.id, find.id);
|
||||
Assert.Equal(newid, find.guidnullable_to_string);
|
||||
|
||||
Assert.Equal(1, orm.Update<ToStringMap>().Where(a => a.id == item.id).Set(a => a.guidnullable_to_string, null).ExecuteAffrows());
|
||||
find = orm.Select<ToStringMap>().Where(a => a.id == item.id && a.guidnullable_to_string == null).First();
|
||||
Assert.NotNull(find);
|
||||
Assert.Equal(item.id, find.id);
|
||||
Assert.Null(find.guidnullable_to_string);
|
||||
|
||||
//delete
|
||||
Assert.Equal(1, orm.Delete<ToStringMap>().Where(a => a.id == item.id && a.guidnullable_to_string == null).ExecuteAffrows());
|
||||
Assert.Null(orm.Select<ToStringMap>().Where(a => a.id == item.id).First());
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,66 @@
|
||||
using FreeSql.DataAnnotations;
|
||||
using System;
|
||||
using Xunit;
|
||||
|
||||
namespace FreeSql.Tests.Odbc.Oracle
|
||||
{
|
||||
public class OracleAdoTest
|
||||
{
|
||||
[Fact]
|
||||
public void Pool()
|
||||
{
|
||||
var t1 = g.oracle.Ado.MasterPool.StatisticsFullily;
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void SlavePools()
|
||||
{
|
||||
var t2 = g.oracle.Ado.SlavePools.Count;
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ExecuteReader()
|
||||
{
|
||||
|
||||
}
|
||||
[Fact]
|
||||
public void ExecuteArray()
|
||||
{
|
||||
|
||||
}
|
||||
[Fact]
|
||||
public void ExecuteNonQuery()
|
||||
{
|
||||
|
||||
}
|
||||
[Fact]
|
||||
public void ExecuteScalar()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Query()
|
||||
{
|
||||
|
||||
var t3 = g.oracle.Ado.Query<xxx>("select * from \"TB_TOPIC\"");
|
||||
|
||||
var t4 = g.oracle.Ado.Query<(int, string, string)>("select * from \"TB_TOPIC\"");
|
||||
|
||||
var t5 = g.oracle.Ado.Query<dynamic>("select * from \"TB_TOPIC\"");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void QueryMultipline()
|
||||
{
|
||||
//var t3 = g.oracle.Ado.Query<xxx, (int, string, string), dynamic>("select * from \"TB_TOPIC\"; select * from \"TB_TOPIC\"; select * from \"TB_TOPIC\"");
|
||||
}
|
||||
|
||||
class xxx
|
||||
{
|
||||
public int Id { get; set; }
|
||||
public string Path { get; set; }
|
||||
public string Title2 { get; set; }
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,40 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Reflection;
|
||||
using System.Text;
|
||||
using Xunit;
|
||||
|
||||
namespace FreeSql.Tests.Odbc.Oracle
|
||||
{
|
||||
public class OracleAopTest
|
||||
{
|
||||
|
||||
class TestAuditValue
|
||||
{
|
||||
public Guid id { get; set; }
|
||||
[Now]
|
||||
public DateTime createtime { get; set; }
|
||||
}
|
||||
class NowAttribute: Attribute { }
|
||||
|
||||
[Fact]
|
||||
public void AuditValue()
|
||||
{
|
||||
var date = DateTime.Now.Date;
|
||||
var item = new TestAuditValue();
|
||||
|
||||
EventHandler<Aop.AuditValueEventArgs> audit = (s, e) =>
|
||||
{
|
||||
if (e.Property.GetCustomAttribute<NowAttribute>(false) != null)
|
||||
e.Value = DateTime.Now.Date;
|
||||
};
|
||||
g.oracle.Aop.AuditValue += audit;
|
||||
|
||||
g.oracle.Insert(item).ExecuteAffrows();
|
||||
|
||||
g.oracle.Aop.AuditValue -= audit;
|
||||
|
||||
Assert.Equal(item.createtime, date);
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,258 @@
|
||||
using FreeSql.DataAnnotations;
|
||||
using Newtonsoft.Json;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using Xunit;
|
||||
|
||||
namespace FreeSql.Tests.Odbc.Oracle
|
||||
{
|
||||
public class OracleCodeFirstTest
|
||||
{
|
||||
|
||||
[Fact]
|
||||
public void 中文表_字段()
|
||||
{
|
||||
var sql = g.oracle.CodeFirst.GetComparisonDDLStatements<测试中文表>();
|
||||
g.oracle.CodeFirst.SyncStructure<测试中文表>();
|
||||
|
||||
var item = new 测试中文表
|
||||
{
|
||||
标题 = "测试标题",
|
||||
创建时间 = DateTime.Now
|
||||
};
|
||||
Assert.Equal(1, g.oracle.Insert<测试中文表>().AppendData(item).ExecuteAffrows());
|
||||
Assert.NotEqual(Guid.Empty, item.编号);
|
||||
var item2 = g.oracle.Select<测试中文表>().Where(a => a.编号 == item.编号).First();
|
||||
Assert.NotNull(item2);
|
||||
Assert.Equal(item.编号, item2.编号);
|
||||
Assert.Equal(item.标题, item2.标题);
|
||||
}
|
||||
class 测试中文表
|
||||
{
|
||||
[Column(IsPrimary = true)]
|
||||
public Guid 编号 { get; set; }
|
||||
|
||||
public string 标题 { get; set; }
|
||||
|
||||
public DateTime 创建时间 { get; set; }
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void AddUniques()
|
||||
{
|
||||
var sql = g.oracle.CodeFirst.GetComparisonDDLStatements<AddUniquesInfo>();
|
||||
g.oracle.CodeFirst.SyncStructure<AddUniquesInfo>();
|
||||
}
|
||||
[Table(Name = "AddUniquesInfo", OldName = "AddUniquesInfo2")]
|
||||
class AddUniquesInfo
|
||||
{
|
||||
public Guid id { get; set; }
|
||||
[Column(Unique = "uk_phone")]
|
||||
public string phone { get; set; }
|
||||
|
||||
[Column(Unique = "uk_group_index, uk_group_index22")]
|
||||
public string group { get; set; }
|
||||
[Column(Unique = "uk_group_index")]
|
||||
public int index { get; set; }
|
||||
[Column(Unique = "uk_group_index22")]
|
||||
public string index22 { get; set; }
|
||||
}
|
||||
[Fact]
|
||||
public void AddField()
|
||||
{
|
||||
var sql = g.oracle.CodeFirst.GetComparisonDDLStatements<TopicAddField>();
|
||||
|
||||
var id = g.oracle.Insert<TopicAddField>().AppendData(new TopicAddField { }).ExecuteIdentity();
|
||||
|
||||
//var inserted = g.oracle.Insert<TopicAddField>().AppendData(new TopicAddField { }).ExecuteInserted();
|
||||
}
|
||||
|
||||
[Table(Name = "TopicAddField", OldName = "xxxtb.TopicAddField")]
|
||||
public class TopicAddField
|
||||
{
|
||||
[Column(IsIdentity = true)]
|
||||
public int Id { get; set; }
|
||||
|
||||
public string name { get; set; }
|
||||
|
||||
[Column(DbType = "varchar2(200 char) not null", OldName = "title")]
|
||||
public string title2 { get; set; } = "10";
|
||||
|
||||
[Column(IsIgnore = true)]
|
||||
public DateTime ct { get; set; } = DateTime.Now;
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void GetComparisonDDLStatements()
|
||||
{
|
||||
|
||||
var sql = g.oracle.CodeFirst.GetComparisonDDLStatements<TableAllType>();
|
||||
if (string.IsNullOrEmpty(sql) == false)
|
||||
{
|
||||
Assert.Equal(@"CREATE TABLE IF NOT EXISTS `cccddd`.`tb_alltype` (
|
||||
`Id` INT(11) NOT NULL AUTO_INCREMENT,
|
||||
`Bool` BIT(1) NOT NULL,
|
||||
`SByte` TINYINT(3) NOT NULL,
|
||||
`Short` SMALLINT(6) NOT NULL,
|
||||
`Int` INT(11) NOT NULL,
|
||||
`Long` BIGINT(20) NOT NULL,
|
||||
`Byte` TINYINT(3) UNSIGNED NOT NULL,
|
||||
`UShort` SMALLINT(5) UNSIGNED NOT NULL,
|
||||
`UInt` INT(10) UNSIGNED NOT NULL,
|
||||
`ULong` BIGINT(20) UNSIGNED NOT NULL,
|
||||
`Double` DOUBLE NOT NULL,
|
||||
`Float` FLOAT NOT NULL,
|
||||
`Decimal` DECIMAL(10,2) NOT NULL,
|
||||
`TimeSpan` TIME NOT NULL,
|
||||
`DateTime` DATETIME NOT NULL,
|
||||
`Bytes` VARBINARY(255),
|
||||
`String` VARCHAR(255),
|
||||
`Guid` VARCHAR(36),
|
||||
`BoolNullable` BIT(1),
|
||||
`SByteNullable` TINYINT(3),
|
||||
`ShortNullable` SMALLINT(6),
|
||||
`IntNullable` INT(11),
|
||||
`testFielLongNullable` BIGINT(20),
|
||||
`ByteNullable` TINYINT(3) UNSIGNED,
|
||||
`UShortNullable` SMALLINT(5) UNSIGNED,
|
||||
`UIntNullable` INT(10) UNSIGNED,
|
||||
`ULongNullable` BIGINT(20) UNSIGNED,
|
||||
`DoubleNullable` DOUBLE,
|
||||
`FloatNullable` FLOAT,
|
||||
`DecimalNullable` DECIMAL(10,2),
|
||||
`TimeSpanNullable` TIME,
|
||||
`DateTimeNullable` DATETIME,
|
||||
`GuidNullable` VARCHAR(36),
|
||||
`Point` POINT,
|
||||
`LineString` LINESTRING,
|
||||
`Polygon` POLYGON,
|
||||
`MultiPoint` MULTIPOINT,
|
||||
`MultiLineString` MULTILINESTRING,
|
||||
`MultiPolygon` MULTIPOLYGON,
|
||||
`Enum1` ENUM('E1','E2','E3') NOT NULL,
|
||||
`Enum1Nullable` ENUM('E1','E2','E3'),
|
||||
`Enum2` SET('F1','F2','F3') NOT NULL,
|
||||
`Enum2Nullable` SET('F1','F2','F3'),
|
||||
PRIMARY KEY (`Id`)
|
||||
) Engine=InnoDB;
|
||||
", sql);
|
||||
}
|
||||
|
||||
//sql = g.oracle.CodeFirst.GetComparisonDDLStatements<Tb_alltype>();
|
||||
}
|
||||
|
||||
IInsert<TableAllType> insert => g.oracle.Insert<TableAllType>();
|
||||
ISelect<TableAllType> select => g.oracle.Select<TableAllType>();
|
||||
|
||||
[Fact]
|
||||
public void CurdAllField()
|
||||
{
|
||||
var item = new TableAllType { };
|
||||
item.Id = (int)insert.AppendData(item).ExecuteIdentity();
|
||||
|
||||
var newitem = select.Where(a => a.Id == item.Id).ToOne();
|
||||
|
||||
var item2 = new TableAllType
|
||||
{
|
||||
Bool = true,
|
||||
BoolNullable = true,
|
||||
Byte = 255,
|
||||
ByteNullable = 127,
|
||||
Bytes = Encoding.UTF8.GetBytes("我是中国人"),
|
||||
DateTime = DateTime.Now,
|
||||
DateTimeNullable = DateTime.Now.AddHours(-1),
|
||||
Decimal = 99.99M,
|
||||
DecimalNullable = 99.98M,
|
||||
Double = 999.99,
|
||||
DoubleNullable = 999.98,
|
||||
Enum1 = TableAllTypeEnumType1.e5,
|
||||
Enum1Nullable = TableAllTypeEnumType1.e3,
|
||||
Enum2 = TableAllTypeEnumType2.f2,
|
||||
Enum2Nullable = TableAllTypeEnumType2.f3,
|
||||
Float = 19.99F,
|
||||
FloatNullable = 19.98F,
|
||||
Guid = Guid.NewGuid(),
|
||||
GuidNullable = Guid.NewGuid(),
|
||||
Int = int.MaxValue,
|
||||
IntNullable = int.MinValue,
|
||||
SByte = 100,
|
||||
SByteNullable = 99,
|
||||
Short = short.MaxValue,
|
||||
ShortNullable = short.MinValue,
|
||||
String = "我是中国人string",
|
||||
TimeSpan = TimeSpan.FromSeconds(999),
|
||||
TimeSpanNullable = TimeSpan.FromSeconds(60),
|
||||
UInt = uint.MaxValue,
|
||||
UIntNullable = uint.MinValue,
|
||||
ULong = ulong.MaxValue,
|
||||
ULongNullable = ulong.MinValue,
|
||||
UShort = ushort.MaxValue,
|
||||
UShortNullable = ushort.MinValue,
|
||||
testFielLongNullable = long.MinValue
|
||||
};
|
||||
var sqlPar = insert.AppendData(item2).ToSql();
|
||||
var sqlText = insert.AppendData(item2).NoneParameter().ToSql();
|
||||
var item3NP = insert.AppendData(item2).NoneParameter().ExecuteIdentity();
|
||||
|
||||
item2.Id = (int)insert.AppendData(item2).ExecuteIdentity();
|
||||
var newitem2 = select.Where(a => a.Id == item2.Id).ToOne();
|
||||
|
||||
var items = select.ToList();
|
||||
}
|
||||
|
||||
[Table(Name = "tb_alltype")]
|
||||
class TableAllType
|
||||
{
|
||||
[Column(IsIdentity = true, IsPrimary = true)]
|
||||
public int Id { get; set; }
|
||||
|
||||
public string id2 { get; set; } = "id2=10";
|
||||
|
||||
public bool Bool { get; set; }
|
||||
public sbyte SByte { get; set; }
|
||||
public short Short { get; set; }
|
||||
public int Int { get; set; }
|
||||
public long Long { get; set; }
|
||||
public byte Byte { get; set; }
|
||||
public ushort UShort { get; set; }
|
||||
public uint UInt { get; set; }
|
||||
public ulong ULong { get; set; }
|
||||
public double Double { get; set; }
|
||||
public float Float { get; set; }
|
||||
public decimal Decimal { get; set; }
|
||||
public TimeSpan TimeSpan { get; set; }
|
||||
public DateTime DateTime { get; set; }
|
||||
public DateTime DateTimeOffSet { get; set; }
|
||||
public byte[] Bytes { get; set; }
|
||||
public string String { get; set; }
|
||||
public Guid Guid { get; set; }
|
||||
|
||||
public bool? BoolNullable { get; set; }
|
||||
public sbyte? SByteNullable { get; set; }
|
||||
public short? ShortNullable { get; set; }
|
||||
public int? IntNullable { get; set; }
|
||||
public long? testFielLongNullable { get; set; }
|
||||
public byte? ByteNullable { get; set; }
|
||||
public ushort? UShortNullable { get; set; }
|
||||
public uint? UIntNullable { get; set; }
|
||||
public ulong? ULongNullable { get; set; }
|
||||
public double? DoubleNullable { get; set; }
|
||||
public float? FloatNullable { get; set; }
|
||||
public decimal? DecimalNullable { get; set; }
|
||||
public TimeSpan? TimeSpanNullable { get; set; }
|
||||
public DateTime? DateTimeNullable { get; set; }
|
||||
public DateTime? DateTimeOffSetNullable { get; set; }
|
||||
public Guid? GuidNullable { get; set; }
|
||||
|
||||
public TableAllTypeEnumType1 Enum1 { get; set; }
|
||||
public TableAllTypeEnumType1? Enum1Nullable { get; set; }
|
||||
public TableAllTypeEnumType2 Enum2 { get; set; }
|
||||
public TableAllTypeEnumType2? Enum2Nullable { get; set; }
|
||||
}
|
||||
|
||||
public enum TableAllTypeEnumType1 { e1, e2, e3, e5 }
|
||||
[Flags] public enum TableAllTypeEnumType2 { f1, f2, f3 }
|
||||
}
|
||||
}
|
@ -0,0 +1,25 @@
|
||||
using FreeSql.DataAnnotations;
|
||||
using System;
|
||||
using Xunit;
|
||||
|
||||
namespace FreeSql.Tests.Odbc.Oracle
|
||||
{
|
||||
public class OracleDbFirstTest
|
||||
{
|
||||
[Fact]
|
||||
public void GetDatabases()
|
||||
{
|
||||
|
||||
var t1 = g.oracle.DbFirst.GetDatabases();
|
||||
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void GetTablesByDatabase()
|
||||
{
|
||||
|
||||
var t2 = g.oracle.DbFirst.GetTablesByDatabase();
|
||||
//var tb = g.oracle.Ado.ExecuteArray(System.Data.CommandType.Text, "select * from \"tb_dbfirst\"");
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,169 @@
|
||||
using FreeSql.DataAnnotations;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Xunit;
|
||||
|
||||
namespace FreeSql.Tests.Odbc.OracleExpression
|
||||
{
|
||||
public class ConvertTest
|
||||
{
|
||||
|
||||
ISelect<Topic> select => g.oracle.Select<Topic>();
|
||||
|
||||
[Table(Name = "tb_topic")]
|
||||
class Topic
|
||||
{
|
||||
[Column(IsIdentity = true, IsPrimary = true)]
|
||||
public int Id { get; set; }
|
||||
public int Clicks { get; set; }
|
||||
public int TypeGuid { get; set; }
|
||||
public TestTypeInfo Type { get; set; }
|
||||
public string Title { get; set; }
|
||||
public DateTime CreateTime { get; set; }
|
||||
}
|
||||
class TestTypeInfo
|
||||
{
|
||||
public int Guid { get; set; }
|
||||
public int ParentId { get; set; }
|
||||
public TestTypeParentInfo Parent { get; set; }
|
||||
public string Name { get; set; }
|
||||
}
|
||||
class TestTypeParentInfo
|
||||
{
|
||||
public int Id { get; set; }
|
||||
public string Name { get; set; }
|
||||
|
||||
public List<TestTypeInfo> Types { get; set; }
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ToBoolean()
|
||||
{
|
||||
var data = new List<object>();
|
||||
//data.Add(select.Where(a => (Convert.ToBoolean(a.Clicks) ? 1 : 0) > 0).ToList());
|
||||
//data.Add(select.Where(a => (bool.Parse(a.Clicks.ToString()) ? 1 : 0) > 0).ToList());
|
||||
}
|
||||
[Fact]
|
||||
public void ToByte()
|
||||
{
|
||||
var data = new List<object>();
|
||||
data.Add(select.Where(a => Convert.ToByte(a.Clicks % 255) > 0).ToList());
|
||||
data.Add(select.Where(a => byte.Parse((a.Clicks % 255).ToString()) > 0).ToList());
|
||||
}
|
||||
[Fact]
|
||||
public void ToChar()
|
||||
{
|
||||
var data = new List<object>();
|
||||
data.Add(select.Where(a => Convert.ToChar(a.Clicks) == '1').ToList());
|
||||
data.Add(select.Where(a => char.Parse(a.Clicks.ToString()) == '1').ToList());
|
||||
}
|
||||
[Fact]
|
||||
public void ToDateTime()
|
||||
{
|
||||
var data = new List<object>();
|
||||
data.Add(select.Where(a => Convert.ToDateTime(a.CreateTime.ToString()).Year > 0).ToList());
|
||||
data.Add(select.Where(a => DateTime.Parse(a.CreateTime.ToString()).Year > 0).ToList());
|
||||
}
|
||||
[Fact]
|
||||
public void ToDecimal()
|
||||
{
|
||||
var data = new List<object>();
|
||||
data.Add(select.Where(a => Convert.ToDecimal(a.Clicks) > 0).ToList());
|
||||
data.Add(select.Where(a => decimal.Parse(a.Clicks.ToString()) > 0).ToList());
|
||||
}
|
||||
[Fact]
|
||||
public void ToDouble()
|
||||
{
|
||||
var data = new List<object>();
|
||||
data.Add(select.Where(a => Convert.ToDouble(a.Clicks) > 0).ToList());
|
||||
data.Add(select.Where(a => double.Parse(a.Clicks.ToString()) > 0).ToList());
|
||||
}
|
||||
[Fact]
|
||||
public void ToInt16()
|
||||
{
|
||||
var data = new List<object>();
|
||||
data.Add(select.Where(a => Convert.ToInt16(a.Clicks) > 0).ToList());
|
||||
data.Add(select.Where(a => short.Parse(a.Clicks.ToString()) > 0).ToList());
|
||||
}
|
||||
[Fact]
|
||||
public void ToInt32()
|
||||
{
|
||||
var data = new List<object>();
|
||||
data.Add(select.Where(a => (int)a.Clicks > 0).ToList());
|
||||
data.Add(select.Where(a => Convert.ToInt32(a.Clicks) > 0).ToList());
|
||||
data.Add(select.Where(a => int.Parse(a.Clicks.ToString()) > 0).ToList());
|
||||
}
|
||||
[Fact]
|
||||
public void ToInt64()
|
||||
{
|
||||
var data = new List<object>();
|
||||
data.Add(select.Where(a => Convert.ToInt64(a.Clicks) > 0).ToList());
|
||||
data.Add(select.Where(a => long.Parse(a.Clicks.ToString()) > 0).ToList());
|
||||
}
|
||||
[Fact]
|
||||
public void ToSByte()
|
||||
{
|
||||
var data = new List<object>();
|
||||
data.Add(select.Where(a => Convert.ToSByte(a.Clicks % 128) > 0).ToList());
|
||||
data.Add(select.Where(a => sbyte.Parse((a.Clicks % 128).ToString()) > 0).ToList());
|
||||
}
|
||||
[Fact]
|
||||
public void ToSingle()
|
||||
{
|
||||
var data = new List<object>();
|
||||
data.Add(select.Where(a => Convert.ToSingle(a.Clicks) > 0).ToList());
|
||||
data.Add(select.Where(a => float.Parse(a.Clicks.ToString()) > 0).ToList());
|
||||
}
|
||||
[Fact]
|
||||
public void this_ToString()
|
||||
{
|
||||
var data = new List<object>();
|
||||
data.Add(select.Where(a => Convert.ToString(a.Clicks).Equals("")).ToList());
|
||||
data.Add(select.Where(a => a.Clicks.ToString().Equals("")).ToList());
|
||||
}
|
||||
[Fact]
|
||||
public void ToUInt16()
|
||||
{
|
||||
var data = new List<object>();
|
||||
data.Add(select.Where(a => Convert.ToUInt16(a.Clicks) > 0).ToList());
|
||||
data.Add(select.Where(a => ushort.Parse(a.Clicks.ToString()) > 0).ToList());
|
||||
}
|
||||
[Fact]
|
||||
public void ToUInt32()
|
||||
{
|
||||
var data = new List<object>();
|
||||
data.Add(select.Where(a => Convert.ToUInt32(a.Clicks) > 0).ToList());
|
||||
data.Add(select.Where(a => uint.Parse(a.Clicks.ToString()) > 0).ToList());
|
||||
}
|
||||
[Fact]
|
||||
public void ToUInt64()
|
||||
{
|
||||
var data = new List<object>();
|
||||
data.Add(select.Where(a => Convert.ToUInt64(a.Clicks) > 0).ToList());
|
||||
data.Add(select.Where(a => ulong.Parse(a.Clicks.ToString()) > 0).ToList());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Guid_Parse()
|
||||
{
|
||||
var data = new List<object>();
|
||||
data.Add(select.Where(a => Guid.Parse(Guid.Empty.ToString()) == Guid.Empty).ToList());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Guid_NewGuid()
|
||||
{
|
||||
var data = new List<object>();
|
||||
//data.Add(select.OrderBy(a => Guid.NewGuid()).Limit(10).ToList());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Random()
|
||||
{
|
||||
var data = new List<object>();
|
||||
data.Add(select.Where(a => new Random().Next() > a.Clicks).Limit(10).ToList());
|
||||
data.Add(select.Where(a => new Random().NextDouble() > a.Clicks).Limit(10).ToList());
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,706 @@
|
||||
using FreeSql.DataAnnotations;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Xunit;
|
||||
|
||||
namespace FreeSql.Tests.Odbc.OracleExpression
|
||||
{
|
||||
public class DateTimeTest
|
||||
{
|
||||
|
||||
ISelect<Topic> select => g.oracle.Select<Topic>();
|
||||
|
||||
[Table(Name = "tb_topic111333")]
|
||||
class Topic
|
||||
{
|
||||
[Column(IsIdentity = true, IsPrimary = true)]
|
||||
public int Id { get; set; }
|
||||
public int Clicks { get; set; }
|
||||
public int TypeGuid { get; set; }
|
||||
public TestTypeInfo Type { get; set; }
|
||||
public string Title { get; set; }
|
||||
public DateTime CreateTime { get; set; }
|
||||
}
|
||||
[Table(Name = "TestTypeInfo333")]
|
||||
class TestTypeInfo
|
||||
{
|
||||
[Column(IsIdentity = true)]
|
||||
public int Guid { get; set; }
|
||||
public int ParentId { get; set; }
|
||||
public TestTypeParentInfo Parent { get; set; }
|
||||
public string Name { get; set; }
|
||||
public DateTime Time { get; set; }
|
||||
}
|
||||
[Table(Name = "TestTypeParentInf1")]
|
||||
class TestTypeParentInfo
|
||||
{
|
||||
public int Id { get; set; }
|
||||
public string Name { get; set; }
|
||||
|
||||
public List<TestTypeInfo> Types { get; set; }
|
||||
public DateTime Time2 { get; set; }
|
||||
}
|
||||
[Fact]
|
||||
public void Now()
|
||||
{
|
||||
var data = new List<object>();
|
||||
data.Add(select.Where(a => a.CreateTime.Date == DateTime.Now.Date).ToList());
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5
|
||||
//FROM `tb_topic111333` a
|
||||
//WHERE (cast(date_format(a.`CreateTime`, '%Y-%m-%d') as datetime) = cast(date_format(now(), '%Y-%m-%d') as datetime))
|
||||
}
|
||||
[Fact]
|
||||
public void UtcNow()
|
||||
{
|
||||
var data = new List<object>();
|
||||
data.Add(select.Where(a => a.CreateTime.Date == DateTime.UtcNow.Date).ToList());
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5
|
||||
//FROM `tb_topic111333` a
|
||||
//WHERE (cast(date_format(a.`CreateTime`, '%Y-%m-%d') as datetime) = cast(date_format(utc_timestamp(), '%Y-%m-%d') as datetime))
|
||||
}
|
||||
[Fact]
|
||||
public void MinValue()
|
||||
{
|
||||
var data = new List<object>();
|
||||
data.Add(select.Where(a => a.CreateTime.Date == DateTime.MinValue.Date).ToList());
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5
|
||||
//FROM `tb_topic111333` a
|
||||
//WHERE (cast(date_format(a.`CreateTime`, '%Y-%m-%d') as datetime) = cast(date_format(cast('0001/1/1 0:00:00' as datetime), '%Y-%m-%d') as datetime))
|
||||
}
|
||||
[Fact]
|
||||
public void MaxValue()
|
||||
{
|
||||
var data = new List<object>();
|
||||
data.Add(select.Where(a => a.CreateTime.Date == DateTime.MaxValue.Date).ToList());
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5
|
||||
//FROM `tb_topic111333` a
|
||||
//WHERE (cast(date_format(a.`CreateTime`, '%Y-%m-%d') as datetime) = cast(date_format(cast('9999/12/31 23:59:59' as datetime), '%Y-%m-%d') as datetime))
|
||||
}
|
||||
[Fact]
|
||||
public void Date()
|
||||
{
|
||||
var data = new List<object>();
|
||||
data.Add(select.Where(a => a.CreateTime.Date == DateTime.Now.Date).ToList());
|
||||
data.Add(select.Where(a => a.Type.Time.Date > DateTime.Now.Date).ToList());
|
||||
data.Add(select.Where(a => a.Type.Parent.Time2.Date > DateTime.Now.Date).ToList());
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5
|
||||
//FROM `tb_topic111333` a
|
||||
//WHERE (cast(date_format(a.`CreateTime`, '%Y-%m-%d') as datetime) = cast(date_format(now(), '%Y-%m-%d') as datetime));
|
||||
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a__Type.`Time` as7, a.`Title` as8, a.`CreateTime` as9
|
||||
//FROM `tb_topic111333` a, `TestTypeInfo333` a__Type
|
||||
//WHERE (cast(date_format(a__Type.`Time`, '%Y-%m-%d') as datetime) > cast(date_format(now(), '%Y-%m-%d') as datetime));
|
||||
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a__Type.`Time` as7, a.`Title` as8, a.`CreateTime` as9
|
||||
//FROM `tb_topic111333` a, `TestTypeInfo333` a__Type, `TestTypeParentInfo23123` a__Type__Parent
|
||||
//WHERE (cast(date_format(a__Type__Parent.`Time2`, '%Y-%m-%d') as datetime) > cast(date_format(now(), '%Y-%m-%d') as datetime));
|
||||
data.Add(select.Where(a => DateTime.Now.Subtract(a.CreateTime.Date).TotalSeconds > 0).ToList());
|
||||
data.Add(select.Where(a => DateTime.Now.Subtract(a.Type.Time.Date).TotalSeconds > 0).ToList());
|
||||
data.Add(select.Where(a => DateTime.Now.Subtract(a.Type.Parent.Time2.Date).TotalSeconds > 0).ToList());
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5
|
||||
//FROM `tb_topic111333` a
|
||||
//WHERE (((timestampdiff(microsecond, cast(date_format(a.`CreateTime`, '%Y-%m-%d') as datetime), now())) / 1000000) > 0);
|
||||
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a__Type.`Time` as7, a.`Title` as8, a.`CreateTime` as9
|
||||
//FROM `tb_topic111333` a, `TestTypeInfo333` a__Type
|
||||
//WHERE (((timestampdiff(microsecond, cast(date_format(a__Type.`Time`, '%Y-%m-%d') as datetime), now())) / 1000000) > 0);
|
||||
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a__Type.`Time` as7, a.`Title` as8, a.`CreateTime` as9
|
||||
//FROM `tb_topic111333` a, `TestTypeInfo333` a__Type, `TestTypeParentInfo23123` a__Type__Parent
|
||||
//WHERE (((timestampdiff(microsecond, cast(date_format(a__Type__Parent.`Time2`, '%Y-%m-%d') as datetime), now())) / 1000000) > 0)
|
||||
}
|
||||
[Fact]
|
||||
public void TimeOfDay()
|
||||
{
|
||||
var data = new List<object>();
|
||||
data.Add(select.Where(a => a.CreateTime.TimeOfDay == DateTime.Now.TimeOfDay).ToList());
|
||||
data.Add(select.Where(a => a.Type.Time.TimeOfDay > DateTime.Now.TimeOfDay).ToList());
|
||||
data.Add(select.Where(a => a.Type.Parent.Time2.TimeOfDay > DateTime.Now.TimeOfDay).ToList());
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5
|
||||
//FROM `tb_topic111333` a
|
||||
//WHERE ((timestampdiff(microsecond, date_format(a.`CreateTime`, '1970-1-1 %H:%i:%s.%f'), a.`CreateTime`) + 62135596800000000) = (timestampdiff(microsecond, date_format(now(), '1970-1-1 %H:%i:%s.%f'), now()) + 62135596800000000));
|
||||
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a__Type.`Time` as7, a.`Title` as8, a.`CreateTime` as9
|
||||
//FROM `tb_topic111333` a, `TestTypeInfo333` a__Type
|
||||
//WHERE ((timestampdiff(microsecond, date_format(a__Type.`Time`, '1970-1-1 %H:%i:%s.%f'), a__Type.`Time`) + 62135596800000000) > (timestampdiff(microsecond, date_format(now(), '1970-1-1 %H:%i:%s.%f'), now()) + 62135596800000000));
|
||||
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a__Type.`Time` as7, a.`Title` as8, a.`CreateTime` as9
|
||||
//FROM `tb_topic111333` a, `TestTypeInfo333` a__Type, `TestTypeParentInfo23123` a__Type__Parent
|
||||
//WHERE ((timestampdiff(microsecond, date_format(a__Type__Parent.`Time2`, '1970-1-1 %H:%i:%s.%f'), a__Type__Parent.`Time2`) + 62135596800000000) > (timestampdiff(microsecond, date_format(now(), '1970-1-1 %H:%i:%s.%f'), now()) + 62135596800000000))
|
||||
}
|
||||
[Fact]
|
||||
public void DayOfWeek()
|
||||
{
|
||||
var data = new List<object>();
|
||||
data.Add(select.Where(a => a.CreateTime.DayOfWeek > DateTime.Now.DayOfWeek).ToList());
|
||||
data.Add(select.Where(a => a.Type.Time.DayOfWeek > DateTime.Now.DayOfWeek).ToList());
|
||||
data.Add(select.Where(a => a.Type.Parent.Time2.DayOfWeek > DateTime.Now.DayOfWeek).ToList());
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5
|
||||
//FROM `tb_topic111333` a
|
||||
//WHERE ((dayofweek(a.`CreateTime`) - 1) > (dayofweek(now()) - 1));
|
||||
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a__Type.`Time` as7, a.`Title` as8, a.`CreateTime` as9
|
||||
//FROM `tb_topic111333` a, `TestTypeInfo333` a__Type
|
||||
//WHERE ((dayofweek(a__Type.`Time`) - 1) > (dayofweek(now()) - 1));
|
||||
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a__Type.`Time` as7, a.`Title` as8, a.`CreateTime` as9
|
||||
//FROM `tb_topic111333` a, `TestTypeInfo333` a__Type, `TestTypeParentInfo23123` a__Type__Parent
|
||||
//WHERE ((dayofweek(a__Type__Parent.`Time2`) - 1) > (dayofweek(now()) - 1))
|
||||
}
|
||||
[Fact]
|
||||
public void Day()
|
||||
{
|
||||
var data = new List<object>();
|
||||
data.Add(select.Where(a => a.CreateTime.Day > DateTime.Now.Day).ToList());
|
||||
data.Add(select.Where(a => a.Type.Time.Day > DateTime.Now.Day).ToList());
|
||||
data.Add(select.Where(a => a.Type.Parent.Time2.Day > DateTime.Now.Day).ToList());
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5
|
||||
//FROM `tb_topic111333` a
|
||||
//WHERE (dayofmonth(a.`CreateTime`) > dayofmonth(now()));
|
||||
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a__Type.`Time` as7, a.`Title` as8, a.`CreateTime` as9
|
||||
//FROM `tb_topic111333` a, `TestTypeInfo333` a__Type
|
||||
//WHERE (dayofmonth(a__Type.`Time`) > dayofmonth(now()));
|
||||
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a__Type.`Time` as7, a.`Title` as8, a.`CreateTime` as9
|
||||
//FROM `tb_topic111333` a, `TestTypeInfo333` a__Type, `TestTypeParentInfo23123` a__Type__Parent
|
||||
//WHERE (dayofmonth(a__Type__Parent.`Time2`) > dayofmonth(now()))
|
||||
}
|
||||
[Fact]
|
||||
public void DayOfYear()
|
||||
{
|
||||
var data = new List<object>();
|
||||
data.Add(select.Where(a => a.CreateTime.DayOfYear > DateTime.Now.DayOfYear).ToList());
|
||||
data.Add(select.Where(a => a.Type.Time.DayOfYear > DateTime.Now.DayOfYear).ToList());
|
||||
data.Add(select.Where(a => a.Type.Parent.Time2.DayOfYear > DateTime.Now.DayOfYear).ToList());
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5
|
||||
//FROM `tb_topic111333` a
|
||||
//WHERE (dayofyear(a.`CreateTime`) > dayofyear(now()));
|
||||
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a__Type.`Time` as7, a.`Title` as8, a.`CreateTime` as9
|
||||
//FROM `tb_topic111333` a, `TestTypeInfo333` a__Type
|
||||
//WHERE (dayofyear(a__Type.`Time`) > dayofyear(now()));
|
||||
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a__Type.`Time` as7, a.`Title` as8, a.`CreateTime` as9
|
||||
//FROM `tb_topic111333` a, `TestTypeInfo333` a__Type, `TestTypeParentInfo23123` a__Type__Parent
|
||||
//WHERE (dayofyear(a__Type__Parent.`Time2`) > dayofyear(now()))
|
||||
}
|
||||
[Fact]
|
||||
public void Month()
|
||||
{
|
||||
var data = new List<object>();
|
||||
data.Add(select.Where(a => a.CreateTime.Month > DateTime.Now.Month).ToList());
|
||||
data.Add(select.Where(a => a.Type.Time.Month > DateTime.Now.Month).ToList());
|
||||
data.Add(select.Where(a => a.Type.Parent.Time2.Month > DateTime.Now.Month).ToList());
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5
|
||||
//FROM `tb_topic111333` a
|
||||
//WHERE (month(a.`CreateTime`) > month(now()));
|
||||
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a__Type.`Time` as7, a.`Title` as8, a.`CreateTime` as9
|
||||
//FROM `tb_topic111333` a, `TestTypeInfo333` a__Type
|
||||
//WHERE (month(a__Type.`Time`) > month(now()));
|
||||
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a__Type.`Time` as7, a.`Title` as8, a.`CreateTime` as9
|
||||
//FROM `tb_topic111333` a, `TestTypeInfo333` a__Type, `TestTypeParentInfo23123` a__Type__Parent
|
||||
//WHERE (month(a__Type__Parent.`Time2`) > month(now()))
|
||||
}
|
||||
[Fact]
|
||||
public void Year()
|
||||
{
|
||||
var data = new List<object>();
|
||||
data.Add(select.Where(a => a.CreateTime.Year > DateTime.Now.Year).ToList());
|
||||
data.Add(select.Where(a => a.Type.Time.Year > DateTime.Now.Year).ToList());
|
||||
data.Add(select.Where(a => a.Type.Parent.Time2.Year > DateTime.Now.Year).ToList());
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5
|
||||
//FROM `tb_topic111333` a
|
||||
//WHERE (year(a.`CreateTime`) > year(now()));
|
||||
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a__Type.`Time` as7, a.`Title` as8, a.`CreateTime` as9
|
||||
//FROM `tb_topic111333` a, `TestTypeInfo333` a__Type
|
||||
//WHERE (year(a__Type.`Time`) > year(now()));
|
||||
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a__Type.`Time` as7, a.`Title` as8, a.`CreateTime` as9
|
||||
//FROM `tb_topic111333` a, `TestTypeInfo333` a__Type, `TestTypeParentInfo23123` a__Type__Parent
|
||||
//WHERE (year(a__Type__Parent.`Time2`) > year(now()))
|
||||
}
|
||||
[Fact]
|
||||
public void Hour()
|
||||
{
|
||||
var data = new List<object>();
|
||||
data.Add(select.Where(a => a.CreateTime.Hour > DateTime.Now.Hour).ToList());
|
||||
data.Add(select.Where(a => a.Type.Time.Hour > DateTime.Now.Hour).ToList());
|
||||
data.Add(select.Where(a => a.Type.Parent.Time2.Hour > DateTime.Now.Hour).ToList());
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5
|
||||
//FROM `tb_topic111333` a
|
||||
//WHERE (hour(a.`CreateTime`) > hour(now()));
|
||||
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a__Type.`Time` as7, a.`Title` as8, a.`CreateTime` as9
|
||||
//FROM `tb_topic111333` a, `TestTypeInfo333` a__Type
|
||||
//WHERE (hour(a__Type.`Time`) > hour(now()));
|
||||
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a__Type.`Time` as7, a.`Title` as8, a.`CreateTime` as9
|
||||
//FROM `tb_topic111333` a, `TestTypeInfo333` a__Type, `TestTypeParentInfo23123` a__Type__Parent
|
||||
//WHERE (hour(a__Type__Parent.`Time2`) > hour(now()))
|
||||
}
|
||||
[Fact]
|
||||
public void Minute()
|
||||
{
|
||||
var data = new List<object>();
|
||||
data.Add(select.Where(a => a.CreateTime.Minute > DateTime.Now.Minute).ToList());
|
||||
data.Add(select.Where(a => a.Type.Time.Minute > DateTime.Now.Minute).ToList());
|
||||
data.Add(select.Where(a => a.Type.Parent.Time2.Minute > DateTime.Now.Minute).ToList());
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5
|
||||
//FROM `tb_topic111333` a
|
||||
//WHERE (minute(a.`CreateTime`) > minute(now()));
|
||||
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a__Type.`Time` as7, a.`Title` as8, a.`CreateTime` as9
|
||||
//FROM `tb_topic111333` a, `TestTypeInfo333` a__Type
|
||||
//WHERE (minute(a__Type.`Time`) > minute(now()));
|
||||
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a__Type.`Time` as7, a.`Title` as8, a.`CreateTime` as9
|
||||
//FROM `tb_topic111333` a, `TestTypeInfo333` a__Type, `TestTypeParentInfo23123` a__Type__Parent
|
||||
//WHERE (minute(a__Type__Parent.`Time2`) > minute(now()))
|
||||
}
|
||||
[Fact]
|
||||
public void Second()
|
||||
{
|
||||
var data = new List<object>();
|
||||
data.Add(select.Where(a => a.CreateTime.Second > DateTime.Now.Second).ToList());
|
||||
data.Add(select.Where(a => a.Type.Time.Second > DateTime.Now.Second).ToList());
|
||||
data.Add(select.Where(a => a.Type.Parent.Time2.Second > DateTime.Now.Second).ToList());
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5
|
||||
//FROM `tb_topic111333` a
|
||||
//WHERE (second(a.`CreateTime`) > second(now()));
|
||||
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a__Type.`Time` as7, a.`Title` as8, a.`CreateTime` as9
|
||||
//FROM `tb_topic111333` a, `TestTypeInfo333` a__Type
|
||||
//WHERE (second(a__Type.`Time`) > second(now()));
|
||||
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a__Type.`Time` as7, a.`Title` as8, a.`CreateTime` as9
|
||||
//FROM `tb_topic111333` a, `TestTypeInfo333` a__Type, `TestTypeParentInfo23123` a__Type__Parent
|
||||
//WHERE (second(a__Type__Parent.`Time2`) > second(now()))
|
||||
}
|
||||
[Fact]
|
||||
public void Millisecond()
|
||||
{
|
||||
var data = new List<object>();
|
||||
data.Add(select.Where(a => a.CreateTime.Millisecond > DateTime.Now.Millisecond).ToList());
|
||||
data.Add(select.Where(a => a.Type.Time.Millisecond > DateTime.Now.Millisecond).ToList());
|
||||
data.Add(select.Where(a => a.Type.Parent.Time2.Millisecond > DateTime.Now.Millisecond).ToList());
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5
|
||||
//FROM `tb_topic111333` a
|
||||
//WHERE (floor(microsecond(a.`CreateTime`) / 1000) > floor(microsecond(now()) / 1000));
|
||||
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a__Type.`Time` as7, a.`Title` as8, a.`CreateTime` as9
|
||||
//FROM `tb_topic111333` a, `TestTypeInfo333` a__Type
|
||||
//WHERE (floor(microsecond(a__Type.`Time`) / 1000) > floor(microsecond(now()) / 1000));
|
||||
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a__Type.`Time` as7, a.`Title` as8, a.`CreateTime` as9
|
||||
//FROM `tb_topic111333` a, `TestTypeInfo333` a__Type, `TestTypeParentInfo23123` a__Type__Parent
|
||||
//WHERE (floor(microsecond(a__Type__Parent.`Time2`) / 1000) > floor(microsecond(now()) / 1000))
|
||||
}
|
||||
[Fact]
|
||||
public void Ticks()
|
||||
{
|
||||
var data = new List<object>();
|
||||
data.Add(select.Where(a => a.CreateTime.Ticks > DateTime.Now.Ticks).ToList());
|
||||
data.Add(select.Where(a => a.Type.Time.Ticks > DateTime.Now.Ticks).ToList());
|
||||
data.Add(select.Where(a => a.Type.Parent.Time2.Ticks > DateTime.Now.Ticks).ToList());
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5
|
||||
//FROM `tb_topic111333` a
|
||||
//WHERE ((timestampdiff(microsecond, '1970-1-1', a.`CreateTime`) * 10 + 621355968000000000) > (timestampdiff(microsecond, '1970-1-1', now()) * 10 + 621355968000000000));
|
||||
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a__Type.`Time` as7, a.`Title` as8, a.`CreateTime` as9
|
||||
//FROM `tb_topic111333` a, `TestTypeInfo333` a__Type
|
||||
//WHERE ((timestampdiff(microsecond, '1970-1-1', a__Type.`Time`) * 10 + 621355968000000000) > (timestampdiff(microsecond, '1970-1-1', now()) * 10 + 621355968000000000));
|
||||
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a__Type.`Time` as7, a.`Title` as8, a.`CreateTime` as9
|
||||
//FROM `tb_topic111333` a, `TestTypeInfo333` a__Type, `TestTypeParentInfo23123` a__Type__Parent
|
||||
//WHERE ((timestampdiff(microsecond, '1970-1-1', a__Type__Parent.`Time2`) * 10 + 621355968000000000) > (timestampdiff(microsecond, '1970-1-1', now()) * 10 + 621355968000000000))
|
||||
}
|
||||
[Fact]
|
||||
public void Add()
|
||||
{
|
||||
var data = new List<object>();
|
||||
data.Add(select.Where(a => a.CreateTime.Add(TimeSpan.FromDays(1)) > DateTime.Now).ToList());
|
||||
data.Add(select.Where(a => a.Type.Time.Add(TimeSpan.FromDays(1)) > DateTime.Now).ToList());
|
||||
data.Add(select.Where(a => a.Type.Parent.Time2.Add(TimeSpan.FromDays(1)) > DateTime.Now).ToList());
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5
|
||||
//FROM `tb_topic111333` a
|
||||
//WHERE (date_add(a.`CreateTime`, interval ((1 * 86400000000)) microsecond) > now());
|
||||
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a__Type.`Time` as7, a.`Title` as8, a.`CreateTime` as9
|
||||
//FROM `tb_topic111333` a, `TestTypeInfo333` a__Type
|
||||
//WHERE (date_add(a__Type.`Time`, interval ((1 * 86400000000)) microsecond) > now());
|
||||
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a__Type.`Time` as7, a.`Title` as8, a.`CreateTime` as9
|
||||
//FROM `tb_topic111333` a, `TestTypeInfo333` a__Type, `TestTypeParentInfo23123` a__Type__Parent
|
||||
//WHERE (date_add(a__Type__Parent.`Time2`, interval ((1 * 86400000000)) microsecond) > now())
|
||||
}
|
||||
[Fact]
|
||||
public void AddDays()
|
||||
{
|
||||
var data = new List<object>();
|
||||
data.Add(select.Where(a => a.CreateTime.AddDays(1) > DateTime.Now).ToList());
|
||||
data.Add(select.Where(a => a.Type.Time.AddDays(1) > DateTime.Now).ToList());
|
||||
data.Add(select.Where(a => a.Type.Parent.Time2.AddDays(1) > DateTime.Now).ToList());
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5
|
||||
//FROM `tb_topic111333` a
|
||||
//WHERE (date_add(a.`CreateTime`, interval (1) day) > now());
|
||||
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a__Type.`Time` as7, a.`Title` as8, a.`CreateTime` as9
|
||||
//FROM `tb_topic111333` a, `TestTypeInfo333` a__Type
|
||||
//WHERE (date_add(a__Type.`Time`, interval (1) day) > now());
|
||||
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a__Type.`Time` as7, a.`Title` as8, a.`CreateTime` as9
|
||||
//FROM `tb_topic111333` a, `TestTypeInfo333` a__Type, `TestTypeParentInfo23123` a__Type__Parent
|
||||
//WHERE (date_add(a__Type__Parent.`Time2`, interval (1) day) > now())
|
||||
}
|
||||
[Fact]
|
||||
public void AddHours()
|
||||
{
|
||||
var data = new List<object>();
|
||||
data.Add(select.Where(a => a.CreateTime.AddHours(1) > DateTime.Now).ToList());
|
||||
data.Add(select.Where(a => a.Type.Time.AddHours(1) > DateTime.Now).ToList());
|
||||
data.Add(select.Where(a => a.Type.Parent.Time2.AddHours(1) > DateTime.Now).ToList());
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5
|
||||
//FROM `tb_topic111333` a
|
||||
//WHERE (date_add(a.`CreateTime`, interval (1) hour) > now());
|
||||
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a__Type.`Time` as7, a.`Title` as8, a.`CreateTime` as9
|
||||
//FROM `tb_topic111333` a, `TestTypeInfo333` a__Type
|
||||
//WHERE (date_add(a__Type.`Time`, interval (1) hour) > now());
|
||||
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a__Type.`Time` as7, a.`Title` as8, a.`CreateTime` as9
|
||||
//FROM `tb_topic111333` a, `TestTypeInfo333` a__Type, `TestTypeParentInfo23123` a__Type__Parent
|
||||
//WHERE (date_add(a__Type__Parent.`Time2`, interval (1) hour) > now())
|
||||
}
|
||||
[Fact]
|
||||
public void AddMilliseconds()
|
||||
{
|
||||
var data = new List<object>();
|
||||
data.Add(select.Where(a => a.CreateTime.AddMilliseconds(1) > DateTime.Now).ToList());
|
||||
data.Add(select.Where(a => a.Type.Time.AddMilliseconds(1) > DateTime.Now).ToList());
|
||||
data.Add(select.Where(a => a.Type.Parent.Time2.AddMilliseconds(1) > DateTime.Now).ToList());
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5
|
||||
//FROM `tb_topic111333` a
|
||||
//WHERE (date_add(a.`CreateTime`, interval (1) * 1000 microsecond) > now());
|
||||
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a__Type.`Time` as7, a.`Title` as8, a.`CreateTime` as9
|
||||
//FROM `tb_topic111333` a, `TestTypeInfo333` a__Type
|
||||
//WHERE (date_add(a__Type.`Time`, interval (1) * 1000 microsecond) > now());
|
||||
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a__Type.`Time` as7, a.`Title` as8, a.`CreateTime` as9
|
||||
//FROM `tb_topic111333` a, `TestTypeInfo333` a__Type, `TestTypeParentInfo23123` a__Type__Parent
|
||||
//WHERE (date_add(a__Type__Parent.`Time2`, interval (1) * 1000 microsecond) > now())
|
||||
}
|
||||
[Fact]
|
||||
public void AddMinutes()
|
||||
{
|
||||
var data = new List<object>();
|
||||
data.Add(select.Where(a => a.CreateTime.AddMinutes(1) > DateTime.Now).ToList());
|
||||
data.Add(select.Where(a => a.Type.Time.AddMinutes(1) > DateTime.Now).ToList());
|
||||
data.Add(select.Where(a => a.Type.Parent.Time2.AddMinutes(1) > DateTime.Now).ToList());
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5
|
||||
//FROM `tb_topic111333` a
|
||||
//WHERE (date_add(a.`CreateTime`, interval (1) minute) > now());
|
||||
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a__Type.`Time` as7, a.`Title` as8, a.`CreateTime` as9
|
||||
//FROM `tb_topic111333` a, `TestTypeInfo333` a__Type
|
||||
//WHERE (date_add(a__Type.`Time`, interval (1) minute) > now());
|
||||
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a__Type.`Time` as7, a.`Title` as8, a.`CreateTime` as9
|
||||
//FROM `tb_topic111333` a, `TestTypeInfo333` a__Type, `TestTypeParentInfo23123` a__Type__Parent
|
||||
//WHERE (date_add(a__Type__Parent.`Time2`, interval (1) minute) > now())
|
||||
}
|
||||
[Fact]
|
||||
public void AddMonths()
|
||||
{
|
||||
var data = new List<object>();
|
||||
data.Add(select.Where(a => a.CreateTime.AddMonths(1) > DateTime.Now).ToList());
|
||||
data.Add(select.Where(a => a.Type.Time.AddMonths(1) > DateTime.Now).ToList());
|
||||
data.Add(select.Where(a => a.Type.Parent.Time2.AddMonths(1) > DateTime.Now).ToList());
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5
|
||||
//FROM `tb_topic111333` a
|
||||
//WHERE (date_add(a.`CreateTime`, interval (1) month) > now());
|
||||
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a__Type.`Time` as7, a.`Title` as8, a.`CreateTime` as9
|
||||
//FROM `tb_topic111333` a, `TestTypeInfo333` a__Type
|
||||
//WHERE (date_add(a__Type.`Time`, interval (1) month) > now());
|
||||
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a__Type.`Time` as7, a.`Title` as8, a.`CreateTime` as9
|
||||
//FROM `tb_topic111333` a, `TestTypeInfo333` a__Type, `TestTypeParentInfo23123` a__Type__Parent
|
||||
//WHERE (date_add(a__Type__Parent.`Time2`, interval (1) month) > now())
|
||||
}
|
||||
[Fact]
|
||||
public void AddSeconds()
|
||||
{
|
||||
var data = new List<object>();
|
||||
data.Add(select.Where(a => a.CreateTime.AddSeconds(1) > DateTime.Now).ToList());
|
||||
data.Add(select.Where(a => a.Type.Time.AddSeconds(1) > DateTime.Now).ToList());
|
||||
data.Add(select.Where(a => a.Type.Parent.Time2.AddSeconds(1) > DateTime.Now).ToList());
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5
|
||||
//FROM `tb_topic111333` a
|
||||
//WHERE (date_add(a.`CreateTime`, interval (1) second) > now());
|
||||
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a__Type.`Time` as7, a.`Title` as8, a.`CreateTime` as9
|
||||
//FROM `tb_topic111333` a, `TestTypeInfo333` a__Type
|
||||
//WHERE (date_add(a__Type.`Time`, interval (1) second) > now());
|
||||
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a__Type.`Time` as7, a.`Title` as8, a.`CreateTime` as9
|
||||
//FROM `tb_topic111333` a, `TestTypeInfo333` a__Type, `TestTypeParentInfo23123` a__Type__Parent
|
||||
//WHERE (date_add(a__Type__Parent.`Time2`, interval (1) second) > now())
|
||||
}
|
||||
[Fact]
|
||||
public void AddTicks()
|
||||
{
|
||||
var data = new List<object>();
|
||||
data.Add(select.Where(a => a.CreateTime.AddTicks(1) > DateTime.Now).ToList());
|
||||
data.Add(select.Where(a => a.Type.Time.AddTicks(1) > DateTime.Now).ToList());
|
||||
data.Add(select.Where(a => a.Type.Parent.Time2.AddTicks(1) > DateTime.Now).ToList());
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5
|
||||
//FROM `tb_topic111333` a
|
||||
//WHERE (date_add(a.`CreateTime`, interval (1) / 10 microsecond) > now());
|
||||
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a__Type.`Time` as7, a.`Title` as8, a.`CreateTime` as9
|
||||
//FROM `tb_topic111333` a, `TestTypeInfo333` a__Type
|
||||
//WHERE (date_add(a__Type.`Time`, interval (1) / 10 microsecond) > now());
|
||||
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a__Type.`Time` as7, a.`Title` as8, a.`CreateTime` as9
|
||||
//FROM `tb_topic111333` a, `TestTypeInfo333` a__Type, `TestTypeParentInfo23123` a__Type__Parent
|
||||
//WHERE (date_add(a__Type__Parent.`Time2`, interval (1) / 10 microsecond) > now())
|
||||
}
|
||||
[Fact]
|
||||
public void AddYears()
|
||||
{
|
||||
var data = new List<object>();
|
||||
data.Add(select.Where(a => a.CreateTime.AddYears(1) > DateTime.Now).ToList());
|
||||
data.Add(select.Where(a => a.Type.Time.AddYears(1) > DateTime.Now).ToList());
|
||||
data.Add(select.Where(a => a.Type.Parent.Time2.AddYears(1) > DateTime.Now).ToList());
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5
|
||||
//FROM `tb_topic111333` a
|
||||
//WHERE (date_add(a.`CreateTime`, interval (1) year) > now());
|
||||
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a__Type.`Time` as7, a.`Title` as8, a.`CreateTime` as9
|
||||
//FROM `tb_topic111333` a, `TestTypeInfo333` a__Type
|
||||
//WHERE (date_add(a__Type.`Time`, interval (1) year) > now());
|
||||
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a__Type.`Time` as7, a.`Title` as8, a.`CreateTime` as9
|
||||
//FROM `tb_topic111333` a, `TestTypeInfo333` a__Type, `TestTypeParentInfo23123` a__Type__Parent
|
||||
//WHERE (date_add(a__Type__Parent.`Time2`, interval (1) year) > now())
|
||||
}
|
||||
[Fact]
|
||||
public void Subtract()
|
||||
{
|
||||
var data = new List<object>();
|
||||
data.Add(select.Where(a => a.CreateTime.Subtract(DateTime.Now).TotalSeconds > 0).ToList());
|
||||
data.Add(select.Where(a => a.Type.Time.Subtract(DateTime.Now).TotalSeconds > 0).ToList());
|
||||
data.Add(select.Where(a => a.Type.Parent.Time2.Subtract(DateTime.Now).TotalSeconds > 0).ToList());
|
||||
//SELECT a."ID", a."CLICKS", a."TYPEGUID", a."TITLE", a."CREATETIME"
|
||||
//FROM "TB_TOPIC111333" a
|
||||
//WHERE ((extract(day from (systimestamp-a."CREATETIME"))*86400+extract(hour from (systimestamp-a."CREATETIME"))*3600+extract(minute from (systimestamp-a."CREATETIME"))*60+extract(second from (systimestamp-a."CREATETIME"))) > 0)
|
||||
|
||||
//SELECT a."ID", a."CLICKS", a."TYPEGUID", a__Type."GUID", a__Type."PARENTID", a__Type."NAME", a__Type."TIME", a."TITLE", a."CREATETIME"
|
||||
//FROM "TB_TOPIC111333" a
|
||||
//LEFT JOIN "TESTTYPEINFO333" a__Type ON a__Type."GUID" = a."TYPEGUID"
|
||||
//WHERE ((extract(day from (systimestamp-a__Type."TIME"))*86400+extract(hour from (systimestamp-a__Type."TIME"))*3600+extract(minute from (systimestamp-a__Type."TIME"))*60+extract(second from (systimestamp-a__Type."TIME"))) > 0)
|
||||
|
||||
//SELECT a."ID", a."CLICKS", a."TYPEGUID", a__Type."GUID", a__Type."PARENTID", a__Type."NAME", a__Type."TIME", a."TITLE", a."CREATETIME"
|
||||
//FROM "TB_TOPIC111333" a
|
||||
//LEFT JOIN "TESTTYPEINFO333" a__Type ON a__Type."GUID" = a."TYPEGUID"
|
||||
//LEFT JOIN "TESTTYPEPARENTINF1" a__Type__Parent ON a__Type__Parent."ID" = a__Type."PARENTID"
|
||||
//WHERE ((extract(day from (systimestamp-a__Type__Parent."TIME2"))*86400+extract(hour from (systimestamp-a__Type__Parent."TIME2"))*3600+extract(minute from (systimestamp-a__Type__Parent."TIME2"))*60+extract(second from (systimestamp-a__Type__Parent."TIME2"))) > 0)
|
||||
data.Add(select.Where(a => a.CreateTime.Subtract(TimeSpan.FromDays(1)) > a.CreateTime).ToList());
|
||||
data.Add(select.Where(a => a.Type.Time.Subtract(TimeSpan.FromDays(1)) > a.CreateTime).ToList());
|
||||
data.Add(select.Where(a => a.Type.Parent.Time2.Subtract(TimeSpan.FromDays(1)) > a.CreateTime).ToList());
|
||||
//SELECT a."ID", a."CLICKS", a."TYPEGUID", a."TITLE", a."CREATETIME"
|
||||
//FROM "TB_TOPIC111333" a
|
||||
//WHERE ((a."CREATETIME"-numtodsinterval((1)*86400,'second')) > a."CREATETIME")
|
||||
//SELECT a."ID", a."CLICKS", a."TYPEGUID", a__Type."GUID", a__Type."PARENTID", a__Type."NAME", a__Type."TIME", a."TITLE", a."CREATETIME"
|
||||
|
||||
//FROM "TB_TOPIC111333" a
|
||||
//LEFT JOIN "TESTTYPEINFO333" a__Type ON a__Type."GUID" = a."TYPEGUID"
|
||||
//WHERE ((a__Type."TIME"-numtodsinterval((1)*86400,'second')) > a."CREATETIME")
|
||||
//SELECT a."ID", a."CLICKS", a."TYPEGUID", a__Type."GUID", a__Type."PARENTID", a__Type."NAME", a__Type."TIME", a."TITLE", a."CREATETIME"
|
||||
|
||||
//FROM "TB_TOPIC111333" a
|
||||
//LEFT JOIN "TESTTYPEINFO333" a__Type ON a__Type."GUID" = a."TYPEGUID"
|
||||
//LEFT JOIN "TESTTYPEPARENTINF1" a__Type__Parent ON a__Type__Parent."ID" = a__Type."PARENTID"
|
||||
//WHERE ((a__Type__Parent."TIME2"-numtodsinterval((1)*86400,'second')) > a."CREATETIME")
|
||||
}
|
||||
[Fact]
|
||||
public void Á½¸öÈÕÆÚÏà¼õ_Ч¹ûͬSubtract()
|
||||
{
|
||||
var data = new List<object>();
|
||||
data.Add(select.Where(a => (a.CreateTime - DateTime.Now).TotalSeconds > 0).ToList());
|
||||
data.Add(select.Where(a => (a.Type.Time - DateTime.Now).TotalSeconds > 0).ToList());
|
||||
data.Add(select.Where(a => (a.Type.Parent.Time2 - DateTime.Now).TotalSeconds > 0).ToList());
|
||||
//SELECT a."ID", a."CLICKS", a."TYPEGUID", a."TITLE", a."CREATETIME"
|
||||
//FROM "TB_TOPIC111333" a
|
||||
//WHERE ((extract(day from (systimestamp-a."CREATETIME"))*86400+extract(hour from (systimestamp-a."CREATETIME"))*3600+extract(minute from (systimestamp-a."CREATETIME"))*60+extract(second from (systimestamp-a."CREATETIME"))) > 0)
|
||||
|
||||
//SELECT a."ID", a."CLICKS", a."TYPEGUID", a__Type."GUID", a__Type."PARENTID", a__Type."NAME", a__Type."TIME", a."TITLE", a."CREATETIME"
|
||||
//FROM "TB_TOPIC111333" a
|
||||
//LEFT JOIN "TESTTYPEINFO333" a__Type ON a__Type."GUID" = a."TYPEGUID"
|
||||
//WHERE ((extract(day from (systimestamp-a__Type."TIME"))*86400+extract(hour from (systimestamp-a__Type."TIME"))*3600+extract(minute from (systimestamp-a__Type."TIME"))*60+extract(second from (systimestamp-a__Type."TIME"))) > 0)
|
||||
|
||||
//SELECT a."ID", a."CLICKS", a."TYPEGUID", a__Type."GUID", a__Type."PARENTID", a__Type."NAME", a__Type."TIME", a."TITLE", a."CREATETIME"
|
||||
//FROM "TB_TOPIC111333" a
|
||||
//LEFT JOIN "TESTTYPEINFO333" a__Type ON a__Type."GUID" = a."TYPEGUID"
|
||||
//LEFT JOIN "TESTTYPEPARENTINF1" a__Type__Parent ON a__Type__Parent."ID" = a__Type."PARENTID"
|
||||
//WHERE ((extract(day from (systimestamp-a__Type__Parent."TIME2"))*86400+extract(hour from (systimestamp-a__Type__Parent."TIME2"))*3600+extract(minute from (systimestamp-a__Type__Parent."TIME2"))*60+extract(second from (systimestamp-a__Type__Parent."TIME2"))) > 0)
|
||||
data.Add(select.Where(a => (a.CreateTime - TimeSpan.FromDays(1)) > a.CreateTime).ToList());
|
||||
data.Add(select.Where(a => (a.Type.Time - TimeSpan.FromDays(1)) > a.CreateTime).ToList());
|
||||
data.Add(select.Where(a => (a.Type.Parent.Time2 - TimeSpan.FromDays(1)) > a.CreateTime).ToList());
|
||||
//SELECT a."ID", a."CLICKS", a."TYPEGUID", a."TITLE", a."CREATETIME"
|
||||
//FROM "TB_TOPIC111333" a
|
||||
//WHERE ((a."CREATETIME"-numtodsinterval((1)*86400,'second')) > a."CREATETIME")
|
||||
//SELECT a."ID", a."CLICKS", a."TYPEGUID", a__Type."GUID", a__Type."PARENTID", a__Type."NAME", a__Type."TIME", a."TITLE", a."CREATETIME"
|
||||
|
||||
//FROM "TB_TOPIC111333" a
|
||||
//LEFT JOIN "TESTTYPEINFO333" a__Type ON a__Type."GUID" = a."TYPEGUID"
|
||||
//WHERE ((a__Type."TIME"-numtodsinterval((1)*86400,'second')) > a."CREATETIME")
|
||||
//SELECT a."ID", a."CLICKS", a."TYPEGUID", a__Type."GUID", a__Type."PARENTID", a__Type."NAME", a__Type."TIME", a."TITLE", a."CREATETIME"
|
||||
|
||||
//FROM "TB_TOPIC111333" a
|
||||
//LEFT JOIN "TESTTYPEINFO333" a__Type ON a__Type."GUID" = a."TYPEGUID"
|
||||
//LEFT JOIN "TESTTYPEPARENTINF1" a__Type__Parent ON a__Type__Parent."ID" = a__Type."PARENTID"
|
||||
//WHERE ((a__Type__Parent."TIME2"-numtodsinterval((1)*86400,'second')) > a."CREATETIME")
|
||||
}
|
||||
[Fact]
|
||||
public void this_Equals()
|
||||
{
|
||||
var data = new List<object>();
|
||||
data.Add(select.Where(a => a.CreateTime.AddYears(1).Equals(DateTime.Now)).ToList());
|
||||
data.Add(select.Where(a => a.Type.Time.AddYears(1).Equals(DateTime.Now)).ToList());
|
||||
data.Add(select.Where(a => a.Type.Parent.Time2.AddYears(1).Equals(DateTime.Now)).ToList());
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5
|
||||
//FROM `tb_topic111333` a
|
||||
//WHERE ((date_add(a.`CreateTime`, interval (1) year) = now()));
|
||||
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a__Type.`Time` as7, a.`Title` as8, a.`CreateTime` as9
|
||||
//FROM `tb_topic111333` a, `TestTypeInfo333` a__Type
|
||||
//WHERE ((date_add(a__Type.`Time`, interval (1) year) = now()));
|
||||
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a__Type.`Time` as7, a.`Title` as8, a.`CreateTime` as9
|
||||
//FROM `tb_topic111333` a, `TestTypeInfo333` a__Type, `TestTypeParentInfo23123` a__Type__Parent
|
||||
//WHERE ((date_add(a__Type__Parent.`Time2`, interval (1) year) = now()))
|
||||
}
|
||||
[Fact]
|
||||
public void this_ToString()
|
||||
{
|
||||
var data = new List<object>();
|
||||
data.Add(select.Where(a => a.CreateTime.ToString().Equals(DateTime.Now)).ToList());
|
||||
data.Add(select.Where(a => a.Type.Time.AddYears(1).ToString().Equals(DateTime.Now)).ToList());
|
||||
data.Add(select.Where(a => a.Type.Parent.Time2.AddYears(1).ToString().Equals(DateTime.Now)).ToList());
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5
|
||||
//FROM `tb_topic111333` a
|
||||
//WHERE ((date_format(a.`CreateTime`, '%Y-%m-%d %H:%i:%s.%f') = now()));
|
||||
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a__Type.`Time` as7, a.`Title` as8, a.`CreateTime` as9
|
||||
//FROM `tb_topic111333` a, `TestTypeInfo333` a__Type
|
||||
//WHERE ((date_format(date_add(a__Type.`Time`, interval (1) year), '%Y-%m-%d %H:%i:%s.%f') = now()));
|
||||
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a__Type.`Time` as7, a.`Title` as8, a.`CreateTime` as9
|
||||
//FROM `tb_topic111333` a, `TestTypeInfo333` a__Type, `TestTypeParentInfo23123` a__Type__Parent
|
||||
//WHERE ((date_format(date_add(a__Type__Parent.`Time2`, interval (1) year), '%Y-%m-%d %H:%i:%s.%f') = now()))
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void DateTime_Compare()
|
||||
{
|
||||
var data = new List<object>();
|
||||
data.Add(select.Where(a => a.CreateTime.CompareTo(DateTime.Now) == 0).ToList());
|
||||
data.Add(select.Where(a => a.Type.Time.AddYears(1).CompareTo(DateTime.Now) == 0).ToList());
|
||||
data.Add(select.Where(a => a.Type.Parent.Time2.AddYears(1).CompareTo(DateTime.Now) == 0).ToList());
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5
|
||||
//FROM `tb_topic111333` a
|
||||
//WHERE (((a.`CreateTime`) - (now())) = 0);
|
||||
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a__Type.`Time` as7, a.`Title` as8, a.`CreateTime` as9
|
||||
//FROM `tb_topic111333` a, `TestTypeInfo333` a__Type
|
||||
//WHERE (((date_add(a__Type.`Time`, interval (1) year)) - (now())) = 0);
|
||||
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a__Type.`Time` as7, a.`Title` as8, a.`CreateTime` as9
|
||||
//FROM `tb_topic111333` a, `TestTypeInfo333` a__Type, `TestTypeParentInfo23123` a__Type__Parent
|
||||
//WHERE (((date_add(a__Type__Parent.`Time2`, interval (1) year)) - (now())) = 0)
|
||||
}
|
||||
[Fact]
|
||||
public void DateTime_DaysInMonth()
|
||||
{
|
||||
var data = new List<object>();
|
||||
data.Add(select.Where(a => DateTime.DaysInMonth(a.CreateTime.Year, a.CreateTime.Month) > 30).ToList());
|
||||
data.Add(select.Where(a => DateTime.DaysInMonth(a.Type.Time.Year, a.Type.Time.Month) > 30).ToList());
|
||||
data.Add(select.Where(a => DateTime.DaysInMonth(a.Type.Parent.Time2.Year, a.Type.Parent.Time2.Month) > 30).ToList());
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5
|
||||
//FROM `tb_topic111333` a
|
||||
//WHERE (dayofmonth(last_day(concat(year(a.`CreateTime`), month(a.`CreateTime`), '-01'))) > 30);
|
||||
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a__Type.`Time` as7, a.`Title` as8, a.`CreateTime` as9
|
||||
//FROM `tb_topic111333` a, `TestTypeInfo333` a__Type
|
||||
//WHERE (dayofmonth(last_day(concat(year(a__Type.`Time`), month(a__Type.`Time`), '-01'))) > 30);
|
||||
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a__Type.`Time` as7, a.`Title` as8, a.`CreateTime` as9
|
||||
//FROM `tb_topic111333` a, `TestTypeInfo333` a__Type, `TestTypeParentInfo23123` a__Type__Parent
|
||||
//WHERE (dayofmonth(last_day(concat(year(a__Type__Parent.`Time2`), month(a__Type__Parent.`Time2`), '-01'))) > 30)
|
||||
}
|
||||
[Fact]
|
||||
public void DateTime_Equals()
|
||||
{
|
||||
var data = new List<object>();
|
||||
data.Add(select.Where(a => DateTime.Equals(a.CreateTime.AddYears(1), DateTime.Now)).ToList());
|
||||
data.Add(select.Where(a => DateTime.Equals(a.Type.Time.AddYears(1), DateTime.Now)).ToList());
|
||||
data.Add(select.Where(a => DateTime.Equals(a.Type.Parent.Time2.AddYears(1), DateTime.Now)).ToList());
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5
|
||||
//FROM `tb_topic111333` a
|
||||
//WHERE ((date_add(a.`CreateTime`, interval (1) year) = now()));
|
||||
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a__Type.`Time` as7, a.`Title` as8, a.`CreateTime` as9
|
||||
//FROM `tb_topic111333` a, `TestTypeInfo333` a__Type
|
||||
//WHERE ((date_add(a__Type.`Time`, interval (1) year) = now()));
|
||||
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a__Type.`Time` as7, a.`Title` as8, a.`CreateTime` as9
|
||||
//FROM `tb_topic111333` a, `TestTypeInfo333` a__Type, `TestTypeParentInfo23123` a__Type__Parent
|
||||
//WHERE ((date_add(a__Type__Parent.`Time2`, interval (1) year) = now()))
|
||||
}
|
||||
[Fact]
|
||||
public void DateTime_IsLeapYear()
|
||||
{
|
||||
var data = new List<object>();
|
||||
data.Add(select.Where(a => DateTime.IsLeapYear(a.CreateTime.Year)).ToList());
|
||||
data.Add(select.Where(a => DateTime.IsLeapYear(a.Type.Time.AddYears(1).Year)).ToList());
|
||||
data.Add(select.Where(a => DateTime.IsLeapYear(a.Type.Parent.Time2.AddYears(1).Year)).ToList());
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5
|
||||
//FROM `tb_topic111333` a
|
||||
//WHERE (((year(a.`CreateTime`)) % 4 = 0 AND (year(a.`CreateTime`)) % 100 <> 0 OR (year(a.`CreateTime`)) % 400 = 0));
|
||||
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a__Type.`Time` as7, a.`Title` as8, a.`CreateTime` as9
|
||||
//FROM `tb_topic111333` a, `TestTypeInfo333` a__Type
|
||||
//WHERE (((year(date_add(a__Type.`Time`, interval (1) year))) % 4 = 0 AND (year(date_add(a__Type.`Time`, interval (1) year))) % 100 <> 0 OR (year(date_add(a__Type.`Time`, interval (1) year))) % 400 = 0));
|
||||
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a__Type.`Time` as7, a.`Title` as8, a.`CreateTime` as9
|
||||
//FROM `tb_topic111333` a, `TestTypeInfo333` a__Type, `TestTypeParentInfo23123` a__Type__Parent
|
||||
//WHERE (((year(date_add(a__Type__Parent.`Time2`, interval (1) year))) % 4 = 0 AND (year(date_add(a__Type__Parent.`Time2`, interval (1) year))) % 100 <> 0 OR (year(date_add(a__Type__Parent.`Time2`, interval (1) year))) % 400 = 0))
|
||||
}
|
||||
[Fact]
|
||||
public void DateTime_Parse()
|
||||
{
|
||||
var data = new List<object>();
|
||||
data.Add(select.Where(a => DateTime.Parse(a.CreateTime.ToString()) > DateTime.Now).ToList());
|
||||
data.Add(select.Where(a => DateTime.Parse(a.Type.Time.AddYears(1).ToString()) > DateTime.Now).ToList());
|
||||
data.Add(select.Where(a => DateTime.Parse(a.Type.Parent.Time2.AddYears(1).ToString()) > DateTime.Now).ToList());
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5
|
||||
//FROM `tb_topic111333` a
|
||||
//WHERE (cast(date_format(a.`CreateTime`, '%Y-%m-%d %H:%i:%s.%f') as datetime) > now());
|
||||
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a__Type.`Time` as7, a.`Title` as8, a.`CreateTime` as9
|
||||
//FROM `tb_topic111333` a, `TestTypeInfo333` a__Type
|
||||
//WHERE (cast(date_format(date_add(a__Type.`Time`, interval (1) year), '%Y-%m-%d %H:%i:%s.%f') as datetime) > now());
|
||||
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a__Type.`Time` as7, a.`Title` as8, a.`CreateTime` as9
|
||||
//FROM `tb_topic111333` a, `TestTypeInfo333` a__Type, `TestTypeParentInfo23123` a__Type__Parent
|
||||
//WHERE (cast(date_format(date_add(a__Type__Parent.`Time2`, interval (1) year), '%Y-%m-%d %H:%i:%s.%f') as datetime) > now())
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,156 @@
|
||||
using FreeSql.DataAnnotations;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Xunit;
|
||||
|
||||
namespace FreeSql.Tests.Odbc.OracleExpression
|
||||
{
|
||||
public class MathTest
|
||||
{
|
||||
|
||||
ISelect<Topic> select => g.oracle.Select<Topic>();
|
||||
|
||||
[Table(Name = "tb_topic")]
|
||||
class Topic
|
||||
{
|
||||
[Column(IsIdentity = true, IsPrimary = true)]
|
||||
public int Id { get; set; }
|
||||
public int Clicks { get; set; }
|
||||
public int TypeGuid { get; set; }
|
||||
public TestTypeInfo Type { get; set; }
|
||||
public string Title { get; set; }
|
||||
public DateTime CreateTime { get; set; }
|
||||
}
|
||||
class TestTypeInfo
|
||||
{
|
||||
public int Guid { get; set; }
|
||||
public int ParentId { get; set; }
|
||||
public TestTypeParentInfo Parent { get; set; }
|
||||
public string Name { get; set; }
|
||||
}
|
||||
class TestTypeParentInfo
|
||||
{
|
||||
public int Id { get; set; }
|
||||
public string Name { get; set; }
|
||||
|
||||
public List<TestTypeInfo> Types { get; set; }
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void PI()
|
||||
{
|
||||
var data = new List<object>();
|
||||
data.Add(select.Where(a => Math.PI + a.Clicks > 0).ToList());
|
||||
}
|
||||
[Fact]
|
||||
public void Abs()
|
||||
{
|
||||
var data = new List<object>();
|
||||
data.Add(select.Where(a => Math.Abs(-a.Clicks) > 0).ToList());
|
||||
}
|
||||
[Fact]
|
||||
public void Sign()
|
||||
{
|
||||
var data = new List<object>();
|
||||
data.Add(select.Where(a => Math.Sign(-a.Clicks) > 0).ToList());
|
||||
}
|
||||
[Fact]
|
||||
public void Floor()
|
||||
{
|
||||
var data = new List<object>();
|
||||
data.Add(select.Where(a => Math.Floor(a.Clicks + 0.5) == a.Clicks).ToList());
|
||||
}
|
||||
[Fact]
|
||||
public void Ceiling()
|
||||
{
|
||||
var data = new List<object>();
|
||||
data.Add(select.Where(a => Math.Ceiling(a.Clicks + 0.5) == a.Clicks + 1).ToList());
|
||||
}
|
||||
[Fact]
|
||||
public void Round()
|
||||
{
|
||||
var data = new List<object>();
|
||||
data.Add(select.Where(a => Math.Round(a.Clicks + 0.5) == a.Clicks).ToList());
|
||||
data.Add(select.Where(a => Math.Round(a.Clicks + 0.5, 1) > a.Clicks).ToList());
|
||||
}
|
||||
[Fact]
|
||||
public void Exp()
|
||||
{
|
||||
var data = new List<object>();
|
||||
data.Add(select.Where(a => Math.Exp(1) == a.Clicks + 1).ToList());
|
||||
}
|
||||
[Fact]
|
||||
public void Log()
|
||||
{
|
||||
var data = new List<object>();
|
||||
data.Add(select.Where(a => Math.Log(a.Clicks + 0.5) == a.Clicks + 1).ToList());
|
||||
}
|
||||
[Fact]
|
||||
public void Log10()
|
||||
{
|
||||
var data = new List<object>();
|
||||
data.Add(select.Where(a => Math.Log10(a.Clicks + 0.5) == a.Clicks + 1).ToList());
|
||||
}
|
||||
[Fact]
|
||||
public void Pow()
|
||||
{
|
||||
var data = new List<object>();
|
||||
data.Add(select.Where(a => Math.Pow(2, a.Clicks % 5) == a.Clicks + 1).ToList());
|
||||
}
|
||||
[Fact]
|
||||
public void Sqrt()
|
||||
{
|
||||
var data = new List<object>();
|
||||
data.Add(select.Where(a => Math.Sqrt(Math.Pow(2, a.Clicks % 5)) == a.Clicks + 1).ToList());
|
||||
}
|
||||
[Fact]
|
||||
public void Cos()
|
||||
{
|
||||
var data = new List<object>();
|
||||
data.Add(select.Where(a => Math.Cos(Math.Pow(2, a.Clicks % 5)) == a.Clicks + 1).ToList());
|
||||
}
|
||||
[Fact]
|
||||
public void Sin()
|
||||
{
|
||||
var data = new List<object>();
|
||||
data.Add(select.Where(a => Math.Sin(Math.Pow(2, a.Clicks % 5)) == a.Clicks + 1).ToList());
|
||||
}
|
||||
[Fact]
|
||||
public void Tan()
|
||||
{
|
||||
var data = new List<object>();
|
||||
data.Add(select.Where(a => Math.Tan(Math.Pow(2, a.Clicks % 5)) == a.Clicks + 1).ToList());
|
||||
}
|
||||
[Fact]
|
||||
public void Acos()
|
||||
{
|
||||
var data = new List<object>();
|
||||
//data.Add(select.Where(a => Math.Acos(Math.Pow(2, a.Clicks % 5)) == a.Clicks + 1).ToList());
|
||||
}
|
||||
[Fact]
|
||||
public void Asin()
|
||||
{
|
||||
var data = new List<object>();
|
||||
//data.Add(select.Where(a => Math.Asin(Math.Pow(2, a.Clicks % 5)) == a.Clicks + 1).ToList());
|
||||
}
|
||||
[Fact]
|
||||
public void Atan()
|
||||
{
|
||||
var data = new List<object>();
|
||||
data.Add(select.Where(a => Math.Atan(Math.Pow(2, a.Clicks % 5)) == a.Clicks + 1).ToList());
|
||||
}
|
||||
[Fact]
|
||||
public void Atan2()
|
||||
{
|
||||
var data = new List<object>();
|
||||
//data.Add(select.Where(a => Math.Atan2(2, a.Clicks) == a.Clicks + 1).ToList());
|
||||
}
|
||||
[Fact]
|
||||
public void Truncate()
|
||||
{
|
||||
var data = new List<object>();
|
||||
data.Add(select.Where(a => Math.Truncate(a.Clicks * 1.0 / 3) == a.Clicks + 1).ToList());
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,135 @@
|
||||
using FreeSql.DataAnnotations;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Xunit;
|
||||
|
||||
namespace FreeSql.Tests.Odbc.OracleExpression
|
||||
{
|
||||
public class OtherTest
|
||||
{
|
||||
|
||||
ISelect<TableAllType> select => g.oracle.Select<TableAllType>();
|
||||
|
||||
public OtherTest()
|
||||
{
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Div()
|
||||
{
|
||||
var t1 = select.Where(a => a.Int / 3 > 3).Limit(10).ToList();
|
||||
var t2 = select.Where(a => a.Long / 3 > 3).Limit(10).ToList();
|
||||
var t3 = select.Where(a => a.Short / 3 > 3).Limit(10).ToList();
|
||||
|
||||
var t4 = select.Where(a => a.Int / 3.0 > 3).Limit(10).ToList();
|
||||
var t5 = select.Where(a => a.Long / 3.0 > 3).Limit(10).ToList();
|
||||
var t6 = select.Where(a => a.Short / 3.0 > 3).Limit(10).ToList();
|
||||
|
||||
var t7 = select.Where(a => a.Double / 3 > 3).Limit(10).ToList();
|
||||
var t8 = select.Where(a => a.Decimal / 3 > 3).Limit(10).ToList();
|
||||
var t9 = select.Where(a => a.Float / 3 > 3).Limit(10).ToList();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Boolean()
|
||||
{
|
||||
var t1 = select.Where(a => a.Bool == true).ToList();
|
||||
var t2 = select.Where(a => a.Bool != true).ToList();
|
||||
var t3 = select.Where(a => a.Bool == false).ToList();
|
||||
var t4 = select.Where(a => !a.Bool).ToList();
|
||||
var t5 = select.Where(a => a.Bool).ToList();
|
||||
|
||||
var t11 = select.Where(a => a.BoolNullable == true).ToList();
|
||||
var t22 = select.Where(a => a.BoolNullable != true).ToList();
|
||||
var t33 = select.Where(a => a.BoolNullable == false).ToList();
|
||||
var t44 = select.Where(a => !a.BoolNullable.Value).ToList();
|
||||
var t55 = select.Where(a => a.BoolNullable.Value).ToList();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Array()
|
||||
{
|
||||
IEnumerable<int> testlinqlist = new List<int>(new[] { 1, 2, 3 });
|
||||
var testlinq = select.Where(a => testlinqlist.Contains(a.Int)).ToList();
|
||||
|
||||
//in not in
|
||||
var sql111 = select.Where(a => new[] { 1, 2, 3 }.Contains(a.Int)).ToList();
|
||||
//var sql112 = select.Where(a => new[] { 1, 2, 3 }.Contains(a.Int) == false).ToList();
|
||||
var sql113 = select.Where(a => !new[] { 1, 2, 3 }.Contains(a.Int)).ToList();
|
||||
|
||||
var inarray = new[] { 1, 2, 3 };
|
||||
var sql1111 = select.Where(a => inarray.Contains(a.Int)).ToList();
|
||||
//var sql1122 = select.Where(a => inarray.Contains(a.Int) == false).ToList();
|
||||
var sql1133 = select.Where(a => !inarray.Contains(a.Int)).ToList();
|
||||
|
||||
|
||||
//in not in
|
||||
var sql11111 = select.Where(a => new List<int>() { 1, 2, 3 }.Contains(a.Int)).ToList();
|
||||
//var sql11222 = select.Where(a => new List<int>() { 1, 2, 3 }.Contains(a.Int) == false).ToList();
|
||||
var sql11333 = select.Where(a => !new List<int>() { 1, 2, 3 }.Contains(a.Int)).ToList();
|
||||
|
||||
var sql11111a = select.Where(a => new List<int>(new[] { 1, 2, 3 }).Contains(a.Int)).ToList();
|
||||
//var sql11222b = select.Where(a => new List<int>(new[] { 1, 2, 3 }).Contains(a.Int) == false).ToList();
|
||||
var sql11333c = select.Where(a => !new List<int>(new[] { 1, 2, 3 }).Contains(a.Int)).ToList();
|
||||
|
||||
var inarray2 = new List<int>() { 1, 2, 3 };
|
||||
var sql111111 = select.Where(a => inarray.Contains(a.Int)).ToList();
|
||||
//var sql112222 = select.Where(a => inarray.Contains(a.Int) == false).ToList();
|
||||
var sql113333 = select.Where(a => !inarray.Contains(a.Int)).ToList();
|
||||
}
|
||||
|
||||
[Table(Name = "tb_alltype")]
|
||||
class TableAllType
|
||||
{
|
||||
[Column(IsIdentity = true, IsPrimary = true)]
|
||||
public int Id { get; set; }
|
||||
|
||||
public string id2 { get; set; } = "id2=10";
|
||||
|
||||
public bool Bool { get; set; }
|
||||
public sbyte SByte { get; set; }
|
||||
public short Short { get; set; }
|
||||
public int Int { get; set; }
|
||||
public long Long { get; set; }
|
||||
public byte Byte { get; set; }
|
||||
public ushort UShort { get; set; }
|
||||
public uint UInt { get; set; }
|
||||
public ulong ULong { get; set; }
|
||||
public double Double { get; set; }
|
||||
public float Float { get; set; }
|
||||
public decimal Decimal { get; set; }
|
||||
public TimeSpan TimeSpan { get; set; }
|
||||
public DateTime DateTime { get; set; }
|
||||
public DateTime DateTimeOffSet { get; set; }
|
||||
public byte[] Bytes { get; set; }
|
||||
public string String { get; set; }
|
||||
public Guid Guid { get; set; }
|
||||
|
||||
public bool? BoolNullable { get; set; }
|
||||
public sbyte? SByteNullable { get; set; }
|
||||
public short? ShortNullable { get; set; }
|
||||
public int? IntNullable { get; set; }
|
||||
public long? testFielLongNullable { get; set; }
|
||||
public byte? ByteNullable { get; set; }
|
||||
public ushort? UShortNullable { get; set; }
|
||||
public uint? UIntNullable { get; set; }
|
||||
public ulong? ULongNullable { get; set; }
|
||||
public double? DoubleNullable { get; set; }
|
||||
public float? FloatNullable { get; set; }
|
||||
public decimal? DecimalNullable { get; set; }
|
||||
public TimeSpan? TimeSpanNullable { get; set; }
|
||||
public DateTime? DateTimeNullable { get; set; }
|
||||
public DateTime? DateTimeOffSetNullable { get; set; }
|
||||
public Guid? GuidNullable { get; set; }
|
||||
|
||||
public TableAllTypeEnumType1 Enum1 { get; set; }
|
||||
public TableAllTypeEnumType1? Enum1Nullable { get; set; }
|
||||
public TableAllTypeEnumType2 Enum2 { get; set; }
|
||||
public TableAllTypeEnumType2? Enum2Nullable { get; set; }
|
||||
}
|
||||
|
||||
public enum TableAllTypeEnumType1 { e1, e2, e3, e5 }
|
||||
[Flags] public enum TableAllTypeEnumType2 { f1, f2, f3 }
|
||||
}
|
||||
}
|
@ -0,0 +1,726 @@
|
||||
using FreeSql.DataAnnotations;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Xunit;
|
||||
|
||||
namespace FreeSql.Tests.Odbc.OracleExpression
|
||||
{
|
||||
public class StringTest
|
||||
{
|
||||
|
||||
ISelect<Topic> select => g.oracle.Select<Topic>();
|
||||
|
||||
[Table(Name = "tb_topic")]
|
||||
class Topic
|
||||
{
|
||||
[Column(IsIdentity = true, IsPrimary = true)]
|
||||
public int Id { get; set; }
|
||||
public int Clicks { get; set; }
|
||||
public int TypeGuid { get; set; }
|
||||
public TestTypeInfo Type { get; set; }
|
||||
public string Title { get; set; }
|
||||
public DateTime CreateTime { get; set; }
|
||||
}
|
||||
class TestTypeInfo
|
||||
{
|
||||
[Column(IsIdentity = true)]
|
||||
public int Guid { get; set; }
|
||||
public int ParentId { get; set; }
|
||||
public TestTypeParentInfo Parent { get; set; }
|
||||
public string Name { get; set; }
|
||||
}
|
||||
class TestTypeParentInfo
|
||||
{
|
||||
public int Id { get; set; }
|
||||
public string Name { get; set; }
|
||||
|
||||
public List<TestTypeInfo> Types { get; set; }
|
||||
}
|
||||
class TestEqualsGuid
|
||||
{
|
||||
public Guid id { get; set; }
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Equals__()
|
||||
{
|
||||
var list = new List<object>();
|
||||
list.Add(select.Where(a => a.Title.Equals("aaa")).ToList());
|
||||
list.Add(g.oracle.Select<TestEqualsGuid>().Where(a => a.id.Equals(Guid.Empty)).ToList());
|
||||
}
|
||||
|
||||
|
||||
[Fact]
|
||||
public void Empty()
|
||||
{
|
||||
var data = new List<object>();
|
||||
data.Add(select.Where(a => (a.Title ?? "") == string.Empty).ToSql());
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5
|
||||
//FROM `tb_topic` a
|
||||
//WHERE (ifnull(a.`Title`, '') = '')
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void StartsWith()
|
||||
{
|
||||
var list = new List<object>();
|
||||
list.Add(select.Where(a => a.Title.StartsWith("aaa")).ToList());
|
||||
list.Add(select.Where(a => a.Title.StartsWith(a.Title)).ToList());
|
||||
list.Add(select.Where(a => a.Title.StartsWith(a.Title + 1)).ToList());
|
||||
list.Add(select.Where(a => a.Title.StartsWith(a.Type.Name)).ToList());
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5
|
||||
//FROM `tb_topic` a
|
||||
//WHERE((a.`Title`) LIKE '%aaa')
|
||||
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5
|
||||
//FROM `tb_topic` a
|
||||
//WHERE((a.`Title`) LIKE concat('%', a.`Title`))
|
||||
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5
|
||||
//FROM `tb_topic` a
|
||||
//WHERE((a.`Title`) LIKE concat('%', concat(a.`Title`, 1)))
|
||||
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a.`Title` as7, a.`CreateTime` as8
|
||||
//FROM `tb_topic` a, `TestTypeInfo` a__Type
|
||||
//WHERE((a.`Title`) LIKE concat('%', a__Type.`Name`))
|
||||
list.Add(select.Where(a => (a.Title + "aaa").StartsWith("aaa")).ToList());
|
||||
list.Add(select.Where(a => (a.Title + "aaa").StartsWith(a.Title)).ToList());
|
||||
list.Add(select.Where(a => (a.Title + "aaa").StartsWith(a.Title + 1)).ToList());
|
||||
list.Add(select.Where(a => (a.Title + "aaa").StartsWith(a.Type.Name)).ToList());
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5
|
||||
//FROM `tb_topic` a
|
||||
//WHERE((concat(a.`Title`, 'aaa')) LIKE '%aaa')
|
||||
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5
|
||||
//FROM `tb_topic` a
|
||||
//WHERE((concat(a.`Title`, 'aaa')) LIKE concat('%', a.`Title`))
|
||||
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5
|
||||
//FROM `tb_topic` a
|
||||
//WHERE((concat(a.`Title`, 'aaa')) LIKE concat('%', concat(a.`Title`, 1)))
|
||||
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a.`Title` as7, a.`CreateTime` as8
|
||||
//FROM `tb_topic` a, `TestTypeInfo` a__Type
|
||||
//WHERE((concat(a.`Title`, 'aaa')) LIKE concat('%', a__Type.`Name`))
|
||||
}
|
||||
[Fact]
|
||||
public void EndsWith()
|
||||
{
|
||||
var list = new List<object>();
|
||||
list.Add(select.Where(a => a.Title.EndsWith("aaa")).ToList());
|
||||
list.Add(select.Where(a => a.Title.EndsWith(a.Title)).ToList());
|
||||
list.Add(select.Where(a => a.Title.EndsWith(a.Title + 1)).ToList());
|
||||
list.Add(select.Where(a => a.Title.EndsWith(a.Type.Name)).ToList());
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5
|
||||
//FROM `tb_topic` a
|
||||
//WHERE((a.`Title`) LIKE 'aaa%')
|
||||
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5
|
||||
//FROM `tb_topic` a
|
||||
//WHERE((a.`Title`) LIKE concat(a.`Title`, '%'))
|
||||
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5
|
||||
//FROM `tb_topic` a
|
||||
//WHERE((a.`Title`) LIKE concat(concat(a.`Title`, 1), '%'))
|
||||
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a.`Title` as7, a.`CreateTime` as8
|
||||
//FROM `tb_topic` a, `TestTypeInfo` a__Type
|
||||
//WHERE((a.`Title`) LIKE concat(a__Type.`Name`, '%'))
|
||||
list.Add(select.Where(a => (a.Title + "aaa").EndsWith("aaa")).ToList());
|
||||
list.Add(select.Where(a => (a.Title + "aaa").EndsWith(a.Title)).ToList());
|
||||
list.Add(select.Where(a => (a.Title + "aaa").EndsWith(a.Title + 1)).ToList());
|
||||
list.Add(select.Where(a => (a.Title + "aaa").EndsWith(a.Type.Name)).ToList());
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5
|
||||
//FROM `tb_topic` a
|
||||
//WHERE((concat(a.`Title`, 'aaa')) LIKE 'aaa%')
|
||||
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5
|
||||
//FROM `tb_topic` a
|
||||
//WHERE((concat(a.`Title`, 'aaa')) LIKE concat(a.`Title`, '%'))
|
||||
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5
|
||||
//FROM `tb_topic` a
|
||||
//WHERE((concat(a.`Title`, 'aaa')) LIKE concat(concat(a.`Title`, 1), '%'))
|
||||
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a.`Title` as7, a.`CreateTime` as8
|
||||
//FROM `tb_topic` a, `TestTypeInfo` a__Type
|
||||
//WHERE((concat(a.`Title`, 'aaa')) LIKE concat(a__Type.`Name`, '%'))
|
||||
}
|
||||
[Fact]
|
||||
public void Contains()
|
||||
{
|
||||
var list = new List<object>();
|
||||
list.Add(select.Where(a => a.Title.Contains("aaa")).ToList());
|
||||
list.Add(select.Where(a => a.Title.Contains(a.Title)).ToList());
|
||||
list.Add(select.Where(a => a.Title.Contains(a.Title + 1)).ToList());
|
||||
list.Add(select.Where(a => a.Title.Contains(a.Type.Name)).ToList());
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5
|
||||
//FROM `tb_topic` a
|
||||
//WHERE((a.`Title`) LIKE '%aaa%')
|
||||
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5
|
||||
//FROM `tb_topic` a
|
||||
//WHERE((a.`Title`) LIKE concat('%', a.`Title`, '%'))
|
||||
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5
|
||||
//FROM `tb_topic` a
|
||||
//WHERE((a.`Title`) LIKE concat('%', a.`Title` +1, '%'))
|
||||
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a.`Title` as7, a.`CreateTime` as8
|
||||
//FROM `tb_topic` a, `TestTypeInfo` a__Type
|
||||
//WHERE((a.`Title`) LIKE concat('%', a__Type.`Name`, '%'))
|
||||
list.Add(select.Where(a => (a.Title + "aaa").Contains("aaa")).ToList());
|
||||
list.Add(select.Where(a => (a.Title + "aaa").Contains(a.Title)).ToList());
|
||||
list.Add(select.Where(a => (a.Title + "aaa").Contains(a.Title + 1)).ToList());
|
||||
list.Add(select.Where(a => (a.Title + "aaa").Contains(a.Type.Name)).ToList());
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5
|
||||
//FROM `tb_topic` a
|
||||
//WHERE((concat(a.`Title`, 'aaa')) LIKE '%aaa%')
|
||||
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5
|
||||
//FROM `tb_topic` a
|
||||
//WHERE((concat(a.`Title`, 'aaa')) LIKE concat('%', a.`Title`, '%'))
|
||||
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5
|
||||
//FROM `tb_topic` a
|
||||
//WHERE((concat(a.`Title`, 'aaa')) LIKE concat('%', concat(a.`Title`, 1), '%'))
|
||||
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a.`Title` as7, a.`CreateTime` as8
|
||||
//FROM `tb_topic` a, `TestTypeInfo` a__Type
|
||||
//WHERE((concat(a.`Title`, 'aaa')) LIKE concat('%', a__Type.`Name`, '%'))
|
||||
}
|
||||
[Fact]
|
||||
public void ToLower()
|
||||
{
|
||||
var data = new List<object>();
|
||||
data.Add(select.Where(a => a.Title.ToLower() == "aaa").ToList());
|
||||
data.Add(select.Where(a => a.Title.ToLower() == a.Title).ToList());
|
||||
data.Add(select.Where(a => a.Title.ToLower() == (a.Title + 1)).ToList());
|
||||
data.Add(select.Where(a => a.Title.ToLower() == a.Type.Name).ToList());
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5
|
||||
//FROM `tb_topic` a
|
||||
//WHERE(lower(a.`Title`) = 'aaa');
|
||||
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5
|
||||
//FROM `tb_topic` a
|
||||
//WHERE(lower(a.`Title`) = a.`Title`);
|
||||
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5
|
||||
//FROM `tb_topic` a
|
||||
//WHERE(lower(a.`Title`) = concat(a.`Title`, 1));
|
||||
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a.`Title` as7, a.`CreateTime` as8
|
||||
//FROM `tb_topic` a, `TestTypeInfo` a__Type
|
||||
//WHERE(lower(a.`Title`) = a__Type.`Name`);
|
||||
data.Add(select.Where(a => (a.Title.ToLower() + "aaa").ToLower() == "aaa").ToList());
|
||||
data.Add(select.Where(a => (a.Title.ToLower() + "aaa").ToLower() == a.Title).ToList());
|
||||
data.Add(select.Where(a => (a.Title.ToLower() + "aaa").ToLower() == (a.Title + 1)).ToList());
|
||||
data.Add(select.Where(a => (a.Title.ToLower() + "aaa").ToLower() == a.Type.Name).ToList());
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5
|
||||
//FROM `tb_topic` a
|
||||
//WHERE(lower(concat(lower(a.`Title`), 'aaa')) = 'aaa');
|
||||
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5
|
||||
//FROM `tb_topic` a
|
||||
//WHERE(lower(concat(lower(a.`Title`), 'aaa')) = a.`Title`);
|
||||
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5
|
||||
//FROM `tb_topic` a
|
||||
//WHERE(lower(concat(lower(a.`Title`), 'aaa')) = concat(a.`Title`, 1));
|
||||
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a.`Title` as7, a.`CreateTime` as8
|
||||
//FROM `tb_topic` a, `TestTypeInfo` a__Type
|
||||
//WHERE(lower(concat(lower(a.`Title`), 'aaa')) = a__Type.`Name`)
|
||||
}
|
||||
[Fact]
|
||||
public void ToUpper()
|
||||
{
|
||||
var data = new List<object>();
|
||||
data.Add(select.Where(a => a.Title.ToUpper() == "aaa").ToList());
|
||||
data.Add(select.Where(a => a.Title.ToUpper() == a.Title).ToList());
|
||||
data.Add(select.Where(a => a.Title.ToUpper() == (a.Title + 1)).ToList());
|
||||
data.Add(select.Where(a => a.Title.ToUpper() == a.Type.Name).ToList());
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5
|
||||
//FROM `tb_topic` a
|
||||
//WHERE (upper(a.`Title`) = 'aaa');
|
||||
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5
|
||||
//FROM `tb_topic` a
|
||||
//WHERE (upper(a.`Title`) = a.`Title`);
|
||||
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5
|
||||
//FROM `tb_topic` a
|
||||
//WHERE (upper(a.`Title`) = concat(a.`Title`, 1));
|
||||
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a.`Title` as7, a.`CreateTime` as8
|
||||
//FROM `tb_topic` a, `TestTypeInfo` a__Type
|
||||
//WHERE (upper(a.`Title`) = a__Type.`Name`);
|
||||
data.Add(select.Where(a => (a.Title.ToUpper() + "aaa").ToUpper() == "aaa").ToList());
|
||||
data.Add(select.Where(a => (a.Title.ToUpper() + "aaa").ToUpper() == a.Title).ToList());
|
||||
data.Add(select.Where(a => (a.Title.ToUpper() + "aaa").ToUpper() == (a.Title + 1)).ToList());
|
||||
data.Add(select.Where(a => (a.Title.ToUpper() + "aaa").ToUpper() == a.Type.Name).ToList());
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5
|
||||
//FROM `tb_topic` a
|
||||
//WHERE (upper(concat(upper(a.`Title`), 'aaa')) = 'aaa');
|
||||
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5
|
||||
//FROM `tb_topic` a
|
||||
//WHERE (upper(concat(upper(a.`Title`), 'aaa')) = a.`Title`);
|
||||
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5
|
||||
//FROM `tb_topic` a
|
||||
//WHERE (upper(concat(upper(a.`Title`), 'aaa')) = concat(a.`Title`, 1));
|
||||
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a.`Title` as7, a.`CreateTime` as8
|
||||
//FROM `tb_topic` a, `TestTypeInfo` a__Type
|
||||
//WHERE (upper(concat(upper(a.`Title`), 'aaa')) = a__Type.`Name`)
|
||||
}
|
||||
[Fact]
|
||||
public void Substring()
|
||||
{
|
||||
var data = new List<object>();
|
||||
data.Add(select.Where(a => a.Title.Substring(0) == "aaa").ToList());
|
||||
data.Add(select.Where(a => a.Title.Substring(0) == a.Title).ToList());
|
||||
data.Add(select.Where(a => a.Title.Substring(0) == (a.Title + 1)).ToList());
|
||||
data.Add(select.Where(a => a.Title.Substring(0) == a.Type.Name).ToList());
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5
|
||||
//FROM `tb_topic` a
|
||||
//WHERE (substr(a.`Title`, 1) = 'aaa');
|
||||
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5
|
||||
//FROM `tb_topic` a
|
||||
//WHERE (substr(a.`Title`, 1) = a.`Title`);
|
||||
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5
|
||||
//FROM `tb_topic` a
|
||||
//WHERE (substr(a.`Title`, 1) = concat(a.`Title`, 1));
|
||||
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a.`Title` as7, a.`CreateTime` as8
|
||||
//FROM `tb_topic` a, `TestTypeInfo` a__Type
|
||||
//WHERE (substr(a.`Title`, 1) = a__Type.`Name`);
|
||||
data.Add(select.Where(a => (a.Title.Substring(0) + "aaa").Substring(a.Title.Length) == "aaa").ToList());
|
||||
data.Add(select.Where(a => (a.Title.Substring(0) + "aaa").Substring(0, a.Title.Length) == a.Title).ToList());
|
||||
data.Add(select.Where(a => (a.Title.Substring(0) + "aaa").Substring(0, 3) == (a.Title + 1)).ToList());
|
||||
data.Add(select.Where(a => (a.Title.Substring(0) + "aaa").Substring(1, 2) == a.Type.Name).ToList());
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5
|
||||
//FROM `tb_topic` a
|
||||
//WHERE (substr(concat(substr(a.`Title`, 1), 'aaa'), char_length(a.`Title`) + 1) = 'aaa');
|
||||
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5
|
||||
//FROM `tb_topic` a
|
||||
//WHERE (substr(concat(substr(a.`Title`, 1), 'aaa'), 1, char_length(a.`Title`)) = a.`Title`);
|
||||
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5
|
||||
//FROM `tb_topic` a
|
||||
//WHERE (substr(concat(substr(a.`Title`, 1), 'aaa'), 1, 3) = concat(a.`Title`, 1));
|
||||
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a.`Title` as7, a.`CreateTime` as8
|
||||
//FROM `tb_topic` a, `TestTypeInfo` a__Type
|
||||
//WHERE (substr(concat(substr(a.`Title`, 1), 'aaa'), 2, 2) = a__Type.`Name`)
|
||||
}
|
||||
[Fact]
|
||||
public void Length()
|
||||
{
|
||||
var data = new List<object>();
|
||||
data.Add(select.Where(a => a.Title.Length == 0).ToList());
|
||||
data.Add(select.Where(a => a.Title.Length == 1).ToList());
|
||||
data.Add(select.Where(a => a.Title.Length == a.Title.Length + 1).ToList());
|
||||
data.Add(select.Where(a => a.Title.Length == a.Type.Name.Length).ToList());
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5
|
||||
//FROM `tb_topic` a
|
||||
//WHERE (char_length(a.`Title`) = 0);
|
||||
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5
|
||||
//FROM `tb_topic` a
|
||||
//WHERE (char_length(a.`Title`) = 1);
|
||||
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5
|
||||
//FROM `tb_topic` a
|
||||
//WHERE (char_length(a.`Title`) = char_length(a.`Title`) + 1);
|
||||
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a.`Title` as7, a.`CreateTime` as8
|
||||
//FROM `tb_topic` a, `TestTypeInfo` a__Type
|
||||
//WHERE (char_length(a.`Title`) = char_length(a__Type.`Name`));
|
||||
data.Add(select.Where(a => (a.Title + "aaa").Length == 0).ToList());
|
||||
data.Add(select.Where(a => (a.Title + "aaa").Length == 1).ToList());
|
||||
data.Add(select.Where(a => (a.Title + "aaa").Length == a.Title.Length + 1).ToList());
|
||||
data.Add(select.Where(a => (a.Title + "aaa").Length == a.Type.Name.Length).ToList());
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5
|
||||
//FROM `tb_topic` a
|
||||
//WHERE (char_length(concat(a.`Title`, 'aaa')) = 0);
|
||||
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5
|
||||
//FROM `tb_topic` a
|
||||
//WHERE (char_length(concat(a.`Title`, 'aaa')) = 1);
|
||||
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5
|
||||
//FROM `tb_topic` a
|
||||
//WHERE (char_length(concat(a.`Title`, 'aaa')) = char_length(a.`Title`) + 1);
|
||||
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a.`Title` as7, a.`CreateTime` as8
|
||||
//FROM `tb_topic` a, `TestTypeInfo` a__Type
|
||||
//WHERE (char_length(concat(a.`Title`, 'aaa')) = char_length(a__Type.`Name`))
|
||||
}
|
||||
[Fact]
|
||||
public void IndexOf()
|
||||
{
|
||||
var data = new List<object>();
|
||||
data.Add(select.Where(a => a.Title.IndexOf("aaa") == -1).ToList());
|
||||
data.Add(select.Where(a => a.Title.IndexOf("aaa", 2) == -1).ToList());
|
||||
data.Add(select.Where(a => a.Title.IndexOf("aaa", 2) == (a.Title.Length + 1)).ToList());
|
||||
data.Add(select.Where(a => a.Title.IndexOf("aaa", 2) == a.Type.Name.Length + 1).ToList());
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5
|
||||
//FROM `tb_topic` a
|
||||
//WHERE ((locate(a.`Title`, 'aaa') - 1) = -1);
|
||||
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5
|
||||
//FROM `tb_topic` a
|
||||
//WHERE ((locate(a.`Title`, 'aaa', 3) - 1) = -1);
|
||||
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5
|
||||
//FROM `tb_topic` a
|
||||
//WHERE ((locate(a.`Title`, 'aaa', 3) - 1) = char_length(a.`Title`) + 1);
|
||||
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a.`Title` as7, a.`CreateTime` as8
|
||||
//FROM `tb_topic` a, `TestTypeInfo` a__Type
|
||||
//WHERE ((locate(a.`Title`, 'aaa', 3) - 1) = char_length(a__Type.`Name`) + 1);
|
||||
data.Add(select.Where(a => (a.Title + "aaa").IndexOf("aaa") == -1).ToList());
|
||||
data.Add(select.Where(a => (a.Title + "aaa").IndexOf("aaa", 2) == -1).ToList());
|
||||
data.Add(select.Where(a => (a.Title + "aaa").IndexOf("aaa", 2) == (a.Title.Length + 1)).ToList());
|
||||
data.Add(select.Where(a => (a.Title + "aaa").IndexOf("aaa", 2) == a.Type.Name.Length + 1).ToList());
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5
|
||||
//FROM `tb_topic` a
|
||||
//WHERE ((locate(concat(a.`Title`, 'aaa'), 'aaa') - 1) = -1);
|
||||
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5
|
||||
//FROM `tb_topic` a
|
||||
//WHERE ((locate(concat(a.`Title`, 'aaa'), 'aaa', 3) - 1) = -1);
|
||||
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5
|
||||
//FROM `tb_topic` a
|
||||
//WHERE ((locate(concat(a.`Title`, 'aaa'), 'aaa', 3) - 1) = char_length(a.`Title`) + 1);
|
||||
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a.`Title` as7, a.`CreateTime` as8
|
||||
//FROM `tb_topic` a, `TestTypeInfo` a__Type
|
||||
//WHERE ((locate(concat(a.`Title`, 'aaa'), 'aaa', 3) - 1) = char_length(a__Type.`Name`) + 1)
|
||||
}
|
||||
[Fact]
|
||||
public void PadLeft()
|
||||
{
|
||||
var data = new List<object>();
|
||||
data.Add(select.Where(a => a.Title.PadLeft(10, 'a') == "aaa").ToList());
|
||||
data.Add(select.Where(a => a.Title.PadLeft(10, 'a') == a.Title).ToList());
|
||||
data.Add(select.Where(a => a.Title.PadLeft(10, 'a') == (a.Title + 1)).ToList());
|
||||
data.Add(select.Where(a => a.Title.PadLeft(10, 'a') == a.Type.Name).ToList());
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5
|
||||
//FROM `tb_topic` a
|
||||
//WHERE (lpad(a.`Title`, 10, 'a') = 'aaa');
|
||||
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5
|
||||
//FROM `tb_topic` a
|
||||
//WHERE (lpad(a.`Title`, 10, 'a') = a.`Title`);
|
||||
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5
|
||||
//FROM `tb_topic` a
|
||||
//WHERE (lpad(a.`Title`, 10, 'a') = concat(a.`Title`, 1));
|
||||
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a.`Title` as7, a.`CreateTime` as8
|
||||
//FROM `tb_topic` a, `TestTypeInfo` a__Type
|
||||
//WHERE (lpad(a.`Title`, 10, 'a') = a__Type.`Name`);
|
||||
data.Add(select.Where(a => (a.Title.PadLeft(10, 'a') + "aaa").PadLeft(20, 'b') == "aaa").ToList());
|
||||
data.Add(select.Where(a => (a.Title.PadLeft(10, 'a') + "aaa").PadLeft(20, 'b') == a.Title).ToList());
|
||||
data.Add(select.Where(a => (a.Title.PadLeft(10, 'a') + "aaa").PadLeft(20, 'b') == (a.Title + 1)).ToList());
|
||||
data.Add(select.Where(a => (a.Title.PadLeft(10, 'a') + "aaa").PadLeft(20, 'b') == a.Type.Name).ToList());
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5
|
||||
//FROM `tb_topic` a
|
||||
//WHERE (lpad(concat(lpad(a.`Title`, 10, 'a'), 'aaa'), 20, 'b') = 'aaa');
|
||||
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5
|
||||
//FROM `tb_topic` a
|
||||
//WHERE (lpad(concat(lpad(a.`Title`, 10, 'a'), 'aaa'), 20, 'b') = a.`Title`);
|
||||
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5
|
||||
//FROM `tb_topic` a
|
||||
//WHERE (lpad(concat(lpad(a.`Title`, 10, 'a'), 'aaa'), 20, 'b') = concat(a.`Title`, 1));
|
||||
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a.`Title` as7, a.`CreateTime` as8
|
||||
//FROM `tb_topic` a, `TestTypeInfo` a__Type
|
||||
//WHERE (lpad(concat(lpad(a.`Title`, 10, 'a'), 'aaa'), 20, 'b') = a__Type.`Name`)
|
||||
}
|
||||
[Fact]
|
||||
public void PadRight()
|
||||
{
|
||||
var data = new List<object>();
|
||||
data.Add(select.Where(a => a.Title.PadRight(10, 'a') == "aaa").ToList());
|
||||
data.Add(select.Where(a => a.Title.PadRight(10, 'a') == a.Title).ToList());
|
||||
data.Add(select.Where(a => a.Title.PadRight(10, 'a') == (a.Title + 1)).ToList());
|
||||
data.Add(select.Where(a => a.Title.PadRight(10, 'a') == a.Type.Name).ToList());
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5
|
||||
//FROM `tb_topic` a
|
||||
//WHERE (rpad(a.`Title`, 10, 'a') = 'aaa');
|
||||
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5
|
||||
//FROM `tb_topic` a
|
||||
//WHERE (rpad(a.`Title`, 10, 'a') = a.`Title`);
|
||||
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5
|
||||
//FROM `tb_topic` a
|
||||
//WHERE (rpad(a.`Title`, 10, 'a') = concat(a.`Title`, 1));
|
||||
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a.`Title` as7, a.`CreateTime` as8
|
||||
//FROM `tb_topic` a, `TestTypeInfo` a__Type
|
||||
//WHERE (rpad(a.`Title`, 10, 'a') = a__Type.`Name`);
|
||||
data.Add(select.Where(a => (a.Title.PadRight(10, 'a') + "aaa").PadRight(20, 'b') == "aaa").ToList());
|
||||
data.Add(select.Where(a => (a.Title.PadRight(10, 'a') + "aaa").PadRight(20, 'b') == a.Title).ToList());
|
||||
data.Add(select.Where(a => (a.Title.PadRight(10, 'a') + "aaa").PadRight(20, 'b') == (a.Title + 1)).ToList());
|
||||
data.Add(select.Where(a => (a.Title.PadRight(10, 'a') + "aaa").PadRight(20, 'b') == a.Type.Name).ToList());
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5
|
||||
//FROM `tb_topic` a
|
||||
//WHERE (rpad(concat(rpad(a.`Title`, 10, 'a'), 'aaa'), 20, 'b') = 'aaa');
|
||||
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5
|
||||
//FROM `tb_topic` a
|
||||
//WHERE (rpad(concat(rpad(a.`Title`, 10, 'a'), 'aaa'), 20, 'b') = a.`Title`);
|
||||
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5
|
||||
//FROM `tb_topic` a
|
||||
//WHERE (rpad(concat(rpad(a.`Title`, 10, 'a'), 'aaa'), 20, 'b') = concat(a.`Title`, 1));
|
||||
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a.`Title` as7, a.`CreateTime` as8
|
||||
//FROM `tb_topic` a, `TestTypeInfo` a__Type
|
||||
//WHERE (rpad(concat(rpad(a.`Title`, 10, 'a'), 'aaa'), 20, 'b') = a__Type.`Name`)
|
||||
}
|
||||
[Fact]
|
||||
public void Trim()
|
||||
{
|
||||
var data = new List<object>();
|
||||
data.Add(select.Where(a => a.Title.Trim() == "aaa").ToList());
|
||||
data.Add(select.Where(a => a.Title.Trim('a') == a.Title).ToList());
|
||||
data.Add(select.Where(a => a.Title.Trim('a', 'b') == (a.Title + 1)).ToList());
|
||||
data.Add(select.Where(a => a.Title.Trim('a', 'b', 'c') == a.Type.Name).ToList());
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5
|
||||
//FROM `tb_topic` a
|
||||
//WHERE (trim(a.`Title`) = 'aaa');
|
||||
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5
|
||||
//FROM `tb_topic` a
|
||||
//WHERE (trim('a' from a.`Title`) = a.`Title`);
|
||||
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5
|
||||
//FROM `tb_topic` a
|
||||
//WHERE (trim('b' from trim('a' from a.`Title`)) = concat(a.`Title`, 1));
|
||||
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a.`Title` as7, a.`CreateTime` as8
|
||||
//FROM `tb_topic` a, `TestTypeInfo` a__Type
|
||||
//WHERE (trim('c' from trim('b' from trim('a' from a.`Title`))) = a__Type.`Name`);
|
||||
data.Add(select.Where(a => (a.Title.Trim() + "aaa").Trim() == "aaa").ToList());
|
||||
data.Add(select.Where(a => (a.Title.Trim('a') + "aaa").Trim('a') == a.Title).ToList());
|
||||
data.Add(select.Where(a => (a.Title.Trim('a', 'b') + "aaa").Trim('a', 'b') == (a.Title + 1)).ToList());
|
||||
data.Add(select.Where(a => (a.Title.Trim('a', 'b', 'c') + "aaa").Trim('a', 'b', 'c') == a.Type.Name).ToList());
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5
|
||||
//FROM `tb_topic` a
|
||||
//WHERE (trim(concat(trim(a.`Title`), 'aaa')) = 'aaa');
|
||||
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5
|
||||
//FROM `tb_topic` a
|
||||
//WHERE (trim('a' from concat(trim('a' from a.`Title`), 'aaa')) = a.`Title`);
|
||||
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5
|
||||
//FROM `tb_topic` a
|
||||
//WHERE (trim('b' from trim('a' from concat(trim('b' from trim('a' from a.`Title`)), 'aaa'))) = concat(a.`Title`, 1));
|
||||
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a.`Title` as7, a.`CreateTime` as8
|
||||
//FROM `tb_topic` a, `TestTypeInfo` a__Type
|
||||
//WHERE (trim('c' from trim('b' from trim('a' from concat(trim('c' from trim('b' from trim('a' from a.`Title`))), 'aaa')))) = a__Type.`Name`)
|
||||
}
|
||||
[Fact]
|
||||
public void TrimStart()
|
||||
{
|
||||
var data = new List<object>();
|
||||
data.Add(select.Where(a => a.Title.TrimStart() == "aaa").ToList());
|
||||
data.Add(select.Where(a => a.Title.TrimStart('a') == a.Title).ToList());
|
||||
data.Add(select.Where(a => a.Title.TrimStart('a', 'b') == (a.Title + 1)).ToList());
|
||||
data.Add(select.Where(a => a.Title.TrimStart('a', 'b', 'c') == a.Type.Name).ToList());
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5
|
||||
//FROM `tb_topic` a
|
||||
//WHERE (ltrim(a.`Title`) = 'aaa');
|
||||
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5
|
||||
//FROM `tb_topic` a
|
||||
//WHERE (trim(trailing 'a' from trim(leading 'a' from a.`Title`)) = a.`Title`);
|
||||
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5
|
||||
//FROM `tb_topic` a
|
||||
//WHERE (trim(trailing 'b' from trim(leading 'b' from trim(trailing 'a' from trim(leading 'a' from a.`Title`)))) = concat(a.`Title`, 1));
|
||||
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a.`Title` as7, a.`CreateTime` as8
|
||||
//FROM `tb_topic` a, `TestTypeInfo` a__Type
|
||||
//WHERE (trim(trailing 'c' from trim(leading 'c' from trim(trailing 'b' from trim(leading 'b' from trim(trailing 'a' from trim(leading 'a' from a.`Title`)))))) = a__Type.`Name`);
|
||||
data.Add(select.Where(a => (a.Title.TrimStart() + "aaa").TrimStart() == "aaa").ToList());
|
||||
data.Add(select.Where(a => (a.Title.TrimStart('a') + "aaa").TrimStart('a') == a.Title).ToList());
|
||||
data.Add(select.Where(a => (a.Title.TrimStart('a', 'b') + "aaa").TrimStart('a', 'b') == (a.Title + 1)).ToList());
|
||||
data.Add(select.Where(a => (a.Title.TrimStart('a', 'b', 'c') + "aaa").TrimStart('a', 'b', 'c') == a.Type.Name).ToList());
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5
|
||||
//FROM `tb_topic` a
|
||||
//WHERE (ltrim(concat(ltrim(a.`Title`), 'aaa')) = 'aaa');
|
||||
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5
|
||||
//FROM `tb_topic` a
|
||||
//WHERE (trim(trailing 'a' from trim(leading 'a' from concat(trim(trailing 'a' from trim(leading 'a' from a.`Title`)), 'aaa'))) = a.`Title`);
|
||||
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5
|
||||
//FROM `tb_topic` a
|
||||
//WHERE (trim(trailing 'b' from trim(leading 'b' from trim(trailing 'a' from trim(leading 'a' from concat(trim(trailing 'b' from trim(leading 'b' from trim(trailing 'a' from trim(leading 'a' from a.`Title`)))), 'aaa'))))) = concat(a.`Title`, 1));
|
||||
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a.`Title` as7, a.`CreateTime` as8
|
||||
//FROM `tb_topic` a, `TestTypeInfo` a__Type
|
||||
//WHERE (trim(trailing 'c' from trim(leading 'c' from trim(trailing 'b' from trim(leading 'b' from trim(trailing 'a' from trim(leading 'a' from concat(trim(trailing 'c' from trim(leading 'c' from trim(trailing 'b' from trim(leading 'b' from trim(trailing 'a' from trim(leading 'a' from a.`Title`)))))), 'aaa'))))))) = a__Type.`Name`)
|
||||
}
|
||||
[Fact]
|
||||
public void TrimEnd()
|
||||
{
|
||||
var data = new List<object>();
|
||||
data.Add(select.Where(a => a.Title.TrimEnd() == "aaa").ToList());
|
||||
data.Add(select.Where(a => a.Title.TrimEnd('a') == a.Title).ToList());
|
||||
data.Add(select.Where(a => a.Title.TrimEnd('a', 'b') == (a.Title + 1)).ToList());
|
||||
data.Add(select.Where(a => a.Title.TrimEnd('a', 'b', 'c') == a.Type.Name).ToList());
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5
|
||||
//FROM `tb_topic` a
|
||||
//WHERE (rtrim(a.`Title`) = 'aaa');
|
||||
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5
|
||||
//FROM `tb_topic` a
|
||||
//WHERE (trim(trailing 'a' from a.`Title`) = a.`Title`);
|
||||
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5
|
||||
//FROM `tb_topic` a
|
||||
//WHERE (trim(trailing 'b' from trim(trailing 'a' from a.`Title`)) = concat(a.`Title`, 1));
|
||||
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a.`Title` as7, a.`CreateTime` as8
|
||||
//FROM `tb_topic` a, `TestTypeInfo` a__Type
|
||||
//WHERE (trim(trailing 'c' from trim(trailing 'b' from trim(trailing 'a' from a.`Title`))) = a__Type.`Name`);
|
||||
data.Add(select.Where(a => (a.Title.TrimEnd() + "aaa").TrimEnd() == "aaa").ToList());
|
||||
data.Add(select.Where(a => (a.Title.TrimEnd('a') + "aaa").TrimEnd('a') == a.Title).ToList());
|
||||
data.Add(select.Where(a => (a.Title.TrimEnd('a', 'b') + "aaa").TrimEnd('a', 'b') == (a.Title + 1)).ToList());
|
||||
data.Add(select.Where(a => (a.Title.TrimEnd('a', 'b', 'c') + "aaa").TrimEnd('a', 'b', 'c') == a.Type.Name).ToList());
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5
|
||||
//FROM `tb_topic` a
|
||||
//WHERE (rtrim(concat(rtrim(a.`Title`), 'aaa')) = 'aaa');
|
||||
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5
|
||||
//FROM `tb_topic` a
|
||||
//WHERE (trim(trailing 'a' from concat(trim(trailing 'a' from a.`Title`), 'aaa')) = a.`Title`);
|
||||
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5
|
||||
//FROM `tb_topic` a
|
||||
//WHERE (trim(trailing 'b' from trim(trailing 'a' from concat(trim(trailing 'b' from trim(trailing 'a' from a.`Title`)), 'aaa'))) = concat(a.`Title`, 1));
|
||||
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a.`Title` as7, a.`CreateTime` as8
|
||||
//FROM `tb_topic` a, `TestTypeInfo` a__Type
|
||||
//WHERE (trim(trailing 'c' from trim(trailing 'b' from trim(trailing 'a' from concat(trim(trailing 'c' from trim(trailing 'b' from trim(trailing 'a' from a.`Title`))), 'aaa')))) = a__Type.`Name`)
|
||||
}
|
||||
[Fact]
|
||||
public void Replace()
|
||||
{
|
||||
var data = new List<object>();
|
||||
data.Add(select.Where(a => a.Title.Replace("a", "b") == "aaa").ToList());
|
||||
data.Add(select.Where(a => a.Title.Replace("a", "b").Replace("b", "c") == a.Title).ToList());
|
||||
data.Add(select.Where(a => a.Title.Replace("a", "b").Replace("b", "c").Replace("c", "a") == (a.Title + 1)).ToList());
|
||||
data.Add(select.Where(a => a.Title.Replace("a", "b").Replace("b", "c").Replace(a.Type.Name, "a") == a.Type.Name).ToList());
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5
|
||||
//FROM `tb_topic` a
|
||||
//WHERE (replace(a.`Title`, 'a', 'b') = 'aaa');
|
||||
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5
|
||||
//FROM `tb_topic` a
|
||||
//WHERE (replace(replace(a.`Title`, 'a', 'b'), 'b', 'c') = a.`Title`);
|
||||
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5
|
||||
//FROM `tb_topic` a
|
||||
//WHERE (replace(replace(replace(a.`Title`, 'a', 'b'), 'b', 'c'), 'c', 'a') = concat(a.`Title`, 1));
|
||||
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a.`Title` as7, a.`CreateTime` as8
|
||||
//FROM `tb_topic` a, `TestTypeInfo` a__Type
|
||||
//WHERE (replace(replace(replace(a.`Title`, 'a', 'b'), 'b', 'c'), a__Type.`Name`, 'a') = a__Type.`Name`);
|
||||
data.Add(select.Where(a => (a.Title.Replace("a", "b") + "aaa").TrimEnd() == "aaa").ToList());
|
||||
data.Add(select.Where(a => (a.Title.Replace("a", "b").Replace("b", "c") + "aaa").TrimEnd('a') == a.Title).ToList());
|
||||
data.Add(select.Where(a => (a.Title.Replace("a", "b").Replace("b", "c").Replace("c", "a") + "aaa").TrimEnd('a', 'b') == (a.Title + 1)).ToList());
|
||||
data.Add(select.Where(a => (a.Title.Replace("a", "b").Replace("b", "c").Replace(a.Type.Name, "a") + "aaa").TrimEnd('a', 'b', 'c') == a.Type.Name).ToList());
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5
|
||||
//FROM `tb_topic` a
|
||||
//WHERE (concat(replace(a.`Title`, 'a', 'b'), 'aaa') = 'aaa');
|
||||
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5
|
||||
//FROM `tb_topic` a
|
||||
//WHERE (concat(replace(replace(a.`Title`, 'a', 'b'), 'b', 'c'), 'aaa') = a.`Title`);
|
||||
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5
|
||||
//FROM `tb_topic` a
|
||||
//WHERE (concat(replace(replace(replace(a.`Title`, 'a', 'b'), 'b', 'c'), 'c', 'a'), 'aaa') = concat(a.`Title`, 1));
|
||||
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a.`Title` as7, a.`CreateTime` as8
|
||||
//FROM `tb_topic` a, `TestTypeInfo` a__Type
|
||||
//WHERE (concat(replace(replace(replace(a.`Title`, 'a', 'b'), 'b', 'c'), a__Type.`Name`, 'a'), 'aaa') = a__Type.`Name`)
|
||||
}
|
||||
[Fact]
|
||||
public void CompareTo()
|
||||
{
|
||||
var data = new List<object>();
|
||||
data.Add(select.Where(a => a.Title.CompareTo(a.Title) == 0).ToList());
|
||||
data.Add(select.Where(a => a.Title.CompareTo(a.Title) > 0).ToList());
|
||||
data.Add(select.Where(a => a.Title.CompareTo(a.Title + 1) == 0).ToList());
|
||||
data.Add(select.Where(a => a.Title.CompareTo(a.Title + a.Type.Name) == 0).ToList());
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5
|
||||
//FROM `tb_topic` a
|
||||
//WHERE (strcmp(a.`Title`, a.`Title`) = 0);
|
||||
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5
|
||||
//FROM `tb_topic` a
|
||||
//WHERE (strcmp(a.`Title`, a.`Title`) > 0);
|
||||
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5
|
||||
//FROM `tb_topic` a
|
||||
//WHERE (strcmp(a.`Title`, concat(a.`Title`, 1)) = 0);
|
||||
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a.`Title` as7, a.`CreateTime` as8
|
||||
//FROM `tb_topic` a, `TestTypeInfo` a__Type
|
||||
//WHERE (strcmp(a.`Title`, concat(a.`Title`, a__Type.`Name`)) = 0);
|
||||
data.Add(select.Where(a => (a.Title + "aaa").CompareTo("aaa") == 0).ToList());
|
||||
data.Add(select.Where(a => (a.Title + "aaa").CompareTo(a.Title) > 0).ToList());
|
||||
data.Add(select.Where(a => (a.Title + "aaa").CompareTo(a.Title + 1) == 0).ToList());
|
||||
data.Add(select.Where(a => (a.Title + "aaa").CompareTo(a.Type.Name) == 0).ToList());
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5
|
||||
//FROM `tb_topic` a
|
||||
//WHERE (strcmp(concat(a.`Title`, 'aaa'), 'aaa') = 0);
|
||||
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5
|
||||
//FROM `tb_topic` a
|
||||
//WHERE (strcmp(concat(a.`Title`, 'aaa'), a.`Title`) > 0);
|
||||
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5
|
||||
//FROM `tb_topic` a
|
||||
//WHERE (strcmp(concat(a.`Title`, 'aaa'), concat(a.`Title`, 1)) = 0);
|
||||
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a.`Title` as7, a.`CreateTime` as8
|
||||
//FROM `tb_topic` a, `TestTypeInfo` a__Type
|
||||
//WHERE (strcmp(concat(a.`Title`, 'aaa'), a__Type.`Name`) = 0)
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void string_IsNullOrEmpty()
|
||||
{
|
||||
var data = new List<object>();
|
||||
data.Add(select.Where(a => string.IsNullOrEmpty(a.Title)).ToList());
|
||||
data.Add(select.Where(a => !string.IsNullOrEmpty(a.Title)).ToList());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void string_IsNullOrWhiteSpace()
|
||||
{
|
||||
var data = new List<object>();
|
||||
data.Add(select.Where(a => string.IsNullOrWhiteSpace(a.Title)).ToList());
|
||||
data.Add(select.Where(a => !string.IsNullOrWhiteSpace(a.Title)).ToList());
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,293 @@
|
||||
using FreeSql.DataAnnotations;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Xunit;
|
||||
|
||||
namespace FreeSql.Tests.Odbc.OracleExpression
|
||||
{
|
||||
public class TimeSpanTest
|
||||
{
|
||||
|
||||
ISelect<Topic> select => g.oracle.Select<Topic>();
|
||||
|
||||
[Table(Name = "tb_topic")]
|
||||
class Topic
|
||||
{
|
||||
[Column(IsIdentity = true, IsPrimary = true)]
|
||||
public int Id { get; set; }
|
||||
public int Clicks { get; set; }
|
||||
public int TypeGuid { get; set; }
|
||||
public TestTypeInfo Type { get; set; }
|
||||
public string Title { get; set; }
|
||||
public DateTime CreateTime { get; set; }
|
||||
}
|
||||
class TestTypeInfo
|
||||
{
|
||||
public int Guid { get; set; }
|
||||
public int ParentId { get; set; }
|
||||
public TestTypeParentInfo Parent { get; set; }
|
||||
public string Name { get; set; }
|
||||
}
|
||||
class TestTypeParentInfo
|
||||
{
|
||||
public int Id { get; set; }
|
||||
public string Name { get; set; }
|
||||
|
||||
public List<TestTypeInfo> Types { get; set; }
|
||||
}
|
||||
[Fact]
|
||||
public void Zero()
|
||||
{
|
||||
var data = new List<object>();
|
||||
data.Add(select.Where(a => a.CreateTime.TimeOfDay > TimeSpan.Zero).ToList());
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5
|
||||
//FROM `tb_topic` a
|
||||
//WHERE (timestampdiff(microsecond, date_format(a.`CreateTime`, '1970-1-1 %H:%i:%s.%f'), a.`CreateTime`) + 62135596800000000) > 0)
|
||||
}
|
||||
[Fact]
|
||||
public void MinValue()
|
||||
{
|
||||
var data = new List<object>();
|
||||
data.Add(select.Where(a => a.CreateTime.TimeOfDay > TimeSpan.MinValue).ToList());
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5
|
||||
//FROM `tb_topic` a
|
||||
//WHERE (timestampdiff(microsecond, date_format(a.`CreateTime`, '1970-1-1 %H:%i:%s.%f'), a.`CreateTime`) + 62135596800000000) > -922337203685477580)
|
||||
}
|
||||
[Fact]
|
||||
public void MaxValue()
|
||||
{
|
||||
var data = new List<object>();
|
||||
data.Add(select.Where(a => a.CreateTime.TimeOfDay < TimeSpan.MaxValue).ToList());
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5
|
||||
//FROM `tb_topic` a
|
||||
//WHERE (timestampdiff(microsecond, date_format(a.`CreateTime`, '1970-1-1 %H:%i:%s.%f'), a.`CreateTime`) + 62135596800000000) < 922337203685477580)
|
||||
}
|
||||
[Fact]
|
||||
public void Days()
|
||||
{
|
||||
var data = new List<object>();
|
||||
data.Add(select.Where(a => a.CreateTime.TimeOfDay.Days == 0).ToList());
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5
|
||||
//FROM `tb_topic` a
|
||||
//WHERE (((timestampdiff(microsecond, date_format(a.`CreateTime`, '1970-1-1 %H:%i:%s.%f'), a.`CreateTime`) + 62135596800000000)) div 86400000000) = 0)
|
||||
}
|
||||
[Fact]
|
||||
public void Hours()
|
||||
{
|
||||
var data = new List<object>();
|
||||
data.Add(select.Where(a => a.CreateTime.TimeOfDay.Hours > 0).ToSql());
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5
|
||||
//FROM `tb_topic` a
|
||||
//WHERE (((timestampdiff(microsecond, date_format(a.`CreateTime`, '1970-1-1 %H:%i:%s.%f'), a.`CreateTime`) + 62135596800000000)) div 3600000000) mod 24 > 0)
|
||||
}
|
||||
[Fact]
|
||||
public void Milliseconds()
|
||||
{
|
||||
var data = new List<object>();
|
||||
data.Add(select.Where(a => a.CreateTime.TimeOfDay.Milliseconds > 0).ToList());
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5
|
||||
//FROM `tb_topic` a
|
||||
//WHERE (((timestampdiff(microsecond, date_format(a.`CreateTime`, '1970-1-1 %H:%i:%s.%f'), a.`CreateTime`) + 62135596800000000)) div 1000 mod 1000) > 0)
|
||||
}
|
||||
[Fact]
|
||||
public void Minutes()
|
||||
{
|
||||
var data = new List<object>();
|
||||
data.Add(select.Where(a => a.CreateTime.TimeOfDay.Minutes > 0).ToList());
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5
|
||||
//FROM `tb_topic` a
|
||||
//WHERE (((timestampdiff(microsecond, date_format(a.`CreateTime`, '1970-1-1 %H:%i:%s.%f'), a.`CreateTime`) + 62135596800000000)) div 60000000 mod 60) > 0)
|
||||
}
|
||||
[Fact]
|
||||
public void Seconds()
|
||||
{
|
||||
var data = new List<object>();
|
||||
data.Add(select.Where(a => a.CreateTime.TimeOfDay.Seconds > 0).ToList());
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5
|
||||
//FROM `tb_topic` a
|
||||
//WHERE (((timestampdiff(microsecond, date_format(a.`CreateTime`, '1970-1-1 %H:%i:%s.%f'), a.`CreateTime`) + 62135596800000000)) div 1000000 mod 60) > 0)
|
||||
}
|
||||
[Fact]
|
||||
public void Ticks()
|
||||
{
|
||||
var data = new List<object>();
|
||||
data.Add(select.Where(a => a.CreateTime.TimeOfDay.Ticks > 0).ToList());
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5
|
||||
//FROM `tb_topic` a
|
||||
//WHERE (((timestampdiff(microsecond, date_format(a.`CreateTime`, '1970-1-1 %H:%i:%s.%f'), a.`CreateTime`) + 62135596800000000)) * 10) > 0)
|
||||
}
|
||||
[Fact]
|
||||
public void TotalDays()
|
||||
{
|
||||
var data = new List<object>();
|
||||
data.Add(select.Where(a => a.CreateTime.TimeOfDay.TotalDays > 0).ToList());
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5
|
||||
//FROM `tb_topic` a
|
||||
//WHERE (((timestampdiff(microsecond, date_format(a.`CreateTime`, '1970-1-1 %H:%i:%s.%f'), a.`CreateTime`) + 62135596800000000)) / 86400000000) > 0)
|
||||
}
|
||||
[Fact]
|
||||
public void TotalHours()
|
||||
{
|
||||
var data = new List<object>();
|
||||
data.Add(select.Where(a => a.CreateTime.TimeOfDay.TotalHours > 0).ToList());
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5
|
||||
//FROM `tb_topic` a
|
||||
//WHERE (((timestampdiff(microsecond, date_format(a.`CreateTime`, '1970-1-1 %H:%i:%s.%f'), a.`CreateTime`) + 62135596800000000)) / 3600000000) > 0)
|
||||
}
|
||||
[Fact]
|
||||
public void TotalMilliseconds()
|
||||
{
|
||||
var data = new List<object>();
|
||||
data.Add(select.Where(a => a.CreateTime.TimeOfDay.TotalMilliseconds > 0).ToList());
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5
|
||||
//FROM `tb_topic` a
|
||||
//WHERE (((timestampdiff(microsecond, date_format(a.`CreateTime`, '1970-1-1 %H:%i:%s.%f'), a.`CreateTime`) + 62135596800000000)) / 1000) > 0)
|
||||
}
|
||||
[Fact]
|
||||
public void TotalMinutes()
|
||||
{
|
||||
var data = new List<object>();
|
||||
data.Add(select.Where(a => a.CreateTime.TimeOfDay.TotalMinutes > 0).ToSql());
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5
|
||||
//FROM `tb_topic` a
|
||||
//WHERE (((timestampdiff(microsecond, date_format(a.`CreateTime`, '1970-1-1 %H:%i:%s.%f'), a.`CreateTime`) + 62135596800000000)) / 60000000) > 0)
|
||||
}
|
||||
[Fact]
|
||||
public void TotalSeconds()
|
||||
{
|
||||
var data = new List<object>();
|
||||
data.Add(select.Where(a => a.CreateTime.TimeOfDay.TotalSeconds > 0).ToList());
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5
|
||||
//FROM `tb_topic` a
|
||||
//WHERE (((timestampdiff(microsecond, date_format(a.`CreateTime`, '1970-1-1 %H:%i:%s.%f'), a.`CreateTime`) + 62135596800000000)) / 1000000) > 0)
|
||||
}
|
||||
[Fact]
|
||||
public void Add()
|
||||
{
|
||||
var data = new List<object>();
|
||||
data.Add(select.Where(a => a.CreateTime.TimeOfDay.Add(TimeSpan.FromDays(1)) > TimeSpan.Zero).ToList());
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5
|
||||
//FROM `tb_topic` a
|
||||
//WHERE ((timestampdiff(microsecond, date_format(a.`CreateTime`, '1970-1-1 %H:%i:%s.%f'), a.`CreateTime`) + 62135596800000000) + (1 * 86400000000)) > 0)
|
||||
}
|
||||
[Fact]
|
||||
public void Subtract()
|
||||
{
|
||||
var data = new List<object>();
|
||||
data.Add(select.Where(a => a.CreateTime.TimeOfDay.Subtract(TimeSpan.FromDays(1)) > TimeSpan.Zero).ToList());
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5
|
||||
//FROM `tb_topic` a
|
||||
//WHERE ((timestampdiff(microsecond, date_format(a.`CreateTime`, '1970-1-1 %H:%i:%s.%f'), a.`CreateTime`) + 62135596800000000) - (1 * 86400000000)) > 0)
|
||||
}
|
||||
[Fact]
|
||||
public void CompareTo()
|
||||
{
|
||||
var data = new List<object>();
|
||||
data.Add(select.Where(a => a.CreateTime.TimeOfDay.CompareTo(TimeSpan.FromDays(1)) > 0).ToList());
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5
|
||||
//FROM `tb_topic` a
|
||||
//WHERE (((timestampdiff(microsecond, date_format(a.`CreateTime`, '1970-1-1 %H:%i:%s.%f'), a.`CreateTime`) + 62135596800000000)) - ((1 * 86400000000))) > 0)
|
||||
}
|
||||
[Fact]
|
||||
public void this_Equals()
|
||||
{
|
||||
var data = new List<object>();
|
||||
data.Add(select.Where(a => a.CreateTime.TimeOfDay.Equals(TimeSpan.FromDays(1))).ToList());
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5
|
||||
//FROM `tb_topic` a
|
||||
//WHERE ((timestampdiff(microsecond, date_format(a.`CreateTime`, '1970-1-1 %H:%i:%s.%f'), a.`CreateTime`) + 62135596800000000) = (1 * 86400000000)))
|
||||
}
|
||||
[Fact]
|
||||
public void this_ToString()
|
||||
{
|
||||
var data = new List<object>();
|
||||
data.Add(select.Where(a => a.CreateTime.TimeOfDay.ToString() == "ssss").ToList());
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5
|
||||
//FROM `tb_topic` a
|
||||
//WHERE (date_format(date_add(cast('0001/1/1 0:00:00' as datetime), interval (timestampdiff(microsecond, date_format(a.`CreateTime`, '1970-1-1 %H:%i:%s.%f'), a.`CreateTime`) + 62135596800000000)) microsecond), '%Y-%m-%d %H:%i:%s.%f') = 'ssss')
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TimeSpan_Compare()
|
||||
{
|
||||
var data = new List<object>();
|
||||
data.Add(select.Where(a => TimeSpan.Compare(a.CreateTime.TimeOfDay, TimeSpan.FromDays(1)) > 0).ToList());
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5
|
||||
//FROM `tb_topic` a
|
||||
//WHERE (((timestampdiff(microsecond, date_format(a.`CreateTime`, '1970-1-1 %H:%i:%s.%f'), a.`CreateTime`) + 62135596800000000)) - ((1 * 86400000000))) > 0)
|
||||
}
|
||||
[Fact]
|
||||
public void TimeSpan_Equals()
|
||||
{
|
||||
var data = new List<object>();
|
||||
data.Add(select.Where(a => TimeSpan.Equals(a.CreateTime.TimeOfDay, TimeSpan.FromDays(1))).ToList());
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5
|
||||
//FROM `tb_topic` a
|
||||
//WHERE ((timestampdiff(microsecond, date_format(a.`CreateTime`, '1970-1-1 %H:%i:%s.%f'), a.`CreateTime`) + 62135596800000000) = (1 * 86400000000)))
|
||||
}
|
||||
[Fact]
|
||||
public void TimeSpan_FromDays()
|
||||
{
|
||||
var data = new List<object>();
|
||||
data.Add(select.Where(a => TimeSpan.Equals(a.CreateTime.TimeOfDay, TimeSpan.FromDays(1))).ToList());
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5
|
||||
//FROM `tb_topic` a
|
||||
//WHERE ((timestampdiff(microsecond, date_format(a.`CreateTime`, '1970-1-1 %H:%i:%s.%f'), a.`CreateTime`) + 62135596800000000) = (1 * 86400000000)))
|
||||
}
|
||||
[Fact]
|
||||
public void TimeSpan_FromHours()
|
||||
{
|
||||
var data = new List<object>();
|
||||
data.Add(select.Where(a => TimeSpan.Equals(a.CreateTime.TimeOfDay, TimeSpan.FromHours(1))).ToList());
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5
|
||||
//FROM `tb_topic` a
|
||||
//WHERE ((timestampdiff(microsecond, date_format(a.`CreateTime`, '1970-1-1 %H:%i:%s.%f'), a.`CreateTime`) + 62135596800000000) = (1 * 3600000000)))
|
||||
}
|
||||
[Fact]
|
||||
public void TimeSpan_FromMilliseconds()
|
||||
{
|
||||
var data = new List<object>();
|
||||
data.Add(select.Where(a => TimeSpan.Equals(a.CreateTime.TimeOfDay, TimeSpan.FromMilliseconds(1))).ToList());
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5
|
||||
//FROM `tb_topic` a
|
||||
//WHERE ((timestampdiff(microsecond, date_format(a.`CreateTime`, '1970-1-1 %H:%i:%s.%f'), a.`CreateTime`) + 62135596800000000) = (1 * 1000)))
|
||||
}
|
||||
[Fact]
|
||||
public void TimeSpan_FromMinutes()
|
||||
{
|
||||
var data = new List<object>();
|
||||
data.Add(select.Where(a => TimeSpan.Equals(a.CreateTime.TimeOfDay, TimeSpan.FromMinutes(1))).ToList());
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5
|
||||
//FROM `tb_topic` a
|
||||
//WHERE ((timestampdiff(microsecond, date_format(a.`CreateTime`, '1970-1-1 %H:%i:%s.%f'), a.`CreateTime`) + 62135596800000000) = (1 * 60000000)))
|
||||
}
|
||||
[Fact]
|
||||
public void TimeSpan_FromSeconds()
|
||||
{
|
||||
var data = new List<object>();
|
||||
data.Add(select.Where(a => TimeSpan.Equals(a.CreateTime.TimeOfDay, TimeSpan.FromSeconds(1))).ToList());
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5
|
||||
//FROM `tb_topic` a
|
||||
//WHERE ((timestampdiff(microsecond, date_format(a.`CreateTime`, '1970-1-1 %H:%i:%s.%f'), a.`CreateTime`) + 62135596800000000) = (1 * 1000000)))
|
||||
}
|
||||
[Fact]
|
||||
public void TimeSpan_FromTicks()
|
||||
{
|
||||
var data = new List<object>();
|
||||
data.Add(select.Where(a => TimeSpan.Equals(a.CreateTime.TimeOfDay, TimeSpan.FromTicks(1))).ToList());
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5
|
||||
//FROM `tb_topic` a
|
||||
//WHERE ((timestampdiff(microsecond, date_format(a.`CreateTime`, '1970-1-1 %H:%i:%s.%f'), a.`CreateTime`) + 62135596800000000) = (1 / 10)))
|
||||
}
|
||||
[Fact]
|
||||
public void TimeSpan_Parse()
|
||||
{
|
||||
var data = new List<object>();
|
||||
data.Add(select.Where(a => TimeSpan.Parse(a.CreateTime.TimeOfDay.ToString()) > TimeSpan.Zero).ToList());
|
||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5
|
||||
//FROM `tb_topic` a
|
||||
//WHERE (cast(date_format(date_add(cast('0001/1/1 0:00:00' as datetime), interval (timestampdiff(microsecond, date_format(a.`CreateTime`, '1970-1-1 %H:%i:%s.%f'), a.`CreateTime`) + 62135596800000000)) microsecond), '%Y-%m-%d %H:%i:%s.%f') as signed) > 0)
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,104 @@
|
||||
using FreeSql.DataAnnotations;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Xunit;
|
||||
|
||||
namespace FreeSql.Tests.Odbc.SqlServer
|
||||
{
|
||||
[Collection("SqlServerCollection")]
|
||||
public class SqlServerDeleteTest
|
||||
{
|
||||
IDelete<Topic> delete => g.sqlserver.Delete<Topic>(); //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
|
||||
[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.sqlserver.Delete<Topic>().ToSql());
|
||||
var sql = g.sqlserver.Delete<Topic>(new[] { 1, 2 }).ToSql();
|
||||
Assert.Equal("DELETE FROM [tb_topic22211] WHERE ([Id] = 1 OR [Id] = 2)", sql);
|
||||
|
||||
sql = g.sqlserver.Delete<Topic>(new Topic { Id = 1, Title = "test" }).ToSql();
|
||||
Assert.Equal("DELETE FROM [tb_topic22211] WHERE ([Id] = 1)", sql);
|
||||
|
||||
sql = g.sqlserver.Delete<Topic>(new[] { new Topic { Id = 1, Title = "test" }, new Topic { Id = 2, Title = "test" } }).ToSql();
|
||||
Assert.Equal("DELETE FROM [tb_topic22211] WHERE ([Id] = 1 OR [Id] = 2)", sql);
|
||||
|
||||
sql = g.sqlserver.Delete<Topic>(new { id = 1 }).ToSql();
|
||||
Assert.Equal("DELETE FROM [tb_topic22211] WHERE ([Id] = 1)", sql);
|
||||
}
|
||||
|
||||
[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 WhereExists()
|
||||
{
|
||||
|
||||
}
|
||||
[Fact]
|
||||
public void ExecuteAffrows()
|
||||
{
|
||||
|
||||
var id = g.sqlserver.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.sqlserver.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);
|
||||
|
||||
var items = Enumerable.Range(0, 301).Select(a => new Topic { Title = "xxxx" + a, CreateTime = DateTime.Now });
|
||||
var itemsInserted = g.sqlserver.Insert<Topic>(items).ExecuteInserted();
|
||||
Assert.Equal(items.First().Title, itemsInserted[0].Title);
|
||||
|
||||
Assert.Equal(itemsInserted[0].Id, delete.Where(a => a.Id == itemsInserted[0].Id).ExecuteDeleted()[0].Id);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void AsTable()
|
||||
{
|
||||
Assert.Null(g.sqlserver.Delete<Topic>().ToSql());
|
||||
var sql = g.sqlserver.Delete<Topic>(new[] { 1, 2 }).AsTable(a => "tb_topic22211AsTable").ToSql();
|
||||
Assert.Equal("DELETE FROM [tb_topic22211AsTable] WHERE ([Id] = 1 OR [Id] = 2)", sql);
|
||||
|
||||
sql = g.sqlserver.Delete<Topic>(new Topic { Id = 1, Title = "test" }).AsTable(a => "tb_topic22211AsTable").ToSql();
|
||||
Assert.Equal("DELETE FROM [tb_topic22211AsTable] WHERE ([Id] = 1)", sql);
|
||||
|
||||
sql = g.sqlserver.Delete<Topic>(new[] { new Topic { Id = 1, Title = "test" }, new Topic { Id = 2, Title = "test" } }).AsTable(a => "tb_topic22211AsTable").ToSql();
|
||||
Assert.Equal("DELETE FROM [tb_topic22211AsTable] WHERE ([Id] = 1 OR [Id] = 2)", sql);
|
||||
|
||||
sql = g.sqlserver.Delete<Topic>(new { id = 1 }).AsTable(a => "tb_topic22211AsTable").ToSql();
|
||||
Assert.Equal("DELETE FROM [tb_topic22211AsTable] WHERE ([Id] = 1)", sql);
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,155 @@
|
||||
using FreeSql.DataAnnotations;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Xunit;
|
||||
|
||||
namespace FreeSql.Tests.Odbc.SqlServer
|
||||
{
|
||||
[Collection("SqlServerCollection")]
|
||||
public class SqlServerInsertTest
|
||||
{
|
||||
IInsert<Topic> insert => g.sqlserver.Insert<Topic>(); //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
|
||||
[Table(Name = "tb_topic")]
|
||||
class Topic
|
||||
{
|
||||
[Column(IsIdentity = true, IsPrimary = true)]
|
||||
public int Id { get; set; }
|
||||
public int? Clicks { get; set; }
|
||||
public int TypeGuid { get; set; }
|
||||
public TestTypeInfo Type { get; set; }
|
||||
public string Title { get; set; }
|
||||
public DateTime CreateTime { get; set; }
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void AppendData()
|
||||
{
|
||||
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, CreateTime = DateTime.Parse("2019-09-19 20:09:37.328") });
|
||||
|
||||
var sql = insert.IgnoreColumns(a => a.TypeGuid).AppendData(items.First()).ToSql();
|
||||
Assert.Equal("INSERT INTO [tb_topic]([Clicks], [Title], [CreateTime]) VALUES(0, N'newtitle0', '2019-09-19 20:09:37.328')", sql);
|
||||
|
||||
sql = insert.IgnoreColumns(a => a.TypeGuid).AppendData(items).ToSql();
|
||||
Assert.Equal("INSERT INTO [tb_topic]([Clicks], [Title], [CreateTime]) VALUES(0, N'newtitle0', '2019-09-19 20:09:37.328'), (100, N'newtitle1', '2019-09-19 20:09:37.328'), (200, N'newtitle2', '2019-09-19 20:09:37.328'), (300, N'newtitle3', '2019-09-19 20:09:37.328'), (400, N'newtitle4', '2019-09-19 20:09:37.328'), (500, N'newtitle5', '2019-09-19 20:09:37.328'), (600, N'newtitle6', '2019-09-19 20:09:37.328'), (700, N'newtitle7', '2019-09-19 20:09:37.328'), (800, N'newtitle8', '2019-09-19 20:09:37.328'), (900, N'newtitle9', '2019-09-19 20:09:37.328')", sql);
|
||||
|
||||
sql = insert.AppendData(items).InsertColumns(a => a.Title).ToSql();
|
||||
Assert.Equal("INSERT INTO [tb_topic]([Title]) VALUES(N'newtitle0'), (N'newtitle1'), (N'newtitle2'), (N'newtitle3'), (N'newtitle4'), (N'newtitle5'), (N'newtitle6'), (N'newtitle7'), (N'newtitle8'), (N'newtitle9')", sql);
|
||||
|
||||
sql = insert.IgnoreColumns(a => new { a.CreateTime, a.TypeGuid }).AppendData(items).ToSql();
|
||||
Assert.Equal("INSERT INTO [tb_topic]([Clicks], [Title]) VALUES(0, N'newtitle0'), (100, N'newtitle1'), (200, N'newtitle2'), (300, N'newtitle3'), (400, N'newtitle4'), (500, N'newtitle5'), (600, N'newtitle6'), (700, N'newtitle7'), (800, N'newtitle8'), (900, N'newtitle9')", sql);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void InsertColumns()
|
||||
{
|
||||
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, CreateTime = DateTime.Now });
|
||||
|
||||
var sql = insert.AppendData(items).InsertColumns(a => a.Title).ToSql();
|
||||
Assert.Equal("INSERT INTO [tb_topic]([Title]) VALUES(N'newtitle0'), (N'newtitle1'), (N'newtitle2'), (N'newtitle3'), (N'newtitle4'), (N'newtitle5'), (N'newtitle6'), (N'newtitle7'), (N'newtitle8'), (N'newtitle9')", sql);
|
||||
|
||||
sql = insert.AppendData(items).InsertColumns(a => new { a.Title, a.Clicks }).ToSql();
|
||||
Assert.Equal("INSERT INTO [tb_topic]([Clicks], [Title]) VALUES(0, N'newtitle0'), (100, N'newtitle1'), (200, N'newtitle2'), (300, N'newtitle3'), (400, N'newtitle4'), (500, N'newtitle5'), (600, N'newtitle6'), (700, N'newtitle7'), (800, N'newtitle8'), (900, N'newtitle9')", sql);
|
||||
}
|
||||
[Fact]
|
||||
public void IgnoreColumns()
|
||||
{
|
||||
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, CreateTime = DateTime.Now });
|
||||
|
||||
var sql = insert.AppendData(items).IgnoreColumns(a => new { a.CreateTime, a.TypeGuid }).ToSql();
|
||||
Assert.Equal("INSERT INTO [tb_topic]([Clicks], [Title]) VALUES(0, N'newtitle0'), (100, N'newtitle1'), (200, N'newtitle2'), (300, N'newtitle3'), (400, N'newtitle4'), (500, N'newtitle5'), (600, N'newtitle6'), (700, N'newtitle7'), (800, N'newtitle8'), (900, N'newtitle9')", sql);
|
||||
|
||||
sql = insert.AppendData(items).IgnoreColumns(a => new { a.Title, a.CreateTime, a.TypeGuid }).ToSql();
|
||||
Assert.Equal("INSERT INTO [tb_topic]([Clicks]) VALUES(0), (100), (200), (300), (400), (500), (600), (700), (800), (900)", sql);
|
||||
|
||||
g.sqlserver.Delete<TopicIgnore>().Where("1=1").ExecuteAffrows();
|
||||
var itemsIgnore = new List<TopicIgnore>();
|
||||
for (var a = 0; a < 2072; a++) itemsIgnore.Add(new TopicIgnore { Id = a + 1, Title = $"newtitle{a}", Clicks = a * 100, CreateTime = DateTime.Now });
|
||||
g.sqlserver.Insert<TopicIgnore>().AppendData(itemsIgnore).IgnoreColumns(a => new { a.Title }).ExecuteAffrows();
|
||||
Assert.Equal(2072, itemsIgnore.Count);
|
||||
Assert.Equal(2072, g.sqlserver.Select<TopicIgnore>().Where(a => a.Title == null).Count());
|
||||
}
|
||||
[Table(Name = "tb_topicIgnoreColumns")]
|
||||
class TopicIgnore
|
||||
{
|
||||
[Column(IsIdentity = true, IsPrimary = true)]
|
||||
public int Id { get; set; }
|
||||
public int Clicks { get; set; }
|
||||
public string Title { get; set; }
|
||||
public DateTime CreateTime { get; set; }
|
||||
}
|
||||
[Fact]
|
||||
public void ExecuteAffrows()
|
||||
{
|
||||
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, CreateTime = DateTime.Now });
|
||||
|
||||
Assert.Equal(1, insert.AppendData(items.First()).ExecuteAffrows());
|
||||
Assert.Equal(10, insert.AppendData(items).ExecuteAffrows());
|
||||
|
||||
//items = Enumerable.Range(0, 9989).Select(a => new Topic { Title = "newtitle" + a, CreateTime = DateTime.Now }).ToList();
|
||||
//Assert.Equal(9989, g.sqlserver.Insert<Topic>(items).ExecuteAffrows());
|
||||
}
|
||||
[Fact]
|
||||
public void ExecuteIdentity()
|
||||
{
|
||||
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, CreateTime = DateTime.Now });
|
||||
|
||||
Assert.NotEqual(0, insert.AppendData(items.First()).ExecuteIdentity());
|
||||
|
||||
|
||||
//items = Enumerable.Range(0, 9999).Select(a => new Topic { Title = "newtitle" + a, CreateTime = DateTime.Now }).ToList();
|
||||
//var lastId = g.sqlite.Select<Topic>().Max(a => a.Id);
|
||||
//Assert.NotEqual(lastId, g.sqlserver.Insert<Topic>(items).ExecuteIdentity());
|
||||
}
|
||||
[Fact]
|
||||
public void ExecuteInserted()
|
||||
{
|
||||
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, CreateTime = DateTime.Now });
|
||||
|
||||
var items2 = insert.AppendData(items).ExecuteInserted();
|
||||
|
||||
items = Enumerable.Range(0, 90).Select(a => new Topic { Title = "newtitle" + a, CreateTime = DateTime.Now }).ToList();
|
||||
var itemsInserted = g.sqlserver.Insert<Topic>(items).ExecuteInserted();
|
||||
Assert.Equal(items.First().Title, itemsInserted.First().Title);
|
||||
Assert.Equal(items.Last().Title, itemsInserted.Last().Title);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void AsTable()
|
||||
{
|
||||
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, CreateTime = DateTime.Parse("2019-09-19 20:01:51.149") });
|
||||
|
||||
var sql = insert.IgnoreColumns(a => a.TypeGuid).AppendData(items.First()).AsTable(a => "tb_topicAsTable").ToSql();
|
||||
Assert.Equal("INSERT INTO [tb_topicAsTable]([Clicks], [Title], [CreateTime]) VALUES(0, N'newtitle0', '2019-09-19 20:01:51.149')", sql);
|
||||
|
||||
sql = insert.IgnoreColumns(a => a.TypeGuid).AppendData(items).AsTable(a => "tb_topicAsTable").ToSql();
|
||||
Assert.Equal("INSERT INTO [tb_topicAsTable]([Clicks], [Title], [CreateTime]) VALUES(0, N'newtitle0', '2019-09-19 20:01:51.149'), (100, N'newtitle1', '2019-09-19 20:01:51.149'), (200, N'newtitle2', '2019-09-19 20:01:51.149'), (300, N'newtitle3', '2019-09-19 20:01:51.149'), (400, N'newtitle4', '2019-09-19 20:01:51.149'), (500, N'newtitle5', '2019-09-19 20:01:51.149'), (600, N'newtitle6', '2019-09-19 20:01:51.149'), (700, N'newtitle7', '2019-09-19 20:01:51.149'), (800, N'newtitle8', '2019-09-19 20:01:51.149'), (900, N'newtitle9', '2019-09-19 20:01:51.149')", sql);
|
||||
|
||||
sql = insert.IgnoreColumns(a => a.TypeGuid).AppendData(items).InsertColumns(a => a.Title).AsTable(a => "tb_topicAsTable").ToSql();
|
||||
Assert.Equal("INSERT INTO [tb_topicAsTable]([Title]) VALUES(N'newtitle0'), (N'newtitle1'), (N'newtitle2'), (N'newtitle3'), (N'newtitle4'), (N'newtitle5'), (N'newtitle6'), (N'newtitle7'), (N'newtitle8'), (N'newtitle9')", sql);
|
||||
|
||||
sql = insert.IgnoreColumns(a => new { a.CreateTime, a.TypeGuid }).AppendData(items).AsTable(a => "tb_topicAsTable").ToSql();
|
||||
Assert.Equal("INSERT INTO [tb_topicAsTable]([Clicks], [Title]) VALUES(0, N'newtitle0'), (100, N'newtitle1'), (200, N'newtitle2'), (300, N'newtitle3'), (400, N'newtitle4'), (500, N'newtitle5'), (600, N'newtitle6'), (700, N'newtitle7'), (800, N'newtitle8'), (900, N'newtitle9')", sql);
|
||||
|
||||
sql = insert.IgnoreColumns(a => new { a.Title, a.TypeGuid }).InsertColumns(a => a.Title).AppendData(items).AsTable(a => "tb_topicAsTable").ToSql();
|
||||
Assert.Equal("INSERT INTO [tb_topicAsTable]([Title]) VALUES(N'newtitle0'), (N'newtitle1'), (N'newtitle2'), (N'newtitle3'), (N'newtitle4'), (N'newtitle5'), (N'newtitle6'), (N'newtitle7'), (N'newtitle8'), (N'newtitle9')", sql);
|
||||
|
||||
sql = insert.IgnoreColumns(a => a.TypeGuid).AppendData(items).InsertColumns(a => new { a.Title, a.Clicks }).AsTable(a => "tb_topicAsTable").ToSql();
|
||||
Assert.Equal("INSERT INTO [tb_topicAsTable]([Clicks], [Title]) VALUES(0, N'newtitle0'), (100, N'newtitle1'), (200, N'newtitle2'), (300, N'newtitle3'), (400, N'newtitle4'), (500, N'newtitle5'), (600, N'newtitle6'), (700, N'newtitle7'), (800, N'newtitle8'), (900, N'newtitle9')", sql);
|
||||
|
||||
sql = insert.IgnoreColumns(a => new { a.CreateTime, a.TypeGuid }).AppendData(items).AsTable(a => "tb_topicAsTable").ToSql();
|
||||
Assert.Equal("INSERT INTO [tb_topicAsTable]([Clicks], [Title]) VALUES(0, N'newtitle0'), (100, N'newtitle1'), (200, N'newtitle2'), (300, N'newtitle3'), (400, N'newtitle4'), (500, N'newtitle5'), (600, N'newtitle6'), (700, N'newtitle7'), (800, N'newtitle8'), (900, N'newtitle9')", sql);
|
||||
|
||||
sql = insert.IgnoreColumns(a => new { a.CreateTime, a.Title, a.TypeGuid }).AppendData(items).AsTable(a => "tb_topicAsTable").ToSql();
|
||||
Assert.Equal("INSERT INTO [tb_topicAsTable]([Clicks]) VALUES(0), (100), (200), (300), (400), (500), (600), (700), (800), (900)", sql);
|
||||
}
|
||||
}
|
||||
}
|
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,161 @@
|
||||
using FreeSql.DataAnnotations;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Xunit;
|
||||
|
||||
namespace FreeSql.Tests.Odbc.SqlServer
|
||||
{
|
||||
[Collection("SqlServerCollection")]
|
||||
public class SqlServerUpdateTest
|
||||
{
|
||||
IUpdate<Topic> update => g.sqlserver.Update<Topic>();
|
||||
|
||||
[Table(Name = "tb_topic")]
|
||||
class Topic
|
||||
{
|
||||
[Column(IsIdentity = true, IsPrimary = true)]
|
||||
public int Id { get; set; }
|
||||
public int? Clicks { get; set; }
|
||||
public int TypeGuid { get; set; }
|
||||
public TestTypeInfo Type { get; set; }
|
||||
public string Title { get; set; }
|
||||
public DateTime CreateTime { get; set; }
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Dywhere()
|
||||
{
|
||||
Assert.Null(g.sqlserver.Update<Topic>().ToSql());
|
||||
Assert.Equal("UPDATE [tb_topic] SET title='test' \r\nWHERE ([Id] = 1 OR [Id] = 2)", g.sqlserver.Update<Topic>(new[] { 1, 2 }).SetRaw("title='test'").ToSql());
|
||||
Assert.Equal("UPDATE [tb_topic] SET title='test1' \r\nWHERE ([Id] = 1)", g.sqlserver.Update<Topic>(new Topic { Id = 1, Title = "test" }).SetRaw("title='test1'").ToSql());
|
||||
Assert.Equal("UPDATE [tb_topic] SET title='test1' \r\nWHERE ([Id] = 1 OR [Id] = 2)", g.sqlserver.Update<Topic>(new[] { new Topic { Id = 1, Title = "test" }, new Topic { Id = 2, Title = "test" } }).SetRaw("title='test1'").ToSql());
|
||||
Assert.Equal("UPDATE [tb_topic] SET title='test1' \r\nWHERE ([Id] = 1)", g.sqlserver.Update<Topic>(new { id = 1 }).SetRaw("title='test1'").ToSql());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void SetSource()
|
||||
{
|
||||
var sql = update.SetSource(new Topic { Id = 1, Title = "newtitle" }).IgnoreColumns(a => a.TypeGuid).ToSql().Replace("\r\n", "");
|
||||
Assert.Equal("UPDATE [tb_topic] SET [Clicks] = NULL, [Title] = N'newtitle', [CreateTime] = '1970-01-01 00:00:00.000' 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 });
|
||||
items[0].Clicks = null;
|
||||
|
||||
sql = update.SetSource(items).IgnoreColumns(a => a.TypeGuid).ToSql().Replace("\r\n", "");
|
||||
Assert.Equal("UPDATE [tb_topic] SET [Clicks] = CASE [Id] WHEN 1 THEN NULL WHEN 2 THEN 100 WHEN 3 THEN 200 WHEN 4 THEN 300 WHEN 5 THEN 400 WHEN 6 THEN 500 WHEN 7 THEN 600 WHEN 8 THEN 700 WHEN 9 THEN 800 WHEN 10 THEN 900 END, [Title] = CASE [Id] WHEN 1 THEN N'newtitle0' WHEN 2 THEN N'newtitle1' WHEN 3 THEN N'newtitle2' WHEN 4 THEN N'newtitle3' WHEN 5 THEN N'newtitle4' WHEN 6 THEN N'newtitle5' WHEN 7 THEN N'newtitle6' WHEN 8 THEN N'newtitle7' WHEN 9 THEN N'newtitle8' WHEN 10 THEN N'newtitle9' END, [CreateTime] = CASE [Id] WHEN 1 THEN '1970-01-01 00:00:00.000' WHEN 2 THEN '1970-01-01 00:00:00.000' WHEN 3 THEN '1970-01-01 00:00:00.000' WHEN 4 THEN '1970-01-01 00:00:00.000' WHEN 5 THEN '1970-01-01 00:00:00.000' WHEN 6 THEN '1970-01-01 00:00:00.000' WHEN 7 THEN '1970-01-01 00:00:00.000' WHEN 8 THEN '1970-01-01 00:00:00.000' WHEN 9 THEN '1970-01-01 00:00:00.000' WHEN 10 THEN '1970-01-01 00:00:00.000' END WHERE ([Id] IN (1,2,3,4,5,6,7,8,9,10))", sql);
|
||||
|
||||
sql = update.SetSource(items).IgnoreColumns(a => new { a.Clicks, a.CreateTime, a.TypeGuid }).ToSql().Replace("\r\n", "");
|
||||
Assert.Equal("UPDATE [tb_topic] SET [Title] = CASE [Id] WHEN 1 THEN N'newtitle0' WHEN 2 THEN N'newtitle1' WHEN 3 THEN N'newtitle2' WHEN 4 THEN N'newtitle3' WHEN 5 THEN N'newtitle4' WHEN 6 THEN N'newtitle5' WHEN 7 THEN N'newtitle6' WHEN 8 THEN N'newtitle7' WHEN 9 THEN N'newtitle8' WHEN 10 THEN N'newtitle9' END WHERE ([Id] IN (1,2,3,4,5,6,7,8,9,10))", sql);
|
||||
|
||||
sql = update.SetSource(items).IgnoreColumns(a => a.TypeGuid).Set(a => a.CreateTime, new DateTime(2020, 1, 1)).ToSql().Replace("\r\n", "");
|
||||
Assert.Equal("UPDATE [tb_topic] SET [CreateTime] = '2020-01-01 00:00:00.000' WHERE ([Id] IN (1,2,3,4,5,6,7,8,9,10))", sql);
|
||||
}
|
||||
[Fact]
|
||||
public void IgnoreColumns()
|
||||
{
|
||||
var sql = update.SetSource(new Topic { Id = 1, Title = "newtitle" }).IgnoreColumns(a => new { a.Clicks, a.CreateTime, a.TypeGuid }).ToSql().Replace("\r\n", "");
|
||||
Assert.Equal("UPDATE [tb_topic] SET [Title] = N'newtitle' WHERE ([Id] = 1)", sql);
|
||||
}
|
||||
[Fact]
|
||||
public void UpdateColumns()
|
||||
{
|
||||
var sql = update.SetSource(new Topic { Id = 1, Title = "newtitle" }).UpdateColumns(a => a.Title).ToSql().Replace("\r\n", "");
|
||||
Assert.Equal("UPDATE [tb_topic] SET [Title] = N'newtitle' WHERE ([Id] = 1)", sql);
|
||||
}
|
||||
[Fact]
|
||||
public void Set()
|
||||
{
|
||||
var sql = update.Where(a => a.Id == 1).Set(a => a.Title, "newtitle").ToSql().Replace("\r\n", "");
|
||||
Assert.Equal("UPDATE [tb_topic] SET [Title] = N'newtitle' WHERE ([Id] = 1)", sql);
|
||||
|
||||
sql = update.Where(a => a.Id == 1).Set(a => a.Title, "newtitle").Set(a => a.CreateTime, new DateTime(2020, 1, 1)).ToSql().Replace("\r\n", "");
|
||||
Assert.Equal("UPDATE [tb_topic] SET [Title] = N'newtitle', [CreateTime] = '2020-01-01 00:00:00.000' WHERE ([Id] = 1)", sql);
|
||||
|
||||
sql = update.Set(a => a.Clicks * 10 / 1).Where(a => a.Id == 1).ToSql().Replace("\r\n", "");
|
||||
Assert.Equal("UPDATE [tb_topic] SET [Clicks] = isnull([Clicks], 0) * 10 / 1 WHERE ([Id] = 1)", sql);
|
||||
|
||||
sql = update.Set(a => a.Id - 10).Where(a => a.Id == 1).ToSql().Replace("\r\n", "");
|
||||
Assert.Equal("UPDATE [tb_topic] SET [Id] = ([Id] - 10) WHERE ([Id] = 1)", sql);
|
||||
|
||||
int incrv = 10;
|
||||
sql = update.Set(a => a.Clicks * incrv / 1).Where(a => a.Id == 1).ToSql().Replace("\r\n", "");
|
||||
Assert.Equal("UPDATE [tb_topic] SET [Clicks] = isnull([Clicks], 0) * 10 / 1 WHERE ([Id] = 1)", sql);
|
||||
|
||||
sql = update.Set(a => a.Id - incrv).Where(a => a.Id == 1).ToSql().Replace("\r\n", "");
|
||||
Assert.Equal("UPDATE [tb_topic] SET [Id] = ([Id] - 10) WHERE ([Id] = 1)", sql);
|
||||
|
||||
sql = update.Set(a => a.Clicks == a.Clicks * 10 / 1).Where(a => a.Id == 1).ToSql().Replace("\r\n", "");
|
||||
Assert.Equal("UPDATE [tb_topic] SET [Clicks] = [Clicks] * 10 / 1 WHERE ([Id] = 1)", sql);
|
||||
|
||||
sql = update.Set(a => a.Id == 10).Where(a => a.Id == 1).ToSql().Replace("\r\n", "");
|
||||
Assert.Equal("UPDATE [tb_topic] SET [Id] = 10 WHERE ([Id] = 1)", sql);
|
||||
}
|
||||
[Fact]
|
||||
public void SetRaw()
|
||||
{
|
||||
var sql = update.Where(a => a.Id == 1).SetRaw("clicks = clicks + ?", new { incrClick = 1 }).ToSql().Replace("\r\n", "");
|
||||
Assert.Equal("UPDATE [tb_topic] SET clicks = clicks + ? WHERE ([Id] = 1)", sql);
|
||||
}
|
||||
[Fact]
|
||||
public void Where()
|
||||
{
|
||||
var sql = update.Where(a => a.Id == 1).SetRaw("title='newtitle'").ToSql().Replace("\r\n", "");
|
||||
Assert.Equal("UPDATE [tb_topic] SET title='newtitle' WHERE ([Id] = 1)", sql);
|
||||
|
||||
sql = update.Where("id = ?", new { id = 1 }).SetRaw("title='newtitle'").ToSql().Replace("\r\n", "");
|
||||
Assert.Equal("UPDATE [tb_topic] SET title='newtitle' WHERE (id = ?)", sql);
|
||||
|
||||
var item = new Topic { Id = 1, Title = "newtitle" };
|
||||
sql = update.Where(item).SetRaw("title='newtitle'").ToSql().Replace("\r\n", "");
|
||||
Assert.Equal("UPDATE [tb_topic] SET title='newtitle' 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 = update.Where(items).SetRaw("title='newtitle'").ToSql().Replace("\r\n", "");
|
||||
Assert.Equal("UPDATE [tb_topic] SET title='newtitle' WHERE ([Id] IN (1,2,3,4,5,6,7,8,9,10))", sql);
|
||||
}
|
||||
[Fact]
|
||||
public void WhereExists()
|
||||
{
|
||||
|
||||
}
|
||||
[Fact]
|
||||
public void ExecuteAffrows()
|
||||
{
|
||||
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 });
|
||||
|
||||
var time = DateTime.Now;
|
||||
var items222 = g.sqlserver.Select<Topic>().Where(a => a.CreateTime > time).Limit(10).ToList();
|
||||
|
||||
update.SetSource(items.First()).NoneParameter().ExecuteAffrows();
|
||||
update.SetSource(items).NoneParameter().ExecuteAffrows();
|
||||
}
|
||||
[Fact]
|
||||
public void ExecuteUpdated()
|
||||
{
|
||||
g.sqlserver.Insert<Topic>().AppendData(new Topic()).ExecuteAffrows();
|
||||
g.sqlserver.Insert<Topic>().AppendData(new Topic()).ExecuteAffrows();
|
||||
g.sqlserver.Insert<Topic>().AppendData(new Topic()).ExecuteAffrows();
|
||||
g.sqlserver.Insert<Topic>().AppendData(new Topic()).ExecuteAffrows();
|
||||
|
||||
var items = g.sqlserver.Select<Topic>().Limit(2).ToList();
|
||||
g.sqlserver.Update<Topic>(items).SetRaw("title='test'").ExecuteUpdated();
|
||||
|
||||
items = g.sqlserver.Select<Topic>().Limit(2).ToList();
|
||||
var result = g.sqlserver.Update<Topic>(items).SetRaw("title='test'").ExecuteUpdatedAsync().Result;
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void AsTable()
|
||||
{
|
||||
Assert.Null(g.sqlserver.Update<Topic>().ToSql());
|
||||
Assert.Equal("UPDATE [tb_topicAsTable] SET title='test' \r\nWHERE ([Id] = 1 OR [Id] = 2)", g.sqlserver.Update<Topic>(new[] { 1, 2 }).SetRaw("title='test'").AsTable(a => "tb_topicAsTable").ToSql());
|
||||
Assert.Equal("UPDATE [tb_topicAsTable] SET title='test1' \r\nWHERE ([Id] = 1)", g.sqlserver.Update<Topic>(new Topic { Id = 1, Title = "test" }).SetRaw("title='test1'").AsTable(a => "tb_topicAsTable").ToSql());
|
||||
Assert.Equal("UPDATE [tb_topicAsTable] SET title='test1' \r\nWHERE ([Id] = 1 OR [Id] = 2)", g.sqlserver.Update<Topic>(new[] { new Topic { Id = 1, Title = "test" }, new Topic { Id = 2, Title = "test" } }).SetRaw("title='test1'").AsTable(a => "tb_topicAsTable").ToSql());
|
||||
Assert.Equal("UPDATE [tb_topicAsTable] SET title='test1' \r\nWHERE ([Id] = 1)", g.sqlserver.Update<Topic>(new { id = 1 }).SetRaw("title='test1'").AsTable(a => "tb_topicAsTable").ToSql());
|
||||
}
|
||||
}
|
||||
}
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,54 @@
|
||||
using FreeSql.DataAnnotations;
|
||||
using System;
|
||||
using System.Numerics;
|
||||
using Xunit;
|
||||
|
||||
namespace FreeSql.Tests.Odbc.SqlServerMapType
|
||||
{
|
||||
public class DateTimeOffSetTest
|
||||
{
|
||||
class DateTimeOffSetTestMap
|
||||
{
|
||||
public Guid id { get; set; }
|
||||
|
||||
[Column(MapType = typeof(DateTime))]
|
||||
public DateTimeOffset dtos_to_dt { get; set; }
|
||||
[Column(MapType = typeof(DateTime))]
|
||||
public DateTimeOffset? dtosnullable_to_dt { get; set; }
|
||||
}
|
||||
[Fact]
|
||||
public void DateTimeToDateTimeOffSet()
|
||||
{
|
||||
//insert
|
||||
var orm = g.sqlserver;
|
||||
var item = new DateTimeOffSetTestMap { dtos_to_dt = DateTimeOffset.Now, dtosnullable_to_dt = DateTimeOffset.Now };
|
||||
Assert.Equal(1, orm.Insert<DateTimeOffSetTestMap>().AppendData(item).ExecuteAffrows());
|
||||
var find = orm.Select<DateTimeOffSetTestMap>().Where(a => a.id == item.id).First();
|
||||
Assert.NotNull(find);
|
||||
Assert.Equal(item.id, find.id);
|
||||
Assert.Equal(item.dtos_to_dt.ToString("g"), find.dtos_to_dt.ToString("g"));
|
||||
Assert.Equal(item.dtosnullable_to_dt.Value.ToString("g"), find.dtosnullable_to_dt.Value.ToString("g"));
|
||||
|
||||
//update all
|
||||
item.dtos_to_dt = DateTimeOffset.Now;
|
||||
Assert.Equal(1, orm.Update<DateTimeOffSetTestMap>().SetSource(item).ExecuteAffrows());
|
||||
find = orm.Select<DateTimeOffSetTestMap>().Where(a => a.id == item.id).First();
|
||||
Assert.NotNull(find);
|
||||
Assert.Equal(item.id, find.id);
|
||||
Assert.Equal(item.dtos_to_dt.ToString("g"), find.dtos_to_dt.ToString("g"));
|
||||
Assert.Equal(item.dtosnullable_to_dt.Value.ToString("g"), find.dtosnullable_to_dt.Value.ToString("g"));
|
||||
|
||||
//update set
|
||||
Assert.Equal(1, orm.Update<DateTimeOffSetTestMap>().Where(a => a.id == item.id).Set(a => a.dtos_to_dt, item.dtos_to_dt = DateTimeOffset.Now).ExecuteAffrows());
|
||||
find = orm.Select<DateTimeOffSetTestMap>().Where(a => a.id == item.id).First();
|
||||
Assert.NotNull(find);
|
||||
Assert.Equal(item.dtos_to_dt.ToString("g"), find.dtos_to_dt.ToString("g"));
|
||||
Assert.Equal(item.dtosnullable_to_dt.Value.ToString("g"), find.dtosnullable_to_dt.Value.ToString("g"));
|
||||
|
||||
//delete
|
||||
Assert.Equal(1, orm.Delete<DateTimeOffSetTestMap>().Where(a => a.id == item.id).ExecuteAffrows());
|
||||
Assert.Null(orm.Select<DateTimeOffSetTestMap>().Where(a => a.id == item.id).First());
|
||||
}
|
||||
|
||||
}
|
||||
}
|
@ -0,0 +1,263 @@
|
||||
using FreeSql.DataAnnotations;
|
||||
using System;
|
||||
using System.Numerics;
|
||||
using Xunit;
|
||||
|
||||
namespace FreeSql.Tests.Odbc.SqlServerMapType
|
||||
{
|
||||
[Collection("SqlServerCollection")]
|
||||
public class EnumTest
|
||||
{
|
||||
|
||||
class EnumTestMap
|
||||
{
|
||||
public Guid id { get; set; }
|
||||
|
||||
[Column(MapType = typeof(string))]
|
||||
public ToStringMapEnum enum_to_string { get; set; }
|
||||
[Column(MapType = typeof(string))]
|
||||
public ToStringMapEnum? enumnullable_to_string { get; set; }
|
||||
|
||||
[Column(MapType = typeof(int))]
|
||||
public ToStringMapEnum enum_to_int { get; set; }
|
||||
[Column(MapType = typeof(int?))]
|
||||
public ToStringMapEnum? enumnullable_to_int { get; set; }
|
||||
}
|
||||
public enum ToStringMapEnum { 中国人, abc, 香港 }
|
||||
[Fact]
|
||||
public void EnumToString()
|
||||
{
|
||||
//insert
|
||||
var orm = g.sqlserver;
|
||||
var item = new EnumTestMap { };
|
||||
Assert.Equal(1, orm.Insert<EnumTestMap>().AppendData(item).ExecuteAffrows());
|
||||
var find = orm.Select<EnumTestMap>().Where(a => a.id == item.id && a.enum_to_string == ToStringMapEnum.中国人).First();
|
||||
Assert.NotNull(find);
|
||||
Assert.Equal(item.id, find.id);
|
||||
Assert.Equal(item.enum_to_string, find.enum_to_string);
|
||||
Assert.Equal(ToStringMapEnum.中国人, find.enum_to_string);
|
||||
|
||||
item = new EnumTestMap { enum_to_string = ToStringMapEnum.abc };
|
||||
Assert.Equal(1, orm.Insert<EnumTestMap>().AppendData(item).ExecuteAffrows());
|
||||
find = orm.Select<EnumTestMap>().Where(a => a.id == item.id && a.enum_to_string == ToStringMapEnum.abc).First();
|
||||
Assert.NotNull(find);
|
||||
Assert.Equal(item.id, find.id);
|
||||
Assert.Equal(item.enum_to_string, find.enum_to_string);
|
||||
Assert.Equal(ToStringMapEnum.abc, find.enum_to_string);
|
||||
|
||||
//update all
|
||||
item.enum_to_string = ToStringMapEnum.香港;
|
||||
Assert.Equal(1, orm.Update<EnumTestMap>().SetSource(item).ExecuteAffrows());
|
||||
find = orm.Select<EnumTestMap>().Where(a => a.id == item.id && a.enum_to_string == ToStringMapEnum.香港).First();
|
||||
Assert.NotNull(find);
|
||||
Assert.Equal(item.id, find.id);
|
||||
Assert.Equal(item.enum_to_string, find.enum_to_string);
|
||||
Assert.Equal(ToStringMapEnum.香港, find.enum_to_string);
|
||||
|
||||
item.enum_to_string = ToStringMapEnum.中国人;
|
||||
Assert.Equal(1, orm.Update<EnumTestMap>().SetSource(item).ExecuteAffrows());
|
||||
find = orm.Select<EnumTestMap>().Where(a => a.id == item.id && a.enum_to_string == ToStringMapEnum.中国人).First();
|
||||
Assert.NotNull(find);
|
||||
Assert.Equal(item.id, find.id);
|
||||
Assert.Equal(item.enum_to_string, find.enum_to_string);
|
||||
Assert.Equal(ToStringMapEnum.中国人, find.enum_to_string);
|
||||
|
||||
//update set
|
||||
Assert.Equal(1, orm.Update<EnumTestMap>().Where(a => a.id == item.id).Set(a => a.enum_to_string, ToStringMapEnum.香港).ExecuteAffrows());
|
||||
find = orm.Select<EnumTestMap>().Where(a => a.id == item.id && a.enum_to_string == ToStringMapEnum.香港).First();
|
||||
Assert.NotNull(find);
|
||||
Assert.Equal(item.id, find.id);
|
||||
Assert.Equal(ToStringMapEnum.香港, find.enum_to_string);
|
||||
|
||||
Assert.Equal(1, orm.Update<EnumTestMap>().Where(a => a.id == item.id).Set(a => a.enum_to_string, ToStringMapEnum.abc).ExecuteAffrows());
|
||||
find = orm.Select<EnumTestMap>().Where(a => a.id == item.id && a.enum_to_string == ToStringMapEnum.abc).First();
|
||||
Assert.NotNull(find);
|
||||
Assert.Equal(item.id, find.id);
|
||||
Assert.Equal(ToStringMapEnum.abc, find.enum_to_string);
|
||||
|
||||
//delete
|
||||
Assert.Equal(0, orm.Delete<EnumTestMap>().Where(a => a.id == item.id && a.enum_to_string == ToStringMapEnum.中国人).ExecuteAffrows());
|
||||
Assert.Equal(0, orm.Delete<EnumTestMap>().Where(a => a.id == item.id && a.enum_to_string == ToStringMapEnum.香港).ExecuteAffrows());
|
||||
Assert.Equal(1, orm.Delete<EnumTestMap>().Where(a => a.id == item.id && a.enum_to_string == ToStringMapEnum.abc).ExecuteAffrows());
|
||||
Assert.Null(orm.Select<EnumTestMap>().Where(a => a.id == item.id).First());
|
||||
}
|
||||
[Fact]
|
||||
public void EnumNullableToString()
|
||||
{
|
||||
//insert
|
||||
var orm = g.sqlserver;
|
||||
var item = new EnumTestMap { };
|
||||
Assert.Equal(1, orm.Insert<EnumTestMap>().AppendData(item).ExecuteAffrows());
|
||||
var find = orm.Select<EnumTestMap>().Where(a => a.id == item.id && a.enumnullable_to_string == null).First();
|
||||
Assert.NotNull(find);
|
||||
Assert.Equal(item.id, find.id);
|
||||
Assert.Equal(item.enumnullable_to_string, find.enumnullable_to_string);
|
||||
Assert.Null(find.enumnullable_to_string);
|
||||
|
||||
item = new EnumTestMap { enumnullable_to_string = ToStringMapEnum.中国人 };
|
||||
Assert.Equal(1, orm.Insert<EnumTestMap>().AppendData(item).ExecuteAffrows());
|
||||
find = orm.Select<EnumTestMap>().Where(a => a.id == item.id && a.enumnullable_to_string == ToStringMapEnum.中国人).First();
|
||||
Assert.NotNull(find);
|
||||
Assert.Equal(item.id, find.id);
|
||||
Assert.Equal(item.enumnullable_to_string, find.enumnullable_to_string);
|
||||
Assert.Equal(ToStringMapEnum.中国人, find.enumnullable_to_string);
|
||||
|
||||
//update all
|
||||
item.enumnullable_to_string = ToStringMapEnum.香港;
|
||||
Assert.Equal(1, orm.Update<EnumTestMap>().SetSource(item).ExecuteAffrows());
|
||||
find = orm.Select<EnumTestMap>().Where(a => a.id == item.id && a.enumnullable_to_string == ToStringMapEnum.香港).First();
|
||||
Assert.NotNull(find);
|
||||
Assert.Equal(item.id, find.id);
|
||||
Assert.Equal(item.enumnullable_to_string, find.enumnullable_to_string);
|
||||
Assert.Equal(ToStringMapEnum.香港, find.enumnullable_to_string);
|
||||
|
||||
item.enumnullable_to_string = null;
|
||||
Assert.Equal(1, orm.Update<EnumTestMap>().SetSource(item).ExecuteAffrows());
|
||||
Assert.Null(orm.Select<EnumTestMap>().Where(a => a.id == item.id && a.enumnullable_to_string == ToStringMapEnum.香港).First());
|
||||
find = orm.Select<EnumTestMap>().Where(a => a.id == item.id && a.enumnullable_to_string == null).First();
|
||||
Assert.NotNull(find);
|
||||
Assert.Equal(item.id, find.id);
|
||||
Assert.Equal(item.enumnullable_to_string, find.enumnullable_to_string);
|
||||
Assert.Null(find.enumnullable_to_string);
|
||||
|
||||
//update set
|
||||
Assert.Equal(1, orm.Update<EnumTestMap>().Where(a => a.id == item.id).Set(a => a.enumnullable_to_string, ToStringMapEnum.abc).ExecuteAffrows());
|
||||
find = orm.Select<EnumTestMap>().Where(a => a.id == item.id && a.enumnullable_to_string == ToStringMapEnum.abc).First();
|
||||
Assert.NotNull(find);
|
||||
Assert.Equal(item.id, find.id);
|
||||
Assert.Equal(ToStringMapEnum.abc, find.enumnullable_to_string);
|
||||
|
||||
|
||||
Assert.Equal(1, orm.Update<EnumTestMap>().Where(a => a.id == item.id).Set(a => a.enumnullable_to_string, null).ExecuteAffrows());
|
||||
Assert.Null(orm.Select<EnumTestMap>().Where(a => a.id == item.id && a.enumnullable_to_string == ToStringMapEnum.abc).First());
|
||||
find = orm.Select<EnumTestMap>().Where(a => a.id == item.id && a.enumnullable_to_string == null).First();
|
||||
Assert.NotNull(find);
|
||||
Assert.Equal(item.id, find.id);
|
||||
Assert.Null(find.enumnullable_to_string);
|
||||
|
||||
//delete
|
||||
Assert.Equal(0, orm.Delete<EnumTestMap>().Where(a => a.id == item.id && a.enumnullable_to_string == ToStringMapEnum.中国人).ExecuteAffrows());
|
||||
Assert.Equal(0, orm.Delete<EnumTestMap>().Where(a => a.id == item.id && a.enumnullable_to_string == ToStringMapEnum.香港).ExecuteAffrows());
|
||||
Assert.Equal(1, orm.Delete<EnumTestMap>().Where(a => a.id == item.id && a.enumnullable_to_string == null).ExecuteAffrows());
|
||||
Assert.Null(orm.Select<EnumTestMap>().Where(a => a.id == item.id).First());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void EnumToInt()
|
||||
{
|
||||
//insert
|
||||
var orm = g.sqlserver;
|
||||
var item = new EnumTestMap { };
|
||||
Assert.Equal(1, orm.Insert<EnumTestMap>().AppendData(item).ExecuteAffrows());
|
||||
var find = orm.Select<EnumTestMap>().Where(a => a.id == item.id && a.enum_to_int == ToStringMapEnum.中国人).First();
|
||||
Assert.NotNull(find);
|
||||
Assert.Equal(item.id, find.id);
|
||||
Assert.Equal(item.enum_to_int, find.enum_to_int);
|
||||
Assert.Equal(ToStringMapEnum.中国人, find.enum_to_int);
|
||||
|
||||
item = new EnumTestMap { enum_to_int = ToStringMapEnum.abc };
|
||||
Assert.Equal(1, orm.Insert<EnumTestMap>().AppendData(item).ExecuteAffrows());
|
||||
find = orm.Select<EnumTestMap>().Where(a => a.id == item.id && a.enum_to_int == ToStringMapEnum.abc).First();
|
||||
Assert.NotNull(find);
|
||||
Assert.Equal(item.id, find.id);
|
||||
Assert.Equal(item.enum_to_int, find.enum_to_int);
|
||||
Assert.Equal(ToStringMapEnum.abc, find.enum_to_int);
|
||||
|
||||
//update all
|
||||
item.enum_to_int = ToStringMapEnum.香港;
|
||||
Assert.Equal(1, orm.Update<EnumTestMap>().SetSource(item).ExecuteAffrows());
|
||||
find = orm.Select<EnumTestMap>().Where(a => a.id == item.id && a.enum_to_int == ToStringMapEnum.香港).First();
|
||||
Assert.NotNull(find);
|
||||
Assert.Equal(item.id, find.id);
|
||||
Assert.Equal(item.enum_to_int, find.enum_to_int);
|
||||
Assert.Equal(ToStringMapEnum.香港, find.enum_to_int);
|
||||
|
||||
item.enum_to_int = ToStringMapEnum.中国人;
|
||||
Assert.Equal(1, orm.Update<EnumTestMap>().SetSource(item).ExecuteAffrows());
|
||||
find = orm.Select<EnumTestMap>().Where(a => a.id == item.id && a.enum_to_int == ToStringMapEnum.中国人).First();
|
||||
Assert.NotNull(find);
|
||||
Assert.Equal(item.id, find.id);
|
||||
Assert.Equal(item.enum_to_int, find.enum_to_int);
|
||||
Assert.Equal(ToStringMapEnum.中国人, find.enum_to_int);
|
||||
|
||||
//update set
|
||||
Assert.Equal(1, orm.Update<EnumTestMap>().Where(a => a.id == item.id).Set(a => a.enum_to_int, ToStringMapEnum.香港).ExecuteAffrows());
|
||||
find = orm.Select<EnumTestMap>().Where(a => a.id == item.id && a.enum_to_int == ToStringMapEnum.香港).First();
|
||||
Assert.NotNull(find);
|
||||
Assert.Equal(item.id, find.id);
|
||||
Assert.Equal(ToStringMapEnum.香港, find.enum_to_int);
|
||||
|
||||
Assert.Equal(1, orm.Update<EnumTestMap>().Where(a => a.id == item.id).Set(a => a.enum_to_int, ToStringMapEnum.abc).ExecuteAffrows());
|
||||
find = orm.Select<EnumTestMap>().Where(a => a.id == item.id && a.enum_to_int == ToStringMapEnum.abc).First();
|
||||
Assert.NotNull(find);
|
||||
Assert.Equal(item.id, find.id);
|
||||
Assert.Equal(ToStringMapEnum.abc, find.enum_to_int);
|
||||
|
||||
//delete
|
||||
Assert.Equal(0, orm.Delete<EnumTestMap>().Where(a => a.id == item.id && a.enum_to_int == ToStringMapEnum.中国人).ExecuteAffrows());
|
||||
Assert.Equal(0, orm.Delete<EnumTestMap>().Where(a => a.id == item.id && a.enum_to_int == ToStringMapEnum.香港).ExecuteAffrows());
|
||||
Assert.Equal(1, orm.Delete<EnumTestMap>().Where(a => a.id == item.id && a.enum_to_int == ToStringMapEnum.abc).ExecuteAffrows());
|
||||
Assert.Null(orm.Select<EnumTestMap>().Where(a => a.id == item.id).First());
|
||||
}
|
||||
[Fact]
|
||||
public void EnumNullableToInt()
|
||||
{
|
||||
//insert
|
||||
var orm = g.sqlserver;
|
||||
var item = new EnumTestMap { };
|
||||
Assert.Equal(1, orm.Insert<EnumTestMap>().AppendData(item).ExecuteAffrows());
|
||||
var find = orm.Select<EnumTestMap>().Where(a => a.id == item.id && a.enumnullable_to_int == null).First();
|
||||
Assert.NotNull(find);
|
||||
Assert.Equal(item.id, find.id);
|
||||
Assert.Equal(item.enumnullable_to_int, find.enumnullable_to_int);
|
||||
Assert.Null(find.enumnullable_to_int);
|
||||
|
||||
item = new EnumTestMap { enumnullable_to_int = ToStringMapEnum.中国人 };
|
||||
Assert.Equal(1, orm.Insert<EnumTestMap>().AppendData(item).ExecuteAffrows());
|
||||
find = orm.Select<EnumTestMap>().Where(a => a.id == item.id && a.enumnullable_to_int == ToStringMapEnum.中国人).First();
|
||||
Assert.NotNull(find);
|
||||
Assert.Equal(item.id, find.id);
|
||||
Assert.Equal(item.enumnullable_to_int, find.enumnullable_to_int);
|
||||
Assert.Equal(ToStringMapEnum.中国人, find.enumnullable_to_int);
|
||||
|
||||
//update all
|
||||
item.enumnullable_to_int = ToStringMapEnum.香港;
|
||||
Assert.Equal(1, orm.Update<EnumTestMap>().SetSource(item).ExecuteAffrows());
|
||||
find = orm.Select<EnumTestMap>().Where(a => a.id == item.id && a.enumnullable_to_int == ToStringMapEnum.香港).First();
|
||||
Assert.NotNull(find);
|
||||
Assert.Equal(item.id, find.id);
|
||||
Assert.Equal(item.enumnullable_to_int, find.enumnullable_to_int);
|
||||
Assert.Equal(ToStringMapEnum.香港, find.enumnullable_to_int);
|
||||
|
||||
item.enumnullable_to_int = null;
|
||||
Assert.Equal(1, orm.Update<EnumTestMap>().SetSource(item).ExecuteAffrows());
|
||||
Assert.Null(orm.Select<EnumTestMap>().Where(a => a.id == item.id && a.enumnullable_to_int == ToStringMapEnum.香港).First());
|
||||
find = orm.Select<EnumTestMap>().Where(a => a.id == item.id && a.enumnullable_to_int == null).First();
|
||||
Assert.NotNull(find);
|
||||
Assert.Equal(item.id, find.id);
|
||||
Assert.Equal(item.enumnullable_to_int, find.enumnullable_to_int);
|
||||
Assert.Null(find.enumnullable_to_int);
|
||||
|
||||
//update set
|
||||
Assert.Equal(1, orm.Update<EnumTestMap>().Where(a => a.id == item.id).Set(a => a.enumnullable_to_int, ToStringMapEnum.abc).ExecuteAffrows());
|
||||
find = orm.Select<EnumTestMap>().Where(a => a.id == item.id && a.enumnullable_to_int == ToStringMapEnum.abc).First();
|
||||
Assert.NotNull(find);
|
||||
Assert.Equal(item.id, find.id);
|
||||
Assert.Equal(ToStringMapEnum.abc, find.enumnullable_to_int);
|
||||
|
||||
|
||||
Assert.Equal(1, orm.Update<EnumTestMap>().Where(a => a.id == item.id).Set(a => a.enumnullable_to_int, null).ExecuteAffrows());
|
||||
Assert.Null(orm.Select<EnumTestMap>().Where(a => a.id == item.id && a.enumnullable_to_int == ToStringMapEnum.abc).First());
|
||||
find = orm.Select<EnumTestMap>().Where(a => a.id == item.id && a.enumnullable_to_int == null).First();
|
||||
Assert.NotNull(find);
|
||||
Assert.Equal(item.id, find.id);
|
||||
Assert.Null(find.enumnullable_to_int);
|
||||
|
||||
//delete
|
||||
Assert.Equal(0, orm.Delete<EnumTestMap>().Where(a => a.id == item.id && a.enumnullable_to_int == ToStringMapEnum.中国人).ExecuteAffrows());
|
||||
Assert.Equal(0, orm.Delete<EnumTestMap>().Where(a => a.id == item.id && a.enumnullable_to_int == ToStringMapEnum.香港).ExecuteAffrows());
|
||||
Assert.Equal(1, orm.Delete<EnumTestMap>().Where(a => a.id == item.id && a.enumnullable_to_int == null).ExecuteAffrows());
|
||||
Assert.Null(orm.Select<EnumTestMap>().Where(a => a.id == item.id).First());
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,571 @@
|
||||
using FreeSql.DataAnnotations;
|
||||
using System;
|
||||
using System.Numerics;
|
||||
using Xunit;
|
||||
|
||||
namespace FreeSql.Tests.Odbc.SqlServerMapType
|
||||
{
|
||||
[Collection("SqlServerCollection")]
|
||||
public class ToStringTest
|
||||
{
|
||||
class ToStringMap
|
||||
{
|
||||
public Guid id { get; set; }
|
||||
|
||||
[Column(MapType = typeof(string))]
|
||||
public TimeSpan timespan_to_string { get; set; }
|
||||
[Column(MapType = typeof(string))]
|
||||
public TimeSpan? timespannullable_to_string { get; set; }
|
||||
|
||||
[Column(MapType = typeof(string))]
|
||||
public DateTime datetime_to_string { get; set; }
|
||||
[Column(MapType = typeof(string))]
|
||||
public DateTime? datetimenullable_to_string { get; set; }
|
||||
|
||||
[Column(MapType = typeof(string))]
|
||||
public Guid guid_to_string { get; set; }
|
||||
[Column(MapType = typeof(string))]
|
||||
public Guid? guidnullable_to_string { get; set; }
|
||||
|
||||
[Column(MapType = typeof(string))]
|
||||
public ToStringMapEnum enum_to_string { get; set; }
|
||||
[Column(MapType = typeof(string))]
|
||||
public ToStringMapEnum? enumnullable_to_string { get; set; }
|
||||
|
||||
[Column(MapType = typeof(string))]
|
||||
public BigInteger biginteger_to_string { get; set; }
|
||||
[Column(MapType = typeof(string))]
|
||||
public BigInteger? bigintegernullable_to_string { get; set; }
|
||||
}
|
||||
public enum ToStringMapEnum { 中国人, abc, 香港 }
|
||||
[Fact]
|
||||
public void Enum1()
|
||||
{
|
||||
//insert
|
||||
var orm = g.sqlserver;
|
||||
var item = new ToStringMap { };
|
||||
Assert.Equal(1, orm.Insert<ToStringMap>().AppendData(item).ExecuteAffrows());
|
||||
var find = orm.Select<ToStringMap>().Where(a => a.id == item.id && a.enum_to_string == ToStringMapEnum.中国人).First();
|
||||
Assert.NotNull(find);
|
||||
Assert.Equal(item.id, find.id);
|
||||
Assert.Equal(item.enum_to_string, find.enum_to_string);
|
||||
Assert.Equal(ToStringMapEnum.中国人, find.enum_to_string);
|
||||
|
||||
item = new ToStringMap { enum_to_string = ToStringMapEnum.abc };
|
||||
Assert.Equal(1, orm.Insert<ToStringMap>().AppendData(item).ExecuteAffrows());
|
||||
find = orm.Select<ToStringMap>().Where(a => a.id == item.id && a.enum_to_string == ToStringMapEnum.abc).First();
|
||||
Assert.NotNull(find);
|
||||
Assert.Equal(item.id, find.id);
|
||||
Assert.Equal(item.enum_to_string, find.enum_to_string);
|
||||
Assert.Equal(ToStringMapEnum.abc, find.enum_to_string);
|
||||
|
||||
//update all
|
||||
item.enum_to_string = ToStringMapEnum.香港;
|
||||
Assert.Equal(1, orm.Update<ToStringMap>().SetSource(item).ExecuteAffrows());
|
||||
find = orm.Select<ToStringMap>().Where(a => a.id == item.id && a.enum_to_string == ToStringMapEnum.香港).First();
|
||||
Assert.NotNull(find);
|
||||
Assert.Equal(item.id, find.id);
|
||||
Assert.Equal(item.enum_to_string, find.enum_to_string);
|
||||
Assert.Equal(ToStringMapEnum.香港, find.enum_to_string);
|
||||
|
||||
item.enum_to_string = ToStringMapEnum.中国人;
|
||||
Assert.Equal(1, orm.Update<ToStringMap>().SetSource(item).ExecuteAffrows());
|
||||
find = orm.Select<ToStringMap>().Where(a => a.id == item.id && a.enum_to_string == ToStringMapEnum.中国人).First();
|
||||
Assert.NotNull(find);
|
||||
Assert.Equal(item.id, find.id);
|
||||
Assert.Equal(item.enum_to_string, find.enum_to_string);
|
||||
Assert.Equal(ToStringMapEnum.中国人, find.enum_to_string);
|
||||
|
||||
//update set
|
||||
Assert.Equal(1, orm.Update<ToStringMap>().Where(a => a.id == item.id).Set(a => a.enum_to_string, ToStringMapEnum.香港).ExecuteAffrows());
|
||||
find = orm.Select<ToStringMap>().Where(a => a.id == item.id && a.enum_to_string == ToStringMapEnum.香港).First();
|
||||
Assert.NotNull(find);
|
||||
Assert.Equal(item.id, find.id);
|
||||
Assert.Equal(ToStringMapEnum.香港, find.enum_to_string);
|
||||
|
||||
Assert.Equal(1, orm.Update<ToStringMap>().Where(a => a.id == item.id).Set(a => a.enum_to_string, ToStringMapEnum.abc).ExecuteAffrows());
|
||||
find = orm.Select<ToStringMap>().Where(a => a.id == item.id && a.enum_to_string == ToStringMapEnum.abc).First();
|
||||
Assert.NotNull(find);
|
||||
Assert.Equal(item.id, find.id);
|
||||
Assert.Equal(ToStringMapEnum.abc, find.enum_to_string);
|
||||
|
||||
//delete
|
||||
Assert.Equal(0, orm.Delete<ToStringMap>().Where(a => a.id == item.id && a.enum_to_string == ToStringMapEnum.中国人).ExecuteAffrows());
|
||||
Assert.Equal(0, orm.Delete<ToStringMap>().Where(a => a.id == item.id && a.enum_to_string == ToStringMapEnum.香港).ExecuteAffrows());
|
||||
Assert.Equal(1, orm.Delete<ToStringMap>().Where(a => a.id == item.id && a.enum_to_string == ToStringMapEnum.abc).ExecuteAffrows());
|
||||
Assert.Null(orm.Select<ToStringMap>().Where(a => a.id == item.id).First());
|
||||
}
|
||||
[Fact]
|
||||
public void EnumNullable()
|
||||
{
|
||||
//insert
|
||||
var orm = g.sqlserver;
|
||||
var item = new ToStringMap { };
|
||||
Assert.Equal(1, orm.Insert<ToStringMap>().AppendData(item).ExecuteAffrows());
|
||||
var find = orm.Select<ToStringMap>().Where(a => a.id == item.id && a.enumnullable_to_string == null).First();
|
||||
Assert.NotNull(find);
|
||||
Assert.Equal(item.id, find.id);
|
||||
Assert.Equal(item.enumnullable_to_string, find.enumnullable_to_string);
|
||||
Assert.Null(find.enumnullable_to_string);
|
||||
|
||||
item = new ToStringMap { enumnullable_to_string = ToStringMapEnum.中国人 };
|
||||
Assert.Equal(1, orm.Insert<ToStringMap>().AppendData(item).ExecuteAffrows());
|
||||
find = orm.Select<ToStringMap>().Where(a => a.id == item.id && a.enumnullable_to_string == ToStringMapEnum.中国人).First();
|
||||
Assert.NotNull(find);
|
||||
Assert.Equal(item.id, find.id);
|
||||
Assert.Equal(item.enumnullable_to_string, find.enumnullable_to_string);
|
||||
Assert.Equal(ToStringMapEnum.中国人, find.enumnullable_to_string);
|
||||
|
||||
//update all
|
||||
item.enumnullable_to_string = ToStringMapEnum.香港;
|
||||
Assert.Equal(1, orm.Update<ToStringMap>().SetSource(item).ExecuteAffrows());
|
||||
find = orm.Select<ToStringMap>().Where(a => a.id == item.id && a.enumnullable_to_string == ToStringMapEnum.香港).First();
|
||||
Assert.NotNull(find);
|
||||
Assert.Equal(item.id, find.id);
|
||||
Assert.Equal(item.enumnullable_to_string, find.enumnullable_to_string);
|
||||
Assert.Equal(ToStringMapEnum.香港, find.enumnullable_to_string);
|
||||
|
||||
item.enumnullable_to_string = null;
|
||||
Assert.Equal(1, orm.Update<ToStringMap>().SetSource(item).ExecuteAffrows());
|
||||
Assert.Null(orm.Select<ToStringMap>().Where(a => a.id == item.id && a.enumnullable_to_string == ToStringMapEnum.香港).First());
|
||||
find = orm.Select<ToStringMap>().Where(a => a.id == item.id && a.enumnullable_to_string == null).First();
|
||||
Assert.NotNull(find);
|
||||
Assert.Equal(item.id, find.id);
|
||||
Assert.Equal(item.enumnullable_to_string, find.enumnullable_to_string);
|
||||
Assert.Null(find.enumnullable_to_string);
|
||||
|
||||
//update set
|
||||
Assert.Equal(1, orm.Update<ToStringMap>().Where(a => a.id == item.id).Set(a => a.enumnullable_to_string, ToStringMapEnum.abc).ExecuteAffrows());
|
||||
find = orm.Select<ToStringMap>().Where(a => a.id == item.id && a.enumnullable_to_string == ToStringMapEnum.abc).First();
|
||||
Assert.NotNull(find);
|
||||
Assert.Equal(item.id, find.id);
|
||||
Assert.Equal(ToStringMapEnum.abc, find.enumnullable_to_string);
|
||||
|
||||
|
||||
Assert.Equal(1, orm.Update<ToStringMap>().Where(a => a.id == item.id).Set(a => a.enumnullable_to_string, null).ExecuteAffrows());
|
||||
Assert.Null(orm.Select<ToStringMap>().Where(a => a.id == item.id && a.enumnullable_to_string == ToStringMapEnum.abc).First());
|
||||
find = orm.Select<ToStringMap>().Where(a => a.id == item.id && a.enumnullable_to_string == null).First();
|
||||
Assert.NotNull(find);
|
||||
Assert.Equal(item.id, find.id);
|
||||
Assert.Null(find.enumnullable_to_string);
|
||||
|
||||
//delete
|
||||
Assert.Equal(0, orm.Delete<ToStringMap>().Where(a => a.id == item.id && a.enumnullable_to_string == ToStringMapEnum.中国人).ExecuteAffrows());
|
||||
Assert.Equal(0, orm.Delete<ToStringMap>().Where(a => a.id == item.id && a.enumnullable_to_string == ToStringMapEnum.香港).ExecuteAffrows());
|
||||
Assert.Equal(1, orm.Delete<ToStringMap>().Where(a => a.id == item.id && a.enumnullable_to_string == null).ExecuteAffrows());
|
||||
Assert.Null(orm.Select<ToStringMap>().Where(a => a.id == item.id).First());
|
||||
}
|
||||
[Fact]
|
||||
public void BigInteger1()
|
||||
{
|
||||
//insert
|
||||
var orm = g.sqlserver;
|
||||
var item = new ToStringMap { };
|
||||
Assert.Equal(1, orm.Insert<ToStringMap>().AppendData(item).ExecuteAffrows());
|
||||
var find = orm.Select<ToStringMap>().Where(a => a.id == item.id && a.biginteger_to_string == 0).First();
|
||||
Assert.NotNull(find);
|
||||
Assert.Equal(item.id, find.id);
|
||||
Assert.Equal(item.biginteger_to_string, find.biginteger_to_string);
|
||||
Assert.Equal(0, find.biginteger_to_string);
|
||||
|
||||
item = new ToStringMap { biginteger_to_string = 100 };
|
||||
Assert.Equal(1, orm.Insert<ToStringMap>().AppendData(item).ExecuteAffrows());
|
||||
find = orm.Select<ToStringMap>().Where(a => a.id == item.id && a.biginteger_to_string == 100).First();
|
||||
Assert.NotNull(find);
|
||||
Assert.Equal(item.id, find.id);
|
||||
Assert.Equal(item.biginteger_to_string, find.biginteger_to_string);
|
||||
Assert.Equal(100, find.biginteger_to_string);
|
||||
|
||||
//update all
|
||||
item.biginteger_to_string = 200;
|
||||
Assert.Equal(1, orm.Update<ToStringMap>().SetSource(item).ExecuteAffrows());
|
||||
find = orm.Select<ToStringMap>().Where(a => a.id == item.id && a.biginteger_to_string == 200).First();
|
||||
Assert.NotNull(find);
|
||||
Assert.Equal(item.id, find.id);
|
||||
Assert.Equal(item.biginteger_to_string, find.biginteger_to_string);
|
||||
Assert.Equal(200, find.biginteger_to_string);
|
||||
|
||||
item.biginteger_to_string = 205;
|
||||
Assert.Equal(1, orm.Update<ToStringMap>().SetSource(item).ExecuteAffrows());
|
||||
find = orm.Select<ToStringMap>().Where(a => a.id == item.id && a.biginteger_to_string == 205).First();
|
||||
Assert.NotNull(find);
|
||||
Assert.Equal(item.id, find.id);
|
||||
Assert.Equal(item.biginteger_to_string, find.biginteger_to_string);
|
||||
Assert.Equal(205, find.biginteger_to_string);
|
||||
|
||||
//update set
|
||||
Assert.Equal(1, orm.Update<ToStringMap>().Where(a => a.id == item.id).Set(a => a.biginteger_to_string, 522).ExecuteAffrows());
|
||||
find = orm.Select<ToStringMap>().Where(a => a.id == item.id && a.biginteger_to_string == 522).First();
|
||||
Assert.NotNull(find);
|
||||
Assert.Equal(item.id, find.id);
|
||||
Assert.Equal(522, find.biginteger_to_string);
|
||||
|
||||
Assert.Equal(1, orm.Update<ToStringMap>().Where(a => a.id == item.id).Set(a => a.biginteger_to_string, 10005).ExecuteAffrows());
|
||||
find = orm.Select<ToStringMap>().Where(a => a.id == item.id && a.biginteger_to_string == 10005).First();
|
||||
Assert.NotNull(find);
|
||||
Assert.Equal(item.id, find.id);
|
||||
Assert.Equal(10005, find.biginteger_to_string);
|
||||
|
||||
//delete
|
||||
Assert.Equal(0, orm.Delete<ToStringMap>().Where(a => a.id == item.id && a.biginteger_to_string == 522).ExecuteAffrows());
|
||||
Assert.Equal(0, orm.Delete<ToStringMap>().Where(a => a.id == item.id && a.biginteger_to_string == 205).ExecuteAffrows());
|
||||
Assert.Equal(1, orm.Delete<ToStringMap>().Where(a => a.id == item.id && a.biginteger_to_string == 10005).ExecuteAffrows());
|
||||
Assert.Null(orm.Select<ToStringMap>().Where(a => a.id == item.id).First());
|
||||
}
|
||||
[Fact]
|
||||
public void BigIntegerNullable()
|
||||
{
|
||||
//insert
|
||||
var orm = g.sqlserver;
|
||||
var item = new ToStringMap { };
|
||||
Assert.Equal(1, orm.Insert<ToStringMap>().AppendData(item).ExecuteAffrows());
|
||||
var find = orm.Select<ToStringMap>().Where(a => a.id == item.id && a.bigintegernullable_to_string == null).First();
|
||||
Assert.NotNull(find);
|
||||
Assert.Equal(item.id, find.id);
|
||||
Assert.Equal(item.bigintegernullable_to_string, find.bigintegernullable_to_string);
|
||||
Assert.Null(find.bigintegernullable_to_string);
|
||||
|
||||
item = new ToStringMap { bigintegernullable_to_string = 101 };
|
||||
Assert.Equal(1, orm.Insert<ToStringMap>().AppendData(item).ExecuteAffrows());
|
||||
find = orm.Select<ToStringMap>().Where(a => a.id == item.id && a.bigintegernullable_to_string == 101).First();
|
||||
Assert.NotNull(find);
|
||||
Assert.Equal(item.id, find.id);
|
||||
Assert.Equal(item.bigintegernullable_to_string, find.bigintegernullable_to_string);
|
||||
Assert.Equal(101, find.bigintegernullable_to_string);
|
||||
|
||||
//update all
|
||||
item.bigintegernullable_to_string = 2004;
|
||||
Assert.Equal(1, orm.Update<ToStringMap>().SetSource(item).ExecuteAffrows());
|
||||
find = orm.Select<ToStringMap>().Where(a => a.id == item.id && a.bigintegernullable_to_string == 2004).First();
|
||||
Assert.NotNull(find);
|
||||
Assert.Equal(item.id, find.id);
|
||||
Assert.Equal(item.bigintegernullable_to_string, find.bigintegernullable_to_string);
|
||||
Assert.Equal(2004, find.bigintegernullable_to_string);
|
||||
|
||||
item.bigintegernullable_to_string = null;
|
||||
Assert.Equal(1, orm.Update<ToStringMap>().SetSource(item).ExecuteAffrows());
|
||||
Assert.Null(orm.Select<ToStringMap>().Where(a => a.id == item.id && a.bigintegernullable_to_string == 2004).First());
|
||||
find = orm.Select<ToStringMap>().Where(a => a.id == item.id && a.bigintegernullable_to_string == null).First();
|
||||
Assert.NotNull(find);
|
||||
Assert.Equal(item.id, find.id);
|
||||
Assert.Equal(item.bigintegernullable_to_string, find.bigintegernullable_to_string);
|
||||
Assert.Null(find.bigintegernullable_to_string);
|
||||
|
||||
//update set
|
||||
Assert.Equal(1, orm.Update<ToStringMap>().Where(a => a.id == item.id).Set(a => a.bigintegernullable_to_string, 998).ExecuteAffrows());
|
||||
find = orm.Select<ToStringMap>().Where(a => a.id == item.id && a.bigintegernullable_to_string == 998).First();
|
||||
Assert.NotNull(find);
|
||||
Assert.Equal(item.id, find.id);
|
||||
Assert.Equal(998, find.bigintegernullable_to_string);
|
||||
|
||||
|
||||
Assert.Equal(1, orm.Update<ToStringMap>().Where(a => a.id == item.id).Set(a => a.bigintegernullable_to_string, null).ExecuteAffrows());
|
||||
Assert.Null(orm.Select<ToStringMap>().Where(a => a.id == item.id && a.bigintegernullable_to_string == 998).First());
|
||||
find = orm.Select<ToStringMap>().Where(a => a.id == item.id && a.bigintegernullable_to_string == null).First();
|
||||
Assert.NotNull(find);
|
||||
Assert.Equal(item.id, find.id);
|
||||
Assert.Null(find.bigintegernullable_to_string);
|
||||
|
||||
//delete
|
||||
Assert.Equal(0, orm.Delete<ToStringMap>().Where(a => a.id == item.id && a.bigintegernullable_to_string == 998).ExecuteAffrows());
|
||||
Assert.Equal(0, orm.Delete<ToStringMap>().Where(a => a.id == item.id && a.bigintegernullable_to_string == 2004).ExecuteAffrows());
|
||||
Assert.Equal(1, orm.Delete<ToStringMap>().Where(a => a.id == item.id && a.bigintegernullable_to_string == null).ExecuteAffrows());
|
||||
Assert.Null(orm.Select<ToStringMap>().Where(a => a.id == item.id).First());
|
||||
}
|
||||
[Fact]
|
||||
public void TimeSpan1()
|
||||
{
|
||||
//insert
|
||||
var orm = g.sqlserver;
|
||||
var item = new ToStringMap { };
|
||||
Assert.Equal(1, orm.Insert<ToStringMap>().AppendData(item).ExecuteAffrows());
|
||||
var find = orm.Select<ToStringMap>().Where(a => a.id == item.id).First();
|
||||
Assert.NotNull(find);
|
||||
Assert.Equal(item.id, find.id);
|
||||
Assert.Equal(item.timespan_to_string, find.timespan_to_string);
|
||||
Assert.Equal(TimeSpan.Zero, find.timespan_to_string);
|
||||
|
||||
item = new ToStringMap { timespan_to_string = TimeSpan.FromDays(1) };
|
||||
Assert.Equal(1, orm.Insert<ToStringMap>().AppendData(item).ExecuteAffrows());
|
||||
find = orm.Select<ToStringMap>().Where(a => a.id == item.id).First();
|
||||
Assert.NotNull(find);
|
||||
Assert.Equal(item.id, find.id);
|
||||
Assert.Equal(item.timespan_to_string, find.timespan_to_string);
|
||||
Assert.Equal(TimeSpan.FromDays(1), find.timespan_to_string);
|
||||
|
||||
//update all
|
||||
item.timespan_to_string = TimeSpan.FromHours(10);
|
||||
Assert.Equal(1, orm.Update<ToStringMap>().SetSource(item).ExecuteAffrows());
|
||||
find = orm.Select<ToStringMap>().Where(a => a.id == item.id).First();
|
||||
Assert.NotNull(find);
|
||||
Assert.Equal(item.id, find.id);
|
||||
Assert.Equal(item.timespan_to_string, find.timespan_to_string);
|
||||
Assert.Equal(TimeSpan.FromHours(10), find.timespan_to_string);
|
||||
|
||||
//update set
|
||||
Assert.Equal(1, orm.Update<ToStringMap>().Where(a => a.id == item.id).Set(a => a.timespan_to_string, TimeSpan.FromHours(11)).ExecuteAffrows());
|
||||
find = orm.Select<ToStringMap>().Where(a => a.id == item.id).First();
|
||||
Assert.NotNull(find);
|
||||
Assert.Equal(item.id, find.id);
|
||||
Assert.Equal(TimeSpan.FromHours(11), find.timespan_to_string);
|
||||
|
||||
//delete
|
||||
Assert.Equal(1, orm.Delete<ToStringMap>().Where(a => a.id == item.id).ExecuteAffrows());
|
||||
Assert.Null(orm.Select<ToStringMap>().Where(a => a.id == item.id).First());
|
||||
}
|
||||
[Fact]
|
||||
public void TimeSpanNullable()
|
||||
{
|
||||
//insert
|
||||
var orm = g.sqlserver;
|
||||
var item = new ToStringMap { };
|
||||
Assert.Equal(1, orm.Insert<ToStringMap>().AppendData(item).ExecuteAffrows());
|
||||
var find = orm.Select<ToStringMap>().Where(a => a.id == item.id).First();
|
||||
Assert.NotNull(find);
|
||||
Assert.Equal(item.id, find.id);
|
||||
Assert.Equal(item.timespannullable_to_string, find.timespannullable_to_string);
|
||||
Assert.Null(find.timespannullable_to_string);
|
||||
|
||||
item = new ToStringMap { timespannullable_to_string = TimeSpan.FromDays(1) };
|
||||
Assert.Equal(1, orm.Insert<ToStringMap>().AppendData(item).ExecuteAffrows());
|
||||
find = orm.Select<ToStringMap>().Where(a => a.id == item.id).First();
|
||||
Assert.NotNull(find);
|
||||
Assert.Equal(item.id, find.id);
|
||||
Assert.Equal(item.timespannullable_to_string, find.timespannullable_to_string);
|
||||
Assert.Equal(TimeSpan.FromDays(1), find.timespannullable_to_string);
|
||||
|
||||
//update all
|
||||
item.timespannullable_to_string = TimeSpan.FromHours(10);
|
||||
Assert.Equal(1, orm.Update<ToStringMap>().SetSource(item).ExecuteAffrows());
|
||||
find = orm.Select<ToStringMap>().Where(a => a.id == item.id).First();
|
||||
Assert.NotNull(find);
|
||||
Assert.Equal(item.id, find.id);
|
||||
Assert.Equal(item.timespannullable_to_string, find.timespannullable_to_string);
|
||||
Assert.Equal(TimeSpan.FromHours(10), find.timespannullable_to_string);
|
||||
|
||||
item.timespannullable_to_string = null;
|
||||
Assert.Equal(1, orm.Update<ToStringMap>().SetSource(item).ExecuteAffrows());
|
||||
find = orm.Select<ToStringMap>().Where(a => a.id == item.id).First();
|
||||
Assert.NotNull(find);
|
||||
Assert.Equal(item.id, find.id);
|
||||
Assert.Equal(item.timespannullable_to_string, find.timespannullable_to_string);
|
||||
Assert.Null(find.timespannullable_to_string);
|
||||
|
||||
//update set
|
||||
Assert.Equal(1, orm.Update<ToStringMap>().Where(a => a.id == item.id).Set(a => a.timespannullable_to_string, TimeSpan.FromHours(11)).ExecuteAffrows());
|
||||
find = orm.Select<ToStringMap>().Where(a => a.id == item.id).First();
|
||||
Assert.NotNull(find);
|
||||
Assert.Equal(item.id, find.id);
|
||||
Assert.Equal(TimeSpan.FromHours(11), find.timespannullable_to_string);
|
||||
|
||||
Assert.Equal(1, orm.Update<ToStringMap>().Where(a => a.id == item.id).Set(a => a.timespannullable_to_string, null).ExecuteAffrows());
|
||||
find = orm.Select<ToStringMap>().Where(a => a.id == item.id).First();
|
||||
Assert.NotNull(find);
|
||||
Assert.Equal(item.id, find.id);
|
||||
Assert.Null(find.timespannullable_to_string);
|
||||
|
||||
//delete
|
||||
Assert.Equal(1, orm.Delete<ToStringMap>().Where(a => a.id == item.id).ExecuteAffrows());
|
||||
Assert.Null(orm.Select<ToStringMap>().Where(a => a.id == item.id).First());
|
||||
}
|
||||
[Fact]
|
||||
public void DateTime1()
|
||||
{
|
||||
//insert
|
||||
var orm = g.sqlserver;
|
||||
var item = new ToStringMap { };
|
||||
Assert.Equal(1, orm.Insert<ToStringMap>().AppendData(item).ExecuteAffrows());
|
||||
var find = orm.Select<ToStringMap>().Where(a => a.id == item.id).First();
|
||||
Assert.NotNull(find);
|
||||
Assert.Equal(item.id, find.id);
|
||||
Assert.Equal(item.datetime_to_string, find.datetime_to_string);
|
||||
Assert.Equal(DateTime.MinValue, find.datetime_to_string);
|
||||
|
||||
item = new ToStringMap { datetime_to_string = DateTime.Parse("2000-1-1") };
|
||||
Assert.Equal(1, orm.Insert<ToStringMap>().AppendData(item).ExecuteAffrows());
|
||||
find = orm.Select<ToStringMap>().Where(a => a.id == item.id).First();
|
||||
Assert.NotNull(find);
|
||||
Assert.Equal(item.id, find.id);
|
||||
Assert.Equal(item.datetime_to_string, find.datetime_to_string);
|
||||
Assert.Equal(DateTime.Parse("2000-1-1"), find.datetime_to_string);
|
||||
|
||||
//update all
|
||||
item.datetime_to_string = DateTime.Parse("2000-1-11");
|
||||
Assert.Equal(1, orm.Update<ToStringMap>().SetSource(item).ExecuteAffrows());
|
||||
find = orm.Select<ToStringMap>().Where(a => a.id == item.id).First();
|
||||
Assert.NotNull(find);
|
||||
Assert.Equal(item.id, find.id);
|
||||
Assert.Equal(item.datetime_to_string, find.datetime_to_string);
|
||||
Assert.Equal(DateTime.Parse("2000-1-11"), find.datetime_to_string);
|
||||
|
||||
//update set
|
||||
Assert.Equal(1, orm.Update<ToStringMap>().Where(a => a.id == item.id).Set(a => a.datetime_to_string, DateTime.Parse("2000-1-12")).ExecuteAffrows());
|
||||
find = orm.Select<ToStringMap>().Where(a => a.id == item.id).First();
|
||||
Assert.NotNull(find);
|
||||
Assert.Equal(item.id, find.id);
|
||||
Assert.Equal(DateTime.Parse("2000-1-12"), find.datetime_to_string);
|
||||
|
||||
//delete
|
||||
Assert.Equal(1, orm.Delete<ToStringMap>().Where(a => a.id == item.id).ExecuteAffrows());
|
||||
Assert.Null(orm.Select<ToStringMap>().Where(a => a.id == item.id).First());
|
||||
}
|
||||
[Fact]
|
||||
public void DateTimeNullable()
|
||||
{
|
||||
//insert
|
||||
var orm = g.sqlserver;
|
||||
var item = new ToStringMap { };
|
||||
Assert.Equal(1, orm.Insert<ToStringMap>().AppendData(item).ExecuteAffrows());
|
||||
var find = orm.Select<ToStringMap>().Where(a => a.id == item.id).First();
|
||||
Assert.NotNull(find);
|
||||
Assert.Equal(item.id, find.id);
|
||||
Assert.Equal(item.datetimenullable_to_string, find.datetimenullable_to_string);
|
||||
Assert.Null(find.datetimenullable_to_string);
|
||||
|
||||
item = new ToStringMap { datetimenullable_to_string = DateTime.Parse("2000-1-1") };
|
||||
Assert.Equal(1, orm.Insert<ToStringMap>().AppendData(item).ExecuteAffrows());
|
||||
find = orm.Select<ToStringMap>().Where(a => a.id == item.id).First();
|
||||
Assert.NotNull(find);
|
||||
Assert.Equal(item.id, find.id);
|
||||
Assert.Equal(item.datetimenullable_to_string, find.datetimenullable_to_string);
|
||||
Assert.Equal(DateTime.Parse("2000-1-1"), find.datetimenullable_to_string);
|
||||
|
||||
//update all
|
||||
item.datetimenullable_to_string = DateTime.Parse("2000-1-11");
|
||||
Assert.Equal(1, orm.Update<ToStringMap>().SetSource(item).ExecuteAffrows());
|
||||
find = orm.Select<ToStringMap>().Where(a => a.id == item.id).First();
|
||||
Assert.NotNull(find);
|
||||
Assert.Equal(item.id, find.id);
|
||||
Assert.Equal(item.datetimenullable_to_string, find.datetimenullable_to_string);
|
||||
Assert.Equal(DateTime.Parse("2000-1-11"), find.datetimenullable_to_string);
|
||||
|
||||
item.datetimenullable_to_string = null;
|
||||
Assert.Equal(1, orm.Update<ToStringMap>().SetSource(item).ExecuteAffrows());
|
||||
find = orm.Select<ToStringMap>().Where(a => a.id == item.id).First();
|
||||
Assert.NotNull(find);
|
||||
Assert.Equal(item.id, find.id);
|
||||
Assert.Equal(item.datetimenullable_to_string, find.datetimenullable_to_string);
|
||||
Assert.Null(find.datetimenullable_to_string);
|
||||
|
||||
//update set
|
||||
Assert.Equal(1, orm.Update<ToStringMap>().Where(a => a.id == item.id).Set(a => a.datetimenullable_to_string, DateTime.Parse("2000-1-12")).ExecuteAffrows());
|
||||
find = orm.Select<ToStringMap>().Where(a => a.id == item.id).First();
|
||||
Assert.NotNull(find);
|
||||
Assert.Equal(item.id, find.id);
|
||||
Assert.Equal(DateTime.Parse("2000-1-12"), find.datetimenullable_to_string);
|
||||
|
||||
Assert.Equal(1, orm.Update<ToStringMap>().Where(a => a.id == item.id).Set(a => a.datetimenullable_to_string, null).ExecuteAffrows());
|
||||
find = orm.Select<ToStringMap>().Where(a => a.id == item.id).First();
|
||||
Assert.NotNull(find);
|
||||
Assert.Equal(item.id, find.id);
|
||||
Assert.Null(find.datetimenullable_to_string);
|
||||
|
||||
//delete
|
||||
Assert.Equal(1, orm.Delete<ToStringMap>().Where(a => a.id == item.id).ExecuteAffrows());
|
||||
Assert.Null(orm.Select<ToStringMap>().Where(a => a.id == item.id).First());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Guid1()
|
||||
{
|
||||
//insert
|
||||
var orm = g.sqlserver;
|
||||
var item = new ToStringMap { };
|
||||
Assert.Equal(1, orm.Insert<ToStringMap>().AppendData(item).ExecuteAffrows());
|
||||
var find = orm.Select<ToStringMap>().Where(a => a.id == item.id && a.guid_to_string == Guid.Empty).First();
|
||||
Assert.NotNull(find);
|
||||
Assert.Equal(item.id, find.id);
|
||||
Assert.Equal(item.guid_to_string, find.guid_to_string);
|
||||
Assert.Equal(Guid.Empty, find.guid_to_string);
|
||||
|
||||
var newid = Guid.NewGuid();
|
||||
item = new ToStringMap { guid_to_string = newid };
|
||||
Assert.Equal(1, orm.Insert<ToStringMap>().AppendData(item).ExecuteAffrows());
|
||||
find = orm.Select<ToStringMap>().Where(a => a.id == item.id && a.guid_to_string == newid).First();
|
||||
Assert.NotNull(find);
|
||||
Assert.Equal(item.id, find.id);
|
||||
Assert.Equal(item.guid_to_string, find.guid_to_string);
|
||||
Assert.Equal(newid, find.guid_to_string);
|
||||
|
||||
//update all
|
||||
newid = Guid.NewGuid();
|
||||
item.guid_to_string = newid;
|
||||
Assert.Equal(1, orm.Update<ToStringMap>().SetSource(item).ExecuteAffrows());
|
||||
find = orm.Select<ToStringMap>().Where(a => a.id == item.id && a.guid_to_string == newid).First();
|
||||
Assert.NotNull(find);
|
||||
Assert.Equal(item.id, find.id);
|
||||
Assert.Equal(item.guid_to_string, find.guid_to_string);
|
||||
Assert.Equal(newid, find.guid_to_string);
|
||||
|
||||
//update set
|
||||
newid = Guid.NewGuid();
|
||||
Assert.Equal(1, orm.Update<ToStringMap>().Where(a => a.id == item.id).Set(a => a.guid_to_string, newid).ExecuteAffrows());
|
||||
find = orm.Select<ToStringMap>().Where(a => a.id == item.id && a.guid_to_string == newid).First();
|
||||
Assert.NotNull(find);
|
||||
Assert.Equal(item.id, find.id);
|
||||
Assert.Equal(newid, find.guid_to_string);
|
||||
|
||||
//delete
|
||||
Assert.Equal(1, orm.Delete<ToStringMap>().Where(a => a.id == item.id && a.guid_to_string == newid).ExecuteAffrows());
|
||||
Assert.Null(orm.Select<ToStringMap>().Where(a => a.id == item.id).First());
|
||||
}
|
||||
[Fact]
|
||||
public void GuidNullable()
|
||||
{
|
||||
//insert
|
||||
var orm = g.sqlserver;
|
||||
var item = new ToStringMap { };
|
||||
Assert.Equal(1, orm.Insert<ToStringMap>().AppendData(item).ExecuteAffrows());
|
||||
var find = orm.Select<ToStringMap>().Where(a => a.id == item.id && a.guidnullable_to_string == null).First();
|
||||
Assert.NotNull(find);
|
||||
Assert.Equal(item.id, find.id);
|
||||
Assert.Equal(item.guidnullable_to_string, find.guidnullable_to_string);
|
||||
Assert.Null(find.guidnullable_to_string);
|
||||
|
||||
var newid = Guid.NewGuid();
|
||||
item = new ToStringMap { guidnullable_to_string = newid };
|
||||
Assert.Equal(1, orm.Insert<ToStringMap>().AppendData(item).ExecuteAffrows());
|
||||
find = orm.Select<ToStringMap>().Where(a => a.id == item.id && a.guidnullable_to_string == newid).First();
|
||||
Assert.NotNull(find);
|
||||
Assert.Equal(item.id, find.id);
|
||||
Assert.Equal(item.guidnullable_to_string, find.guidnullable_to_string);
|
||||
Assert.Equal(newid, find.guidnullable_to_string);
|
||||
|
||||
//update all
|
||||
newid = Guid.NewGuid();
|
||||
item.guidnullable_to_string = newid;
|
||||
Assert.Equal(1, orm.Update<ToStringMap>().SetSource(item).ExecuteAffrows());
|
||||
find = orm.Select<ToStringMap>().Where(a => a.id == item.id && a.guidnullable_to_string == newid).First();
|
||||
Assert.NotNull(find);
|
||||
Assert.Equal(item.id, find.id);
|
||||
Assert.Equal(item.guidnullable_to_string, find.guidnullable_to_string);
|
||||
Assert.Equal(newid, find.guidnullable_to_string);
|
||||
|
||||
item.guidnullable_to_string = null;
|
||||
Assert.Equal(1, orm.Update<ToStringMap>().SetSource(item).ExecuteAffrows());
|
||||
find = orm.Select<ToStringMap>().Where(a => a.id == item.id && a.guidnullable_to_string == null).First();
|
||||
Assert.NotNull(find);
|
||||
Assert.Equal(item.id, find.id);
|
||||
Assert.Equal(item.guidnullable_to_string, find.guidnullable_to_string);
|
||||
Assert.Null(find.guidnullable_to_string);
|
||||
|
||||
//update set
|
||||
newid = Guid.NewGuid();
|
||||
Assert.Equal(1, orm.Update<ToStringMap>().Where(a => a.id == item.id).Set(a => a.guidnullable_to_string, newid).ExecuteAffrows());
|
||||
find = orm.Select<ToStringMap>().Where(a => a.id == item.id && a.guidnullable_to_string == newid).First();
|
||||
Assert.NotNull(find);
|
||||
Assert.Equal(item.id, find.id);
|
||||
Assert.Equal(newid, find.guidnullable_to_string);
|
||||
|
||||
Assert.Equal(1, orm.Update<ToStringMap>().Where(a => a.id == item.id).Set(a => a.guidnullable_to_string, null).ExecuteAffrows());
|
||||
find = orm.Select<ToStringMap>().Where(a => a.id == item.id && a.guidnullable_to_string == null).First();
|
||||
Assert.NotNull(find);
|
||||
Assert.Equal(item.id, find.id);
|
||||
Assert.Null(find.guidnullable_to_string);
|
||||
|
||||
//delete
|
||||
Assert.Equal(1, orm.Delete<ToStringMap>().Where(a => a.id == item.id && a.guidnullable_to_string == null).ExecuteAffrows());
|
||||
Assert.Null(orm.Select<ToStringMap>().Where(a => a.id == item.id).First());
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,96 @@
|
||||
using FreeSql.DataAnnotations;
|
||||
using System;
|
||||
using System.Data.Odbc;
|
||||
using Xunit;
|
||||
|
||||
namespace FreeSql.Tests.Odbc.SqlServer
|
||||
{
|
||||
[Collection("SqlServerCollection")]
|
||||
public class SqlServerAdoTest
|
||||
{
|
||||
[Fact]
|
||||
public void Pool()
|
||||
{
|
||||
var t1 = g.sqlserver.Ado.MasterPool.StatisticsFullily;
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void SlavePools()
|
||||
{
|
||||
var t2 = g.sqlserver.Ado.SlavePools.Count;
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ExecuteReader()
|
||||
{
|
||||
|
||||
}
|
||||
[Fact]
|
||||
public void ExecuteArray()
|
||||
{
|
||||
|
||||
}
|
||||
[Fact]
|
||||
public void ExecuteNonQuery()
|
||||
{
|
||||
|
||||
}
|
||||
[Fact]
|
||||
public void ExecuteScalar()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Query()
|
||||
{
|
||||
|
||||
//var tt1 = g.sqlserver.Select<xxx>()
|
||||
// .LeftJoin(a => a.ParentId == a.Parent.Id)
|
||||
// .ToSql(a => new { a.Id, a.Title });
|
||||
|
||||
//var tt2result = g.sqlserver.Select<xxx>()
|
||||
// .LeftJoin(a => a.ParentId == a.Parent.Id)
|
||||
// .ToList(a => new { a.Id, a.Title });
|
||||
|
||||
//var tt = g.sqlserver.Select<xxx>()
|
||||
// .LeftJoin<xxx>((a, b) => b.Id == a.Id)
|
||||
// .ToSql(a => new { a.Id, a.Title });
|
||||
|
||||
//var ttresult = g.sqlserver.Select<xxx>()
|
||||
// .LeftJoin<xxx>((a, b) => b.Id == a.Id)
|
||||
// .ToList(a => new { a.Id, a.Title });
|
||||
|
||||
var tnsql1 = g.sqlserver.Select<xxx>().Where(a => a.Id > 0).Where(b => b.Title != null).Page(1, 3).ToSql(a => a.Id);
|
||||
var tnsql2 = g.sqlserver.Select<xxx>().Where(a => a.Id > 0).Where(b => b.Title != null).Page(2, 3).ToSql(a => a.Id);
|
||||
|
||||
var tn1 = g.sqlserver.Select<xxx>().Where(a => a.Id > 0).Where(b => b.Title != null).Page(1, 3).ToList(a => a.Id);
|
||||
var tn2 = g.sqlserver.Select<xxx>().Where(a => a.Id > 0).Where(b => b.Title != null).Page(2, 3).ToList(a => a.Id);
|
||||
|
||||
var t3 = g.sqlserver.Ado.Query<xxx>("select * from xxx");
|
||||
|
||||
var t4 = g.sqlserver.Ado.Query<(int, int, string, string DateTime)>("select * from xxx");
|
||||
|
||||
var t5 = g.sqlserver.Ado.Query<dynamic>(System.Data.CommandType.Text, "select * from xxx where Id = ?",
|
||||
new OdbcParameter("@Id", 1));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void QueryMultipline()
|
||||
{
|
||||
var tnsql1 = g.sqlserver.Select<xxx>().Where(a => a.Id > 0).Where(b => b.Title != null).Page(1, 3).ToSql(a => a.Id);
|
||||
|
||||
var t3 = g.sqlserver.Ado.Query<xxx, (int, string, string), dynamic>("select * from xxx; select * from xxx; select * from xxx");
|
||||
}
|
||||
|
||||
class xxx
|
||||
{
|
||||
public int Id { get; set; }
|
||||
public int ParentId { get; set; }
|
||||
public xxx Parent { get; set; }
|
||||
public string Title { get; set; }
|
||||
public string Url { get; set; }
|
||||
public DateTime Create_time { get; set; }
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,40 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Reflection;
|
||||
using System.Text;
|
||||
using Xunit;
|
||||
|
||||
namespace FreeSql.Tests.Odbc.SqlServer
|
||||
{
|
||||
public class SqlServerAopTest
|
||||
{
|
||||
|
||||
class TestAuditValue
|
||||
{
|
||||
public Guid id { get; set; }
|
||||
[Now]
|
||||
public DateTime createtime { get; set; }
|
||||
}
|
||||
class NowAttribute: Attribute { }
|
||||
|
||||
[Fact]
|
||||
public void AuditValue()
|
||||
{
|
||||
var date = DateTime.Now.Date;
|
||||
var item = new TestAuditValue();
|
||||
|
||||
EventHandler<Aop.AuditValueEventArgs> audit = (s, e) =>
|
||||
{
|
||||
if (e.Property.GetCustomAttribute<NowAttribute>(false) != null)
|
||||
e.Value = DateTime.Now.Date;
|
||||
};
|
||||
g.sqlserver.Aop.AuditValue += audit;
|
||||
|
||||
g.sqlserver.Insert(item).ExecuteAffrows();
|
||||
|
||||
g.sqlserver.Aop.AuditValue -= audit;
|
||||
|
||||
Assert.Equal(item.createtime, date);
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,380 @@
|
||||
using FreeSql.DataAnnotations;
|
||||
using Newtonsoft.Json;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using Xunit;
|
||||
|
||||
namespace FreeSql.Tests.Odbc.SqlServer
|
||||
{
|
||||
|
||||
[Collection("SqlServerCollection")]
|
||||
public class SqlServerCodeFirstTest
|
||||
{
|
||||
[Fact]
|
||||
public void 中文表_字段()
|
||||
{
|
||||
var sql = g.sqlserver.CodeFirst.GetComparisonDDLStatements<测试中文表>();
|
||||
g.sqlserver.CodeFirst.SyncStructure<测试中文表>();
|
||||
|
||||
var item = new 测试中文表
|
||||
{
|
||||
标题 = "测试标题",
|
||||
创建时间 = DateTime.Now
|
||||
};
|
||||
Assert.Equal(1, g.sqlserver.Insert<测试中文表>().AppendData(item).ExecuteAffrows());
|
||||
Assert.NotEqual(Guid.Empty, item.编号);
|
||||
var item2 = g.sqlserver.Select<测试中文表>().Where(a => a.编号 == item.编号).First();
|
||||
Assert.NotNull(item2);
|
||||
Assert.Equal(item.编号, item2.编号);
|
||||
Assert.Equal(item.标题, item2.标题);
|
||||
}
|
||||
class 测试中文表
|
||||
{
|
||||
[Column(IsPrimary = true)]
|
||||
public Guid 编号 { get; set; }
|
||||
|
||||
public string 标题 { get; set; }
|
||||
|
||||
public DateTime 创建时间 { get; set; }
|
||||
}
|
||||
|
||||
|
||||
[Fact]
|
||||
public void AddUniques()
|
||||
{
|
||||
var sql = g.sqlserver.CodeFirst.GetComparisonDDLStatements<AddUniquesInfo>();
|
||||
g.sqlserver.CodeFirst.SyncStructure<AddUniquesInfo>();
|
||||
}
|
||||
[Table(Name = "AddUniquesInfo", OldName = "AddUniquesInfo2")]
|
||||
class AddUniquesInfo
|
||||
{
|
||||
public Guid id { get; set; }
|
||||
[Column(Unique = "uk_phone")]
|
||||
public string phone { get; set; }
|
||||
|
||||
[Column(Unique = "uk_group_index, uk_group_index22")]
|
||||
public string group { get; set; }
|
||||
[Column(Unique = "uk_group_index")]
|
||||
public int index { get; set; }
|
||||
[Column(Unique = "uk_group_index22")]
|
||||
public string index22 { get; set; }
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void AddField()
|
||||
{
|
||||
var sql = g.sqlserver.CodeFirst.GetComparisonDDLStatements<TopicAddField>();
|
||||
|
||||
var id = g.sqlserver.Insert<TopicAddField>().AppendData(new TopicAddField { }).ExecuteIdentity();
|
||||
}
|
||||
|
||||
[Table(Name = "dbo2.TopicAddField", OldName = "tedb1.dbo.TopicAddField")]
|
||||
public class TopicAddField
|
||||
{
|
||||
[Column(IsIdentity = true)]
|
||||
public int Id { get; set; }
|
||||
|
||||
public int name { get; set; } = 3000;
|
||||
|
||||
[Column(DbType = "varchar(200) not null", OldName = "title")]
|
||||
public string title222 { get; set; } = "333";
|
||||
|
||||
[Column(DbType = "varchar(200) not null")]
|
||||
public string title222333 { get; set; } = "xxx";
|
||||
|
||||
[Column(DbType = "varchar(100) not null", OldName = "title122333aaa")]
|
||||
public string titleaaa { get; set; } = "fsdf";
|
||||
|
||||
[Column(IsIgnore = true)]
|
||||
public DateTime ct { get; set; } = DateTime.Now;
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void GetComparisonDDLStatements()
|
||||
{
|
||||
|
||||
var sql = g.sqlserver.CodeFirst.GetComparisonDDLStatements<TableAllType>();
|
||||
|
||||
sql = g.sqlserver.CodeFirst.GetComparisonDDLStatements<Tb_alltype>();
|
||||
}
|
||||
|
||||
IInsert<TableAllType> insert => g.sqlserver.Insert<TableAllType>();
|
||||
ISelect<TableAllType> select => g.sqlserver.Select<TableAllType>();
|
||||
|
||||
[Fact]
|
||||
public void CurdAllField()
|
||||
{
|
||||
var item = new TableAllType { };
|
||||
item.Id = (int)insert.AppendData(item).ExecuteIdentity();
|
||||
|
||||
var newitem = select.Where(a => a.Id == item.Id).ToOne();
|
||||
|
||||
var item2 = new TableAllType
|
||||
{
|
||||
testFieldBool = true,
|
||||
testFieldBoolNullable = true,
|
||||
testFieldByte = byte.MaxValue,
|
||||
testFieldByteNullable = byte.MinValue,
|
||||
testFieldBytes = Encoding.UTF8.GetBytes("我是中国人"),
|
||||
testFieldDateTime = DateTime.Now,
|
||||
testFieldDateTimeNullable = DateTime.Now.AddHours(1),
|
||||
testFieldDateTimeNullableOffset = new DateTimeOffset(DateTime.Now.AddHours(1), TimeSpan.FromHours(8)),
|
||||
testFieldDateTimeOffset = new DateTimeOffset(DateTime.Now, TimeSpan.FromHours(8)),
|
||||
testFieldDecimal = 998.99M,
|
||||
testFieldDecimalNullable = 999.12M,
|
||||
testFieldDouble = 99.199,
|
||||
testFieldDoubleNullable = 99.211,
|
||||
testFieldEnum1 = TableAllTypeEnumType1.e2,
|
||||
testFieldEnum1Nullable = TableAllTypeEnumType1.e3,
|
||||
testFieldEnum2 = TableAllTypeEnumType2.f3,
|
||||
testFieldEnum2Nullable = TableAllTypeEnumType2.f2,
|
||||
testFieldFloat = 0.99F,
|
||||
testFieldFloatNullable = 0.11F,
|
||||
testFieldGuid = Guid.NewGuid(),
|
||||
testFieldGuidNullable = Guid.NewGuid(),
|
||||
testFieldInt = int.MaxValue,
|
||||
testFieldIntNullable = int.MinValue,
|
||||
testFieldLong = long.MaxValue,
|
||||
testFieldSByte = sbyte.MaxValue,
|
||||
testFieldSByteNullable = sbyte.MinValue,
|
||||
testFieldShort = short.MaxValue,
|
||||
testFieldShortNullable = short.MinValue,
|
||||
testFieldString = "我是中国人string",
|
||||
testFieldTimeSpan = TimeSpan.FromSeconds(999),
|
||||
testFieldTimeSpanNullable = TimeSpan.FromSeconds(30),
|
||||
testFieldUInt = uint.MaxValue,
|
||||
testFieldUIntNullable = uint.MinValue,
|
||||
testFieldULong = ulong.MaxValue,
|
||||
testFieldULongNullable = ulong.MinValue,
|
||||
testFieldUShort = ushort.MaxValue,
|
||||
testFieldUShortNullable = ushort.MinValue,
|
||||
testFielLongNullable = long.MinValue
|
||||
};
|
||||
|
||||
var sqlPar = insert.AppendData(item2).ToSql();
|
||||
var sqlText = insert.AppendData(item2).NoneParameter().ToSql();
|
||||
var item3NP = insert.AppendData(item2).NoneParameter().ExecuteInserted();
|
||||
|
||||
var sqlTestUpdate = g.sqlserver.Update<TableAllType>().SetSource(item3NP).NoneParameter().ToSql();
|
||||
|
||||
var item3 = insert.AppendData(item2).ExecuteInserted();
|
||||
var newitem2 = select.Where(a => a.Id == item2.Id).ToOne();
|
||||
|
||||
var items = select.ToList();
|
||||
}
|
||||
|
||||
[JsonObject(MemberSerialization.OptIn), Table(Name = "dbo.tb_alltype")]
|
||||
public partial class Tb_alltype
|
||||
{
|
||||
|
||||
[JsonProperty, Column(Name = "Id", DbType = "int", IsPrimary = true, IsIdentity = true)]
|
||||
public int Id { get; set; }
|
||||
|
||||
|
||||
[JsonProperty, Column(Name = "testFieldBool1111", DbType = "bit")]
|
||||
public bool TestFieldBool1111 { get; set; }
|
||||
|
||||
|
||||
[JsonProperty, Column(Name = "testFieldBoolNullable", DbType = "bit", IsNullable = true)]
|
||||
public bool? TestFieldBoolNullable { get; set; }
|
||||
|
||||
|
||||
[JsonProperty, Column(Name = "testFieldByte", DbType = "tinyint")]
|
||||
public sbyte TestFieldByte { get; set; }
|
||||
|
||||
|
||||
[JsonProperty, Column(Name = "testFieldByteNullable", DbType = "tinyint", IsNullable = true)]
|
||||
public sbyte? TestFieldByteNullable { get; set; }
|
||||
|
||||
|
||||
[JsonProperty, Column(Name = "testFieldBytes", DbType = "varbinary(255)", IsNullable = true)]
|
||||
public byte[] TestFieldBytes { get; set; }
|
||||
|
||||
|
||||
[JsonProperty, Column(Name = "testFieldDateTime", DbType = "datetime")]
|
||||
public DateTime TestFieldDateTime { get; set; }
|
||||
|
||||
|
||||
[JsonProperty, Column(Name = "testFieldDateTimeNullable", DbType = "datetime", IsNullable = true)]
|
||||
public DateTime? TestFieldDateTimeNullable { get; set; }
|
||||
|
||||
|
||||
[JsonProperty, Column(Name = "testFieldDateTimeNullableOffset", DbType = "datetimeoffset", IsNullable = true)]
|
||||
public DateTime? TestFieldDateTimeNullableOffset { get; set; }
|
||||
|
||||
|
||||
[JsonProperty, Column(Name = "testFieldDateTimeOffset", DbType = "datetimeoffset")]
|
||||
public DateTime TestFieldDateTimeOffset { get; set; }
|
||||
|
||||
|
||||
[JsonProperty, Column(Name = "testFieldDecimal", DbType = "decimal(10,2)")]
|
||||
public decimal TestFieldDecimal { get; set; }
|
||||
|
||||
|
||||
[JsonProperty, Column(Name = "testFieldDecimalNullable", DbType = "decimal(10,2)", IsNullable = true)]
|
||||
public decimal? TestFieldDecimalNullable { get; set; }
|
||||
|
||||
|
||||
[JsonProperty, Column(Name = "testFieldDouble", DbType = "float")]
|
||||
public double TestFieldDouble { get; set; }
|
||||
|
||||
|
||||
[JsonProperty, Column(Name = "testFieldDoubleNullable", DbType = "float", IsNullable = true)]
|
||||
public double? TestFieldDoubleNullable { get; set; }
|
||||
|
||||
|
||||
[JsonProperty, Column(Name = "testFieldEnum1", DbType = "int")]
|
||||
public int TestFieldEnum1 { get; set; }
|
||||
|
||||
|
||||
[JsonProperty, Column(Name = "testFieldEnum1Nullable", DbType = "int", IsNullable = true)]
|
||||
public int? TestFieldEnum1Nullable { get; set; }
|
||||
|
||||
|
||||
[JsonProperty, Column(Name = "testFieldEnum2", DbType = "bigint")]
|
||||
public long TestFieldEnum2 { get; set; }
|
||||
|
||||
|
||||
[JsonProperty, Column(Name = "testFieldEnum2Nullable", DbType = "bigint", IsNullable = true)]
|
||||
public long? TestFieldEnum2Nullable { get; set; }
|
||||
|
||||
|
||||
[JsonProperty, Column(Name = "testFieldFloat", DbType = "real")]
|
||||
public float TestFieldFloat { get; set; }
|
||||
|
||||
|
||||
[JsonProperty, Column(Name = "testFieldFloatNullable", DbType = "real", IsNullable = true)]
|
||||
public float? TestFieldFloatNullable { get; set; }
|
||||
|
||||
|
||||
[JsonProperty, Column(Name = "testFieldGuid", DbType = "uniqueidentifier")]
|
||||
public Guid TestFieldGuid { get; set; }
|
||||
|
||||
|
||||
[JsonProperty, Column(Name = "testFieldGuidNullable", DbType = "uniqueidentifier", IsNullable = true)]
|
||||
public Guid? TestFieldGuidNullable { get; set; }
|
||||
|
||||
|
||||
[JsonProperty, Column(Name = "testFieldInt", DbType = "int")]
|
||||
public int TestFieldInt { get; set; }
|
||||
|
||||
|
||||
[JsonProperty, Column(Name = "testFieldIntNullable", DbType = "int", IsNullable = true)]
|
||||
public int? TestFieldIntNullable { get; set; }
|
||||
|
||||
|
||||
[JsonProperty, Column(Name = "testFieldLong", DbType = "bigint")]
|
||||
public long TestFieldLong { get; set; }
|
||||
|
||||
|
||||
[JsonProperty, Column(Name = "testFieldSByte", DbType = "tinyint")]
|
||||
public sbyte TestFieldSByte { get; set; }
|
||||
|
||||
|
||||
[JsonProperty, Column(Name = "testFieldSByteNullable", DbType = "tinyint", IsNullable = true)]
|
||||
public sbyte? TestFieldSByteNullable { get; set; }
|
||||
|
||||
|
||||
[JsonProperty, Column(Name = "testFieldShort", DbType = "smallint")]
|
||||
public short TestFieldShort { get; set; }
|
||||
|
||||
|
||||
[JsonProperty, Column(Name = "testFieldShortNullable", DbType = "smallint", IsNullable = true)]
|
||||
public short? TestFieldShortNullable { get; set; }
|
||||
|
||||
|
||||
[JsonProperty, Column(Name = "testFieldString", DbType = "nvarchar(255)", IsNullable = true)]
|
||||
public string TestFieldString { get; set; }
|
||||
|
||||
|
||||
[JsonProperty, Column(Name = "testFieldTimeSpan", DbType = "time")]
|
||||
public TimeSpan TestFieldTimeSpan { get; set; }
|
||||
|
||||
|
||||
[JsonProperty, Column(Name = "testFieldTimeSpanNullable", DbType = "time", IsNullable = true)]
|
||||
public TimeSpan? TestFieldTimeSpanNullable { get; set; }
|
||||
|
||||
|
||||
[JsonProperty, Column(Name = "testFieldUInt", DbType = "int")]
|
||||
public int TestFieldUInt { get; set; }
|
||||
|
||||
|
||||
[JsonProperty, Column(Name = "testFieldUIntNullable", DbType = "int", IsNullable = true)]
|
||||
public int? TestFieldUIntNullable { get; set; }
|
||||
|
||||
|
||||
[JsonProperty, Column(Name = "testFieldULong", DbType = "bigint")]
|
||||
public long TestFieldULong { get; set; }
|
||||
|
||||
|
||||
[JsonProperty, Column(Name = "testFieldULongNullable", DbType = "bigint", IsNullable = true)]
|
||||
public long? TestFieldULongNullable { get; set; }
|
||||
|
||||
|
||||
[JsonProperty, Column(Name = "testFieldUShort", DbType = "smallint")]
|
||||
public short TestFieldUShort { get; set; }
|
||||
|
||||
|
||||
[JsonProperty, Column(Name = "testFieldUShortNullable", DbType = "smallint", IsNullable = true)]
|
||||
public short? TestFieldUShortNullable { get; set; }
|
||||
|
||||
|
||||
[JsonProperty, Column(Name = "testFielLongNullable", DbType = "bigint", IsNullable = true)]
|
||||
public long? TestFielLongNullable { get; set; }
|
||||
}
|
||||
|
||||
[Table(Name = "tb_alltype")]
|
||||
class TableAllType
|
||||
{
|
||||
[Column(IsIdentity = true, IsPrimary = true)]
|
||||
public int Id { get; set; }
|
||||
|
||||
[Column(Name = "testFieldBool1111")]
|
||||
public bool testFieldBool { get; set; }
|
||||
public sbyte testFieldSByte { get; set; }
|
||||
public short testFieldShort { get; set; }
|
||||
public int testFieldInt { get; set; }
|
||||
public long testFieldLong { get; set; }
|
||||
public byte testFieldByte { get; set; }
|
||||
public ushort testFieldUShort { get; set; }
|
||||
public uint testFieldUInt { get; set; }
|
||||
public ulong testFieldULong { get; set; }
|
||||
public double testFieldDouble { get; set; }
|
||||
public float testFieldFloat { get; set; }
|
||||
public decimal testFieldDecimal { get; set; }
|
||||
public TimeSpan testFieldTimeSpan { get; set; }
|
||||
public DateTime testFieldDateTime { get; set; }
|
||||
public DateTimeOffset testFieldDateTimeOffset { get; set; }
|
||||
public byte[] testFieldBytes { get; set; }
|
||||
public string testFieldString { get; set; }
|
||||
public Guid testFieldGuid { get; set; }
|
||||
|
||||
public bool? testFieldBoolNullable { get; set; }
|
||||
public sbyte? testFieldSByteNullable { get; set; }
|
||||
public short? testFieldShortNullable { get; set; }
|
||||
public int? testFieldIntNullable { get; set; }
|
||||
public long? testFielLongNullable { get; set; }
|
||||
public byte? testFieldByteNullable { get; set; }
|
||||
public ushort? testFieldUShortNullable { get; set; }
|
||||
public uint? testFieldUIntNullable { get; set; }
|
||||
public ulong? testFieldULongNullable { get; set; }
|
||||
public double? testFieldDoubleNullable { get; set; }
|
||||
public float? testFieldFloatNullable { get; set; }
|
||||
public decimal? testFieldDecimalNullable { get; set; }
|
||||
public TimeSpan? testFieldTimeSpanNullable { get; set; }
|
||||
public DateTime? testFieldDateTimeNullable { get; set; }
|
||||
public DateTimeOffset? testFieldDateTimeNullableOffset { get; set; }
|
||||
public Guid? testFieldGuidNullable { get; set; }
|
||||
|
||||
public TableAllTypeEnumType1 testFieldEnum1 { get; set; }
|
||||
public TableAllTypeEnumType1? testFieldEnum1Nullable { get; set; }
|
||||
public TableAllTypeEnumType2 testFieldEnum2 { get; set; }
|
||||
public TableAllTypeEnumType2? testFieldEnum2Nullable { get; set; }
|
||||
}
|
||||
|
||||
public enum TableAllTypeEnumType1 { e1, e2, e3, e5 }
|
||||
[Flags] public enum TableAllTypeEnumType2 { f1, f2, f3 }
|
||||
}
|
||||
}
|
@ -0,0 +1,26 @@
|
||||
using FreeSql.DataAnnotations;
|
||||
using System;
|
||||
using Xunit;
|
||||
|
||||
namespace FreeSql.Tests.Odbc.SqlServer
|
||||
{
|
||||
[Collection("SqlServerCollection")]
|
||||
public class SqlServerDbFirstTest
|
||||
{
|
||||
[Fact]
|
||||
public void GetDatabases()
|
||||
{
|
||||
|
||||
var t1 = g.sqlserver.DbFirst.GetDatabases();
|
||||
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void GetTablesByDatabase()
|
||||
{
|
||||
|
||||
var t2 = g.sqlserver.DbFirst.GetTablesByDatabase();
|
||||
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,169 @@
|
||||
using FreeSql.DataAnnotations;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Xunit;
|
||||
|
||||
namespace FreeSql.Tests.Odbc.SqlServerExpression
|
||||
{
|
||||
[Collection("SqlServerCollection")]
|
||||
public class ConvertTest
|
||||
{
|
||||
ISelect<Topic> select => g.sqlserver.Select<Topic>();
|
||||
|
||||
[Table(Name = "tb_topic")]
|
||||
class Topic
|
||||
{
|
||||
[Column(IsIdentity = true, IsPrimary = true)]
|
||||
public int Id { get; set; }
|
||||
public int Clicks { get; set; }
|
||||
public int TypeGuid { get; set; }
|
||||
public TestTypeInfo Type { get; set; }
|
||||
public string Title { get; set; }
|
||||
public DateTime CreateTime { get; set; }
|
||||
}
|
||||
class TestTypeInfo
|
||||
{
|
||||
public int Guid { get; set; }
|
||||
public int ParentId { get; set; }
|
||||
public TestTypeParentInfo Parent { get; set; }
|
||||
public string Name { get; set; }
|
||||
}
|
||||
class TestTypeParentInfo
|
||||
{
|
||||
public int Id { get; set; }
|
||||
public string Name { get; set; }
|
||||
|
||||
public List<TestTypeInfo> Types { get; set; }
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ToBoolean()
|
||||
{
|
||||
var data = new List<object>();
|
||||
data.Add(select.Where(a => (Convert.ToBoolean(a.Clicks) ? 1 : 0) > 0).ToList());
|
||||
data.Add(select.Where(a => (bool.Parse(a.Clicks.ToString()) ? 1 : 0) > 0).ToList());
|
||||
}
|
||||
[Fact]
|
||||
public void ToByte()
|
||||
{
|
||||
var data = new List<object>();
|
||||
data.Add(select.Where(a => Convert.ToByte(a.Clicks % 255) > 0).ToList());
|
||||
data.Add(select.Where(a => byte.Parse((a.Clicks % 255).ToString()) > 0).ToList());
|
||||
}
|
||||
[Fact]
|
||||
public void ToChar()
|
||||
{
|
||||
var data = new List<object>();
|
||||
data.Add(select.Where(a => Convert.ToChar(a.Clicks) == '1').ToList());
|
||||
data.Add(select.Where(a => char.Parse(a.Clicks.ToString()) == '1').ToList());
|
||||
}
|
||||
[Fact]
|
||||
public void ToDateTime()
|
||||
{
|
||||
var data = new List<object>();
|
||||
data.Add(select.Where(a => Convert.ToDateTime(a.CreateTime.ToString()).Year > 0).ToList());
|
||||
data.Add(select.Where(a => DateTime.Parse(a.CreateTime.ToString()).Year > 0).ToList());
|
||||
}
|
||||
[Fact]
|
||||
public void ToDecimal()
|
||||
{
|
||||
var data = new List<object>();
|
||||
data.Add(select.Where(a => Convert.ToDecimal(a.Clicks) > 0).ToList());
|
||||
data.Add(select.Where(a => decimal.Parse(a.Clicks.ToString()) > 0).ToList());
|
||||
}
|
||||
[Fact]
|
||||
public void ToDouble()
|
||||
{
|
||||
var data = new List<object>();
|
||||
data.Add(select.Where(a => Convert.ToDouble(a.Clicks) > 0).ToList());
|
||||
data.Add(select.Where(a => double.Parse(a.Clicks.ToString()) > 0).ToList());
|
||||
}
|
||||
[Fact]
|
||||
public void ToInt16()
|
||||
{
|
||||
var data = new List<object>();
|
||||
//data.Add(select.Where(a => Convert.ToInt16(a.Clicks) > 0).ToList());
|
||||
//data.Add(select.Where(a => short.Parse(a.Clicks.ToString()) > 0).ToList());
|
||||
}
|
||||
[Fact]
|
||||
public void ToInt32()
|
||||
{
|
||||
var data = new List<object>();
|
||||
data.Add(select.Where(a => (int)a.Clicks > 0).ToList());
|
||||
data.Add(select.Where(a => Convert.ToInt32(a.Clicks) > 0).ToList());
|
||||
data.Add(select.Where(a => int.Parse(a.Clicks.ToString()) > 0).ToList());
|
||||
}
|
||||
[Fact]
|
||||
public void ToInt64()
|
||||
{
|
||||
var data = new List<object>();
|
||||
data.Add(select.Where(a => Convert.ToInt64(a.Clicks) > 0).ToList());
|
||||
data.Add(select.Where(a => long.Parse(a.Clicks.ToString()) > 0).ToList());
|
||||
}
|
||||
[Fact]
|
||||
public void ToSByte()
|
||||
{
|
||||
var data = new List<object>();
|
||||
data.Add(select.Where(a => Convert.ToSByte(a.Clicks % 128) > 0).ToList());
|
||||
data.Add(select.Where(a => sbyte.Parse((a.Clicks % 128).ToString()) > 0).ToList());
|
||||
}
|
||||
[Fact]
|
||||
public void ToSingle()
|
||||
{
|
||||
var data = new List<object>();
|
||||
data.Add(select.Where(a => Convert.ToSingle(a.Clicks) > 0).ToList());
|
||||
data.Add(select.Where(a => float.Parse(a.Clicks.ToString()) > 0).ToList());
|
||||
}
|
||||
[Fact]
|
||||
public void this_ToString()
|
||||
{
|
||||
var data = new List<object>();
|
||||
data.Add(select.Where(a => Convert.ToString(a.Clicks).Equals("")).ToList());
|
||||
data.Add(select.Where(a => a.Clicks.ToString().Equals("")).ToList());
|
||||
}
|
||||
[Fact]
|
||||
public void ToUInt16()
|
||||
{
|
||||
var data = new List<object>();
|
||||
//data.Add(select.Where(a => Convert.ToUInt16(a.Clicks) > 0).ToList());
|
||||
//data.Add(select.Where(a => ushort.Parse(a.Clicks.ToString()) > 0).ToList());
|
||||
}
|
||||
[Fact]
|
||||
public void ToUInt32()
|
||||
{
|
||||
var data = new List<object>();
|
||||
data.Add(select.Where(a => Convert.ToUInt32(a.Clicks) > 0).ToList());
|
||||
data.Add(select.Where(a => uint.Parse(a.Clicks.ToString()) > 0).ToList());
|
||||
}
|
||||
[Fact]
|
||||
public void ToUInt64()
|
||||
{
|
||||
var data = new List<object>();
|
||||
data.Add(select.Where(a => Convert.ToUInt64(a.Clicks) > 0).ToList());
|
||||
data.Add(select.Where(a => ulong.Parse(a.Clicks.ToString()) > 0).ToList());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Guid_Parse()
|
||||
{
|
||||
var data = new List<object>();
|
||||
data.Add(select.Where(a => Guid.Parse(Guid.NewGuid().ToString()) == Guid.Empty).ToList());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Guid_NewGuid()
|
||||
{
|
||||
var data = new List<object>();
|
||||
data.Add(select.OrderBy(a => Guid.NewGuid()).Limit(10).ToList());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Random()
|
||||
{
|
||||
var data = new List<object>();
|
||||
data.Add(select.Where(a => new Random().Next() > a.Clicks).Limit(10).ToList());
|
||||
data.Add(select.Where(a => new Random().NextDouble() > a.Clicks).Limit(10).ToList());
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,322 @@
|
||||
using FreeSql.DataAnnotations;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Xunit;
|
||||
|
||||
namespace FreeSql.Tests.Odbc.SqlServerExpression
|
||||
{
|
||||
[Collection("SqlServerCollection")]
|
||||
public class DateTimeTest
|
||||
{
|
||||
ISelect<Topic> select => g.sqlserver.Select<Topic>();
|
||||
|
||||
[Table(Name = "tb_topic111333")]
|
||||
class Topic
|
||||
{
|
||||
[Column(IsIdentity = true, IsPrimary = true)]
|
||||
public int Id { get; set; }
|
||||
public int Clicks { get; set; }
|
||||
public int TypeGuid { get; set; }
|
||||
public TestTypeInfo Type { get; set; }
|
||||
public string Title { get; set; }
|
||||
public DateTime CreateTime { get; set; }
|
||||
}
|
||||
[Table(Name = "TestTypeInfo333")]
|
||||
class TestTypeInfo
|
||||
{
|
||||
[Column(IsIdentity = true)]
|
||||
public int Guid { get; set; }
|
||||
public int ParentId { get; set; }
|
||||
public TestTypeParentInfo Parent { get; set; }
|
||||
public string Name { get; set; }
|
||||
public DateTime Time { get; set; }
|
||||
}
|
||||
[Table(Name = "TestTypeParentInfo23123")]
|
||||
class TestTypeParentInfo
|
||||
{
|
||||
public int Id { get; set; }
|
||||
public string Name { get; set; }
|
||||
|
||||
public List<TestTypeInfo> Types { get; set; }
|
||||
public DateTime Time2 { get; set; }
|
||||
}
|
||||
[Fact]
|
||||
public void Now()
|
||||
{
|
||||
var data = new List<object>();
|
||||
data.Add(select.Where(a => a.CreateTime.Date == DateTime.Now.Date).ToList());
|
||||
}
|
||||
[Fact]
|
||||
public void UtcNow()
|
||||
{
|
||||
var data = new List<object>();
|
||||
data.Add(select.Where(a => a.CreateTime.Date == DateTime.UtcNow.Date).ToList());
|
||||
}
|
||||
[Fact]
|
||||
public void MinValue()
|
||||
{
|
||||
var data = new List<object>();
|
||||
data.Add(select.Where(a => a.CreateTime.Date == DateTime.MinValue.Date).ToList());
|
||||
}
|
||||
[Fact]
|
||||
public void MaxValue()
|
||||
{
|
||||
var data = new List<object>();
|
||||
data.Add(select.Where(a => a.CreateTime.Date == DateTime.MaxValue.Date).ToList());
|
||||
}
|
||||
[Fact]
|
||||
public void Date()
|
||||
{
|
||||
var data = new List<object>();
|
||||
data.Add(select.Where(a => a.CreateTime.Date == DateTime.Now.Date).ToList());
|
||||
data.Add(select.Where(a => a.Type.Time.Date > DateTime.Now.Date).ToList());
|
||||
data.Add(select.Where(a => a.Type.Parent.Time2.Date > DateTime.Now.Date).ToList());
|
||||
|
||||
data.Add(select.Where(a => DateTime.Now.Subtract(a.CreateTime.Date).TotalSeconds > 0).ToList());
|
||||
data.Add(select.Where(a => DateTime.Now.Subtract(a.Type.Time.Date).TotalSeconds > 0).ToList());
|
||||
data.Add(select.Where(a => DateTime.Now.Subtract(a.Type.Parent.Time2.Date).TotalSeconds > 0).ToList());
|
||||
}
|
||||
[Fact]
|
||||
public void TimeOfDay()
|
||||
{
|
||||
var data = new List<object>();
|
||||
data.Add(select.Where(a => a.CreateTime.TimeOfDay == DateTime.Now.TimeOfDay).ToList());
|
||||
data.Add(select.Where(a => a.Type.Time.TimeOfDay > DateTime.Now.TimeOfDay).ToList());
|
||||
data.Add(select.Where(a => a.Type.Parent.Time2.TimeOfDay > DateTime.Now.TimeOfDay).ToList());
|
||||
}
|
||||
[Fact]
|
||||
public void DayOfWeek()
|
||||
{
|
||||
var data = new List<object>();
|
||||
data.Add(select.Where(a => a.CreateTime.DayOfWeek > DateTime.Now.DayOfWeek).ToList());
|
||||
data.Add(select.Where(a => a.Type.Time.DayOfWeek > DateTime.Now.DayOfWeek).ToList());
|
||||
data.Add(select.Where(a => a.Type.Parent.Time2.DayOfWeek > DateTime.Now.DayOfWeek).ToList());
|
||||
}
|
||||
[Fact]
|
||||
public void Day()
|
||||
{
|
||||
var data = new List<object>();
|
||||
data.Add(select.Where(a => a.CreateTime.Day > DateTime.Now.Day).ToList());
|
||||
data.Add(select.Where(a => a.Type.Time.Day > DateTime.Now.Day).ToList());
|
||||
data.Add(select.Where(a => a.Type.Parent.Time2.Day > DateTime.Now.Day).ToList());
|
||||
}
|
||||
[Fact]
|
||||
public void DayOfYear()
|
||||
{
|
||||
var data = new List<object>();
|
||||
data.Add(select.Where(a => a.CreateTime.DayOfYear > DateTime.Now.DayOfYear).ToList());
|
||||
data.Add(select.Where(a => a.Type.Time.DayOfYear > DateTime.Now.DayOfYear).ToList());
|
||||
data.Add(select.Where(a => a.Type.Parent.Time2.DayOfYear > DateTime.Now.DayOfYear).ToList());
|
||||
}
|
||||
[Fact]
|
||||
public void Month()
|
||||
{
|
||||
var data = new List<object>();
|
||||
data.Add(select.Where(a => a.CreateTime.Month > DateTime.Now.Month).ToList());
|
||||
data.Add(select.Where(a => a.Type.Time.Month > DateTime.Now.Month).ToList());
|
||||
data.Add(select.Where(a => a.Type.Parent.Time2.Month > DateTime.Now.Month).ToList());
|
||||
}
|
||||
[Fact]
|
||||
public void Year()
|
||||
{
|
||||
var data = new List<object>();
|
||||
data.Add(select.Where(a => a.CreateTime.Year > DateTime.Now.Year).ToList());
|
||||
data.Add(select.Where(a => a.Type.Time.Year > DateTime.Now.Year).ToList());
|
||||
data.Add(select.Where(a => a.Type.Parent.Time2.Year > DateTime.Now.Year).ToList());
|
||||
}
|
||||
[Fact]
|
||||
public void Hour()
|
||||
{
|
||||
var data = new List<object>();
|
||||
data.Add(select.Where(a => a.CreateTime.Hour > DateTime.Now.Hour).ToList());
|
||||
data.Add(select.Where(a => a.Type.Time.Hour > DateTime.Now.Hour).ToList());
|
||||
data.Add(select.Where(a => a.Type.Parent.Time2.Hour > DateTime.Now.Hour).ToList());
|
||||
}
|
||||
[Fact]
|
||||
public void Minute()
|
||||
{
|
||||
var data = new List<object>();
|
||||
data.Add(select.Where(a => a.CreateTime.Minute > DateTime.Now.Minute).ToList());
|
||||
data.Add(select.Where(a => a.Type.Time.Minute > DateTime.Now.Minute).ToList());
|
||||
data.Add(select.Where(a => a.Type.Parent.Time2.Minute > DateTime.Now.Minute).ToList());
|
||||
}
|
||||
[Fact]
|
||||
public void Second()
|
||||
{
|
||||
var data = new List<object>();
|
||||
data.Add(select.Where(a => a.CreateTime.Second > DateTime.Now.Second).ToList());
|
||||
data.Add(select.Where(a => a.Type.Time.Second > DateTime.Now.Second).ToList());
|
||||
data.Add(select.Where(a => a.Type.Parent.Time2.Second > DateTime.Now.Second).ToList());
|
||||
}
|
||||
[Fact]
|
||||
public void Millisecond()
|
||||
{
|
||||
var data = new List<object>();
|
||||
data.Add(select.Where(a => a.CreateTime.Millisecond > DateTime.Now.Millisecond).ToList());
|
||||
data.Add(select.Where(a => a.Type.Time.Millisecond > DateTime.Now.Millisecond).ToList());
|
||||
data.Add(select.Where(a => a.Type.Parent.Time2.Millisecond > DateTime.Now.Millisecond).ToList());
|
||||
}
|
||||
[Fact]
|
||||
public void Ticks()
|
||||
{
|
||||
var data = new List<object>();
|
||||
data.Add(select.Where(a => a.CreateTime.Ticks > DateTime.Now.Ticks).ToList());
|
||||
data.Add(select.Where(a => a.Type.Time.Ticks > DateTime.Now.Ticks).ToList());
|
||||
data.Add(select.Where(a => a.Type.Parent.Time2.Ticks > DateTime.Now.Ticks).ToList());
|
||||
}
|
||||
[Fact]
|
||||
public void Add()
|
||||
{
|
||||
var data = new List<object>();
|
||||
data.Add(select.Where(a => a.CreateTime.Add(TimeSpan.FromDays(1)) > DateTime.Now).ToList());
|
||||
data.Add(select.Where(a => a.Type.Time.Add(TimeSpan.FromDays(1)) > DateTime.Now).ToList());
|
||||
data.Add(select.Where(a => a.Type.Parent.Time2.Add(TimeSpan.FromDays(1)) > DateTime.Now).ToList());
|
||||
}
|
||||
[Fact]
|
||||
public void AddDays()
|
||||
{
|
||||
var data = new List<object>();
|
||||
data.Add(select.Where(a => a.CreateTime.AddDays(1) > DateTime.Now).ToList());
|
||||
data.Add(select.Where(a => a.Type.Time.AddDays(1) > DateTime.Now).ToList());
|
||||
data.Add(select.Where(a => a.Type.Parent.Time2.AddDays(1) > DateTime.Now).ToList());
|
||||
}
|
||||
[Fact]
|
||||
public void AddHours()
|
||||
{
|
||||
var data = new List<object>();
|
||||
data.Add(select.Where(a => a.CreateTime.AddHours(1) > DateTime.Now).ToList());
|
||||
data.Add(select.Where(a => a.Type.Time.AddHours(1) > DateTime.Now).ToList());
|
||||
data.Add(select.Where(a => a.Type.Parent.Time2.AddHours(1) > DateTime.Now).ToList());
|
||||
}
|
||||
[Fact]
|
||||
public void AddMilliseconds()
|
||||
{
|
||||
var data = new List<object>();
|
||||
data.Add(select.Where(a => a.CreateTime.AddMilliseconds(1) > DateTime.Now).ToList());
|
||||
data.Add(select.Where(a => a.Type.Time.AddMilliseconds(1) > DateTime.Now).ToList());
|
||||
data.Add(select.Where(a => a.Type.Parent.Time2.AddMilliseconds(1) > DateTime.Now).ToList());
|
||||
}
|
||||
[Fact]
|
||||
public void AddMinutes()
|
||||
{
|
||||
var data = new List<object>();
|
||||
data.Add(select.Where(a => a.CreateTime.AddMinutes(1) > DateTime.Now).ToList());
|
||||
data.Add(select.Where(a => a.Type.Time.AddMinutes(1) > DateTime.Now).ToList());
|
||||
data.Add(select.Where(a => a.Type.Parent.Time2.AddMinutes(1) > DateTime.Now).ToList());
|
||||
}
|
||||
[Fact]
|
||||
public void AddMonths()
|
||||
{
|
||||
var data = new List<object>();
|
||||
data.Add(select.Where(a => a.CreateTime.AddMonths(1) > DateTime.Now).ToList());
|
||||
data.Add(select.Where(a => a.Type.Time.AddMonths(1) > DateTime.Now).ToList());
|
||||
data.Add(select.Where(a => a.Type.Parent.Time2.AddMonths(1) > DateTime.Now).ToList());
|
||||
}
|
||||
[Fact]
|
||||
public void AddSeconds()
|
||||
{
|
||||
var data = new List<object>();
|
||||
data.Add(select.Where(a => a.CreateTime.AddSeconds(1) > DateTime.Now).ToList());
|
||||
data.Add(select.Where(a => a.Type.Time.AddSeconds(1) > DateTime.Now).ToList());
|
||||
data.Add(select.Where(a => a.Type.Parent.Time2.AddSeconds(1) > DateTime.Now).ToList());
|
||||
}
|
||||
[Fact]
|
||||
public void AddTicks()
|
||||
{
|
||||
var data = new List<object>();
|
||||
data.Add(select.Where(a => a.CreateTime.AddTicks(1) > DateTime.Now).ToList());
|
||||
data.Add(select.Where(a => a.Type.Time.AddTicks(1) > DateTime.Now).ToList());
|
||||
data.Add(select.Where(a => a.Type.Parent.Time2.AddTicks(1) > DateTime.Now).ToList());
|
||||
}
|
||||
[Fact]
|
||||
public void AddYears()
|
||||
{
|
||||
var data = new List<object>();
|
||||
data.Add(select.Where(a => a.CreateTime.AddYears(1) > DateTime.Now).ToList());
|
||||
data.Add(select.Where(a => a.Type.Time.AddYears(1) > DateTime.Now).ToList());
|
||||
data.Add(select.Where(a => a.Type.Parent.Time2.AddYears(1) > DateTime.Now).ToList());
|
||||
}
|
||||
[Fact]
|
||||
public void Subtract()
|
||||
{
|
||||
var data = new List<object>();
|
||||
data.Add(select.Where(a => a.CreateTime.Subtract(DateTime.Now).TotalSeconds > 0).ToList());
|
||||
data.Add(select.Where(a => a.Type.Time.Subtract(DateTime.Now).TotalSeconds > 0).ToList());
|
||||
data.Add(select.Where(a => a.Type.Parent.Time2.Subtract(DateTime.Now).TotalSeconds > 0).ToList());
|
||||
|
||||
data.Add(select.Where(a => a.CreateTime.Subtract(TimeSpan.FromDays(1)) > a.CreateTime).ToList());
|
||||
data.Add(select.Where(a => a.Type.Time.Subtract(TimeSpan.FromDays(1)) > a.CreateTime).ToList());
|
||||
data.Add(select.Where(a => a.Type.Parent.Time2.Subtract(TimeSpan.FromDays(1)) > a.CreateTime).ToList());
|
||||
}
|
||||
[Fact]
|
||||
public void Á½¸öÈÕÆÚÏà¼õ_Ч¹ûͬSubtract()
|
||||
{
|
||||
var data = new List<object>();
|
||||
data.Add(select.Where(a => (a.CreateTime - DateTime.Now).TotalSeconds > 0).ToList());
|
||||
data.Add(select.Where(a => (a.Type.Time - DateTime.Now).TotalSeconds > 0).ToList());
|
||||
data.Add(select.Where(a => (a.Type.Parent.Time2 - DateTime.Now).TotalSeconds > 0).ToList());
|
||||
|
||||
data.Add(select.Where(a => (a.CreateTime - TimeSpan.FromDays(1)) > a.CreateTime).ToList());
|
||||
data.Add(select.Where(a => (a.Type.Time - TimeSpan.FromDays(1)) > a.CreateTime).ToList());
|
||||
data.Add(select.Where(a => (a.Type.Parent.Time2 - TimeSpan.FromDays(1)) > a.CreateTime).ToList());
|
||||
}
|
||||
[Fact]
|
||||
public void this_Equals()
|
||||
{
|
||||
var data = new List<object>();
|
||||
data.Add(select.Where(a => a.CreateTime.AddYears(1).Equals(DateTime.Now)).ToList());
|
||||
data.Add(select.Where(a => a.Type.Time.AddYears(1).Equals(DateTime.Now)).ToList());
|
||||
data.Add(select.Where(a => a.Type.Parent.Time2.AddYears(1).Equals(DateTime.Now)).ToList());
|
||||
}
|
||||
[Fact]
|
||||
public void this_ToString()
|
||||
{
|
||||
var data = new List<object>();
|
||||
data.Add(select.Where(a => a.CreateTime.ToString().Equals(DateTime.Now)).ToList());
|
||||
data.Add(select.Where(a => a.Type.Time.AddYears(1).ToString().Equals(DateTime.Now)).ToList());
|
||||
data.Add(select.Where(a => a.Type.Parent.Time2.AddYears(1).ToString().Equals(DateTime.Now)).ToList());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void DateTime_Compare()
|
||||
{
|
||||
var data = new List<object>();
|
||||
data.Add(select.Where(a => a.CreateTime.CompareTo(DateTime.Now) == 0).ToList());
|
||||
data.Add(select.Where(a => a.Type.Time.AddYears(1).CompareTo(DateTime.Now) == 0).ToList());
|
||||
data.Add(select.Where(a => a.Type.Parent.Time2.AddYears(1).CompareTo(DateTime.Now) == 0).ToList());
|
||||
}
|
||||
[Fact]
|
||||
public void DateTime_DaysInMonth()
|
||||
{
|
||||
var data = new List<object>();
|
||||
data.Add(select.Where(a => DateTime.DaysInMonth(a.CreateTime.Year, a.CreateTime.Month) > 30).ToList());
|
||||
data.Add(select.Where(a => DateTime.DaysInMonth(a.Type.Time.Year, a.Type.Time.Month) > 30).ToList());
|
||||
data.Add(select.Where(a => DateTime.DaysInMonth(a.Type.Parent.Time2.Year, a.Type.Parent.Time2.Month) > 30).ToList());
|
||||
}
|
||||
[Fact]
|
||||
public void DateTime_Equals()
|
||||
{
|
||||
var data = new List<object>();
|
||||
data.Add(select.Where(a => DateTime.Equals(a.CreateTime.AddYears(1), DateTime.Now)).ToList());
|
||||
data.Add(select.Where(a => DateTime.Equals(a.Type.Time.AddYears(1), DateTime.Now)).ToList());
|
||||
data.Add(select.Where(a => DateTime.Equals(a.Type.Parent.Time2.AddYears(1), DateTime.Now)).ToList());
|
||||
}
|
||||
[Fact]
|
||||
public void DateTime_IsLeapYear()
|
||||
{
|
||||
var data = new List<object>();
|
||||
data.Add(select.Where(a => DateTime.IsLeapYear(a.CreateTime.Year)).ToList());
|
||||
data.Add(select.Where(a => DateTime.IsLeapYear(a.Type.Time.AddYears(1).Year)).ToList());
|
||||
data.Add(select.Where(a => DateTime.IsLeapYear(a.Type.Parent.Time2.AddYears(1).Year)).ToList());
|
||||
}
|
||||
[Fact]
|
||||
public void DateTime_Parse()
|
||||
{
|
||||
var data = new List<object>();
|
||||
data.Add(select.Where(a => DateTime.Parse(a.CreateTime.ToString()) > DateTime.Now).ToList());
|
||||
data.Add(select.Where(a => DateTime.Parse(a.Type.Time.AddYears(1).ToString()) > DateTime.Now).ToList());
|
||||
data.Add(select.Where(a => DateTime.Parse(a.Type.Parent.Time2.AddYears(1).ToString()) > DateTime.Now).ToList());
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,156 @@
|
||||
using FreeSql.DataAnnotations;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Xunit;
|
||||
|
||||
namespace FreeSql.Tests.Odbc.SqlServerExpression
|
||||
{
|
||||
[Collection("SqlServerCollection")]
|
||||
public class MathTest
|
||||
{
|
||||
ISelect<Topic> select => g.sqlserver.Select<Topic>();
|
||||
|
||||
[Table(Name = "tb_topic")]
|
||||
class Topic
|
||||
{
|
||||
[Column(IsIdentity = true, IsPrimary = true)]
|
||||
public int Id { get; set; }
|
||||
public int Clicks { get; set; }
|
||||
public int TypeGuid { get; set; }
|
||||
public TestTypeInfo Type { get; set; }
|
||||
public string Title { get; set; }
|
||||
public DateTime CreateTime { get; set; }
|
||||
}
|
||||
class TestTypeInfo
|
||||
{
|
||||
public int Guid { get; set; }
|
||||
public int ParentId { get; set; }
|
||||
public TestTypeParentInfo Parent { get; set; }
|
||||
public string Name { get; set; }
|
||||
}
|
||||
class TestTypeParentInfo
|
||||
{
|
||||
public int Id { get; set; }
|
||||
public string Name { get; set; }
|
||||
|
||||
public List<TestTypeInfo> Types { get; set; }
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void PI()
|
||||
{
|
||||
var data = new List<object>();
|
||||
data.Add(select.Where(a => Math.PI + a.Clicks > 0).ToList());
|
||||
}
|
||||
[Fact]
|
||||
public void Abs()
|
||||
{
|
||||
var data = new List<object>();
|
||||
data.Add(select.Where(a => Math.Abs(-a.Clicks) > 0).ToList());
|
||||
}
|
||||
[Fact]
|
||||
public void Sign()
|
||||
{
|
||||
var data = new List<object>();
|
||||
data.Add(select.Where(a => Math.Sign(-a.Clicks) > 0).ToList());
|
||||
}
|
||||
[Fact]
|
||||
public void Floor()
|
||||
{
|
||||
var data = new List<object>();
|
||||
data.Add(select.Where(a => Math.Floor(a.Clicks + 0.5) == a.Clicks).ToList());
|
||||
}
|
||||
[Fact]
|
||||
public void Ceiling()
|
||||
{
|
||||
var data = new List<object>();
|
||||
data.Add(select.Where(a => Math.Ceiling(a.Clicks + 0.5) == a.Clicks + 1).ToList());
|
||||
}
|
||||
[Fact]
|
||||
public void Round()
|
||||
{
|
||||
var data = new List<object>();
|
||||
data.Add(select.Where(a => Math.Round(a.Clicks + 0.5) == a.Clicks).ToList());
|
||||
data.Add(select.Where(a => Math.Round(a.Clicks + 0.5, 1) > a.Clicks).ToList());
|
||||
}
|
||||
[Fact]
|
||||
public void Exp()
|
||||
{
|
||||
var data = new List<object>();
|
||||
data.Add(select.Where(a => Math.Exp(1) == a.Clicks + 1).ToList());
|
||||
}
|
||||
[Fact]
|
||||
public void Log()
|
||||
{
|
||||
//var data = new List<object>();
|
||||
//data.Add(select.Where(a => Math.Log(a.Clicks + 0.5) == a.Clicks + 1).ToList());
|
||||
}
|
||||
[Fact]
|
||||
public void Log10()
|
||||
{
|
||||
//var data = new List<object>();
|
||||
//data.Add(select.Where(a => Math.Log10(a.Clicks + 0.5) == a.Clicks + 1).ToList());
|
||||
}
|
||||
[Fact]
|
||||
public void Pow()
|
||||
{
|
||||
var data = new List<object>();
|
||||
//data.Add(select.Where(a => Math.Pow(2, a.Clicks) == a.Clicks + 1).ToList());
|
||||
}
|
||||
[Fact]
|
||||
public void Sqrt()
|
||||
{
|
||||
var data = new List<object>();
|
||||
//data.Add(select.Where(a => Math.Sqrt(Math.Pow(2, a.Clicks)) == a.Clicks + 1).ToList());
|
||||
}
|
||||
[Fact]
|
||||
public void Cos()
|
||||
{
|
||||
var data = new List<object>();
|
||||
//data.Add(select.Where(a => Math.Cos(Math.Pow(2, a.Clicks)) == a.Clicks + 1).ToList());
|
||||
}
|
||||
[Fact]
|
||||
public void Sin()
|
||||
{
|
||||
var data = new List<object>();
|
||||
//data.Add(select.Where(a => Math.Sin(Math.Pow(2, a.Clicks)) == a.Clicks + 1).ToList());
|
||||
}
|
||||
[Fact]
|
||||
public void Tan()
|
||||
{
|
||||
var data = new List<object>();
|
||||
//data.Add(select.Where(a => Math.Tan(Math.Pow(2, a.Clicks)) == a.Clicks + 1).ToList());
|
||||
}
|
||||
[Fact]
|
||||
public void Acos()
|
||||
{
|
||||
var data = new List<object>();
|
||||
//data.Add(select.Where(a => Math.Acos(Math.Pow(2, a.Clicks)) == a.Clicks + 1).ToList());
|
||||
}
|
||||
[Fact]
|
||||
public void Asin()
|
||||
{
|
||||
var data = new List<object>();
|
||||
//data.Add(select.Where(a => Math.Asin(Math.Pow(2, a.Clicks)) == a.Clicks + 1).ToList());
|
||||
}
|
||||
[Fact]
|
||||
public void Atan()
|
||||
{
|
||||
var data = new List<object>();
|
||||
//data.Add(select.Where(a => Math.Atan(Math.Pow(2, a.Clicks)) == a.Clicks + 1).ToList());
|
||||
}
|
||||
[Fact]
|
||||
public void Atan2()
|
||||
{
|
||||
var data = new List<object>();
|
||||
//data.Add(select.Where(a => Math.Atan2(2, a.Clicks) == a.Clicks + 1).ToList());
|
||||
}
|
||||
[Fact]
|
||||
public void Truncate()
|
||||
{
|
||||
var data = new List<object>();
|
||||
data.Add(select.Where(a => Math.Truncate(a.Clicks * 1.0 / 3) == a.Clicks + 1).ToList());
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,130 @@
|
||||
using FreeSql.DataAnnotations;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Xunit;
|
||||
|
||||
namespace FreeSql.Tests.Odbc.SqlServerExpression
|
||||
{
|
||||
[Collection("SqlServerCollection")]
|
||||
public class OtherTest
|
||||
{
|
||||
|
||||
ISelect<TableAllType> select => g.sqlserver.Select<TableAllType>();
|
||||
|
||||
[Fact]
|
||||
public void Div()
|
||||
{
|
||||
var t1 = select.Where(a => a.testFieldInt / 3 > 3).Limit(10).ToList();
|
||||
var t2 = select.Where(a => a.testFieldLong / 3 > 3).Limit(10).ToList();
|
||||
var t3 = select.Where(a => a.testFieldShort / 3 > 3).Limit(10).ToList();
|
||||
|
||||
var t4 = select.Where(a => a.testFieldInt / 3.0 > 3).Limit(10).ToList();
|
||||
var t5 = select.Where(a => a.testFieldLong / 3.0 > 3).Limit(10).ToList();
|
||||
var t6 = select.Where(a => a.testFieldShort / 3.0 > 3).Limit(10).ToList();
|
||||
|
||||
var t7 = select.Where(a => a.testFieldDouble / 3 > 3).Limit(10).ToList();
|
||||
var t8 = select.Where(a => a.testFieldDecimal / 3 > 3).Limit(10).ToList();
|
||||
var t9 = select.Where(a => a.testFieldFloat / 3 > 3).Limit(10).ToList();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Boolean()
|
||||
{
|
||||
var t1 = select.Where(a => a.testFieldBool == true).ToList();
|
||||
var t2 = select.Where(a => a.testFieldBool != true).ToList();
|
||||
var t3 = select.Where(a => a.testFieldBool == false).ToList();
|
||||
var t4 = select.Where(a => !a.testFieldBool).ToList();
|
||||
var t5 = select.Where(a => a.testFieldBool).ToList();
|
||||
|
||||
var t11 = select.Where(a => a.testFieldBoolNullable == true).ToList();
|
||||
var t22 = select.Where(a => a.testFieldBoolNullable != true).ToList();
|
||||
var t33 = select.Where(a => a.testFieldBoolNullable == false).ToList();
|
||||
var t44 = select.Where(a => !a.testFieldBoolNullable.Value).ToList();
|
||||
var t55 = select.Where(a => a.testFieldBoolNullable.Value).ToList();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Array()
|
||||
{
|
||||
IEnumerable<int> testlinqlist = new List<int>(new[] { 1, 2, 3 });
|
||||
var testlinq = select.Where(a => testlinqlist.Contains(a.testFieldInt)).ToList();
|
||||
|
||||
//in not in
|
||||
var sql111 = select.Where(a => new[] { 1, 2, 3 }.Contains(a.testFieldInt)).ToList();
|
||||
var sql112 = select.Where(a => new[] { 1, 2, 3 }.Contains(a.testFieldInt) == false).ToList();
|
||||
var sql113 = select.Where(a => !new[] { 1, 2, 3 }.Contains(a.testFieldInt)).ToList();
|
||||
|
||||
var inarray = new[] { 1, 2, 3 };
|
||||
var sql1111 = select.Where(a => inarray.Contains(a.testFieldInt)).ToList();
|
||||
var sql1122 = select.Where(a => inarray.Contains(a.testFieldInt) == false).ToList();
|
||||
var sql1133 = select.Where(a => !inarray.Contains(a.testFieldInt)).ToList();
|
||||
|
||||
//in not in
|
||||
var sql11111 = select.Where(a => new List<int>() { 1, 2, 3 }.Contains(a.testFieldInt)).ToList();
|
||||
var sql11222 = select.Where(a => new List<int>() { 1, 2, 3 }.Contains(a.testFieldInt) == false).ToList();
|
||||
var sql11333 = select.Where(a => !new List<int>() { 1, 2, 3 }.Contains(a.testFieldInt)).ToList();
|
||||
|
||||
var sql11111a = select.Where(a => new List<int>(new[] { 1, 2, 3 }).Contains(a.testFieldInt)).ToList();
|
||||
var sql11222b = select.Where(a => new List<int>(new[] { 1, 2, 3 }).Contains(a.testFieldInt) == false).ToList();
|
||||
var sql11333c = select.Where(a => !new List<int>(new[] { 1, 2, 3 }).Contains(a.testFieldInt)).ToList();
|
||||
|
||||
var inarray2 = new List<int>() { 1, 2, 3 };
|
||||
var sql111111 = select.Where(a => inarray.Contains(a.testFieldInt)).ToList();
|
||||
var sql112222 = select.Where(a => inarray.Contains(a.testFieldInt) == false).ToList();
|
||||
var sql113333 = select.Where(a => !inarray.Contains(a.testFieldInt)).ToList();
|
||||
}
|
||||
|
||||
[Table(Name = "tb_alltype")]
|
||||
class TableAllType
|
||||
{
|
||||
[Column(IsIdentity = true, IsPrimary = true)]
|
||||
public int Id { get; set; }
|
||||
|
||||
[Column(Name = "testFieldBool1111")]
|
||||
public bool testFieldBool { get; set; }
|
||||
public sbyte testFieldSByte { get; set; }
|
||||
public short testFieldShort { get; set; }
|
||||
public int testFieldInt { get; set; }
|
||||
public long testFieldLong { get; set; }
|
||||
public byte testFieldByte { get; set; }
|
||||
public ushort testFieldUShort { get; set; }
|
||||
public uint testFieldUInt { get; set; }
|
||||
public ulong testFieldULong { get; set; }
|
||||
public double testFieldDouble { get; set; }
|
||||
public float testFieldFloat { get; set; }
|
||||
public decimal testFieldDecimal { get; set; }
|
||||
public TimeSpan testFieldTimeSpan { get; set; }
|
||||
public DateTime testFieldDateTime { get; set; }
|
||||
public DateTimeOffset testFieldDateTimeOffset { get; set; }
|
||||
public byte[] testFieldBytes { get; set; }
|
||||
public string testFieldString { get; set; }
|
||||
public Guid testFieldGuid { get; set; }
|
||||
|
||||
public bool? testFieldBoolNullable { get; set; }
|
||||
public sbyte? testFieldSByteNullable { get; set; }
|
||||
public short? testFieldShortNullable { get; set; }
|
||||
public int? testFieldIntNullable { get; set; }
|
||||
public long? testFielLongNullable { get; set; }
|
||||
public byte? testFieldByteNullable { get; set; }
|
||||
public ushort? testFieldUShortNullable { get; set; }
|
||||
public uint? testFieldUIntNullable { get; set; }
|
||||
public ulong? testFieldULongNullable { get; set; }
|
||||
public double? testFieldDoubleNullable { get; set; }
|
||||
public float? testFieldFloatNullable { get; set; }
|
||||
public decimal? testFieldDecimalNullable { get; set; }
|
||||
public TimeSpan? testFieldTimeSpanNullable { get; set; }
|
||||
public DateTime? testFieldDateTimeNullable { get; set; }
|
||||
public DateTimeOffset? testFieldDateTimeNullableOffset { get; set; }
|
||||
public Guid? testFieldGuidNullable { get; set; }
|
||||
|
||||
public TableAllTypeEnumType1 testFieldEnum1 { get; set; }
|
||||
public TableAllTypeEnumType1? testFieldEnum1Nullable { get; set; }
|
||||
public TableAllTypeEnumType2 testFieldEnum2 { get; set; }
|
||||
public TableAllTypeEnumType2? testFieldEnum2Nullable { get; set; }
|
||||
}
|
||||
|
||||
public enum TableAllTypeEnumType1 { e1, e2, e3, e5 }
|
||||
[Flags] public enum TableAllTypeEnumType2 { f1, f2, f3 }
|
||||
}
|
||||
}
|
@ -0,0 +1,290 @@
|
||||
using FreeSql.DataAnnotations;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Xunit;
|
||||
|
||||
namespace FreeSql.Tests.Odbc.SqlServerExpression
|
||||
{
|
||||
[Collection("SqlServerCollection")]
|
||||
public class StringTest
|
||||
{
|
||||
|
||||
ISelect<Topic> select => g.sqlserver.Select<Topic>();
|
||||
|
||||
[Table(Name = "tb_topic")]
|
||||
class Topic
|
||||
{
|
||||
[Column(IsIdentity = true, IsPrimary = true)]
|
||||
public int Id { get; set; }
|
||||
public int Clicks { get; set; }
|
||||
public int TypeGuid { get; set; }
|
||||
public TestTypeInfo Type { get; set; }
|
||||
public string Title { get; set; }
|
||||
public DateTime CreateTime { get; set; }
|
||||
}
|
||||
class TestTypeInfo
|
||||
{
|
||||
[Column(IsIdentity = true)]
|
||||
public int Guid { get; set; }
|
||||
public int ParentId { get; set; }
|
||||
public TestTypeParentInfo Parent { get; set; }
|
||||
public string Name { get; set; }
|
||||
}
|
||||
class TestTypeParentInfo
|
||||
{
|
||||
public int Id { get; set; }
|
||||
public string Name { get; set; }
|
||||
|
||||
public List<TestTypeInfo> Types { get; set; }
|
||||
}
|
||||
class TestEqualsGuid
|
||||
{
|
||||
public Guid id { get; set; }
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Equals__()
|
||||
{
|
||||
var list = new List<object>();
|
||||
list.Add(select.Where(a => a.Title.Equals("aaa")).ToList());
|
||||
list.Add(g.sqlserver.Select<TestEqualsGuid>().Where(a => a.id.Equals(Guid.Empty)).ToList());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Empty()
|
||||
{
|
||||
var data = new List<object>();
|
||||
data.Add(select.Where(a => (a.Title ?? "") == string.Empty).ToSql());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void StartsWith()
|
||||
{
|
||||
var list = new List<object>();
|
||||
list.Add(select.Where(a => a.Title.StartsWith("aaa")).ToList());
|
||||
list.Add(select.Where(a => a.Title.StartsWith(a.Title)).ToList());
|
||||
list.Add(select.Where(a => a.Title.StartsWith(a.Title + 1)).ToList());
|
||||
list.Add(select.Where(a => a.Title.StartsWith(a.Type.Name)).ToList());
|
||||
|
||||
list.Add(select.Where(a => (a.Title + "aaa").StartsWith("aaa")).ToList());
|
||||
list.Add(select.Where(a => (a.Title + "aaa").StartsWith(a.Title)).ToList());
|
||||
list.Add(select.Where(a => (a.Title + "aaa").StartsWith(a.Title + 1)).ToList());
|
||||
list.Add(select.Where(a => (a.Title + "aaa").StartsWith(a.Type.Name)).ToList());
|
||||
}
|
||||
[Fact]
|
||||
public void EndsWith()
|
||||
{
|
||||
var list = new List<object>();
|
||||
list.Add(select.Where(a => a.Title.EndsWith("aaa")).ToList());
|
||||
list.Add(select.Where(a => a.Title.EndsWith(a.Title)).ToList());
|
||||
list.Add(select.Where(a => a.Title.EndsWith(a.Title + 1)).ToList());
|
||||
list.Add(select.Where(a => a.Title.EndsWith(a.Type.Name)).ToList());
|
||||
|
||||
list.Add(select.Where(a => (a.Title + "aaa").EndsWith("aaa")).ToList());
|
||||
list.Add(select.Where(a => (a.Title + "aaa").EndsWith(a.Title)).ToList());
|
||||
list.Add(select.Where(a => (a.Title + "aaa").EndsWith(a.Title + 1)).ToList());
|
||||
list.Add(select.Where(a => (a.Title + "aaa").EndsWith(a.Type.Name)).ToList());
|
||||
}
|
||||
[Fact]
|
||||
public void Contains()
|
||||
{
|
||||
var list = new List<object>();
|
||||
list.Add(select.Where(a => a.Title.Contains("aaa")).ToList());
|
||||
list.Add(select.Where(a => a.Title.Contains(a.Title)).ToList());
|
||||
list.Add(select.Where(a => a.Title.Contains(a.Title + 1)).ToList());
|
||||
list.Add(select.Where(a => a.Title.Contains(a.Type.Name)).ToList());
|
||||
|
||||
list.Add(select.Where(a => (a.Title + "aaa").Contains("aaa")).ToList());
|
||||
list.Add(select.Where(a => (a.Title + "aaa").Contains(a.Title)).ToList());
|
||||
list.Add(select.Where(a => (a.Title + "aaa").Contains(a.Title + 1)).ToList());
|
||||
list.Add(select.Where(a => (a.Title + "aaa").Contains(a.Type.Name)).ToList());
|
||||
}
|
||||
[Fact]
|
||||
public void ToLower()
|
||||
{
|
||||
var data = new List<object>();
|
||||
data.Add(select.Where(a => a.Title.ToLower() == "aaa").ToList());
|
||||
data.Add(select.Where(a => a.Title.ToLower() == a.Title).ToList());
|
||||
data.Add(select.Where(a => a.Title.ToLower() == (a.Title + 1)).ToList());
|
||||
data.Add(select.Where(a => a.Title.ToLower() == a.Type.Name).ToList());
|
||||
|
||||
data.Add(select.Where(a => (a.Title.ToLower() + "aaa").ToLower() == "aaa").ToList());
|
||||
data.Add(select.Where(a => (a.Title.ToLower() + "aaa").ToLower() == a.Title).ToList());
|
||||
data.Add(select.Where(a => (a.Title.ToLower() + "aaa").ToLower() == (a.Title + 1)).ToList());
|
||||
data.Add(select.Where(a => (a.Title.ToLower() + "aaa").ToLower() == a.Type.Name).ToList());
|
||||
}
|
||||
[Fact]
|
||||
public void ToUpper()
|
||||
{
|
||||
var data = new List<object>();
|
||||
data.Add(select.Where(a => a.Title.ToUpper() == "aaa").ToList());
|
||||
data.Add(select.Where(a => a.Title.ToUpper() == a.Title).ToList());
|
||||
data.Add(select.Where(a => a.Title.ToUpper() == (a.Title + 1)).ToList());
|
||||
data.Add(select.Where(a => a.Title.ToUpper() == a.Type.Name).ToList());
|
||||
|
||||
data.Add(select.Where(a => (a.Title.ToUpper() + "aaa").ToUpper() == "aaa").ToList());
|
||||
data.Add(select.Where(a => (a.Title.ToUpper() + "aaa").ToUpper() == a.Title).ToList());
|
||||
data.Add(select.Where(a => (a.Title.ToUpper() + "aaa").ToUpper() == (a.Title + 1)).ToList());
|
||||
data.Add(select.Where(a => (a.Title.ToUpper() + "aaa").ToUpper() == a.Type.Name).ToList());
|
||||
}
|
||||
[Fact]
|
||||
public void Substring()
|
||||
{
|
||||
var data = new List<object>();
|
||||
data.Add(select.Where(a => a.Title.Substring(0) == "aaa").ToList());
|
||||
data.Add(select.Where(a => a.Title.Substring(0) == a.Title).ToList());
|
||||
data.Add(select.Where(a => a.Title.Substring(0) == (a.Title + 1)).ToList());
|
||||
data.Add(select.Where(a => a.Title.Substring(0) == a.Type.Name).ToList());
|
||||
|
||||
data.Add(select.Where(a => (a.Title.Substring(0) + "aaa").Substring(a.Title.Length) == "aaa").ToList());
|
||||
data.Add(select.Where(a => (a.Title.Substring(0) + "aaa").Substring(0, a.Title.Length) == a.Title).ToList());
|
||||
data.Add(select.Where(a => (a.Title.Substring(0) + "aaa").Substring(0, 3) == (a.Title + 1)).ToList());
|
||||
data.Add(select.Where(a => (a.Title.Substring(0) + "aaa").Substring(1, 2) == a.Type.Name).ToList());
|
||||
}
|
||||
[Fact]
|
||||
public void Length()
|
||||
{
|
||||
var data = new List<object>();
|
||||
data.Add(select.Where(a => a.Title.Length == 0).ToList());
|
||||
data.Add(select.Where(a => a.Title.Length == 1).ToList());
|
||||
data.Add(select.Where(a => a.Title.Length == a.Title.Length + 1).ToList());
|
||||
data.Add(select.Where(a => a.Title.Length == a.Type.Name.Length).ToList());
|
||||
|
||||
data.Add(select.Where(a => (a.Title + "aaa").Length == 0).ToList());
|
||||
data.Add(select.Where(a => (a.Title + "aaa").Length == 1).ToList());
|
||||
data.Add(select.Where(a => (a.Title + "aaa").Length == a.Title.Length + 1).ToList());
|
||||
data.Add(select.Where(a => (a.Title + "aaa").Length == a.Type.Name.Length).ToList());
|
||||
}
|
||||
[Fact]
|
||||
public void IndexOf()
|
||||
{
|
||||
var data = new List<object>();
|
||||
data.Add(select.Where(a => a.Title.IndexOf("aaa") == -1).ToList());
|
||||
data.Add(select.Where(a => a.Title.IndexOf("aaa", 2) == -1).ToList());
|
||||
data.Add(select.Where(a => a.Title.IndexOf("aaa", 2) == (a.Title.Length + 1)).ToList());
|
||||
data.Add(select.Where(a => a.Title.IndexOf("aaa", 2) == a.Type.Name.Length + 1).ToList());
|
||||
|
||||
data.Add(select.Where(a => (a.Title + "aaa").IndexOf("aaa") == -1).ToList());
|
||||
data.Add(select.Where(a => (a.Title + "aaa").IndexOf("aaa", 2) == -1).ToList());
|
||||
data.Add(select.Where(a => (a.Title + "aaa").IndexOf("aaa", 2) == (a.Title.Length + 1)).ToList());
|
||||
data.Add(select.Where(a => (a.Title + "aaa").IndexOf("aaa", 2) == a.Type.Name.Length + 1).ToList());
|
||||
}
|
||||
[Fact]
|
||||
public void PadLeft()
|
||||
{
|
||||
//var data = new List<object>();
|
||||
//data.Add(select.Where(a => a.Title.PadLeft(10, 'a') == "aaa").ToList());
|
||||
//data.Add(select.Where(a => a.Title.PadLeft(10, 'a') == a.Title).ToList());
|
||||
//data.Add(select.Where(a => a.Title.PadLeft(10, 'a') == (a.Title + 1)).ToList());
|
||||
//data.Add(select.Where(a => a.Title.PadLeft(10, 'a') == a.Type.Name).ToList());
|
||||
|
||||
//data.Add(select.Where(a => (a.Title.PadLeft(10, 'a') + "aaa").PadLeft(20, 'b') == "aaa").ToList());
|
||||
//data.Add(select.Where(a => (a.Title.PadLeft(10, 'a') + "aaa").PadLeft(20, 'b') == a.Title).ToList());
|
||||
//data.Add(select.Where(a => (a.Title.PadLeft(10, 'a') + "aaa").PadLeft(20, 'b') == (a.Title + 1)).ToList());
|
||||
//data.Add(select.Where(a => (a.Title.PadLeft(10, 'a') + "aaa").PadLeft(20, 'b') == a.Type.Name).ToList());
|
||||
}
|
||||
[Fact]
|
||||
public void PadRight()
|
||||
{
|
||||
//var data = new List<object>();
|
||||
//data.Add(select.Where(a => a.Title.PadRight(10, 'a') == "aaa").ToList());
|
||||
//data.Add(select.Where(a => a.Title.PadRight(10, 'a') == a.Title).ToList());
|
||||
//data.Add(select.Where(a => a.Title.PadRight(10, 'a') == (a.Title + 1)).ToList());
|
||||
//data.Add(select.Where(a => a.Title.PadRight(10, 'a') == a.Type.Name).ToList());
|
||||
|
||||
//data.Add(select.Where(a => (a.Title.PadRight(10, 'a') + "aaa").PadRight(20, 'b') == "aaa").ToList());
|
||||
//data.Add(select.Where(a => (a.Title.PadRight(10, 'a') + "aaa").PadRight(20, 'b') == a.Title).ToList());
|
||||
//data.Add(select.Where(a => (a.Title.PadRight(10, 'a') + "aaa").PadRight(20, 'b') == (a.Title + 1)).ToList());
|
||||
//data.Add(select.Where(a => (a.Title.PadRight(10, 'a') + "aaa").PadRight(20, 'b') == a.Type.Name).ToList());
|
||||
}
|
||||
[Fact]
|
||||
public void Trim()
|
||||
{
|
||||
var data = new List<object>();
|
||||
data.Add(select.Where(a => a.Title.Trim() == "aaa").ToList());
|
||||
data.Add(select.Where(a => a.Title.Trim('a') == a.Title).ToList());
|
||||
data.Add(select.Where(a => a.Title.Trim('a', 'b') == (a.Title + 1)).ToList());
|
||||
data.Add(select.Where(a => a.Title.Trim('a', 'b', 'c') == a.Type.Name).ToList());
|
||||
|
||||
data.Add(select.Where(a => (a.Title.Trim() + "aaa").Trim() == "aaa").ToList());
|
||||
data.Add(select.Where(a => (a.Title.Trim('a') + "aaa").Trim('a') == a.Title).ToList());
|
||||
data.Add(select.Where(a => (a.Title.Trim('a', 'b') + "aaa").Trim('a', 'b') == (a.Title + 1)).ToList());
|
||||
data.Add(select.Where(a => (a.Title.Trim('a', 'b', 'c') + "aaa").Trim('a', 'b', 'c') == a.Type.Name).ToList());
|
||||
}
|
||||
[Fact]
|
||||
public void TrimStart()
|
||||
{
|
||||
var data = new List<object>();
|
||||
data.Add(select.Where(a => a.Title.TrimStart() == "aaa").ToList());
|
||||
data.Add(select.Where(a => a.Title.TrimStart('a') == a.Title).ToList());
|
||||
data.Add(select.Where(a => a.Title.TrimStart('a', 'b') == (a.Title + 1)).ToList());
|
||||
data.Add(select.Where(a => a.Title.TrimStart('a', 'b', 'c') == a.Type.Name).ToList());
|
||||
|
||||
data.Add(select.Where(a => (a.Title.TrimStart() + "aaa").TrimStart() == "aaa").ToList());
|
||||
data.Add(select.Where(a => (a.Title.TrimStart('a') + "aaa").TrimStart('a') == a.Title).ToList());
|
||||
data.Add(select.Where(a => (a.Title.TrimStart('a', 'b') + "aaa").TrimStart('a', 'b') == (a.Title + 1)).ToList());
|
||||
data.Add(select.Where(a => (a.Title.TrimStart('a', 'b', 'c') + "aaa").TrimStart('a', 'b', 'c') == a.Type.Name).ToList());
|
||||
}
|
||||
[Fact]
|
||||
public void TrimEnd()
|
||||
{
|
||||
var data = new List<object>();
|
||||
data.Add(select.Where(a => a.Title.TrimEnd() == "aaa").ToList());
|
||||
data.Add(select.Where(a => a.Title.TrimEnd('a') == a.Title).ToList());
|
||||
data.Add(select.Where(a => a.Title.TrimEnd('a', 'b') == (a.Title + 1)).ToList());
|
||||
data.Add(select.Where(a => a.Title.TrimEnd('a', 'b', 'c') == a.Type.Name).ToList());
|
||||
|
||||
data.Add(select.Where(a => (a.Title.TrimEnd() + "aaa").TrimEnd() == "aaa").ToList());
|
||||
data.Add(select.Where(a => (a.Title.TrimEnd('a') + "aaa").TrimEnd('a') == a.Title).ToList());
|
||||
data.Add(select.Where(a => (a.Title.TrimEnd('a', 'b') + "aaa").TrimEnd('a', 'b') == (a.Title + 1)).ToList());
|
||||
data.Add(select.Where(a => (a.Title.TrimEnd('a', 'b', 'c') + "aaa").TrimEnd('a', 'b', 'c') == a.Type.Name).ToList());
|
||||
}
|
||||
[Fact]
|
||||
public void Replace()
|
||||
{
|
||||
var data = new List<object>();
|
||||
data.Add(select.Where(a => a.Title.Replace("a", "b") == "aaa").ToList());
|
||||
data.Add(select.Where(a => a.Title.Replace("a", "b").Replace("b", "c") == a.Title).ToList());
|
||||
data.Add(select.Where(a => a.Title.Replace("a", "b").Replace("b", "c").Replace("c", "a") == (a.Title + 1)).ToList());
|
||||
data.Add(select.Where(a => a.Title.Replace("a", "b").Replace("b", "c").Replace(a.Type.Name, "a") == a.Type.Name).ToList());
|
||||
|
||||
data.Add(select.Where(a => (a.Title.Replace("a", "b") + "aaa").TrimEnd() == "aaa").ToList());
|
||||
data.Add(select.Where(a => (a.Title.Replace("a", "b").Replace("b", "c") + "aaa").TrimEnd('a') == a.Title).ToList());
|
||||
data.Add(select.Where(a => (a.Title.Replace("a", "b").Replace("b", "c").Replace("c", "a") + "aaa").TrimEnd('a', 'b') == (a.Title + 1)).ToList());
|
||||
data.Add(select.Where(a => (a.Title.Replace("a", "b").Replace("b", "c").Replace(a.Type.Name, "a") + "aaa").TrimEnd('a', 'b', 'c') == a.Type.Name).ToList());
|
||||
}
|
||||
[Fact]
|
||||
public void CompareTo()
|
||||
{
|
||||
//var data = new List<object>();
|
||||
//data.Add(select.Where(a => a.Title.CompareTo(a.Title) == 0).ToList());
|
||||
//data.Add(select.Where(a => a.Title.CompareTo(a.Title) > 0).ToList());
|
||||
//data.Add(select.Where(a => a.Title.CompareTo(a.Title + 1) == 0).ToList());
|
||||
//data.Add(select.Where(a => a.Title.CompareTo(a.Title + a.Type.Name) == 0).ToList());
|
||||
|
||||
//data.Add(select.Where(a => (a.Title + "aaa").CompareTo("aaa") == 0).ToList());
|
||||
//data.Add(select.Where(a => (a.Title + "aaa").CompareTo(a.Title) > 0).ToList());
|
||||
//data.Add(select.Where(a => (a.Title + "aaa").CompareTo(a.Title + 1) == 0).ToList());
|
||||
//data.Add(select.Where(a => (a.Title + "aaa").CompareTo(a.Type.Name) == 0).ToList());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void string_IsNullOrEmpty()
|
||||
{
|
||||
var data = new List<object>();
|
||||
data.Add(select.Where(a => string.IsNullOrEmpty(a.Title)).ToList());
|
||||
//data.Add(select.Where(a => string.IsNullOrEmpty(a.Title) == false).ToList());
|
||||
data.Add(select.Where(a => !string.IsNullOrEmpty(a.Title)).ToList());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void string_IsNullOrWhiteSpace()
|
||||
{
|
||||
var data = new List<object>();
|
||||
data.Add(select.Where(a => string.IsNullOrWhiteSpace(a.Title)).ToList());
|
||||
data.Add(select.Where(a => string.IsNullOrWhiteSpace(a.Title) == false).ToList());
|
||||
data.Add(select.Where(a => !string.IsNullOrWhiteSpace(a.Title)).ToList());
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,210 @@
|
||||
using FreeSql.DataAnnotations;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Xunit;
|
||||
|
||||
namespace FreeSql.Tests.Odbc.SqlServerExpression
|
||||
{
|
||||
[Collection("SqlServerCollection")]
|
||||
public class TimeSpanTest
|
||||
{
|
||||
|
||||
ISelect<Topic> select => g.sqlserver.Select<Topic>();
|
||||
|
||||
[Table(Name = "tb_topic")]
|
||||
class Topic
|
||||
{
|
||||
[Column(IsIdentity = true, IsPrimary = true)]
|
||||
public int Id { get; set; }
|
||||
public int Clicks { get; set; }
|
||||
public int TypeGuid { get; set; }
|
||||
public TestTypeInfo Type { get; set; }
|
||||
public string Title { get; set; }
|
||||
public DateTime CreateTime { get; set; }
|
||||
}
|
||||
class TestTypeInfo
|
||||
{
|
||||
public int Guid { get; set; }
|
||||
public int ParentId { get; set; }
|
||||
public TestTypeParentInfo Parent { get; set; }
|
||||
public string Name { get; set; }
|
||||
}
|
||||
class TestTypeParentInfo
|
||||
{
|
||||
public int Id { get; set; }
|
||||
public string Name { get; set; }
|
||||
|
||||
public List<TestTypeInfo> Types { get; set; }
|
||||
}
|
||||
[Fact]
|
||||
public void Zero()
|
||||
{
|
||||
var data = new List<object>();
|
||||
data.Add(select.Where(a => a.CreateTime.TimeOfDay > TimeSpan.Zero).ToList());
|
||||
}
|
||||
[Fact]
|
||||
public void MinValue()
|
||||
{
|
||||
var data = new List<object>();
|
||||
data.Add(select.Where(a => a.CreateTime.TimeOfDay > TimeSpan.MinValue).ToList());
|
||||
}
|
||||
[Fact]
|
||||
public void MaxValue()
|
||||
{
|
||||
var data = new List<object>();
|
||||
data.Add(select.Where(a => a.CreateTime.TimeOfDay < TimeSpan.MaxValue).ToList());
|
||||
}
|
||||
[Fact]
|
||||
public void Days()
|
||||
{
|
||||
var data = new List<object>();
|
||||
data.Add(select.Where(a => a.CreateTime.TimeOfDay.Days == 0).ToList());
|
||||
}
|
||||
[Fact]
|
||||
public void Hours()
|
||||
{
|
||||
var data = new List<object>();
|
||||
data.Add(select.Where(a => a.CreateTime.TimeOfDay.Hours > 0).ToSql());
|
||||
}
|
||||
[Fact]
|
||||
public void Milliseconds()
|
||||
{
|
||||
var data = new List<object>();
|
||||
data.Add(select.Where(a => a.CreateTime.TimeOfDay.Milliseconds > 0).ToList());
|
||||
}
|
||||
[Fact]
|
||||
public void Minutes()
|
||||
{
|
||||
var data = new List<object>();
|
||||
data.Add(select.Where(a => a.CreateTime.TimeOfDay.Minutes > 0).ToList());
|
||||
}
|
||||
[Fact]
|
||||
public void Seconds()
|
||||
{
|
||||
var data = new List<object>();
|
||||
data.Add(select.Where(a => a.CreateTime.TimeOfDay.Seconds > 0).ToList());
|
||||
}
|
||||
[Fact]
|
||||
public void Ticks()
|
||||
{
|
||||
var data = new List<object>();
|
||||
data.Add(select.Where(a => a.CreateTime.TimeOfDay.Ticks > 0).ToList());
|
||||
}
|
||||
[Fact]
|
||||
public void TotalDays()
|
||||
{
|
||||
var data = new List<object>();
|
||||
data.Add(select.Where(a => a.CreateTime.TimeOfDay.TotalDays > 0).ToList());
|
||||
}
|
||||
[Fact]
|
||||
public void TotalHours()
|
||||
{
|
||||
var data = new List<object>();
|
||||
data.Add(select.Where(a => a.CreateTime.TimeOfDay.TotalHours > 0).ToList());
|
||||
}
|
||||
[Fact]
|
||||
public void TotalMilliseconds()
|
||||
{
|
||||
var data = new List<object>();
|
||||
data.Add(select.Where(a => a.CreateTime.TimeOfDay.TotalMilliseconds > 0).ToList());
|
||||
}
|
||||
[Fact]
|
||||
public void TotalMinutes()
|
||||
{
|
||||
var data = new List<object>();
|
||||
data.Add(select.Where(a => a.CreateTime.TimeOfDay.TotalMinutes > 0).ToSql());
|
||||
}
|
||||
[Fact]
|
||||
public void TotalSeconds()
|
||||
{
|
||||
var data = new List<object>();
|
||||
data.Add(select.Where(a => a.CreateTime.TimeOfDay.TotalSeconds > 0).ToList());
|
||||
}
|
||||
[Fact]
|
||||
public void Add()
|
||||
{
|
||||
var data = new List<object>();
|
||||
data.Add(select.Where(a => a.CreateTime.TimeOfDay.Add(TimeSpan.FromDays(1)) > TimeSpan.Zero).ToList());
|
||||
}
|
||||
[Fact]
|
||||
public void Subtract()
|
||||
{
|
||||
var data = new List<object>();
|
||||
data.Add(select.Where(a => a.CreateTime.TimeOfDay.Subtract(TimeSpan.FromDays(1)) > TimeSpan.Zero).ToList());
|
||||
}
|
||||
[Fact]
|
||||
public void CompareTo()
|
||||
{
|
||||
var data = new List<object>();
|
||||
data.Add(select.Where(a => a.CreateTime.TimeOfDay.CompareTo(TimeSpan.FromDays(1)) > 0).ToList());
|
||||
}
|
||||
[Fact]
|
||||
public void this_Equals()
|
||||
{
|
||||
var data = new List<object>();
|
||||
data.Add(select.Where(a => a.CreateTime.TimeOfDay.Equals(TimeSpan.FromDays(1))).ToList());
|
||||
}
|
||||
[Fact]
|
||||
public void this_ToString()
|
||||
{
|
||||
var data = new List<object>();
|
||||
data.Add(select.Where(a => a.CreateTime.TimeOfDay.ToString() == "ssss").ToList());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TimeSpan_Compare()
|
||||
{
|
||||
var data = new List<object>();
|
||||
data.Add(select.Where(a => TimeSpan.Compare(a.CreateTime.TimeOfDay, TimeSpan.FromDays(1)) > 0).ToList());
|
||||
}
|
||||
[Fact]
|
||||
public void TimeSpan_Equals()
|
||||
{
|
||||
var data = new List<object>();
|
||||
data.Add(select.Where(a => TimeSpan.Equals(a.CreateTime.TimeOfDay, TimeSpan.FromDays(1))).ToList());
|
||||
}
|
||||
[Fact]
|
||||
public void TimeSpan_FromDays()
|
||||
{
|
||||
var data = new List<object>();
|
||||
data.Add(select.Where(a => TimeSpan.Equals(a.CreateTime.TimeOfDay, TimeSpan.FromDays(1))).ToList());
|
||||
}
|
||||
[Fact]
|
||||
public void TimeSpan_FromHours()
|
||||
{
|
||||
var data = new List<object>();
|
||||
data.Add(select.Where(a => TimeSpan.Equals(a.CreateTime.TimeOfDay, TimeSpan.FromHours(1))).ToList());
|
||||
}
|
||||
[Fact]
|
||||
public void TimeSpan_FromMilliseconds()
|
||||
{
|
||||
var data = new List<object>();
|
||||
data.Add(select.Where(a => TimeSpan.Equals(a.CreateTime.TimeOfDay, TimeSpan.FromMilliseconds(1))).ToList());
|
||||
}
|
||||
[Fact]
|
||||
public void TimeSpan_FromMinutes()
|
||||
{
|
||||
var data = new List<object>();
|
||||
data.Add(select.Where(a => TimeSpan.Equals(a.CreateTime.TimeOfDay, TimeSpan.FromMinutes(1))).ToList());
|
||||
}
|
||||
[Fact]
|
||||
public void TimeSpan_FromSeconds()
|
||||
{
|
||||
var data = new List<object>();
|
||||
data.Add(select.Where(a => TimeSpan.Equals(a.CreateTime.TimeOfDay, TimeSpan.FromSeconds(1))).ToList());
|
||||
}
|
||||
[Fact]
|
||||
public void TimeSpan_FromTicks()
|
||||
{
|
||||
var data = new List<object>();
|
||||
data.Add(select.Where(a => TimeSpan.Equals(a.CreateTime.TimeOfDay, TimeSpan.FromTicks(1))).ToList());
|
||||
}
|
||||
[Fact]
|
||||
public void TimeSpan_Parse()
|
||||
{
|
||||
var data = new List<object>();
|
||||
data.Add(select.Where(a => TimeSpan.Parse(a.CreateTime.TimeOfDay.ToString()) > TimeSpan.Zero).ToList());
|
||||
}
|
||||
}
|
||||
}
|
1081
FreeSql.Tests/FreeSql.Tests.Provider.Odbc/UnitTest1.cs
Normal file
1081
FreeSql.Tests/FreeSql.Tests.Provider.Odbc/UnitTest1.cs
Normal file
File diff suppressed because it is too large
Load Diff
41
FreeSql.Tests/FreeSql.Tests.Provider.Odbc/g.cs
Normal file
41
FreeSql.Tests/FreeSql.Tests.Provider.Odbc/g.cs
Normal file
@ -0,0 +1,41 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Text;
|
||||
|
||||
|
||||
public class g
|
||||
{
|
||||
static Lazy<IFreeSql> mysqlLazy = new Lazy<IFreeSql>(() => new FreeSql.FreeSqlBuilder()
|
||||
.UseConnectionString(FreeSql.DataType.OdbcMySql, "Driver={MySQL ODBC 8.0 Unicode Driver};Server=127.0.0.1;Persist Security Info=False;Trusted_Connection=Yes;UID=root;PWD=root;DATABASE=cccddd_odbc;Charset=utf8;SslMode=none;Max pool size=2")
|
||||
.UseAutoSyncStructure(true)
|
||||
.UseMonitorCommand(
|
||||
cmd => Trace.WriteLine(cmd.CommandText), //监听SQL命令对象,在执行前
|
||||
(cmd, traceLog) => Console.WriteLine(traceLog))
|
||||
.UseLazyLoading(true)
|
||||
.Build());
|
||||
public static IFreeSql mysql => mysqlLazy.Value;
|
||||
|
||||
static Lazy<IFreeSql> sqlserverLazy = new Lazy<IFreeSql>(() => new FreeSql.FreeSqlBuilder()
|
||||
.UseConnectionString(FreeSql.DataType.OdbcSqlServer, "Driver={SQL Server};Server=.;Persist Security Info=False;Trusted_Connection=Yes;Integrated Security=True;DATABASE=freesqlTest_odbc;Pooling=true;Max pool size=3")
|
||||
.UseAutoSyncStructure(true)
|
||||
.UseMonitorCommand(
|
||||
cmd => Trace.WriteLine(cmd.CommandText), //监听SQL命令对象,在执行前
|
||||
(cmd, traceLog) => Console.WriteLine(traceLog))
|
||||
.UseLazyLoading(true)
|
||||
.Build());
|
||||
public static IFreeSql sqlserver => sqlserverLazy.Value;
|
||||
|
||||
static Lazy<IFreeSql> oracleLazy = new Lazy<IFreeSql>(() => new FreeSql.FreeSqlBuilder()
|
||||
.UseConnectionString(FreeSql.DataType.OdbcOracle, "Driver={Oracle in XE};Server=//127.0.0.1:1521/XE;Persist Security Info=False;Trusted_Connection=Yes;UID=odbc1;PWD=123456")
|
||||
.UseAutoSyncStructure(true)
|
||||
.UseLazyLoading(true)
|
||||
.UseSyncStructureToUpper(true)
|
||||
//.UseNoneCommandParameter(true)
|
||||
|
||||
.UseMonitorCommand(
|
||||
cmd => Trace.WriteLine(cmd.CommandText), //监听SQL命令对象,在执行前
|
||||
(cmd, traceLog) => Console.WriteLine(traceLog))
|
||||
.Build());
|
||||
public static IFreeSql oracle => oracleLazy.Value;
|
||||
}
|
@ -9,6 +9,31 @@
|
||||
保存或添加,如果主键有值则尝试 Update,如果影响的行为 0 则尝试 Insert
|
||||
</summary>
|
||||
</member>
|
||||
<member name="P:FreeSql.Tests.FaceFeatEntity.UesrId">
|
||||
<summary>
|
||||
用户Id
|
||||
</summary>
|
||||
</member>
|
||||
<member name="P:FreeSql.Tests.FaceFeatEntity.FaceId">
|
||||
<summary>
|
||||
人脸Id
|
||||
</summary>
|
||||
</member>
|
||||
<member name="P:FreeSql.Tests.FaceFeatEntity.CreateTime">
|
||||
<summary>
|
||||
创建时间
|
||||
</summary>
|
||||
</member>
|
||||
<member name="P:FreeSql.Tests.FaceFeatEntity.FaceFeat">
|
||||
<summary>
|
||||
创建时间
|
||||
</summary>
|
||||
</member>
|
||||
<member name="P:FreeSql.Tests.FaceFeatEntity.IsDelete">
|
||||
<summary>
|
||||
相似度
|
||||
</summary>
|
||||
</member>
|
||||
<member name="T:FreeSql.Tests.UnitTest1.NewsArticle">
|
||||
<summary>
|
||||
|
||||
|
@ -12,14 +12,8 @@ public class g
|
||||
.UseConnectionString(FreeSql.DataType.MySql, "Data Source=127.0.0.1;Port=3306;User ID=root;Password=root;Initial Catalog=cccddd;Charset=utf8;SslMode=none;Max pool size=2")
|
||||
.UseAutoSyncStructure(true)
|
||||
.UseMonitorCommand(
|
||||
cmd =>
|
||||
{
|
||||
Trace.WriteLine(cmd.CommandText);
|
||||
}, //监听SQL命令对象,在执行前
|
||||
(cmd, traceLog) =>
|
||||
{
|
||||
Console.WriteLine(traceLog);
|
||||
}) //监听SQL命令对象,在执行后
|
||||
cmd => Trace.WriteLine(cmd.CommandText), //监听SQL命令对象,在执行前
|
||||
(cmd, traceLog) => Console.WriteLine(traceLog))
|
||||
.UseLazyLoading(true)
|
||||
.Build());
|
||||
public static IFreeSql mysql => mysqlLazy.Value;
|
||||
@ -33,14 +27,8 @@ public class g
|
||||
.UseSyncStructureToLower(true)
|
||||
.UseLazyLoading(true)
|
||||
.UseMonitorCommand(
|
||||
cmd =>
|
||||
{
|
||||
Trace.WriteLine(cmd.CommandText);
|
||||
}, //监听SQL命令对象,在执行前
|
||||
(cmd, traceLog) =>
|
||||
{
|
||||
Console.WriteLine(traceLog);
|
||||
}) //监听SQL命令对象,在执行后
|
||||
cmd => Trace.WriteLine(cmd.CommandText), //监听SQL命令对象,在执行前
|
||||
(cmd, traceLog) => Console.WriteLine(traceLog))
|
||||
.Build();
|
||||
});
|
||||
public static IFreeSql pgsql => pgsqlLazy.Value;
|
||||
@ -49,14 +37,8 @@ public class g
|
||||
.UseConnectionString(FreeSql.DataType.SqlServer, "Data Source=.;Integrated Security=True;Initial Catalog=freesqlTest;Pooling=true;Max Pool Size=3")
|
||||
.UseAutoSyncStructure(true)
|
||||
.UseMonitorCommand(
|
||||
cmd =>
|
||||
{
|
||||
Trace.WriteLine(cmd.CommandText);
|
||||
}, //监听SQL命令对象,在执行前
|
||||
(cmd, traceLog) =>
|
||||
{
|
||||
Console.WriteLine(traceLog);
|
||||
}) //监听SQL命令对象,在执行后
|
||||
cmd => Trace.WriteLine(cmd.CommandText), //监听SQL命令对象,在执行前
|
||||
(cmd, traceLog) => Console.WriteLine(traceLog))
|
||||
.UseLazyLoading(true)
|
||||
.Build());
|
||||
public static IFreeSql sqlserver => sqlserverLazy.Value;
|
||||
@ -69,14 +51,8 @@ public class g
|
||||
//.UseNoneCommandParameter(true)
|
||||
|
||||
.UseMonitorCommand(
|
||||
cmd =>
|
||||
{
|
||||
Trace.WriteLine(cmd.CommandText);
|
||||
}, //监听SQL命令对象,在执行前
|
||||
(cmd, traceLog) =>
|
||||
{
|
||||
Console.WriteLine(traceLog);
|
||||
}) //监听SQL命令对象,在执行后
|
||||
cmd => Trace.WriteLine(cmd.CommandText), //监听SQL命令对象,在执行前
|
||||
(cmd, traceLog) => Console.WriteLine(traceLog))
|
||||
.Build());
|
||||
public static IFreeSql oracle => oracleLazy.Value;
|
||||
|
||||
@ -85,14 +61,8 @@ public class g
|
||||
.UseAutoSyncStructure(true)
|
||||
.UseLazyLoading(true)
|
||||
.UseMonitorCommand(
|
||||
cmd =>
|
||||
{
|
||||
Trace.WriteLine(cmd.CommandText);
|
||||
}, //监听SQL命令对象,在执行前
|
||||
(cmd, traceLog) =>
|
||||
{
|
||||
Console.WriteLine(traceLog);
|
||||
}) //监听SQL命令对象,在执行后
|
||||
cmd => Trace.WriteLine(cmd.CommandText), //监听SQL命令对象,在执行前
|
||||
(cmd, traceLog) => Console.WriteLine(traceLog))
|
||||
.Build());
|
||||
public static IFreeSql sqlite => sqliteLazy.Value;
|
||||
}
|
||||
|
29
FreeSql.sln
29
FreeSql.sln
@ -60,6 +60,10 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "FreeSql.Extensions.BaseEnti
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "FreeSql.Extensions.JsonMap", "Extensions\FreeSql.Extensions.JsonMap\FreeSql.Extensions.JsonMap.csproj", "{3043DEF1-85DF-47AD-8D5D-327270794356}"
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "FreeSql.Provider.Odbc", "Providers\FreeSql.Provider.Odbc\FreeSql.Provider.Odbc.csproj", "{C57444BA-8BF7-4790-A864-7F237123219B}"
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "FreeSql.Tests.Provider.Odbc", "FreeSql.Tests\FreeSql.Tests.Provider.Odbc\FreeSql.Tests.Provider.Odbc.csproj", "{FA5667B9-BA85-4970-8818-BF09DD8DA3B4}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
@ -346,6 +350,30 @@ Global
|
||||
{3043DEF1-85DF-47AD-8D5D-327270794356}.Release|x64.Build.0 = Release|Any CPU
|
||||
{3043DEF1-85DF-47AD-8D5D-327270794356}.Release|x86.ActiveCfg = Release|Any CPU
|
||||
{3043DEF1-85DF-47AD-8D5D-327270794356}.Release|x86.Build.0 = Release|Any CPU
|
||||
{C57444BA-8BF7-4790-A864-7F237123219B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{C57444BA-8BF7-4790-A864-7F237123219B}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{C57444BA-8BF7-4790-A864-7F237123219B}.Debug|x64.ActiveCfg = Debug|Any CPU
|
||||
{C57444BA-8BF7-4790-A864-7F237123219B}.Debug|x64.Build.0 = Debug|Any CPU
|
||||
{C57444BA-8BF7-4790-A864-7F237123219B}.Debug|x86.ActiveCfg = Debug|Any CPU
|
||||
{C57444BA-8BF7-4790-A864-7F237123219B}.Debug|x86.Build.0 = Debug|Any CPU
|
||||
{C57444BA-8BF7-4790-A864-7F237123219B}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{C57444BA-8BF7-4790-A864-7F237123219B}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{C57444BA-8BF7-4790-A864-7F237123219B}.Release|x64.ActiveCfg = Release|Any CPU
|
||||
{C57444BA-8BF7-4790-A864-7F237123219B}.Release|x64.Build.0 = Release|Any CPU
|
||||
{C57444BA-8BF7-4790-A864-7F237123219B}.Release|x86.ActiveCfg = Release|Any CPU
|
||||
{C57444BA-8BF7-4790-A864-7F237123219B}.Release|x86.Build.0 = Release|Any CPU
|
||||
{FA5667B9-BA85-4970-8818-BF09DD8DA3B4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{FA5667B9-BA85-4970-8818-BF09DD8DA3B4}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{FA5667B9-BA85-4970-8818-BF09DD8DA3B4}.Debug|x64.ActiveCfg = Debug|Any CPU
|
||||
{FA5667B9-BA85-4970-8818-BF09DD8DA3B4}.Debug|x64.Build.0 = Debug|Any CPU
|
||||
{FA5667B9-BA85-4970-8818-BF09DD8DA3B4}.Debug|x86.ActiveCfg = Debug|Any CPU
|
||||
{FA5667B9-BA85-4970-8818-BF09DD8DA3B4}.Debug|x86.Build.0 = Debug|Any CPU
|
||||
{FA5667B9-BA85-4970-8818-BF09DD8DA3B4}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{FA5667B9-BA85-4970-8818-BF09DD8DA3B4}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{FA5667B9-BA85-4970-8818-BF09DD8DA3B4}.Release|x64.ActiveCfg = Release|Any CPU
|
||||
{FA5667B9-BA85-4970-8818-BF09DD8DA3B4}.Release|x64.Build.0 = Release|Any CPU
|
||||
{FA5667B9-BA85-4970-8818-BF09DD8DA3B4}.Release|x86.ActiveCfg = Release|Any CPU
|
||||
{FA5667B9-BA85-4970-8818-BF09DD8DA3B4}.Release|x86.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
@ -367,6 +395,7 @@ Global
|
||||
{D3A1869C-A8DE-46D0-8587-89EBBE3E4DD0} = {94C8A78D-AA15-47B2-A348-530CD86BFC1B}
|
||||
{FE0CB06E-493F-4CE8-B2D7-BF48CA8015C6} = {4A92E8A6-9A6D-41A1-9CDA-DE10899648AA}
|
||||
{3043DEF1-85DF-47AD-8D5D-327270794356} = {4A92E8A6-9A6D-41A1-9CDA-DE10899648AA}
|
||||
{C57444BA-8BF7-4790-A864-7F237123219B} = {2A381C57-2697-427B-9F10-55DA11FD02E4}
|
||||
EndGlobalSection
|
||||
GlobalSection(ExtensibilityGlobals) = postSolution
|
||||
SolutionGuid = {089687FD-5D25-40AB-BA8A-A10D1E137F98}
|
||||
|
@ -4,5 +4,10 @@ using System.Text;
|
||||
|
||||
namespace FreeSql
|
||||
{
|
||||
public enum DataType { MySql, SqlServer, PostgreSQL, Oracle, Sqlite }
|
||||
public enum DataType {
|
||||
|
||||
MySql, SqlServer, PostgreSQL, Oracle, Sqlite,
|
||||
|
||||
OdbcOracle, OdbcSqlServer, OdbcMySql
|
||||
}
|
||||
}
|
||||
|
@ -2,7 +2,7 @@
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFrameworks>netstandard2.0;net45</TargetFrameworks>
|
||||
<Version>0.9.16</Version>
|
||||
<Version>0.9.17</Version>
|
||||
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
|
||||
<Authors>YeXiangQin</Authors>
|
||||
<Description>FreeSql is the most convenient ORM in dotnet. It supports Mysql, Postgresql, SqlServer, Oracle and Sqlite.</Description>
|
||||
|
@ -467,12 +467,13 @@
|
||||
<param name="columnType"></param>
|
||||
<param name="setExp"></param>
|
||||
</member>
|
||||
<member name="M:FreeSql.FreeSqlBuilder.UseConnectionString(FreeSql.DataType,System.String)">
|
||||
<member name="M:FreeSql.FreeSqlBuilder.UseConnectionString(FreeSql.DataType,System.String,System.Type)">
|
||||
<summary>
|
||||
使用连接串
|
||||
</summary>
|
||||
<param name="dataType">数据库类型</param>
|
||||
<param name="connectionString">数据库连接串</param>
|
||||
<param name="providerType">提供者的类型,一般不需要指定,如果一直提示“缺少 FreeSql 数据库实现包:FreeSql.Provider.MySql.dll,可前往 nuget 下载”的错误,说明反射获取不到类型,此时该参数可排上用场</param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:FreeSql.FreeSqlBuilder.UseSlave(System.String[])">
|
||||
|
@ -21,17 +21,20 @@ namespace FreeSql
|
||||
StringConvertType _entityPropertyConvertType = StringConvertType.None;
|
||||
Action<DbCommand> _aopCommandExecuting = null;
|
||||
Action<DbCommand, string> _aopCommandExecuted = null;
|
||||
Type _providerType = null;
|
||||
|
||||
/// <summary>
|
||||
/// 使用连接串
|
||||
/// </summary>
|
||||
/// <param name="dataType">数据库类型</param>
|
||||
/// <param name="connectionString">数据库连接串</param>
|
||||
/// <param name="providerType">提供者的类型,一般不需要指定,如果一直提示“缺少 FreeSql 数据库实现包:FreeSql.Provider.MySql.dll,可前往 nuget 下载”的错误,说明反射获取不到类型,此时该参数可排上用场</param>
|
||||
/// <returns></returns>
|
||||
public FreeSqlBuilder UseConnectionString(DataType dataType, string connectionString)
|
||||
public FreeSqlBuilder UseConnectionString(DataType dataType, string connectionString, Type providerType = null)
|
||||
{
|
||||
_dataType = dataType;
|
||||
_masterConnectionString = connectionString;
|
||||
_providerType = providerType;
|
||||
return this;
|
||||
}
|
||||
/// <summary>
|
||||
@ -135,31 +138,49 @@ namespace FreeSql
|
||||
{
|
||||
if (string.IsNullOrEmpty(_masterConnectionString)) throw new Exception("参数 masterConnectionString 不可为空,请检查 UseConnectionString");
|
||||
IFreeSql<TMark> ret = null;
|
||||
Type type = null;
|
||||
switch (_dataType)
|
||||
var type = _providerType;
|
||||
if (type?.IsGenericType == true) type = type.MakeGenericType(typeof(TMark));
|
||||
if (type == null)
|
||||
{
|
||||
case DataType.MySql:
|
||||
type = Type.GetType("FreeSql.MySql.MySqlProvider`1,FreeSql.Provider.MySql")?.MakeGenericType(typeof(TMark));
|
||||
if (type == null) type = Type.GetType("FreeSql.MySql.MySqlProvider`1,FreeSql.Provider.MySqlConnector")?.MakeGenericType(typeof(TMark));
|
||||
if (type == null) throw new Exception("缺少 FreeSql 数据库实现包:FreeSql.Provider.MySql.dll,可前往 nuget 下载");
|
||||
break;
|
||||
case DataType.SqlServer:
|
||||
type = Type.GetType("FreeSql.SqlServer.SqlServerProvider`1,FreeSql.Provider.SqlServer")?.MakeGenericType(typeof(TMark));
|
||||
if (type == null) throw new Exception("缺少 FreeSql 数据库实现包:FreeSql.Provider.SqlServer.dll,可前往 nuget 下载");
|
||||
break;
|
||||
case DataType.PostgreSQL:
|
||||
type = Type.GetType("FreeSql.PostgreSQL.PostgreSQLProvider`1,FreeSql.Provider.PostgreSQL")?.MakeGenericType(typeof(TMark));
|
||||
if (type == null) throw new Exception("缺少 FreeSql 数据库实现包:FreeSql.Provider.PostgreSQL.dll,可前往 nuget 下载");
|
||||
break;
|
||||
case DataType.Oracle:
|
||||
type = Type.GetType("FreeSql.Oracle.OracleProvider`1,FreeSql.Provider.Oracle")?.MakeGenericType(typeof(TMark));
|
||||
if (type == null) throw new Exception("缺少 FreeSql 数据库实现包:FreeSql.Provider.Oracle.dll,可前往 nuget 下载");
|
||||
break;
|
||||
case DataType.Sqlite:
|
||||
type = Type.GetType("FreeSql.Sqlite.SqliteProvider`1,FreeSql.Provider.Sqlite")?.MakeGenericType(typeof(TMark));
|
||||
if (type == null) throw new Exception("缺少 FreeSql 数据库实现包:FreeSql.Provider.Sqlite.dll,可前往 nuget 下载");
|
||||
break;
|
||||
default: throw new Exception("未指定 UseConnectionString");
|
||||
switch (_dataType)
|
||||
{
|
||||
case DataType.MySql:
|
||||
type = Type.GetType("FreeSql.MySql.MySqlProvider`1,FreeSql.Provider.MySql")?.MakeGenericType(typeof(TMark));
|
||||
if (type == null) type = Type.GetType("FreeSql.MySql.MySqlProvider`1,FreeSql.Provider.MySqlConnector")?.MakeGenericType(typeof(TMark));
|
||||
if (type == null) throw new Exception("缺少 FreeSql 数据库实现包:FreeSql.Provider.MySql.dll,可前往 nuget 下载");
|
||||
break;
|
||||
case DataType.SqlServer:
|
||||
type = Type.GetType("FreeSql.SqlServer.SqlServerProvider`1,FreeSql.Provider.SqlServer")?.MakeGenericType(typeof(TMark));
|
||||
if (type == null) throw new Exception("缺少 FreeSql 数据库实现包:FreeSql.Provider.SqlServer.dll,可前往 nuget 下载");
|
||||
break;
|
||||
case DataType.PostgreSQL:
|
||||
type = Type.GetType("FreeSql.PostgreSQL.PostgreSQLProvider`1,FreeSql.Provider.PostgreSQL")?.MakeGenericType(typeof(TMark));
|
||||
if (type == null) throw new Exception("缺少 FreeSql 数据库实现包:FreeSql.Provider.PostgreSQL.dll,可前往 nuget 下载");
|
||||
break;
|
||||
case DataType.Oracle:
|
||||
type = Type.GetType("FreeSql.Oracle.OracleProvider`1,FreeSql.Provider.Oracle")?.MakeGenericType(typeof(TMark));
|
||||
if (type == null) throw new Exception("缺少 FreeSql 数据库实现包:FreeSql.Provider.Oracle.dll,可前往 nuget 下载");
|
||||
break;
|
||||
case DataType.Sqlite:
|
||||
type = Type.GetType("FreeSql.Sqlite.SqliteProvider`1,FreeSql.Provider.Sqlite")?.MakeGenericType(typeof(TMark));
|
||||
if (type == null) throw new Exception("缺少 FreeSql 数据库实现包:FreeSql.Provider.Sqlite.dll,可前往 nuget 下载");
|
||||
break;
|
||||
|
||||
case DataType.OdbcOracle:
|
||||
type = Type.GetType("FreeSql.Odbc.Oracle.OdbcOracleProvider`1,FreeSql.Provider.Odbc")?.MakeGenericType(typeof(TMark));
|
||||
if (type == null) throw new Exception("缺少 FreeSql 数据库实现包:FreeSql.Provider.Odbc.dll,可前往 nuget 下载");
|
||||
break;
|
||||
case DataType.OdbcSqlServer:
|
||||
type = Type.GetType("FreeSql.Odbc.SqlServer.OdbcSqlServerProvider`1,FreeSql.Provider.Odbc")?.MakeGenericType(typeof(TMark));
|
||||
if (type == null) throw new Exception("缺少 FreeSql 数据库实现包:FreeSql.Provider.Odbc.dll,可前往 nuget 下载");
|
||||
break;
|
||||
case DataType.OdbcMySql:
|
||||
type = Type.GetType("FreeSql.Odbc.MySql.OdbcMySqlProvider`1,FreeSql.Provider.Odbc")?.MakeGenericType(typeof(TMark));
|
||||
if (type == null) throw new Exception("缺少 FreeSql 数据库实现包:FreeSql.Provider.Odbc.dll,可前往 nuget 下载");
|
||||
break;
|
||||
|
||||
default: throw new Exception("未指定 UseConnectionString");
|
||||
}
|
||||
}
|
||||
ret = Activator.CreateInstance(type, new object[] { _masterConnectionString, _slaveConnectionString }) as IFreeSql<TMark>;
|
||||
if (ret != null)
|
||||
@ -230,25 +251,28 @@ namespace FreeSql
|
||||
if (maxlenAttr != null)
|
||||
{
|
||||
var lenProp = maxlenAttr.GetType().GetProperties().Where(a => a.PropertyType.IsNumberType()).FirstOrDefault();
|
||||
if (lenProp != null && int.TryParse(string.Concat(lenProp.GetValue(maxlenAttr, null)), out var tryval) && tryval > 0)
|
||||
if (lenProp != null && int.TryParse(string.Concat(lenProp.GetValue(maxlenAttr, null)), out var tryval))
|
||||
{
|
||||
switch (ret.Ado.DataType)
|
||||
if (tryval != 0)
|
||||
{
|
||||
case DataType.MySql:
|
||||
e.ModifyResult.DbType = $"varchar({tryval})";
|
||||
break;
|
||||
case DataType.SqlServer:
|
||||
e.ModifyResult.DbType = $"nvarchar({tryval})";
|
||||
break;
|
||||
case DataType.PostgreSQL:
|
||||
e.ModifyResult.DbType = $"varchar({tryval})";
|
||||
break;
|
||||
case DataType.Oracle:
|
||||
e.ModifyResult.DbType = $"nvarchar2({tryval})";
|
||||
break;
|
||||
case DataType.Sqlite:
|
||||
e.ModifyResult.DbType = $"nvarchar({tryval})";
|
||||
break;
|
||||
switch (ret.Ado.DataType)
|
||||
{
|
||||
case DataType.MySql:
|
||||
e.ModifyResult.DbType = tryval > 0 ? $"varchar({tryval})" : "text";
|
||||
break;
|
||||
case DataType.SqlServer:
|
||||
e.ModifyResult.DbType = tryval > 0 ? $"nvarchar({tryval})" : "nvarchar(max)";
|
||||
break;
|
||||
case DataType.PostgreSQL:
|
||||
e.ModifyResult.DbType = tryval > 0 ? $"varchar({tryval})" : "text";
|
||||
break;
|
||||
case DataType.Oracle:
|
||||
e.ModifyResult.DbType = tryval > 0 ? $"nvarchar2({tryval})" : "nvarchar2(4000)";
|
||||
break;
|
||||
case DataType.Sqlite:
|
||||
e.ModifyResult.DbType = tryval > 0 ? $"nvarchar({tryval})" : "text";
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -31,7 +31,7 @@ namespace FreeSql.Internal.CommonProvider
|
||||
public bool IsSyncStructureToLower { get; set; } = false;
|
||||
public bool IsSyncStructureToUpper { get; set; } = false;
|
||||
public bool IsConfigEntityFromDbFirst { get; set; } = false;
|
||||
public bool IsNoneCommandParameter { get; set; } = false;
|
||||
public virtual bool IsNoneCommandParameter { get; set; } = false;
|
||||
public bool IsLazyLoading { get; set; } = false;
|
||||
|
||||
public abstract (int type, string dbtype, string dbtypeFull, bool? isnullable, object defaultValue)? GetDbInfo(Type type);
|
||||
@ -50,7 +50,7 @@ namespace FreeSql.Internal.CommonProvider
|
||||
public bool SyncStructure(params Type[] entityTypes)
|
||||
{
|
||||
if (entityTypes == null) return false;
|
||||
var syncTypes = entityTypes.Where(a => dicSyced.ContainsKey(a) == false && GetTableByEntity(a)?.DisableSyncStructure == false).ToArray();
|
||||
var syncTypes = entityTypes.Where(a => dicSyced.ContainsKey(a) == false && GetTableByEntity(a)?.DisableSyncStructure == false).ToArray().Distinct().ToArray();
|
||||
if (syncTypes.Any() == false) return false;
|
||||
var before = new Aop.SyncStructureBeforeEventArgs(entityTypes);
|
||||
_orm.Aop.SyncStructureBefore?.Invoke(this, before);
|
||||
@ -66,7 +66,7 @@ namespace FreeSql.Internal.CommonProvider
|
||||
foreach (var syncType in syncTypes) dicSyced.TryAdd(syncType, true);
|
||||
return true;
|
||||
}
|
||||
var affrows = _orm.Ado.ExecuteNonQuery(CommandType.Text, ddl);
|
||||
var affrows = ExecuteDDLStatements(ddl);
|
||||
foreach (var syncType in syncTypes) dicSyced.TryAdd(syncType, true);
|
||||
return true;
|
||||
}
|
||||
@ -82,5 +82,7 @@ namespace FreeSql.Internal.CommonProvider
|
||||
_orm.Aop.SyncStructureAfter?.Invoke(this, after);
|
||||
}
|
||||
}
|
||||
|
||||
public virtual int ExecuteDDLStatements(string ddl) => _orm.Ado.ExecuteNonQuery(CommandType.Text, ddl);
|
||||
}
|
||||
}
|
@ -76,7 +76,7 @@ namespace FreeSql.Internal
|
||||
var setMethod = trytb.Type.GetMethod($"set_{p.Name}");
|
||||
var colattr = common.GetEntityColumnAttribute(entity, p);
|
||||
var tp = common.CodeFirst.GetDbInfo(colattr?.MapType ?? p.PropertyType);
|
||||
if (setMethod == null) // 属性没有 set自动忽略
|
||||
if (setMethod == null || (tp == null && p.PropertyType.IsValueType)) // 属性没有 set自动忽略
|
||||
{
|
||||
if (colattr == null) colattr = new ColumnAttribute { IsIgnore = true };
|
||||
else colattr.IsIgnore = true;
|
||||
@ -976,7 +976,7 @@ namespace FreeSql.Internal
|
||||
var ps = type.GetProperties();
|
||||
foreach (var p in ps)
|
||||
{
|
||||
if (sql.IndexOf($"{paramPrefix}{p.Name}", StringComparison.CurrentCultureIgnoreCase) == -1) continue;
|
||||
if (string.IsNullOrEmpty(paramPrefix) == false && sql.IndexOf($"{paramPrefix}{p.Name}", StringComparison.CurrentCultureIgnoreCase) == -1) continue;
|
||||
var pvalue = p.GetValue(obj);
|
||||
if (p.PropertyType == ttype) ret.Add((T)Convert.ChangeType(pvalue, ttype));
|
||||
else ret.Add(constructorParamter(p.Name, p.PropertyType, pvalue));
|
||||
|
@ -2,7 +2,7 @@
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFrameworks>netstandard2.0;net452</TargetFrameworks>
|
||||
<Version>0.9.16</Version>
|
||||
<Version>0.9.17</Version>
|
||||
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
|
||||
<Authors>YeXiangQin</Authors>
|
||||
<Description>FreeSql 数据库实现,基于 MySql 5.6</Description>
|
||||
|
@ -2,7 +2,7 @@
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFrameworks>netstandard2.0;net45</TargetFrameworks>
|
||||
<Version>0.9.16</Version>
|
||||
<Version>0.9.17</Version>
|
||||
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
|
||||
<Authors>YeXiangQin</Authors>
|
||||
<Description>FreeSql 数据库实现,基于 MySql 5.6</Description>
|
||||
|
30
Providers/FreeSql.Provider.Odbc/FreeSql.Provider.Odbc.csproj
Normal file
30
Providers/FreeSql.Provider.Odbc/FreeSql.Provider.Odbc.csproj
Normal file
@ -0,0 +1,30 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFrameworks>netstandard2.0;net45</TargetFrameworks>
|
||||
<Version>0.9.17</Version>
|
||||
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
|
||||
<Authors>YeXiangQin</Authors>
|
||||
<Description>FreeSql 数据库 Odbc 实现,基于 {Oracle}、{SQL Server}、{MySQL ODBC 8.0 Unicode Driver}</Description>
|
||||
<PackageProjectUrl>https://github.com/2881099/FreeSql</PackageProjectUrl>
|
||||
<RepositoryUrl>https://github.com/2881099/FreeSql</RepositoryUrl>
|
||||
<RepositoryType>git</RepositoryType>
|
||||
<PackageLicenseExpression>MIT</PackageLicenseExpression>
|
||||
<PackageTags>FreeSql;ORM</PackageTags>
|
||||
<PackageId>$(AssemblyName)</PackageId>
|
||||
<PackageIconUrl>https://github.com/2881099/FreeSql/blob/master/logo.png?raw=true</PackageIconUrl>
|
||||
<Title>$(AssemblyName)</Title>
|
||||
<IsPackable>true</IsPackable>
|
||||
<GenerateAssemblyInfo>true</GenerateAssemblyInfo>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup Condition="'$(TargetFramework)' == 'netstandard2.0'">
|
||||
<PackageReference Include="System.Data.Odbc" Version="4.5.0" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\FreeSql\FreeSql.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
@ -0,0 +1,30 @@
|
||||
public static partial class FreeSqlOdbcGlobalExtensions
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
/// 特殊处理类似 string.Format 的使用方法,防止注入,以及 IS NULL 转换
|
||||
/// </summary>
|
||||
/// <param name="that"></param>
|
||||
/// <param name="args"></param>
|
||||
/// <returns></returns>
|
||||
public static string FormatOdbcOracle(this string that, params object[] args) => _odbcOracleAdo.Addslashes(that, args);
|
||||
static FreeSql.Odbc.Oracle.OdbcOracleAdo _odbcOracleAdo = new FreeSql.Odbc.Oracle.OdbcOracleAdo();
|
||||
|
||||
/// <summary>
|
||||
/// 特殊处理类似 string.Format 的使用方法,防止注入,以及 IS NULL 转换
|
||||
/// </summary>
|
||||
/// <param name="that"></param>
|
||||
/// <param name="args"></param>
|
||||
/// <returns></returns>
|
||||
public static string FormatOdbcSqlServer(this string that, params object[] args) => _sqlserverAdo.Addslashes(that, args);
|
||||
static FreeSql.Odbc.SqlServer.OdbcSqlServerAdo _sqlserverAdo = new FreeSql.Odbc.SqlServer.OdbcSqlServerAdo();
|
||||
|
||||
/// <summary>
|
||||
/// 特殊处理类似 string.Format 的使用方法,防止注入,以及 IS NULL 转换
|
||||
/// </summary>
|
||||
/// <param name="that"></param>
|
||||
/// <param name="args"></param>
|
||||
/// <returns></returns>
|
||||
public static string FormatOdbcMySql(this string that, params object[] args) => _mysqlAdo.Addslashes(that, args);
|
||||
static FreeSql.Odbc.MySql.OdbcMySqlAdo _mysqlAdo = new FreeSql.Odbc.MySql.OdbcMySqlAdo();
|
||||
}
|
@ -0,0 +1,95 @@
|
||||
using FreeSql.Internal;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace FreeSql.Odbc.MySql
|
||||
{
|
||||
|
||||
class OdbcMySqlDelete<T1> : Internal.CommonProvider.DeleteProvider<T1> where T1 : class
|
||||
{
|
||||
public OdbcMySqlDelete(IFreeSql orm, CommonUtils commonUtils, CommonExpression commonExpression, object dywhere)
|
||||
: base(orm, commonUtils, commonExpression, dywhere)
|
||||
{
|
||||
}
|
||||
|
||||
public override List<T1> ExecuteDeleted()
|
||||
{
|
||||
var sql = this.ToSql();
|
||||
if (string.IsNullOrEmpty(sql)) return new List<T1>();
|
||||
|
||||
var sb = new StringBuilder();
|
||||
sb.Append(sql).Append(" RETURNING ");
|
||||
|
||||
var colidx = 0;
|
||||
foreach (var col in _table.Columns.Values)
|
||||
{
|
||||
if (colidx > 0) sb.Append(", ");
|
||||
sb.Append(_commonUtils.QuoteReadColumn(col.Attribute.MapType, _commonUtils.QuoteSqlName(col.Attribute.Name))).Append(" as ").Append(_commonUtils.QuoteSqlName(col.CsName));
|
||||
++colidx;
|
||||
}
|
||||
sql = sb.ToString();
|
||||
var dbParms = _params.ToArray();
|
||||
var before = new Aop.CurdBeforeEventArgs(_table.Type, Aop.CurdType.Delete, sql, dbParms);
|
||||
_orm.Aop.CurdBefore?.Invoke(this, before);
|
||||
var ret = new List<T1>();
|
||||
Exception exception = null;
|
||||
try
|
||||
{
|
||||
ret = _orm.Ado.Query<T1>(_connection, _transaction, CommandType.Text, sql, dbParms);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
exception = ex;
|
||||
throw ex;
|
||||
}
|
||||
finally
|
||||
{
|
||||
var after = new Aop.CurdAfterEventArgs(before, exception, ret);
|
||||
_orm.Aop.CurdAfter?.Invoke(this, after);
|
||||
}
|
||||
this.ClearData();
|
||||
return ret;
|
||||
}
|
||||
async public override Task<List<T1>> ExecuteDeletedAsync()
|
||||
{
|
||||
var sql = this.ToSql();
|
||||
if (string.IsNullOrEmpty(sql)) return new List<T1>();
|
||||
|
||||
var sb = new StringBuilder();
|
||||
sb.Append(sql).Append(" RETURNING ");
|
||||
|
||||
var colidx = 0;
|
||||
foreach (var col in _table.Columns.Values)
|
||||
{
|
||||
if (colidx > 0) sb.Append(", ");
|
||||
sb.Append(_commonUtils.QuoteReadColumn(col.Attribute.MapType, _commonUtils.QuoteSqlName(col.Attribute.Name))).Append(" as ").Append(_commonUtils.QuoteSqlName(col.CsName));
|
||||
++colidx;
|
||||
}
|
||||
sql = sb.ToString();
|
||||
var dbParms = _params.ToArray();
|
||||
var before = new Aop.CurdBeforeEventArgs(_table.Type, Aop.CurdType.Delete, sql, dbParms);
|
||||
_orm.Aop.CurdBefore?.Invoke(this, before);
|
||||
var ret = new List<T1>();
|
||||
Exception exception = null;
|
||||
try
|
||||
{
|
||||
ret = await _orm.Ado.QueryAsync<T1>(_connection, _transaction, CommandType.Text, sql, dbParms);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
exception = ex;
|
||||
throw ex;
|
||||
}
|
||||
finally
|
||||
{
|
||||
var after = new Aop.CurdAfterEventArgs(before, exception, ret);
|
||||
_orm.Aop.CurdAfter?.Invoke(this, after);
|
||||
}
|
||||
this.ClearData();
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
}
|
175
Providers/FreeSql.Provider.Odbc/MySql/Curd/OdbcMySqlInsert.cs
Normal file
175
Providers/FreeSql.Provider.Odbc/MySql/Curd/OdbcMySqlInsert.cs
Normal file
@ -0,0 +1,175 @@
|
||||
using FreeSql.Internal;
|
||||
using SafeObjectPool;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
using System.Data.Common;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace FreeSql.Odbc.MySql
|
||||
{
|
||||
|
||||
class OdbcMySqlInsert<T1> : Internal.CommonProvider.InsertProvider<T1> where T1 : class
|
||||
{
|
||||
public OdbcMySqlInsert(IFreeSql orm, CommonUtils commonUtils, CommonExpression commonExpression)
|
||||
: base(orm, commonUtils, commonExpression)
|
||||
{
|
||||
}
|
||||
|
||||
public override int ExecuteAffrows() => base.SplitExecuteAffrows(5000, 3000);
|
||||
public override Task<int> ExecuteAffrowsAsync() => base.SplitExecuteAffrowsAsync(5000, 3000);
|
||||
public override long ExecuteIdentity() => base.SplitExecuteIdentity(5000, 3000);
|
||||
public override Task<long> ExecuteIdentityAsync() => base.SplitExecuteIdentityAsync(5000, 3000);
|
||||
public override List<T1> ExecuteInserted() => base.SplitExecuteInserted(5000, 3000);
|
||||
public override Task<List<T1>> ExecuteInsertedAsync() => base.SplitExecuteInsertedAsync(5000, 3000);
|
||||
|
||||
|
||||
protected override long RawExecuteIdentity()
|
||||
{
|
||||
var sql = this.ToSql();
|
||||
if (string.IsNullOrEmpty(sql)) return 0;
|
||||
|
||||
Object<DbConnection> poolConn = null;
|
||||
var before = new Aop.CurdBeforeEventArgs(_table.Type, Aop.CurdType.Insert, string.Concat(sql, "; SELECT LAST_INSERT_ID();"), _params);
|
||||
_orm.Aop.CurdBefore?.Invoke(this, before);
|
||||
long ret = 0;
|
||||
Exception exception = null;
|
||||
try
|
||||
{
|
||||
var conn = _connection;
|
||||
if (_transaction != null) conn = _transaction.Connection;
|
||||
if (conn == null)
|
||||
{
|
||||
poolConn = _orm.Ado.MasterPool.Get();
|
||||
conn = poolConn.Value;
|
||||
}
|
||||
_orm.Ado.ExecuteNonQuery(conn, _transaction, CommandType.Text, sql, _params);
|
||||
ret = long.TryParse(string.Concat(_orm.Ado.ExecuteScalar(conn, _transaction, CommandType.Text, "SELECT LAST_INSERT_ID()")), out var trylng) ? trylng : 0;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
exception = ex;
|
||||
throw ex;
|
||||
}
|
||||
finally
|
||||
{
|
||||
if (poolConn != null)
|
||||
_orm.Ado.MasterPool.Return(poolConn);
|
||||
|
||||
var after = new Aop.CurdAfterEventArgs(before, exception, ret);
|
||||
_orm.Aop.CurdAfter?.Invoke(this, after);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
async protected override Task<long> RawExecuteIdentityAsync()
|
||||
{
|
||||
var sql = this.ToSql();
|
||||
if (string.IsNullOrEmpty(sql)) return 0;
|
||||
|
||||
Object<DbConnection> poolConn = null;
|
||||
var before = new Aop.CurdBeforeEventArgs(_table.Type, Aop.CurdType.Insert, string.Concat(sql, "; SELECT LAST_INSERT_ID();"), _params);
|
||||
_orm.Aop.CurdBefore?.Invoke(this, before);
|
||||
long ret = 0;
|
||||
Exception exception = null;
|
||||
try
|
||||
{
|
||||
var conn = _connection;
|
||||
if (_transaction != null) conn = _transaction.Connection;
|
||||
if (conn == null)
|
||||
{
|
||||
poolConn = _orm.Ado.MasterPool.Get();
|
||||
conn = poolConn.Value;
|
||||
}
|
||||
await _orm.Ado.ExecuteNonQueryAsync(conn, _transaction, CommandType.Text, sql, _params);
|
||||
ret = long.TryParse(string.Concat(await _orm.Ado.ExecuteScalarAsync(conn, _transaction, CommandType.Text, "SELECT LAST_INSERT_ID()")), out var trylng) ? trylng : 0;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
exception = ex;
|
||||
throw ex;
|
||||
}
|
||||
finally
|
||||
{
|
||||
if (poolConn != null)
|
||||
_orm.Ado.MasterPool.Return(poolConn);
|
||||
|
||||
var after = new Aop.CurdAfterEventArgs(before, exception, ret);
|
||||
_orm.Aop.CurdAfter?.Invoke(this, after);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
protected override List<T1> RawExecuteInserted()
|
||||
{
|
||||
var sql = this.ToSql();
|
||||
if (string.IsNullOrEmpty(sql)) return new List<T1>();
|
||||
|
||||
var sb = new StringBuilder();
|
||||
sb.Append(sql).Append(" RETURNING ");
|
||||
|
||||
var colidx = 0;
|
||||
foreach (var col in _table.Columns.Values)
|
||||
{
|
||||
if (colidx > 0) sb.Append(", ");
|
||||
sb.Append(_commonUtils.QuoteReadColumn(col.Attribute.MapType, _commonUtils.QuoteSqlName(col.Attribute.Name))).Append(" as ").Append(_commonUtils.QuoteSqlName(col.CsName));
|
||||
++colidx;
|
||||
}
|
||||
sql = sb.ToString();
|
||||
var before = new Aop.CurdBeforeEventArgs(_table.Type, Aop.CurdType.Insert, sql, _params);
|
||||
_orm.Aop.CurdBefore?.Invoke(this, before);
|
||||
var ret = new List<T1>();
|
||||
Exception exception = null;
|
||||
try
|
||||
{
|
||||
ret = _orm.Ado.Query<T1>(_connection, _transaction, CommandType.Text, sql, _params);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
exception = ex;
|
||||
throw ex;
|
||||
}
|
||||
finally
|
||||
{
|
||||
var after = new Aop.CurdAfterEventArgs(before, exception, ret);
|
||||
_orm.Aop.CurdAfter?.Invoke(this, after);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
async protected override Task<List<T1>> RawExecuteInsertedAsync()
|
||||
{
|
||||
var sql = this.ToSql();
|
||||
if (string.IsNullOrEmpty(sql)) return new List<T1>();
|
||||
|
||||
var sb = new StringBuilder();
|
||||
sb.Append(sql).Append(" RETURNING ");
|
||||
|
||||
var colidx = 0;
|
||||
foreach (var col in _table.Columns.Values)
|
||||
{
|
||||
if (colidx > 0) sb.Append(", ");
|
||||
sb.Append(_commonUtils.QuoteReadColumn(col.Attribute.MapType, _commonUtils.QuoteSqlName(col.Attribute.Name))).Append(" as ").Append(_commonUtils.QuoteSqlName(col.CsName));
|
||||
++colidx;
|
||||
}
|
||||
sql = sb.ToString();
|
||||
var before = new Aop.CurdBeforeEventArgs(_table.Type, Aop.CurdType.Insert, sql, _params);
|
||||
_orm.Aop.CurdBefore?.Invoke(this, before);
|
||||
var ret = new List<T1>();
|
||||
Exception exception = null;
|
||||
try
|
||||
{
|
||||
ret = await _orm.Ado.QueryAsync<T1>(_connection, _transaction, CommandType.Text, sql, _params);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
exception = ex;
|
||||
throw ex;
|
||||
}
|
||||
finally
|
||||
{
|
||||
var after = new Aop.CurdAfterEventArgs(before, exception, ret);
|
||||
_orm.Aop.CurdAfter?.Invoke(this, after);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
}
|
173
Providers/FreeSql.Provider.Odbc/MySql/Curd/OdbcMySqlSelect.cs
Normal file
173
Providers/FreeSql.Provider.Odbc/MySql/Curd/OdbcMySqlSelect.cs
Normal file
@ -0,0 +1,173 @@
|
||||
using FreeSql.Internal;
|
||||
using FreeSql.Internal.Model;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Linq.Expressions;
|
||||
using System.Text;
|
||||
|
||||
namespace FreeSql.Odbc.MySql
|
||||
{
|
||||
|
||||
class OdbcMySqlSelect<T1> : FreeSql.Internal.CommonProvider.Select1Provider<T1> where T1 : class
|
||||
{
|
||||
|
||||
internal static string ToSqlStatic(CommonUtils _commonUtils, CommonExpression _commonExpression, string _select, bool _distinct, string field, StringBuilder _join, StringBuilder _where, string _groupby, string _having, string _orderby, int _skip, int _limit, List<SelectTableInfo> _tables, List<Dictionary<Type, string>> tbUnions, List<LambdaExpression> _whereCascadeExpression, IFreeSql _orm)
|
||||
{
|
||||
if (_orm.CodeFirst.IsAutoSyncStructure)
|
||||
_orm.CodeFirst.SyncStructure(_tables.Select(a => a.Table.Type).ToArray());
|
||||
|
||||
if (_whereCascadeExpression.Any())
|
||||
foreach (var tb in _tables.Where(a => a.Type != SelectTableInfoType.Parent))
|
||||
tb.Cascade = _commonExpression.GetWhereCascadeSql(tb, _whereCascadeExpression);
|
||||
|
||||
var sb = new StringBuilder();
|
||||
var tbUnionsGt0 = tbUnions.Count > 1;
|
||||
for (var tbUnionsIdx = 0; tbUnionsIdx < tbUnions.Count; tbUnionsIdx++)
|
||||
{
|
||||
if (tbUnionsIdx > 0) sb.Append(" \r\n\r\nUNION ALL\r\n\r\n");
|
||||
if (tbUnionsGt0) sb.Append("select * from (");
|
||||
var tbUnion = tbUnions[tbUnionsIdx];
|
||||
|
||||
var sbnav = new StringBuilder();
|
||||
sb.Append(_select);
|
||||
if (_distinct) sb.Append("DISTINCT ");
|
||||
sb.Append(field).Append(" \r\nFROM ");
|
||||
var tbsjoin = _tables.Where(a => a.Type != SelectTableInfoType.From).ToArray();
|
||||
var tbsfrom = _tables.Where(a => a.Type == SelectTableInfoType.From).ToArray();
|
||||
for (var a = 0; a < tbsfrom.Length; a++)
|
||||
{
|
||||
sb.Append(_commonUtils.QuoteSqlName(tbUnion[tbsfrom[a].Table.Type])).Append(" ").Append(tbsfrom[a].Alias);
|
||||
if (tbsjoin.Length > 0)
|
||||
{
|
||||
//如果存在 join 查询,则处理 from t1, t2 改为 from t1 inner join t2 on 1 = 1
|
||||
for (var b = 1; b < tbsfrom.Length; b++)
|
||||
{
|
||||
sb.Append(" \r\nLEFT JOIN ").Append(_commonUtils.QuoteSqlName(tbUnion[tbsfrom[b].Table.Type])).Append(" ").Append(tbsfrom[b].Alias);
|
||||
|
||||
if (string.IsNullOrEmpty(tbsfrom[b].NavigateCondition) && string.IsNullOrEmpty(tbsfrom[b].On) && string.IsNullOrEmpty(tbsfrom[b].Cascade)) sb.Append(" ON 1 = 1");
|
||||
else
|
||||
{
|
||||
sb.Append(" ON ").Append(tbsfrom[b].NavigateCondition ?? tbsfrom[b].On);
|
||||
if (string.IsNullOrEmpty(tbsfrom[b].Cascade) == false) sb.Append(" AND (").Append(tbsfrom[b].Cascade).Append(")");
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!string.IsNullOrEmpty(tbsfrom[a].NavigateCondition)) sbnav.Append(" AND (").Append(tbsfrom[a].NavigateCondition).Append(")");
|
||||
if (!string.IsNullOrEmpty(tbsfrom[a].On)) sbnav.Append(" AND (").Append(tbsfrom[a].On).Append(")");
|
||||
if (a > 0 && !string.IsNullOrEmpty(tbsfrom[a].Cascade)) sbnav.Append(" AND (").Append(tbsfrom[a].Cascade).Append(")");
|
||||
}
|
||||
if (a < tbsfrom.Length - 1) sb.Append(", ");
|
||||
}
|
||||
foreach (var tb in tbsjoin)
|
||||
{
|
||||
if (tb.Type == SelectTableInfoType.Parent) continue;
|
||||
switch (tb.Type)
|
||||
{
|
||||
case SelectTableInfoType.LeftJoin:
|
||||
sb.Append(" \r\nLEFT JOIN ");
|
||||
break;
|
||||
case SelectTableInfoType.InnerJoin:
|
||||
sb.Append(" \r\nINNER JOIN ");
|
||||
break;
|
||||
case SelectTableInfoType.RightJoin:
|
||||
sb.Append(" \r\nRIGHT JOIN ");
|
||||
break;
|
||||
}
|
||||
sb.Append(_commonUtils.QuoteSqlName(tbUnion[tb.Table.Type])).Append(" ").Append(tb.Alias).Append(" ON ").Append(tb.On ?? tb.NavigateCondition);
|
||||
if (!string.IsNullOrEmpty(tb.Cascade)) sb.Append(" AND (").Append(tb.Cascade).Append(")");
|
||||
if (!string.IsNullOrEmpty(tb.On) && !string.IsNullOrEmpty(tb.NavigateCondition)) sbnav.Append(" AND (").Append(tb.NavigateCondition).Append(")");
|
||||
}
|
||||
if (_join.Length > 0) sb.Append(_join);
|
||||
|
||||
sbnav.Append(_where);
|
||||
if (!string.IsNullOrEmpty(_tables[0].Cascade))
|
||||
sbnav.Append(" AND (").Append(_tables[0].Cascade).Append(")");
|
||||
|
||||
foreach (var tb in _tables)
|
||||
{
|
||||
if (tb.Type == SelectTableInfoType.Parent) continue;
|
||||
if (string.IsNullOrEmpty(tb.Table.SelectFilter) == false)
|
||||
sbnav.Append(" AND (").Append(tb.Table.SelectFilter.Replace("a.", $"{tb.Alias}.")).Append(")");
|
||||
}
|
||||
if (sbnav.Length > 0)
|
||||
{
|
||||
sb.Append(" \r\nWHERE ").Append(sbnav.Remove(0, 5));
|
||||
}
|
||||
if (string.IsNullOrEmpty(_groupby) == false)
|
||||
{
|
||||
sb.Append(_groupby);
|
||||
if (string.IsNullOrEmpty(_having) == false)
|
||||
sb.Append(" \r\nHAVING ").Append(_having.Substring(5));
|
||||
}
|
||||
sb.Append(_orderby);
|
||||
if (_skip > 0 || _limit > 0)
|
||||
sb.Append(" \r\nlimit ").Append(Math.Max(0, _skip)).Append(",").Append(_limit > 0 ? _limit : -1);
|
||||
|
||||
sbnav.Clear();
|
||||
if (tbUnionsGt0) sb.Append(") ftb");
|
||||
}
|
||||
return sb.ToString();
|
||||
}
|
||||
|
||||
public OdbcMySqlSelect(IFreeSql orm, CommonUtils commonUtils, CommonExpression commonExpression, object dywhere) : base(orm, commonUtils, commonExpression, dywhere) { }
|
||||
public override ISelect<T1, T2> From<T2>(Expression<Func<ISelectFromExpression<T1>, T2, ISelectFromExpression<T1>>> exp) { this.InternalFrom(exp); var ret = new MySqlSelect<T1, T2>(_orm, _commonUtils, _commonExpression, null); OdbcMySqlSelect<T1>.CopyData(this, ret, exp?.Parameters); return ret; }
|
||||
public override ISelect<T1, T2, T3> From<T2, T3>(Expression<Func<ISelectFromExpression<T1>, T2, T3, ISelectFromExpression<T1>>> exp) { this.InternalFrom(exp); var ret = new MySqlSelect<T1, T2, T3>(_orm, _commonUtils, _commonExpression, null); OdbcMySqlSelect<T1>.CopyData(this, ret, exp?.Parameters); return ret; }
|
||||
public override ISelect<T1, T2, T3, T4> From<T2, T3, T4>(Expression<Func<ISelectFromExpression<T1>, T2, T3, T4, ISelectFromExpression<T1>>> exp) { this.InternalFrom(exp); var ret = new MySqlSelect<T1, T2, T3, T4>(_orm, _commonUtils, _commonExpression, null); OdbcMySqlSelect<T1>.CopyData(this, ret, exp?.Parameters); return ret; }
|
||||
public override ISelect<T1, T2, T3, T4, T5> From<T2, T3, T4, T5>(Expression<Func<ISelectFromExpression<T1>, T2, T3, T4, T5, ISelectFromExpression<T1>>> exp) { this.InternalFrom(exp); var ret = new MySqlSelect<T1, T2, T3, T4, T5>(_orm, _commonUtils, _commonExpression, null); OdbcMySqlSelect<T1>.CopyData(this, ret, exp?.Parameters); return ret; }
|
||||
public override ISelect<T1, T2, T3, T4, T5, T6> From<T2, T3, T4, T5, T6>(Expression<Func<ISelectFromExpression<T1>, T2, T3, T4, T5, T6, ISelectFromExpression<T1>>> exp) { this.InternalFrom(exp); var ret = new MySqlSelect<T1, T2, T3, T4, T5, T6>(_orm, _commonUtils, _commonExpression, null); OdbcMySqlSelect<T1>.CopyData(this, ret, exp?.Parameters); return ret; }
|
||||
public override ISelect<T1, T2, T3, T4, T5, T6, T7> From<T2, T3, T4, T5, T6, T7>(Expression<Func<ISelectFromExpression<T1>, T2, T3, T4, T5, T6, T7, ISelectFromExpression<T1>>> exp) { this.InternalFrom(exp); var ret = new MySqlSelect<T1, T2, T3, T4, T5, T6, T7>(_orm, _commonUtils, _commonExpression, null); OdbcMySqlSelect<T1>.CopyData(this, ret, exp?.Parameters); return ret; }
|
||||
public override ISelect<T1, T2, T3, T4, T5, T6, T7, T8> From<T2, T3, T4, T5, T6, T7, T8>(Expression<Func<ISelectFromExpression<T1>, T2, T3, T4, T5, T6, T7, T8, ISelectFromExpression<T1>>> exp) { this.InternalFrom(exp); var ret = new MySqlSelect<T1, T2, T3, T4, T5, T6, T7, T8>(_orm, _commonUtils, _commonExpression, null); OdbcMySqlSelect<T1>.CopyData(this, ret, exp?.Parameters); return ret; }
|
||||
public override ISelect<T1, T2, T3, T4, T5, T6, T7, T8, T9> From<T2, T3, T4, T5, T6, T7, T8, T9>(Expression<Func<ISelectFromExpression<T1>, T2, T3, T4, T5, T6, T7, T8, T9, ISelectFromExpression<T1>>> exp) { this.InternalFrom(exp); var ret = new MySqlSelect<T1, T2, T3, T4, T5, T6, T7, T8, T9>(_orm, _commonUtils, _commonExpression, null); OdbcMySqlSelect<T1>.CopyData(this, ret, exp?.Parameters); return ret; }
|
||||
public override ISelect<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10> From<T2, T3, T4, T5, T6, T7, T8, T9, T10>(Expression<Func<ISelectFromExpression<T1>, T2, T3, T4, T5, T6, T7, T8, T9, T10, ISelectFromExpression<T1>>> exp) { this.InternalFrom(exp); var ret = new MySqlSelect<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10>(_orm, _commonUtils, _commonExpression, null); OdbcMySqlSelect<T1>.CopyData(this, ret, exp?.Parameters); return ret; }
|
||||
public override string ToSql(string field = null) => ToSqlStatic(_commonUtils, _commonExpression, _select, _distinct, field ?? this.GetAllFieldExpressionTreeLevel2().Field, _join, _where, _groupby, _having, _orderby, _skip, _limit, _tables, this.GetTableRuleUnions(), _whereCascadeExpression, _orm);
|
||||
}
|
||||
class MySqlSelect<T1, T2> : FreeSql.Internal.CommonProvider.Select2Provider<T1, T2> where T1 : class where T2 : class
|
||||
{
|
||||
public MySqlSelect(IFreeSql orm, CommonUtils commonUtils, CommonExpression commonExpression, object dywhere) : base(orm, commonUtils, commonExpression, dywhere) { }
|
||||
public override string ToSql(string field = null) => OdbcMySqlSelect<T1>.ToSqlStatic(_commonUtils, _commonExpression, _select, _distinct, field ?? this.GetAllFieldExpressionTreeLevel2().Field, _join, _where, _groupby, _having, _orderby, _skip, _limit, _tables, this.GetTableRuleUnions(), _whereCascadeExpression, _orm);
|
||||
}
|
||||
class MySqlSelect<T1, T2, T3> : FreeSql.Internal.CommonProvider.Select3Provider<T1, T2, T3> where T1 : class where T2 : class where T3 : class
|
||||
{
|
||||
public MySqlSelect(IFreeSql orm, CommonUtils commonUtils, CommonExpression commonExpression, object dywhere) : base(orm, commonUtils, commonExpression, dywhere) { }
|
||||
public override string ToSql(string field = null) => OdbcMySqlSelect<T1>.ToSqlStatic(_commonUtils, _commonExpression, _select, _distinct, field ?? this.GetAllFieldExpressionTreeLevel2().Field, _join, _where, _groupby, _having, _orderby, _skip, _limit, _tables, this.GetTableRuleUnions(), _whereCascadeExpression, _orm);
|
||||
}
|
||||
class MySqlSelect<T1, T2, T3, T4> : FreeSql.Internal.CommonProvider.Select4Provider<T1, T2, T3, T4> where T1 : class where T2 : class where T3 : class where T4 : class
|
||||
{
|
||||
public MySqlSelect(IFreeSql orm, CommonUtils commonUtils, CommonExpression commonExpression, object dywhere) : base(orm, commonUtils, commonExpression, dywhere) { }
|
||||
public override string ToSql(string field = null) => OdbcMySqlSelect<T1>.ToSqlStatic(_commonUtils, _commonExpression, _select, _distinct, field ?? this.GetAllFieldExpressionTreeLevel2().Field, _join, _where, _groupby, _having, _orderby, _skip, _limit, _tables, this.GetTableRuleUnions(), _whereCascadeExpression, _orm);
|
||||
}
|
||||
class MySqlSelect<T1, T2, T3, T4, T5> : FreeSql.Internal.CommonProvider.Select5Provider<T1, T2, T3, T4, T5> where T1 : class where T2 : class where T3 : class where T4 : class where T5 : class
|
||||
{
|
||||
public MySqlSelect(IFreeSql orm, CommonUtils commonUtils, CommonExpression commonExpression, object dywhere) : base(orm, commonUtils, commonExpression, dywhere) { }
|
||||
public override string ToSql(string field = null) => OdbcMySqlSelect<T1>.ToSqlStatic(_commonUtils, _commonExpression, _select, _distinct, field ?? this.GetAllFieldExpressionTreeLevel2().Field, _join, _where, _groupby, _having, _orderby, _skip, _limit, _tables, this.GetTableRuleUnions(), _whereCascadeExpression, _orm);
|
||||
}
|
||||
class MySqlSelect<T1, T2, T3, T4, T5, T6> : FreeSql.Internal.CommonProvider.Select6Provider<T1, T2, T3, T4, T5, T6> where T1 : class where T2 : class where T3 : class where T4 : class where T5 : class where T6 : class
|
||||
{
|
||||
public MySqlSelect(IFreeSql orm, CommonUtils commonUtils, CommonExpression commonExpression, object dywhere) : base(orm, commonUtils, commonExpression, dywhere) { }
|
||||
public override string ToSql(string field = null) => OdbcMySqlSelect<T1>.ToSqlStatic(_commonUtils, _commonExpression, _select, _distinct, field ?? this.GetAllFieldExpressionTreeLevel2().Field, _join, _where, _groupby, _having, _orderby, _skip, _limit, _tables, this.GetTableRuleUnions(), _whereCascadeExpression, _orm);
|
||||
}
|
||||
class MySqlSelect<T1, T2, T3, T4, T5, T6, T7> : FreeSql.Internal.CommonProvider.Select7Provider<T1, T2, T3, T4, T5, T6, T7> where T1 : class where T2 : class where T3 : class where T4 : class where T5 : class where T6 : class where T7 : class
|
||||
{
|
||||
public MySqlSelect(IFreeSql orm, CommonUtils commonUtils, CommonExpression commonExpression, object dywhere) : base(orm, commonUtils, commonExpression, dywhere) { }
|
||||
public override string ToSql(string field = null) => OdbcMySqlSelect<T1>.ToSqlStatic(_commonUtils, _commonExpression, _select, _distinct, field ?? this.GetAllFieldExpressionTreeLevel2().Field, _join, _where, _groupby, _having, _orderby, _skip, _limit, _tables, this.GetTableRuleUnions(), _whereCascadeExpression, _orm);
|
||||
}
|
||||
class MySqlSelect<T1, T2, T3, T4, T5, T6, T7, T8> : FreeSql.Internal.CommonProvider.Select8Provider<T1, T2, T3, T4, T5, T6, T7, T8> where T1 : class where T2 : class where T3 : class where T4 : class where T5 : class where T6 : class where T7 : class where T8 : class
|
||||
{
|
||||
public MySqlSelect(IFreeSql orm, CommonUtils commonUtils, CommonExpression commonExpression, object dywhere) : base(orm, commonUtils, commonExpression, dywhere) { }
|
||||
public override string ToSql(string field = null) => OdbcMySqlSelect<T1>.ToSqlStatic(_commonUtils, _commonExpression, _select, _distinct, field ?? this.GetAllFieldExpressionTreeLevel2().Field, _join, _where, _groupby, _having, _orderby, _skip, _limit, _tables, this.GetTableRuleUnions(), _whereCascadeExpression, _orm);
|
||||
}
|
||||
class MySqlSelect<T1, T2, T3, T4, T5, T6, T7, T8, T9> : FreeSql.Internal.CommonProvider.Select9Provider<T1, T2, T3, T4, T5, T6, T7, T8, T9> where T1 : class where T2 : class where T3 : class where T4 : class where T5 : class where T6 : class where T7 : class where T8 : class where T9 : class
|
||||
{
|
||||
public MySqlSelect(IFreeSql orm, CommonUtils commonUtils, CommonExpression commonExpression, object dywhere) : base(orm, commonUtils, commonExpression, dywhere) { }
|
||||
public override string ToSql(string field = null) => OdbcMySqlSelect<T1>.ToSqlStatic(_commonUtils, _commonExpression, _select, _distinct, field ?? this.GetAllFieldExpressionTreeLevel2().Field, _join, _where, _groupby, _having, _orderby, _skip, _limit, _tables, this.GetTableRuleUnions(), _whereCascadeExpression, _orm);
|
||||
}
|
||||
class MySqlSelect<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10> : FreeSql.Internal.CommonProvider.Select10Provider<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10> where T1 : class where T2 : class where T3 : class where T4 : class where T5 : class where T6 : class where T7 : class where T8 : class where T9 : class where T10 : class
|
||||
{
|
||||
public MySqlSelect(IFreeSql orm, CommonUtils commonUtils, CommonExpression commonExpression, object dywhere) : base(orm, commonUtils, commonExpression, dywhere) { }
|
||||
public override string ToSql(string field = null) => OdbcMySqlSelect<T1>.ToSqlStatic(_commonUtils, _commonExpression, _select, _distinct, field ?? this.GetAllFieldExpressionTreeLevel2().Field, _join, _where, _groupby, _having, _orderby, _skip, _limit, _tables, this.GetTableRuleUnions(), _whereCascadeExpression, _orm);
|
||||
}
|
||||
}
|
140
Providers/FreeSql.Provider.Odbc/MySql/Curd/OdbcMySqlUpdate.cs
Normal file
140
Providers/FreeSql.Provider.Odbc/MySql/Curd/OdbcMySqlUpdate.cs
Normal file
@ -0,0 +1,140 @@
|
||||
using FreeSql.Internal;
|
||||
using FreeSql.Internal.Model;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace FreeSql.Odbc.MySql
|
||||
{
|
||||
|
||||
class OdbcMySqlUpdate<T1> : Internal.CommonProvider.UpdateProvider<T1> where T1 : class
|
||||
{
|
||||
|
||||
public OdbcMySqlUpdate(IFreeSql orm, CommonUtils commonUtils, CommonExpression commonExpression, object dywhere)
|
||||
: base(orm, commonUtils, commonExpression, dywhere)
|
||||
{
|
||||
}
|
||||
|
||||
public override int ExecuteAffrows() => base.SplitExecuteAffrows(500, 3000);
|
||||
public override Task<int> ExecuteAffrowsAsync() => base.SplitExecuteAffrowsAsync(500, 3000);
|
||||
public override List<T1> ExecuteUpdated() => base.SplitExecuteUpdated(500, 3000);
|
||||
public override Task<List<T1>> ExecuteUpdatedAsync() => base.SplitExecuteUpdatedAsync(500, 3000);
|
||||
|
||||
|
||||
protected override List<T1> RawExecuteUpdated()
|
||||
{
|
||||
var sql = this.ToSql();
|
||||
if (string.IsNullOrEmpty(sql)) return new List<T1>();
|
||||
|
||||
var sb = new StringBuilder();
|
||||
sb.Append(sql).Append(" RETURNING ");
|
||||
|
||||
var colidx = 0;
|
||||
foreach (var col in _table.Columns.Values)
|
||||
{
|
||||
if (colidx > 0) sb.Append(", ");
|
||||
sb.Append(_commonUtils.QuoteReadColumn(col.Attribute.MapType, _commonUtils.QuoteSqlName(col.Attribute.Name))).Append(" as ").Append(_commonUtils.QuoteSqlName(col.CsName));
|
||||
++colidx;
|
||||
}
|
||||
sql = sb.ToString();
|
||||
var dbParms = _params.Concat(_paramsSource).ToArray();
|
||||
var before = new Aop.CurdBeforeEventArgs(_table.Type, Aop.CurdType.Update, sql, dbParms);
|
||||
_orm.Aop.CurdBefore?.Invoke(this, before);
|
||||
var ret = new List<T1>();
|
||||
Exception exception = null;
|
||||
try
|
||||
{
|
||||
ret = _orm.Ado.Query<T1>(_connection, _transaction, CommandType.Text, sql, dbParms);
|
||||
ValidateVersionAndThrow(ret.Count);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
exception = ex;
|
||||
throw ex;
|
||||
}
|
||||
finally
|
||||
{
|
||||
var after = new Aop.CurdAfterEventArgs(before, exception, ret);
|
||||
_orm.Aop.CurdAfter?.Invoke(this, after);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
async protected override Task<List<T1>> RawExecuteUpdatedAsync()
|
||||
{
|
||||
var sql = this.ToSql();
|
||||
if (string.IsNullOrEmpty(sql)) return new List<T1>();
|
||||
|
||||
var sb = new StringBuilder();
|
||||
sb.Append(sql).Append(" RETURNING ");
|
||||
|
||||
var colidx = 0;
|
||||
foreach (var col in _table.Columns.Values)
|
||||
{
|
||||
if (colidx > 0) sb.Append(", ");
|
||||
sb.Append(_commonUtils.QuoteReadColumn(col.Attribute.MapType, _commonUtils.QuoteSqlName(col.Attribute.Name))).Append(" as ").Append(_commonUtils.QuoteSqlName(col.CsName));
|
||||
++colidx;
|
||||
}
|
||||
sql = sb.ToString();
|
||||
var dbParms = _params.Concat(_paramsSource).ToArray();
|
||||
var before = new Aop.CurdBeforeEventArgs(_table.Type, Aop.CurdType.Update, sql, dbParms);
|
||||
_orm.Aop.CurdBefore?.Invoke(this, before);
|
||||
var ret = new List<T1>();
|
||||
Exception exception = null;
|
||||
try
|
||||
{
|
||||
ret = await _orm.Ado.QueryAsync<T1>(_connection, _transaction, CommandType.Text, sql, dbParms);
|
||||
ValidateVersionAndThrow(ret.Count);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
exception = ex;
|
||||
throw ex;
|
||||
}
|
||||
finally
|
||||
{
|
||||
var after = new Aop.CurdAfterEventArgs(before, exception, ret);
|
||||
_orm.Aop.CurdAfter?.Invoke(this, after);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
protected override void ToSqlCase(StringBuilder caseWhen, ColumnInfo[] primarys)
|
||||
{
|
||||
if (_table.Primarys.Length == 1)
|
||||
{
|
||||
caseWhen.Append(_commonUtils.QuoteReadColumn(_table.Primarys.First().Attribute.MapType, _commonUtils.QuoteSqlName(_table.Primarys.First().Attribute.Name)));
|
||||
return;
|
||||
}
|
||||
caseWhen.Append("CONCAT(");
|
||||
var pkidx = 0;
|
||||
foreach (var pk in _table.Primarys)
|
||||
{
|
||||
if (pkidx > 0) caseWhen.Append(", ");
|
||||
caseWhen.Append(_commonUtils.QuoteReadColumn(pk.Attribute.MapType, _commonUtils.QuoteSqlName(pk.Attribute.Name)));
|
||||
++pkidx;
|
||||
}
|
||||
caseWhen.Append(")");
|
||||
}
|
||||
|
||||
protected override void ToSqlWhen(StringBuilder sb, ColumnInfo[] primarys, object d)
|
||||
{
|
||||
if (_table.Primarys.Length == 1)
|
||||
{
|
||||
sb.Append(_commonUtils.FormatSql("{0}", _table.Primarys.First().GetMapValue(d)));
|
||||
return;
|
||||
}
|
||||
sb.Append("CONCAT(");
|
||||
var pkidx = 0;
|
||||
foreach (var pk in _table.Primarys)
|
||||
{
|
||||
if (pkidx > 0) sb.Append(", ");
|
||||
sb.Append(_commonUtils.FormatSql("{0}", pk.GetMapValue(d)));
|
||||
++pkidx;
|
||||
}
|
||||
sb.Append(")");
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,70 @@
|
||||
using FreeSql.Internal;
|
||||
using SafeObjectPool;
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Data.Common;
|
||||
using System.Data.Odbc;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
|
||||
namespace FreeSql.Odbc.MySql
|
||||
{
|
||||
class OdbcMySqlAdo : FreeSql.Internal.CommonProvider.AdoProvider
|
||||
{
|
||||
|
||||
public OdbcMySqlAdo() : base(DataType.MySql) { }
|
||||
public OdbcMySqlAdo(CommonUtils util, string masterConnectionString, string[] slaveConnectionStrings) : base(DataType.MySql)
|
||||
{
|
||||
base._util = util;
|
||||
if (!string.IsNullOrEmpty(masterConnectionString))
|
||||
MasterPool = new OdbcMySqlConnectionPool("主库", masterConnectionString, null, null);
|
||||
if (slaveConnectionStrings != null)
|
||||
{
|
||||
foreach (var slaveConnectionString in slaveConnectionStrings)
|
||||
{
|
||||
var slavePool = new OdbcMySqlConnectionPool($"从库{SlavePools.Count + 1}", slaveConnectionString, () => Interlocked.Decrement(ref slaveUnavailables), () => Interlocked.Increment(ref slaveUnavailables));
|
||||
SlavePools.Add(slavePool);
|
||||
}
|
||||
}
|
||||
}
|
||||
static DateTime dt1970 = new DateTime(1970, 1, 1);
|
||||
public override object AddslashesProcessParam(object param, Type mapType)
|
||||
{
|
||||
if (param == null) return "NULL";
|
||||
if (mapType != null && mapType != param.GetType())
|
||||
param = Utils.GetDataReaderValue(mapType, param);
|
||||
if (param is bool || param is bool?)
|
||||
return (bool)param ? 1 : 0;
|
||||
else if (param is string || param is char)
|
||||
return string.Concat("'", param.ToString().Replace("'", "''"), "'");
|
||||
else if (param is Enum)
|
||||
return string.Concat("'", param.ToString().Replace("'", "''"), "'"); //((Enum)val).ToInt64();
|
||||
else if (decimal.TryParse(string.Concat(param), out var trydec))
|
||||
return param;
|
||||
else if (param is DateTime || param is DateTime?)
|
||||
return string.Concat("'", ((DateTime)param).ToString("yyyy-MM-dd HH:mm:ss.fff"), "'");
|
||||
else if (param is TimeSpan || param is TimeSpan?)
|
||||
return ((TimeSpan)param).Ticks / 10;
|
||||
else if (param is IEnumerable)
|
||||
{
|
||||
var sb = new StringBuilder();
|
||||
var ie = param as IEnumerable;
|
||||
foreach (var z in ie) sb.Append(",").Append(AddslashesProcessParam(z, mapType));
|
||||
return sb.Length == 0 ? "(NULL)" : sb.Remove(0, 1).Insert(0, "(").Append(")").ToString();
|
||||
}
|
||||
return string.Concat("'", param.ToString().Replace("'", "''"), "'");
|
||||
}
|
||||
|
||||
protected override DbCommand CreateCommand()
|
||||
{
|
||||
return new OdbcCommand();
|
||||
}
|
||||
|
||||
protected override void ReturnConnection(ObjectPool<DbConnection> pool, Object<DbConnection> conn, Exception ex)
|
||||
{
|
||||
(pool as OdbcMySqlConnectionPool).Return(conn, ex);
|
||||
}
|
||||
|
||||
protected override DbParameter[] GetDbParamtersByObject(string sql, object obj) => _util.GetDbParamtersByObject(sql, obj);
|
||||
}
|
||||
}
|
@ -0,0 +1,229 @@
|
||||
using SafeObjectPool;
|
||||
using System;
|
||||
using System.Collections.Concurrent;
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
using System.Data.Common;
|
||||
using System.Data.Odbc;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace FreeSql.Odbc.MySql
|
||||
{
|
||||
|
||||
class OdbcMySqlConnectionPool : ObjectPool<DbConnection>
|
||||
{
|
||||
|
||||
internal Action availableHandler;
|
||||
internal Action unavailableHandler;
|
||||
|
||||
public OdbcMySqlConnectionPool(string name, string connectionString, Action availableHandler, Action unavailableHandler) : base(null)
|
||||
{
|
||||
var policy = new OdbcMySqlConnectionPoolPolicy
|
||||
{
|
||||
_pool = this,
|
||||
Name = name
|
||||
};
|
||||
this.Policy = policy;
|
||||
policy.ConnectionString = connectionString;
|
||||
|
||||
this.availableHandler = availableHandler;
|
||||
this.unavailableHandler = unavailableHandler;
|
||||
}
|
||||
|
||||
public void Return(Object<DbConnection> obj, Exception exception, bool isRecreate = false)
|
||||
{
|
||||
if (exception != null && exception is OdbcException)
|
||||
{
|
||||
try { if (obj.Value.Ping() == false) obj.Value.Open(); } catch { base.SetUnavailable(exception); }
|
||||
}
|
||||
base.Return(obj, isRecreate);
|
||||
}
|
||||
}
|
||||
|
||||
class OdbcMySqlConnectionPoolPolicy : IPolicy<DbConnection>
|
||||
{
|
||||
|
||||
internal OdbcMySqlConnectionPool _pool;
|
||||
public string Name { get; set; } = "MySql OdbcConnection 对象池";
|
||||
public int PoolSize { get; set; } = 100;
|
||||
public TimeSpan SyncGetTimeout { get; set; } = TimeSpan.FromSeconds(10);
|
||||
public TimeSpan IdleTimeout { get; set; } = TimeSpan.Zero;
|
||||
public int AsyncGetCapacity { get; set; } = 10000;
|
||||
public bool IsThrowGetTimeoutException { get; set; } = true;
|
||||
public int CheckAvailableInterval { get; set; } = 5;
|
||||
|
||||
static ConcurrentDictionary<string, int> dicConnStrIncr = new ConcurrentDictionary<string, int>(StringComparer.CurrentCultureIgnoreCase);
|
||||
private string _connectionString;
|
||||
public string ConnectionString
|
||||
{
|
||||
get => _connectionString;
|
||||
set
|
||||
{
|
||||
_connectionString = value ?? "";
|
||||
|
||||
var pattern = @"Max\s*pool\s*size\s*=\s*(\d+)";
|
||||
var m = Regex.Match(_connectionString, pattern, RegexOptions.IgnoreCase);
|
||||
if (m.Success == false || int.TryParse(m.Groups[1].Value, out var poolsize) == false || poolsize <= 0) poolsize = 100;
|
||||
var connStrIncr = dicConnStrIncr.AddOrUpdate(_connectionString, 1, (oldkey, oldval) => oldval + 1);
|
||||
PoolSize = poolsize + connStrIncr;
|
||||
_connectionString = m.Success ?
|
||||
Regex.Replace(_connectionString, pattern, $"Max pool size={PoolSize}", RegexOptions.IgnoreCase) :
|
||||
$"{_connectionString};Max pool size={PoolSize}";
|
||||
|
||||
pattern = @"Connection\s*LifeTime\s*=\s*(\d+)";
|
||||
m = Regex.Match(_connectionString, pattern, RegexOptions.IgnoreCase);
|
||||
if (m.Success)
|
||||
{
|
||||
IdleTimeout = TimeSpan.FromSeconds(int.Parse(m.Groups[1].Value));
|
||||
_connectionString = Regex.Replace(_connectionString, pattern, "", RegexOptions.IgnoreCase);
|
||||
}
|
||||
|
||||
var minPoolSize = 0;
|
||||
pattern = @"Min\s*pool\s*size\s*=\s*(\d+)";
|
||||
m = Regex.Match(_connectionString, pattern, RegexOptions.IgnoreCase);
|
||||
if (m.Success)
|
||||
{
|
||||
minPoolSize = int.Parse(m.Groups[1].Value);
|
||||
_connectionString = Regex.Replace(_connectionString, pattern, "", RegexOptions.IgnoreCase);
|
||||
}
|
||||
|
||||
FreeSql.Internal.CommonUtils.PrevReheatConnectionPool(_pool, minPoolSize);
|
||||
}
|
||||
}
|
||||
|
||||
public bool OnCheckAvailable(Object<DbConnection> obj)
|
||||
{
|
||||
if (obj.Value.State == ConnectionState.Closed) obj.Value.Open();
|
||||
return obj.Value.Ping(true);
|
||||
}
|
||||
|
||||
public DbConnection OnCreate()
|
||||
{
|
||||
var conn = new OdbcConnection(_connectionString);
|
||||
return conn;
|
||||
}
|
||||
|
||||
public void OnDestroy(DbConnection obj)
|
||||
{
|
||||
if (obj.State != ConnectionState.Closed) obj.Close();
|
||||
obj.Dispose();
|
||||
}
|
||||
|
||||
public void OnGet(Object<DbConnection> obj)
|
||||
{
|
||||
|
||||
if (_pool.IsAvailable)
|
||||
{
|
||||
if (obj.Value == null)
|
||||
{
|
||||
if (_pool.SetUnavailable(new Exception("连接字符串错误")) == true)
|
||||
throw new Exception($"【{this.Name}】连接字符串错误,请检查。");
|
||||
return;
|
||||
}
|
||||
|
||||
if (obj.Value.State != ConnectionState.Open || DateTime.Now.Subtract(obj.LastReturnTime).TotalSeconds > 60 && obj.Value.Ping() == false)
|
||||
{
|
||||
|
||||
try
|
||||
{
|
||||
obj.Value.Open();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
if (_pool.SetUnavailable(ex) == true)
|
||||
throw new Exception($"【{this.Name}】状态不可用,等待后台检查程序恢复方可使用。{ex.Message}");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
async public Task OnGetAsync(Object<DbConnection> obj)
|
||||
{
|
||||
|
||||
if (_pool.IsAvailable)
|
||||
{
|
||||
if (obj.Value == null)
|
||||
{
|
||||
if (_pool.SetUnavailable(new Exception("连接字符串错误")) == true)
|
||||
throw new Exception($"【{this.Name}】连接字符串错误,请检查。");
|
||||
return;
|
||||
}
|
||||
|
||||
if (obj.Value.State != ConnectionState.Open || DateTime.Now.Subtract(obj.LastReturnTime).TotalSeconds > 60 && (await obj.Value.PingAsync()) == false)
|
||||
{
|
||||
|
||||
try
|
||||
{
|
||||
await obj.Value.OpenAsync();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
if (_pool.SetUnavailable(ex) == true)
|
||||
throw new Exception($"【{this.Name}】状态不可用,等待后台检查程序恢复方可使用。{ex.Message}");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void OnGetTimeout()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public void OnReturn(Object<DbConnection> obj)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public void OnAvailable()
|
||||
{
|
||||
_pool.availableHandler?.Invoke();
|
||||
}
|
||||
|
||||
public void OnUnavailable()
|
||||
{
|
||||
_pool.unavailableHandler?.Invoke();
|
||||
}
|
||||
}
|
||||
|
||||
static class DbConnectionExtensions
|
||||
{
|
||||
|
||||
static DbCommand PingCommand(DbConnection conn)
|
||||
{
|
||||
var cmd = conn.CreateCommand();
|
||||
cmd.CommandTimeout = 5;
|
||||
cmd.CommandText = "select 1";
|
||||
return cmd;
|
||||
}
|
||||
public static bool Ping(this DbConnection that, bool isThrow = false)
|
||||
{
|
||||
try
|
||||
{
|
||||
PingCommand(that).ExecuteNonQuery();
|
||||
return true;
|
||||
}
|
||||
catch
|
||||
{
|
||||
if (that.State != ConnectionState.Closed) try { that.Close(); } catch { }
|
||||
if (isThrow) throw;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
async public static Task<bool> PingAsync(this DbConnection that, bool isThrow = false)
|
||||
{
|
||||
try
|
||||
{
|
||||
await PingCommand(that).ExecuteNonQueryAsync();
|
||||
return true;
|
||||
}
|
||||
catch
|
||||
{
|
||||
if (that.State != ConnectionState.Closed) try { that.Close(); } catch { }
|
||||
if (isThrow) throw;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
337
Providers/FreeSql.Provider.Odbc/MySql/OdbcMySqlCodeFirst.cs
Normal file
337
Providers/FreeSql.Provider.Odbc/MySql/OdbcMySqlCodeFirst.cs
Normal file
@ -0,0 +1,337 @@
|
||||
using FreeSql.DataAnnotations;
|
||||
using FreeSql.DatabaseModel;
|
||||
using FreeSql.Internal;
|
||||
using FreeSql.Internal.Model;
|
||||
using System;
|
||||
using System.Collections.Concurrent;
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
using System.Data.Odbc;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Text.RegularExpressions;
|
||||
|
||||
namespace FreeSql.Odbc.MySql
|
||||
{
|
||||
|
||||
class OdbcMySqlCodeFirst : Internal.CommonProvider.CodeFirstProvider
|
||||
{
|
||||
public override bool IsNoneCommandParameter { get => true; set => base.IsNoneCommandParameter = true; }
|
||||
public OdbcMySqlCodeFirst(IFreeSql orm, CommonUtils commonUtils, CommonExpression commonExpression) : base(orm, commonUtils, commonExpression) { }
|
||||
|
||||
static object _dicCsToDbLock = new object();
|
||||
static Dictionary<string, (OdbcType type, string dbtype, string dbtypeFull, bool? isUnsigned, bool? isnullable, object defaultValue)> _dicCsToDb = new Dictionary<string, (OdbcType type, string dbtype, string dbtypeFull, bool? isUnsigned, bool? isnullable, object defaultValue)>() {
|
||||
{ typeof(bool).FullName, (OdbcType.Bit, "bit","bit(1) NOT NULL", null, false, false) },{ typeof(bool?).FullName, (OdbcType.Bit, "bit","bit(1)", null, true, null) },
|
||||
|
||||
{ typeof(sbyte).FullName, (OdbcType.SmallInt, "tinyint", "tinyint(3) NOT NULL", false, false, 0) },{ typeof(sbyte?).FullName, (OdbcType.SmallInt, "tinyint", "tinyint(3)", false, true, null) },
|
||||
{ typeof(short).FullName, (OdbcType.SmallInt, "smallint","smallint(6) NOT NULL", false, false, 0) },{ typeof(short?).FullName, (OdbcType.SmallInt, "smallint", "smallint(6)", false, true, null) },
|
||||
{ typeof(int).FullName, (OdbcType.Int, "int", "int(11) NOT NULL", false, false, 0) },{ typeof(int?).FullName, (OdbcType.Int, "int", "int(11)", false, true, null) },
|
||||
{ typeof(long).FullName, (OdbcType.BigInt, "bigint","bigint(20) NOT NULL", false, false, 0) },{ typeof(long?).FullName, (OdbcType.BigInt, "bigint","bigint(20)", false, true, null) },
|
||||
|
||||
{ typeof(byte).FullName, (OdbcType.TinyInt, "tinyint","tinyint(3) unsigned NOT NULL", true, false, 0) },{ typeof(byte?).FullName, (OdbcType.TinyInt, "tinyint","tinyint(3) unsigned", true, true, null) },
|
||||
{ typeof(ushort).FullName, (OdbcType.Int, "smallint","smallint(5) unsigned NOT NULL", true, false, 0) },{ typeof(ushort?).FullName, (OdbcType.Int, "smallint", "smallint(5) unsigned", true, true, null) },
|
||||
{ typeof(uint).FullName, (OdbcType.BigInt, "int", "int(10) unsigned NOT NULL", true, false, 0) },{ typeof(uint?).FullName, (OdbcType.BigInt, "int", "int(10) unsigned", true, true, null) },
|
||||
{ typeof(ulong).FullName, (OdbcType.Decimal, "bigint", "bigint(20) unsigned NOT NULL", true, false, 0) },{ typeof(ulong?).FullName, (OdbcType.Decimal, "bigint", "bigint(20) unsigned", true, true, null) },
|
||||
|
||||
{ typeof(double).FullName, (OdbcType.Double, "double", "double NOT NULL", false, false, 0) },{ typeof(double?).FullName, (OdbcType.Double, "double", "double", false, true, null) },
|
||||
{ typeof(float).FullName, (OdbcType.Real, "float","float NOT NULL", false, false, 0) },{ typeof(float?).FullName, (OdbcType.Real, "float","float", false, true, null) },
|
||||
{ typeof(decimal).FullName, (OdbcType.Decimal, "decimal", "decimal(10,2) NOT NULL", false, false, 0) },{ typeof(decimal?).FullName, (OdbcType.Decimal, "decimal", "decimal(10,2)", false, true, null) },
|
||||
|
||||
{ typeof(TimeSpan).FullName, (OdbcType.Time, "time","time NOT NULL", false, false, 0) },{ typeof(TimeSpan?).FullName, (OdbcType.Time, "time", "time",false, true, null) },
|
||||
{ typeof(DateTime).FullName, (OdbcType.DateTime, "datetime(3)", "datetime(3) NOT NULL", false, false, new DateTime(1970,1,1)) },{ typeof(DateTime?).FullName, (OdbcType.DateTime, "datetime(3)", "datetime(3)", false, true, null) },
|
||||
|
||||
{ typeof(byte[]).FullName, (OdbcType.VarBinary, "varbinary", "varbinary(255)", false, null, new byte[0]) },
|
||||
{ typeof(string).FullName, (OdbcType.VarChar, "varchar", "varchar(255)", false, null, "") },
|
||||
|
||||
{ typeof(Guid).FullName, (OdbcType.VarChar, "char", "char(36) NOT NULL", false, false, Guid.Empty) },{ typeof(Guid?).FullName, (OdbcType.VarChar, "char", "char(36)", false, true, null) },
|
||||
};
|
||||
|
||||
public override (int type, string dbtype, string dbtypeFull, bool? isnullable, object defaultValue)? GetDbInfo(Type type)
|
||||
{
|
||||
if (_dicCsToDb.TryGetValue(type.FullName, out var trydc)) return new (int, string, string, bool?, object)?(((int)trydc.type, trydc.dbtype, trydc.dbtypeFull, trydc.isnullable, trydc.defaultValue));
|
||||
if (type.IsArray) return null;
|
||||
var enumType = type.IsEnum ? type : null;
|
||||
if (enumType == null && type.IsNullableType() && type.GenericTypeArguments.Length == 1 && type.GenericTypeArguments.First().IsEnum) enumType = type.GenericTypeArguments.First();
|
||||
if (enumType != null)
|
||||
{
|
||||
var names = string.Join(",", Enum.GetNames(enumType).Select(a => _commonUtils.FormatSql("{0}", a)));
|
||||
var newItem = enumType.GetCustomAttributes(typeof(FlagsAttribute), false).Any() ?
|
||||
(OdbcType.VarChar, "set", $"set({names}){(type.IsEnum ? " NOT NULL" : "")}", false, type.IsEnum ? false : true, Enum.GetValues(enumType).GetValue(0)) :
|
||||
(OdbcType.VarChar, "enum", $"enum({names}){(type.IsEnum ? " NOT NULL" : "")}", false, type.IsEnum ? false : true, Enum.GetValues(enumType).GetValue(0));
|
||||
if (_dicCsToDb.ContainsKey(type.FullName) == false)
|
||||
{
|
||||
lock (_dicCsToDbLock)
|
||||
{
|
||||
if (_dicCsToDb.ContainsKey(type.FullName) == false)
|
||||
_dicCsToDb.Add(type.FullName, newItem);
|
||||
}
|
||||
}
|
||||
return ((int)newItem.Item1, newItem.Item2, newItem.Item3, newItem.Item5, newItem.Item6);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public override string GetComparisonDDLStatements(params Type[] entityTypes)
|
||||
{
|
||||
var conn = _orm.Ado.MasterPool.Get(TimeSpan.FromSeconds(5));
|
||||
var database = conn.Value.Database;
|
||||
Func<string, string, object> ExecuteScalar = (db, sql) =>
|
||||
{
|
||||
if (string.Compare(database, db) != 0) conn.Value.ChangeDatabase(db);
|
||||
try
|
||||
{
|
||||
using (var cmd = conn.Value.CreateCommand())
|
||||
{
|
||||
cmd.CommandText = sql;
|
||||
cmd.CommandType = CommandType.Text;
|
||||
return cmd.ExecuteScalar();
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
if (string.Compare(database, db) != 0) conn.Value.ChangeDatabase(database);
|
||||
}
|
||||
};
|
||||
var sb = new StringBuilder();
|
||||
try
|
||||
{
|
||||
foreach (var entityType in entityTypes)
|
||||
{
|
||||
if (sb.Length > 0) sb.Append("\r\n");
|
||||
var tb = _commonUtils.GetTableByEntity(entityType);
|
||||
if (tb == null) throw new Exception($"类型 {entityType.FullName} 不可迁移");
|
||||
if (tb.Columns.Any() == false) throw new Exception($"类型 {entityType.FullName} 不可迁移,可迁移属性0个");
|
||||
var tbname = tb.DbName.Split(new[] { '.' }, 2);
|
||||
if (tbname?.Length == 1) tbname = new[] { database, tbname[0] };
|
||||
|
||||
var tboldname = tb.DbOldName?.Split(new[] { '.' }, 2); //旧表名
|
||||
if (tboldname?.Length == 1) tboldname = new[] { database, tboldname[0] };
|
||||
|
||||
if (string.Compare(tbname[0], database, true) != 0 && ExecuteScalar(database, _commonUtils.FormatSql(" select 1 from information_schema.schemata where schema_name={0}", tbname[0])) == null) //创建数据库
|
||||
sb.Append($"CREATE DATABASE IF NOT EXISTS ").Append(_commonUtils.QuoteSqlName(tbname[0])).Append(" default charset utf8 COLLATE utf8_general_ci;\r\n");
|
||||
|
||||
var sbalter = new StringBuilder();
|
||||
var istmpatler = false; //创建临时表,导入数据,删除旧表,修改
|
||||
if (ExecuteScalar(tbname[0], _commonUtils.FormatSql(" SELECT 1 FROM information_schema.TABLES WHERE table_schema={0} and table_name={1}", tbname)) == null)
|
||||
{ //表不存在
|
||||
if (tboldname != null)
|
||||
{
|
||||
if (string.Compare(tboldname[0], tbname[0], true) != 0 && ExecuteScalar(database, _commonUtils.FormatSql(" select 1 from information_schema.schemata where schema_name={0}", tboldname[0])) == null ||
|
||||
ExecuteScalar(tboldname[0], _commonUtils.FormatSql(" SELECT 1 FROM information_schema.TABLES WHERE table_schema={0} and table_name={1}", tboldname)) == null)
|
||||
//数据库或表不存在
|
||||
tboldname = null;
|
||||
}
|
||||
if (tboldname == null)
|
||||
{
|
||||
//创建表
|
||||
sb.Append("CREATE TABLE IF NOT EXISTS ").Append(_commonUtils.QuoteSqlName($"{tbname[0]}.{tbname[1]}")).Append(" ( ");
|
||||
foreach (var tbcol in tb.ColumnsByPosition)
|
||||
{
|
||||
sb.Append(" \r\n ").Append(_commonUtils.QuoteSqlName(tbcol.Attribute.Name)).Append(" ");
|
||||
sb.Append(tbcol.Attribute.DbType);
|
||||
if (tbcol.Attribute.IsIdentity == true && tbcol.Attribute.DbType.IndexOf("AUTO_INCREMENT", StringComparison.CurrentCultureIgnoreCase) == -1) sb.Append(" AUTO_INCREMENT");
|
||||
if (string.IsNullOrEmpty(tbcol.Comment) == false) sb.Append(" COMMENT ").Append(_commonUtils.FormatSql("{0}", tbcol.Comment));
|
||||
sb.Append(",");
|
||||
}
|
||||
if (tb.Primarys.Any())
|
||||
{
|
||||
sb.Append(" \r\n PRIMARY KEY (");
|
||||
foreach (var tbcol in tb.Primarys) sb.Append(_commonUtils.QuoteSqlName(tbcol.Attribute.Name)).Append(", ");
|
||||
sb.Remove(sb.Length - 2, 2).Append("),");
|
||||
}
|
||||
foreach (var uk in tb.Uniques)
|
||||
{
|
||||
sb.Append(" \r\n UNIQUE KEY ").Append(_commonUtils.QuoteSqlName(uk.Key)).Append("(");
|
||||
foreach (var tbcol in uk.Value) sb.Append(_commonUtils.QuoteSqlName(tbcol.Attribute.Name)).Append(", ");
|
||||
sb.Remove(sb.Length - 2, 2).Append("),");
|
||||
}
|
||||
sb.Remove(sb.Length - 1, 1);
|
||||
sb.Append("\r\n) Engine=InnoDB;\r\n");
|
||||
continue;
|
||||
}
|
||||
//如果新表,旧表在一个数据库下,直接修改表名
|
||||
if (string.Compare(tbname[0], tboldname[0], true) == 0)
|
||||
sbalter.Append("ALTER TABLE ").Append(_commonUtils.QuoteSqlName($"{tboldname[0]}.{tboldname[1]}")).Append(" RENAME TO ").Append(_commonUtils.QuoteSqlName($"{tbname[0]}.{tbname[1]}")).Append(";\r\n");
|
||||
else
|
||||
{
|
||||
//如果新表,旧表不在一起,创建新表,导入数据,删除旧表
|
||||
istmpatler = true;
|
||||
}
|
||||
}
|
||||
else
|
||||
tboldname = null; //如果新表已经存在,不走改表名逻辑
|
||||
|
||||
//对比字段,只可以修改类型、增加字段、有限的修改字段名;保证安全不删除字段
|
||||
var sql = _commonUtils.FormatSql(@"
|
||||
select
|
||||
a.column_name,
|
||||
a.column_type,
|
||||
case when a.is_nullable = 'YES' then 1 else 0 end 'is_nullable',
|
||||
case when locate('auto_increment', a.extra) > 0 then 1 else 0 end 'is_identity',
|
||||
a.column_comment 'comment'
|
||||
from information_schema.columns a
|
||||
where a.table_schema in ({0}) and a.table_name in ({1})", tboldname ?? tbname);
|
||||
var ds = _orm.Ado.ExecuteArray(CommandType.Text, sql);
|
||||
var tbstruct = ds.ToDictionary(a => string.Concat(a[0]), a =>
|
||||
{
|
||||
var a1 = string.Concat(a[1]);
|
||||
if (a1 == "datetime") a1 = string.Concat(a1, "(0)");
|
||||
return new
|
||||
{
|
||||
column = string.Concat(a[0]),
|
||||
sqlType = a1,
|
||||
is_nullable = string.Concat(a[2]) == "1",
|
||||
is_identity = string.Concat(a[3]) == "1",
|
||||
is_unsigned = string.Concat(a[1]).EndsWith(" unsigned"),
|
||||
comment = string.Concat(a[4])
|
||||
};
|
||||
}, StringComparer.CurrentCultureIgnoreCase);
|
||||
|
||||
if (istmpatler == false)
|
||||
{
|
||||
var existsPrimary = ExecuteScalar(tbname[0], _commonUtils.FormatSql("select 1 from information_schema.key_column_usage where table_schema={0} and table_name={1} and constraint_name = 'PRIMARY' limit 1", tbname));
|
||||
foreach (var tbcol in tb.ColumnsByPosition)
|
||||
{
|
||||
var isIdentityChanged = tbcol.Attribute.IsIdentity == true && tbcol.Attribute.DbType.IndexOf("AUTO_INCREMENT", StringComparison.CurrentCultureIgnoreCase) == -1;
|
||||
if (tbstruct.TryGetValue(tbcol.Attribute.Name, out var tbstructcol) ||
|
||||
string.IsNullOrEmpty(tbcol.Attribute.OldName) == false && tbstruct.TryGetValue(tbcol.Attribute.OldName, out tbstructcol))
|
||||
{
|
||||
var isCommentChanged = tbstructcol.comment != (tbcol.Comment ?? "");
|
||||
if ((tbcol.Attribute.DbType.IndexOf(" unsigned", StringComparison.CurrentCultureIgnoreCase) != -1) != tbstructcol.is_unsigned ||
|
||||
tbcol.Attribute.DbType.StartsWith(tbstructcol.sqlType, StringComparison.CurrentCultureIgnoreCase) == false ||
|
||||
tbcol.Attribute.IsNullable != tbstructcol.is_nullable ||
|
||||
tbcol.Attribute.IsIdentity != tbstructcol.is_identity ||
|
||||
isCommentChanged)
|
||||
{
|
||||
sbalter.Append("ALTER TABLE ").Append(_commonUtils.QuoteSqlName($"{tbname[0]}.{tbname[1]}")).Append(" MODIFY ").Append(_commonUtils.QuoteSqlName(tbstructcol.column)).Append(" ").Append(tbcol.Attribute.DbType);
|
||||
if (isCommentChanged) sbalter.Append(" COMMENT ").Append(_commonUtils.FormatSql("{0}", tbcol.Comment ?? ""));
|
||||
if (isIdentityChanged) sbalter.Append(" AUTO_INCREMENT").Append(existsPrimary == null ? "" : ", DROP PRIMARY KEY").Append(", ADD PRIMARY KEY(").Append(_commonUtils.QuoteSqlName(tbstructcol.column)).Append(")");
|
||||
sbalter.Append(";\r\n");
|
||||
}
|
||||
if (string.Compare(tbstructcol.column, tbcol.Attribute.OldName, true) == 0)
|
||||
{
|
||||
//修改列名
|
||||
sbalter.Append("ALTER TABLE ").Append(_commonUtils.QuoteSqlName($"{tbname[0]}.{tbname[1]}")).Append(" CHANGE COLUMN ").Append(_commonUtils.QuoteSqlName(tbstructcol.column)).Append(" ").Append(_commonUtils.QuoteSqlName(tbcol.Attribute.Name)).Append(" ").Append(tbcol.Attribute.DbType);
|
||||
if (isCommentChanged) sbalter.Append(" COMMENT ").Append(_commonUtils.FormatSql("{0}", tbcol.Comment ?? ""));
|
||||
if (isIdentityChanged) sbalter.Append(" AUTO_INCREMENT").Append(existsPrimary == null ? "" : ", DROP PRIMARY KEY").Append(", ADD PRIMARY KEY(").Append(_commonUtils.QuoteSqlName(tbcol.Attribute.Name)).Append(")");
|
||||
sbalter.Append(";\r\n");
|
||||
}
|
||||
continue;
|
||||
}
|
||||
//添加列
|
||||
sbalter.Append("ALTER TABLE ").Append(_commonUtils.QuoteSqlName($"{tbname[0]}.{tbname[1]}")).Append(" ADD ").Append(_commonUtils.QuoteSqlName(tbcol.Attribute.Name)).Append(" ").Append(tbcol.Attribute.DbType);
|
||||
if (tbcol.Attribute.IsNullable == false) sbalter.Append(" DEFAULT ").Append(_commonUtils.FormatSql("{0}", tbcol.Attribute.DbDefautValue));
|
||||
if (string.IsNullOrEmpty(tbcol.Comment) == false) sbalter.Append(" COMMENT ").Append(_commonUtils.FormatSql("{0}", tbcol.Comment ?? ""));
|
||||
if (isIdentityChanged) sbalter.Append(" AUTO_INCREMENT").Append(existsPrimary == null ? "" : ", DROP PRIMARY KEY").Append(", ADD PRIMARY KEY(").Append(_commonUtils.QuoteSqlName(tbcol.Attribute.Name)).Append(")");
|
||||
sbalter.Append(";\r\n");
|
||||
}
|
||||
var dsuksql = _commonUtils.FormatSql(@"
|
||||
select
|
||||
a.column_name,
|
||||
a.constraint_name 'index_id'
|
||||
from information_schema.key_column_usage a
|
||||
where a.constraint_schema IN ({0}) and a.table_name IN ({1})", tboldname ?? tbname);
|
||||
var dsuk = _orm.Ado.ExecuteArray(CommandType.Text, dsuksql).Select(a => new[] { string.Concat(a[0]), string.Concat(a[1]) });
|
||||
foreach (var uk in tb.Uniques)
|
||||
{
|
||||
if (uk.Key == "PRIMARY" || string.IsNullOrEmpty(uk.Key) || uk.Value.Any() == false) continue;
|
||||
var dsukfind1 = dsuk.Where(a => string.Compare(a[1], uk.Key, true) == 0).ToArray();
|
||||
if (dsukfind1.Any() == false || dsukfind1.Length != uk.Value.Count || dsukfind1.Where(a => uk.Value.Where(b => string.Compare(b.Attribute.Name, a[0], true) == 0).Any()).Count() != uk.Value.Count)
|
||||
{
|
||||
if (dsukfind1.Any()) sbalter.Append("ALTER TABLE ").Append(_commonUtils.QuoteSqlName($"{tbname[0]}.{tbname[1]}")).Append(" DROP INDEX ").Append(_commonUtils.QuoteSqlName(uk.Key)).Append(";\r\n");
|
||||
sbalter.Append("ALTER TABLE ").Append(_commonUtils.QuoteSqlName($"{tbname[0]}.{tbname[1]}")).Append(" ADD CONSTRAINT ").Append(_commonUtils.QuoteSqlName(uk.Key)).Append(" UNIQUE(");
|
||||
foreach (var tbcol in uk.Value) sbalter.Append(_commonUtils.QuoteSqlName(tbcol.Attribute.Name)).Append(", ");
|
||||
sbalter.Remove(sbalter.Length - 2, 2).Append(");\r\n");
|
||||
}
|
||||
}
|
||||
}
|
||||
if (istmpatler == false)
|
||||
{
|
||||
sb.Append(sbalter);
|
||||
continue;
|
||||
}
|
||||
|
||||
//创建临时表,数据导进临时表,然后删除原表,将临时表改名为原表名
|
||||
var tablename = tboldname == null ? _commonUtils.QuoteSqlName($"{tbname[0]}.{tbname[1]}") : _commonUtils.QuoteSqlName($"{tboldname[0]}.{tboldname[1]}");
|
||||
var tmptablename = _commonUtils.QuoteSqlName($"{tbname[0]}.FreeSqlTmp_{tbname[1]}");
|
||||
//创建临时表
|
||||
sb.Append("CREATE TABLE IF NOT EXISTS ").Append(tmptablename).Append(" ( ");
|
||||
foreach (var tbcol in tb.ColumnsByPosition)
|
||||
{
|
||||
sb.Append(" \r\n ").Append(_commonUtils.QuoteSqlName(tbcol.Attribute.Name)).Append(" ");
|
||||
sb.Append(tbcol.Attribute.DbType);
|
||||
if (tbcol.Attribute.IsIdentity == true && tbcol.Attribute.DbType.IndexOf("AUTO_INCREMENT", StringComparison.CurrentCultureIgnoreCase) == -1) sb.Append(" AUTO_INCREMENT");
|
||||
if (string.IsNullOrEmpty(tbcol.Comment) == false) sb.Append(" COMMENT ").Append(_commonUtils.FormatSql("{0}", tbcol.Comment));
|
||||
sb.Append(",");
|
||||
}
|
||||
if (tb.Primarys.Any())
|
||||
{
|
||||
sb.Append(" \r\n PRIMARY KEY (");
|
||||
foreach (var tbcol in tb.Primarys) sb.Append(_commonUtils.QuoteSqlName(tbcol.Attribute.Name)).Append(", ");
|
||||
sb.Remove(sb.Length - 2, 2).Append("),");
|
||||
}
|
||||
foreach (var uk in tb.Uniques)
|
||||
{
|
||||
sb.Append(" \r\n UNIQUE KEY ").Append(_commonUtils.QuoteSqlName(uk.Key)).Append("(");
|
||||
foreach (var tbcol in uk.Value) sb.Append(_commonUtils.QuoteSqlName(tbcol.Attribute.Name)).Append(", ");
|
||||
sb.Remove(sb.Length - 2, 2).Append("),");
|
||||
}
|
||||
sb.Remove(sb.Length - 1, 1);
|
||||
sb.Append("\r\n) Engine=InnoDB;\r\n");
|
||||
sb.Append("INSERT INTO ").Append(tmptablename).Append(" (");
|
||||
foreach (var tbcol in tb.ColumnsByPosition)
|
||||
sb.Append(_commonUtils.QuoteSqlName(tbcol.Attribute.Name)).Append(", ");
|
||||
sb.Remove(sb.Length - 2, 2).Append(")\r\nSELECT ");
|
||||
foreach (var tbcol in tb.ColumnsByPosition)
|
||||
{
|
||||
var insertvalue = "NULL";
|
||||
if (tbstruct.TryGetValue(tbcol.Attribute.Name, out var tbstructcol) ||
|
||||
string.IsNullOrEmpty(tbcol.Attribute.OldName) == false && tbstruct.TryGetValue(tbcol.Attribute.OldName, out tbstructcol))
|
||||
{
|
||||
insertvalue = _commonUtils.QuoteSqlName(tbstructcol.column);
|
||||
if (tbcol.Attribute.DbType.StartsWith(tbstructcol.sqlType, StringComparison.CurrentCultureIgnoreCase) == false)
|
||||
{
|
||||
//insertvalue = $"cast({insertvalue} as {tbcol.Attribute.DbType.Split(' ').First()})";
|
||||
}
|
||||
if (tbcol.Attribute.IsNullable != tbstructcol.is_nullable)
|
||||
insertvalue = $"ifnull({insertvalue},{_commonUtils.FormatSql("{0}", tbcol.Attribute.DbDefautValue)})";
|
||||
}
|
||||
else if (tbcol.Attribute.IsNullable == false)
|
||||
insertvalue = _commonUtils.FormatSql("{0}", tbcol.Attribute.DbDefautValue);
|
||||
sb.Append(insertvalue).Append(", ");
|
||||
}
|
||||
sb.Remove(sb.Length - 2, 2).Append(" FROM ").Append(tablename).Append(";\r\n");
|
||||
sb.Append("DROP TABLE ").Append(tablename).Append(";\r\n");
|
||||
sb.Append("ALTER TABLE ").Append(tmptablename).Append(" RENAME TO ").Append(_commonUtils.QuoteSqlName($"{tbname[0]}.{tbname[1]}")).Append(";\r\n");
|
||||
}
|
||||
return sb.Length == 0 ? null : sb.ToString();
|
||||
}
|
||||
finally
|
||||
{
|
||||
try
|
||||
{
|
||||
conn.Value.ChangeDatabase(database);
|
||||
_orm.Ado.MasterPool.Return(conn);
|
||||
}
|
||||
catch
|
||||
{
|
||||
_orm.Ado.MasterPool.Return(conn, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public override int ExecuteDDLStatements(string ddl)
|
||||
{
|
||||
if (string.IsNullOrEmpty(ddl)) return 0;
|
||||
var scripts = ddl.Split(new string[] { ";\r\n" }, StringSplitOptions.None).Where(a => string.IsNullOrEmpty(a.Trim()) == false).ToArray();
|
||||
|
||||
if (scripts.Any() == false) return 0;
|
||||
if (scripts.Length == 1) return base.ExecuteDDLStatements(ddl);
|
||||
|
||||
var affrows = 0;
|
||||
foreach (var script in scripts)
|
||||
affrows += base.ExecuteDDLStatements(script);
|
||||
return affrows;
|
||||
}
|
||||
}
|
||||
}
|
385
Providers/FreeSql.Provider.Odbc/MySql/OdbcMySqlDbFirst.cs
Normal file
385
Providers/FreeSql.Provider.Odbc/MySql/OdbcMySqlDbFirst.cs
Normal file
@ -0,0 +1,385 @@
|
||||
using FreeSql.DatabaseModel;
|
||||
using FreeSql.Internal;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
using System.Data.Odbc;
|
||||
using System.Linq;
|
||||
using System.Text.RegularExpressions;
|
||||
|
||||
namespace FreeSql.Odbc.MySql
|
||||
{
|
||||
class OdbcMySqlDbFirst : IDbFirst
|
||||
{
|
||||
IFreeSql _orm;
|
||||
protected CommonUtils _commonUtils;
|
||||
protected CommonExpression _commonExpression;
|
||||
public OdbcMySqlDbFirst(IFreeSql orm, CommonUtils commonUtils, CommonExpression commonExpression)
|
||||
{
|
||||
_orm = orm;
|
||||
_commonUtils = commonUtils;
|
||||
_commonExpression = commonExpression;
|
||||
}
|
||||
|
||||
public int GetDbType(DbColumnInfo column) => (int)GetOdbcType(column);
|
||||
OdbcType GetOdbcType(DbColumnInfo column)
|
||||
{
|
||||
var is_unsigned = column.DbTypeTextFull.ToLower().EndsWith(" unsigned");
|
||||
switch (column.DbTypeText.ToLower())
|
||||
{
|
||||
case "bit": return OdbcType.Bit;
|
||||
|
||||
case "tinyint": return is_unsigned ? OdbcType.TinyInt : OdbcType.SmallInt;
|
||||
case "smallint": return is_unsigned ? OdbcType.Int : OdbcType.SmallInt;
|
||||
case "mediumint": return is_unsigned ? OdbcType.Int : OdbcType.Int;
|
||||
case "int": return is_unsigned ? OdbcType.BigInt : OdbcType.Int;
|
||||
case "bigint": return is_unsigned ? OdbcType.Decimal : OdbcType.BigInt;
|
||||
|
||||
case "real":
|
||||
case "double": return OdbcType.Double;
|
||||
case "float": return OdbcType.Real;
|
||||
case "numeric":
|
||||
case "decimal": return OdbcType.Decimal;
|
||||
|
||||
case "year": return OdbcType.Int;
|
||||
case "time": return OdbcType.Time;
|
||||
case "date": return OdbcType.Date;
|
||||
case "timestamp": return OdbcType.Timestamp;
|
||||
case "datetime": return OdbcType.DateTime;
|
||||
|
||||
case "tinyblob": return OdbcType.VarBinary;
|
||||
case "blob": return OdbcType.VarBinary;
|
||||
case "mediumblob": return OdbcType.VarBinary;
|
||||
case "longblob": return OdbcType.VarBinary;
|
||||
|
||||
case "binary": return OdbcType.Binary;
|
||||
case "varbinary": return OdbcType.VarBinary;
|
||||
|
||||
case "tinytext": return OdbcType.Text;
|
||||
case "text": return OdbcType.Text;
|
||||
case "mediumtext": return OdbcType.Text;
|
||||
case "longtext": return OdbcType.Text;
|
||||
|
||||
case "char": return column.MaxLength == 36 ? OdbcType.Char : OdbcType.VarChar;
|
||||
case "varchar": return OdbcType.VarChar;
|
||||
|
||||
case "set": return OdbcType.VarChar;
|
||||
case "enum": return OdbcType.VarChar;
|
||||
|
||||
default: return OdbcType.VarChar;
|
||||
}
|
||||
}
|
||||
|
||||
static readonly Dictionary<int, (string csConvert, string csParse, string csStringify, string csType, Type csTypeInfo, Type csNullableTypeInfo, string csTypeValue, string dataReaderMethod)> _dicDbToCs = new Dictionary<int, (string csConvert, string csParse, string csStringify, string csType, Type csTypeInfo, Type csNullableTypeInfo, string csTypeValue, string dataReaderMethod)>() {
|
||||
{ (int)OdbcType.Bit, ("(bool?)", "{0} == \"1\"", "{0} == true ? \"1\" : \"0\"", "bool?", typeof(bool), typeof(bool?), "{0}.Value", "GetBoolean") },
|
||||
|
||||
{ (int)OdbcType.TinyInt, ("(sbyte?)", "sbyte.Parse({0})", "{0}.ToString()", "sbyte?", typeof(sbyte), typeof(sbyte?), "{0}.Value", "GetByte") },
|
||||
{ (int)OdbcType.SmallInt, ("(short?)", "short.Parse({0})", "{0}.ToString()", "short?", typeof(short), typeof(short?), "{0}.Value", "GetInt16") },
|
||||
{ (int)OdbcType.Int, ("(int?)", "int.Parse({0})", "{0}.ToString()", "int?", typeof(int), typeof(int?), "{0}.Value", "GetInt32") },
|
||||
{ (int)OdbcType.BigInt, ("(long?)", "long.Parse({0})", "{0}.ToString()", "long?", typeof(long), typeof(long?), "{0}.Value", "GetInt64") },
|
||||
|
||||
{ (int)OdbcType.Double, ("(double?)", "double.Parse({0})", "{0}.ToString()", "double?", typeof(double), typeof(double?), "{0}.Value", "GetDouble") },
|
||||
{ (int)OdbcType.Real, ("(float?)", "float.Parse({0})", "{0}.ToString()", "float?", typeof(float), typeof(float?), "{0}.Value", "GetFloat") },
|
||||
{ (int)OdbcType.Decimal, ("(decimal?)", "decimal.Parse({0})", "{0}.ToString()", "decimal?", typeof(decimal), typeof(decimal?), "{0}.Value", "GetDecimal") },
|
||||
|
||||
{ (int)OdbcType.Time, ("(TimeSpan?)", "TimeSpan.Parse(double.Parse({0}))", "{0}.Ticks.ToString()", "TimeSpan?", typeof(TimeSpan), typeof(TimeSpan?), "{0}.Value", "GetValue") },
|
||||
{ (int)OdbcType.Date, ("(DateTime?)", "new DateTime(long.Parse({0}))", "{0}.Ticks.ToString()", "DateTime?", typeof(DateTime), typeof(DateTime?), "{0}.Value", "GetDateTime") },
|
||||
{ (int)OdbcType.Timestamp, ("(DateTime?)", "new DateTime(long.Parse({0}))", "{0}.Ticks.ToString()", "DateTime?", typeof(DateTime), typeof(DateTime?), "{0}.Value", "GetDateTime") },
|
||||
{ (int)OdbcType.DateTime, ("(DateTime?)", "new DateTime(long.Parse({0}))", "{0}.Ticks.ToString()", "DateTime?", typeof(DateTime), typeof(DateTime?), "{0}.Value", "GetDateTime") },
|
||||
|
||||
{ (int)OdbcType.Binary, ("(byte[])", "Convert.FromBase64String({0})", "Convert.ToBase64String({0})", "byte[]", typeof(byte[]), typeof(byte[]), "{0}", "GetValue") },
|
||||
{ (int)OdbcType.VarBinary, ("(byte[])", "Convert.FromBase64String({0})", "Convert.ToBase64String({0})", "byte[]", typeof(byte[]), typeof(byte[]), "{0}", "GetValue") },
|
||||
|
||||
{ (int)OdbcType.Text, ("", "{0}.Replace(StringifySplit, \"|\")", "{0}.Replace(\"|\", StringifySplit)", "string", typeof(string), typeof(string), "{0}", "GetString") },
|
||||
|
||||
{ (int)OdbcType.Char, ("", "{0}.Replace(StringifySplit, \"|\")", "{0}.Replace(\"|\", StringifySplit)", "string", typeof(string), typeof(string), "{0}", "GetString") },
|
||||
{ (int)OdbcType.UniqueIdentifier, ("(Guid?)", "Guid.Parse({0})", "{0}.ToString()", "Guid?", typeof(Guid), typeof(Guid?), "{0}", "GetString") },
|
||||
{ (int)OdbcType.VarChar, ("", "{0}.Replace(StringifySplit, \"|\")", "{0}.Replace(\"|\", StringifySplit)", "string", typeof(string), typeof(string), "{0}", "GetString") },
|
||||
};
|
||||
|
||||
public string GetCsConvert(DbColumnInfo column) => _dicDbToCs.TryGetValue(column.DbType, out var trydc) ? (column.IsNullable ? trydc.csConvert : trydc.csConvert.Replace("?", "")) : null;
|
||||
public string GetCsParse(DbColumnInfo column) => _dicDbToCs.TryGetValue(column.DbType, out var trydc) ? trydc.csParse : null;
|
||||
public string GetCsStringify(DbColumnInfo column) => _dicDbToCs.TryGetValue(column.DbType, out var trydc) ? trydc.csStringify : null;
|
||||
public string GetCsType(DbColumnInfo column) => _dicDbToCs.TryGetValue(column.DbType, out var trydc) ? (column.IsNullable ? trydc.csType : trydc.csType.Replace("?", "")) : null;
|
||||
public Type GetCsTypeInfo(DbColumnInfo column) => _dicDbToCs.TryGetValue(column.DbType, out var trydc) ? trydc.csTypeInfo : null;
|
||||
public string GetCsTypeValue(DbColumnInfo column) => _dicDbToCs.TryGetValue(column.DbType, out var trydc) ? trydc.csTypeValue : null;
|
||||
public string GetDataReaderMethod(DbColumnInfo column) => _dicDbToCs.TryGetValue(column.DbType, out var trydc) ? trydc.dataReaderMethod : null;
|
||||
|
||||
public List<string> GetDatabases()
|
||||
{
|
||||
var sql = @" select schema_name from information_schema.schemata where schema_name not in ('information_schema', 'mysql', 'performance_schema')";
|
||||
var ds = _orm.Ado.ExecuteArray(CommandType.Text, sql);
|
||||
return ds.Select(a => a.FirstOrDefault()?.ToString()).ToList();
|
||||
}
|
||||
|
||||
public List<DbTableInfo> GetTablesByDatabase(params string[] database2)
|
||||
{
|
||||
var loc1 = new List<DbTableInfo>();
|
||||
var loc2 = new Dictionary<string, DbTableInfo>();
|
||||
var loc3 = new Dictionary<string, Dictionary<string, DbColumnInfo>>();
|
||||
var database = database2?.ToArray();
|
||||
|
||||
if (database == null || database.Any() == false)
|
||||
{
|
||||
using (var conn = _orm.Ado.MasterPool.Get())
|
||||
{
|
||||
if (string.IsNullOrEmpty(conn.Value.Database)) return loc1;
|
||||
database = new[] { conn.Value.Database };
|
||||
}
|
||||
}
|
||||
var databaseIn = string.Join(",", database.Select(a => _commonUtils.FormatSql("{0}", a)));
|
||||
var sql = string.Format(@"
|
||||
select
|
||||
concat(a.table_schema, '.', a.table_name) 'id',
|
||||
a.table_schema 'schema',
|
||||
a.table_name 'table',
|
||||
a.table_comment,
|
||||
a.table_type 'type'
|
||||
from information_schema.tables a
|
||||
where a.table_schema in ({0})", databaseIn);
|
||||
var ds = _orm.Ado.ExecuteArray(CommandType.Text, sql);
|
||||
if (ds == null) return loc1;
|
||||
|
||||
var loc6 = new List<string>();
|
||||
var loc66 = new List<string>();
|
||||
foreach (var row in ds)
|
||||
{
|
||||
var table_id = string.Concat(row[0]);
|
||||
var schema = string.Concat(row[1]);
|
||||
var table = string.Concat(row[2]);
|
||||
var comment = string.Concat(row[3]);
|
||||
var type = string.Concat(row[4]) == "VIEW" ? DbTableType.VIEW : DbTableType.TABLE;
|
||||
if (database.Length == 1)
|
||||
{
|
||||
table_id = table_id.Substring(table_id.IndexOf('.') + 1);
|
||||
schema = "";
|
||||
}
|
||||
loc2.Add(table_id, new DbTableInfo { Id = table_id, Schema = schema, Name = table, Comment = comment, Type = type });
|
||||
loc3.Add(table_id, new Dictionary<string, DbColumnInfo>());
|
||||
switch (type)
|
||||
{
|
||||
case DbTableType.TABLE:
|
||||
case DbTableType.VIEW:
|
||||
loc6.Add(table.Replace("'", "''"));
|
||||
break;
|
||||
case DbTableType.StoreProcedure:
|
||||
loc66.Add(table.Replace("'", "''"));
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (loc6.Count == 0) return loc1;
|
||||
var loc8 = "'" + string.Join("','", loc6.ToArray()) + "'";
|
||||
var loc88 = "'" + string.Join("','", loc66.ToArray()) + "'";
|
||||
|
||||
sql = string.Format(@"
|
||||
select
|
||||
concat(a.table_schema, '.', a.table_name),
|
||||
a.column_name,
|
||||
a.data_type,
|
||||
ifnull(a.character_maximum_length, 0) 'len',
|
||||
a.column_type,
|
||||
case when a.is_nullable = 'YES' then 1 else 0 end 'is_nullable',
|
||||
case when locate('auto_increment', a.extra) > 0 then 1 else 0 end 'is_identity',
|
||||
a.column_comment 'comment'
|
||||
from information_schema.columns a
|
||||
where a.table_schema in ({1}) and a.table_name in ({0})
|
||||
", loc8, databaseIn);
|
||||
ds = _orm.Ado.ExecuteArray(CommandType.Text, sql);
|
||||
if (ds == null) return loc1;
|
||||
|
||||
foreach (var row in ds)
|
||||
{
|
||||
string table_id = string.Concat(row[0]);
|
||||
string column = string.Concat(row[1]);
|
||||
string type = string.Concat(row[2]);
|
||||
//long max_length = long.Parse(string.Concat(row[3]));
|
||||
string sqlType = string.Concat(row[4]);
|
||||
var m_len = Regex.Match(sqlType, @"\w+\((\d+)");
|
||||
int max_length = m_len.Success ? int.Parse(m_len.Groups[1].Value) : -1;
|
||||
bool is_nullable = string.Concat(row[5]) == "1";
|
||||
bool is_identity = string.Concat(row[6]) == "1";
|
||||
string comment = string.Concat(row[7]);
|
||||
if (max_length == 0) max_length = -1;
|
||||
if (database.Length == 1)
|
||||
{
|
||||
table_id = table_id.Substring(table_id.IndexOf('.') + 1);
|
||||
}
|
||||
loc3[table_id].Add(column, new DbColumnInfo
|
||||
{
|
||||
Name = column,
|
||||
MaxLength = max_length,
|
||||
IsIdentity = is_identity,
|
||||
IsNullable = is_nullable,
|
||||
IsPrimary = false,
|
||||
DbTypeText = type,
|
||||
DbTypeTextFull = sqlType,
|
||||
Table = loc2[table_id],
|
||||
Coment = comment
|
||||
});
|
||||
loc3[table_id][column].DbType = this.GetDbType(loc3[table_id][column]);
|
||||
loc3[table_id][column].CsType = this.GetCsTypeInfo(loc3[table_id][column]);
|
||||
}
|
||||
|
||||
sql = string.Format(@"
|
||||
select
|
||||
concat(a.constraint_schema, '.', a.table_name) 'table_id',
|
||||
a.column_name,
|
||||
a.constraint_name 'index_id',
|
||||
1 'IsUnique',
|
||||
case when a.constraint_name = 'PRIMARY' then 1 else 0 end 'IsPrimaryKey',
|
||||
0 'IsClustered',
|
||||
0 'IsDesc'
|
||||
from information_schema.key_column_usage a
|
||||
where a.constraint_schema in ({1}) and a.table_name in ({0}) and isnull(position_in_unique_constraint)
|
||||
", loc8, databaseIn);
|
||||
ds = _orm.Ado.ExecuteArray(CommandType.Text, sql);
|
||||
if (ds == null) return loc1;
|
||||
|
||||
var indexColumns = new Dictionary<string, Dictionary<string, List<DbColumnInfo>>>();
|
||||
var uniqueColumns = new Dictionary<string, Dictionary<string, List<DbColumnInfo>>>();
|
||||
foreach (var row in ds)
|
||||
{
|
||||
string table_id = string.Concat(row[0]);
|
||||
string column = string.Concat(row[1]);
|
||||
string index_id = string.Concat(row[2]);
|
||||
bool is_unique = string.Concat(row[3]) == "1";
|
||||
bool is_primary_key = string.Concat(row[4]) == "1";
|
||||
bool is_clustered = string.Concat(row[5]) == "1";
|
||||
int is_desc = int.Parse(string.Concat(row[6]));
|
||||
if (database.Length == 1)
|
||||
{
|
||||
table_id = table_id.Substring(table_id.IndexOf('.') + 1);
|
||||
}
|
||||
if (loc3.ContainsKey(table_id) == false || loc3[table_id].ContainsKey(column) == false) continue;
|
||||
var loc9 = loc3[table_id][column];
|
||||
if (loc9.IsPrimary == false && is_primary_key) loc9.IsPrimary = is_primary_key;
|
||||
|
||||
Dictionary<string, List<DbColumnInfo>> loc10 = null;
|
||||
List<DbColumnInfo> loc11 = null;
|
||||
if (!indexColumns.TryGetValue(table_id, out loc10))
|
||||
indexColumns.Add(table_id, loc10 = new Dictionary<string, List<DbColumnInfo>>());
|
||||
if (!loc10.TryGetValue(index_id, out loc11))
|
||||
loc10.Add(index_id, loc11 = new List<DbColumnInfo>());
|
||||
loc11.Add(loc9);
|
||||
if (is_unique && !is_primary_key)
|
||||
{
|
||||
if (!uniqueColumns.TryGetValue(table_id, out loc10))
|
||||
uniqueColumns.Add(table_id, loc10 = new Dictionary<string, List<DbColumnInfo>>());
|
||||
if (!loc10.TryGetValue(index_id, out loc11))
|
||||
loc10.Add(index_id, loc11 = new List<DbColumnInfo>());
|
||||
loc11.Add(loc9);
|
||||
}
|
||||
}
|
||||
foreach (string table_id in indexColumns.Keys)
|
||||
{
|
||||
foreach (var column in indexColumns[table_id])
|
||||
loc2[table_id].IndexesDict.Add(column.Key, column.Value);
|
||||
}
|
||||
foreach (string table_id in uniqueColumns.Keys)
|
||||
{
|
||||
foreach (var column in uniqueColumns[table_id])
|
||||
{
|
||||
column.Value.Sort((c1, c2) => c1.Name.CompareTo(c2.Name));
|
||||
loc2[table_id].UniquesDict.Add(column.Key, column.Value);
|
||||
}
|
||||
}
|
||||
|
||||
sql = string.Format(@"
|
||||
select
|
||||
concat(a.constraint_schema, '.', a.table_name) 'table_id',
|
||||
a.column_name,
|
||||
a.constraint_name 'FKId',
|
||||
concat(a.referenced_table_schema, '.', a.referenced_table_name) 'ref_table_id',
|
||||
1 'IsForeignKey',
|
||||
a.referenced_column_name 'ref_column'
|
||||
from information_schema.key_column_usage a
|
||||
where a.constraint_schema in ({1}) and a.table_name in ({0}) and not isnull(position_in_unique_constraint)
|
||||
", loc8, databaseIn);
|
||||
ds = _orm.Ado.ExecuteArray(CommandType.Text, sql);
|
||||
if (ds == null) return loc1;
|
||||
|
||||
var fkColumns = new Dictionary<string, Dictionary<string, DbForeignInfo>>();
|
||||
foreach (var row in ds)
|
||||
{
|
||||
string table_id = string.Concat(row[0]);
|
||||
string column = string.Concat(row[1]);
|
||||
string fk_id = string.Concat(row[2]);
|
||||
string ref_table_id = string.Concat(row[3]);
|
||||
bool is_foreign_key = string.Concat(row[4]) == "1";
|
||||
string referenced_column = string.Concat(row[5]);
|
||||
if (database.Length == 1)
|
||||
{
|
||||
table_id = table_id.Substring(table_id.IndexOf('.') + 1);
|
||||
ref_table_id = ref_table_id.Substring(ref_table_id.IndexOf('.') + 1);
|
||||
}
|
||||
if (loc3.ContainsKey(table_id) == false || loc3[table_id].ContainsKey(column) == false) continue;
|
||||
var loc9 = loc3[table_id][column];
|
||||
if (loc2.ContainsKey(ref_table_id) == false) continue;
|
||||
var loc10 = loc2[ref_table_id];
|
||||
var loc11 = loc3[ref_table_id][referenced_column];
|
||||
|
||||
Dictionary<string, DbForeignInfo> loc12 = null;
|
||||
DbForeignInfo loc13 = null;
|
||||
if (!fkColumns.TryGetValue(table_id, out loc12))
|
||||
fkColumns.Add(table_id, loc12 = new Dictionary<string, DbForeignInfo>());
|
||||
if (!loc12.TryGetValue(fk_id, out loc13))
|
||||
loc12.Add(fk_id, loc13 = new DbForeignInfo { Table = loc2[table_id], ReferencedTable = loc10 });
|
||||
loc13.Columns.Add(loc9);
|
||||
loc13.ReferencedColumns.Add(loc11);
|
||||
}
|
||||
foreach (var table_id in fkColumns.Keys)
|
||||
foreach (var fk in fkColumns[table_id])
|
||||
loc2[table_id].ForeignsDict.Add(fk.Key, fk.Value);
|
||||
|
||||
foreach (var table_id in loc3.Keys)
|
||||
{
|
||||
foreach (var loc5 in loc3[table_id].Values)
|
||||
{
|
||||
loc2[table_id].Columns.Add(loc5);
|
||||
if (loc5.IsIdentity) loc2[table_id].Identitys.Add(loc5);
|
||||
if (loc5.IsPrimary) loc2[table_id].Primarys.Add(loc5);
|
||||
}
|
||||
}
|
||||
foreach (var loc4 in loc2.Values)
|
||||
{
|
||||
if (loc4.Primarys.Count == 0 && loc4.UniquesDict.Count > 0)
|
||||
{
|
||||
foreach (var loc5 in loc4.UniquesDict.First().Value)
|
||||
{
|
||||
loc5.IsPrimary = true;
|
||||
loc4.Primarys.Add(loc5);
|
||||
}
|
||||
}
|
||||
loc4.Primarys.Sort((c1, c2) => c1.Name.CompareTo(c2.Name));
|
||||
loc4.Columns.Sort((c1, c2) =>
|
||||
{
|
||||
int compare = c2.IsPrimary.CompareTo(c1.IsPrimary);
|
||||
if (compare == 0)
|
||||
{
|
||||
bool b1 = loc4.ForeignsDict.Values.Where(fk => fk.Columns.Where(c3 => c3.Name == c1.Name).Any()).Any();
|
||||
bool b2 = loc4.ForeignsDict.Values.Where(fk => fk.Columns.Where(c3 => c3.Name == c2.Name).Any()).Any();
|
||||
compare = b2.CompareTo(b1);
|
||||
}
|
||||
if (compare == 0) compare = c1.Name.CompareTo(c2.Name);
|
||||
return compare;
|
||||
});
|
||||
loc1.Add(loc4);
|
||||
}
|
||||
loc1.Sort((t1, t2) =>
|
||||
{
|
||||
var ret = t1.Schema.CompareTo(t2.Schema);
|
||||
if (ret == 0) ret = t1.Name.CompareTo(t2.Name);
|
||||
return ret;
|
||||
});
|
||||
|
||||
loc2.Clear();
|
||||
loc3.Clear();
|
||||
return loc1;
|
||||
}
|
||||
|
||||
public List<DbEnumInfo> GetEnumsByDatabase(params string[] database)
|
||||
{
|
||||
return new List<DbEnumInfo>();
|
||||
}
|
||||
}
|
||||
}
|
456
Providers/FreeSql.Provider.Odbc/MySql/OdbcMySqlExpression.cs
Normal file
456
Providers/FreeSql.Provider.Odbc/MySql/OdbcMySqlExpression.cs
Normal file
@ -0,0 +1,456 @@
|
||||
using FreeSql.Internal;
|
||||
using FreeSql.Internal.Model;
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Linq.Expressions;
|
||||
using System.Text;
|
||||
|
||||
namespace FreeSql.Odbc.MySql
|
||||
{
|
||||
class OdbcMySqlExpression : CommonExpression
|
||||
{
|
||||
|
||||
public OdbcMySqlExpression(CommonUtils common) : base(common) { }
|
||||
|
||||
public override string ExpressionLambdaToSqlOther(Expression exp, ExpTSC tsc)
|
||||
{
|
||||
Func<Expression, string> getExp = exparg => ExpressionLambdaToSql(exparg, tsc);
|
||||
switch (exp.NodeType)
|
||||
{
|
||||
case ExpressionType.Convert:
|
||||
var operandExp = (exp as UnaryExpression)?.Operand;
|
||||
var gentype = exp.Type.NullableTypeOrThis();
|
||||
if (gentype != operandExp.Type.NullableTypeOrThis())
|
||||
{
|
||||
switch (gentype.ToString())
|
||||
{
|
||||
case "System.Boolean": return $"({getExp(operandExp)} not in ('0','false'))";
|
||||
case "System.Byte": return $"cast({getExp(operandExp)} as unsigned)";
|
||||
case "System.Char": return $"substr(cast({getExp(operandExp)} as char), 1, 1)";
|
||||
case "System.DateTime": return $"cast({getExp(operandExp)} as datetime)";
|
||||
case "System.Decimal": return $"cast({getExp(operandExp)} as decimal(36,18))";
|
||||
case "System.Double": return $"cast({getExp(operandExp)} as decimal(32,16))";
|
||||
case "System.Int16":
|
||||
case "System.Int32":
|
||||
case "System.Int64":
|
||||
case "System.SByte": return $"cast({getExp(operandExp)} as signed)";
|
||||
case "System.Single": return $"cast({getExp(operandExp)} as decimal(14,7))";
|
||||
case "System.String": return $"cast({getExp(operandExp)} as char)";
|
||||
case "System.UInt16":
|
||||
case "System.UInt32":
|
||||
case "System.UInt64": return $"cast({getExp(operandExp)} as unsigned)";
|
||||
case "System.Guid": return $"substr(cast({getExp(operandExp)} as char), 1, 36)";
|
||||
}
|
||||
}
|
||||
break;
|
||||
case ExpressionType.Call:
|
||||
var callExp = exp as MethodCallExpression;
|
||||
|
||||
switch (callExp.Method.Name)
|
||||
{
|
||||
case "Parse":
|
||||
case "TryParse":
|
||||
switch (callExp.Method.DeclaringType.NullableTypeOrThis().ToString())
|
||||
{
|
||||
case "System.Boolean": return $"({getExp(callExp.Arguments[0])} not in ('0','false'))";
|
||||
case "System.Byte": return $"cast({getExp(callExp.Arguments[0])} as unsigned)";
|
||||
case "System.Char": return $"substr(cast({getExp(callExp.Arguments[0])} as char), 1, 1)";
|
||||
case "System.DateTime": return $"cast({getExp(callExp.Arguments[0])} as datetime)";
|
||||
case "System.Decimal": return $"cast({getExp(callExp.Arguments[0])} as decimal(36,18))";
|
||||
case "System.Double": return $"cast({getExp(callExp.Arguments[0])} as decimal(32,16))";
|
||||
case "System.Int16":
|
||||
case "System.Int32":
|
||||
case "System.Int64":
|
||||
case "System.SByte": return $"cast({getExp(callExp.Arguments[0])} as signed)";
|
||||
case "System.Single": return $"cast({getExp(callExp.Arguments[0])} as decimal(14,7))";
|
||||
case "System.UInt16":
|
||||
case "System.UInt32":
|
||||
case "System.UInt64": return $"cast({getExp(callExp.Arguments[0])} as unsigned)";
|
||||
case "System.Guid": return $"substr(cast({getExp(callExp.Arguments[0])} as char), 1, 36)";
|
||||
}
|
||||
break;
|
||||
case "NewGuid":
|
||||
break;
|
||||
case "Next":
|
||||
if (callExp.Object?.Type == typeof(Random)) return "cast(rand()*1000000000 as signed)";
|
||||
break;
|
||||
case "NextDouble":
|
||||
if (callExp.Object?.Type == typeof(Random)) return "rand()";
|
||||
break;
|
||||
case "Random":
|
||||
if (callExp.Method.DeclaringType.IsNumberType()) return "rand()";
|
||||
break;
|
||||
case "ToString":
|
||||
if (callExp.Object != null) return callExp.Arguments.Count == 0 ? $"cast({getExp(callExp.Object)} as char)" : null;
|
||||
break;
|
||||
}
|
||||
|
||||
var objExp = callExp.Object;
|
||||
var objType = objExp?.Type;
|
||||
if (objType?.FullName == "System.Byte[]") return null;
|
||||
|
||||
var argIndex = 0;
|
||||
if (objType == null && callExp.Method.DeclaringType == typeof(Enumerable))
|
||||
{
|
||||
objExp = callExp.Arguments.FirstOrDefault();
|
||||
objType = objExp?.Type;
|
||||
argIndex++;
|
||||
}
|
||||
if (objType == null) objType = callExp.Method.DeclaringType;
|
||||
if (objType != null || objType.IsArray || typeof(IList).IsAssignableFrom(callExp.Method.DeclaringType))
|
||||
{
|
||||
var left = objExp == null ? null : getExp(objExp);
|
||||
switch (callExp.Method.Name)
|
||||
{
|
||||
case "Contains":
|
||||
//判断 in
|
||||
return $"({getExp(callExp.Arguments[argIndex])}) in {left}";
|
||||
}
|
||||
}
|
||||
break;
|
||||
case ExpressionType.NewArrayInit:
|
||||
var arrExp = exp as NewArrayExpression;
|
||||
var arrSb = new StringBuilder();
|
||||
arrSb.Append("(");
|
||||
for (var a = 0; a < arrExp.Expressions.Count; a++)
|
||||
{
|
||||
if (a > 0) arrSb.Append(",");
|
||||
arrSb.Append(getExp(arrExp.Expressions[a]));
|
||||
}
|
||||
if (arrSb.Length == 1) arrSb.Append("NULL");
|
||||
return arrSb.Append(")").ToString();
|
||||
case ExpressionType.ListInit:
|
||||
var listExp = exp as ListInitExpression;
|
||||
var listSb = new StringBuilder();
|
||||
listSb.Append("(");
|
||||
for (var a = 0; a < listExp.Initializers.Count; a++)
|
||||
{
|
||||
if (listExp.Initializers[a].Arguments.Any() == false) continue;
|
||||
if (a > 0) listSb.Append(",");
|
||||
listSb.Append(getExp(listExp.Initializers[a].Arguments.FirstOrDefault()));
|
||||
}
|
||||
if (listSb.Length == 1) listSb.Append("NULL");
|
||||
return listSb.Append(")").ToString();
|
||||
case ExpressionType.New:
|
||||
var newExp = exp as NewExpression;
|
||||
if (typeof(IList).IsAssignableFrom(newExp.Type))
|
||||
{
|
||||
if (newExp.Arguments.Count == 0) return "(NULL)";
|
||||
if (typeof(IEnumerable).IsAssignableFrom(newExp.Arguments[0].Type) == false) return "(NULL)";
|
||||
return getExp(newExp.Arguments[0]);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public override string ExpressionLambdaToSqlMemberAccessString(MemberExpression exp, ExpTSC tsc)
|
||||
{
|
||||
if (exp.Expression == null)
|
||||
{
|
||||
switch (exp.Member.Name)
|
||||
{
|
||||
case "Empty": return "''";
|
||||
}
|
||||
return null;
|
||||
}
|
||||
var left = ExpressionLambdaToSql(exp.Expression, tsc);
|
||||
switch (exp.Member.Name)
|
||||
{
|
||||
case "Length": return $"char_length({left})";
|
||||
}
|
||||
return null;
|
||||
}
|
||||
public override string ExpressionLambdaToSqlMemberAccessDateTime(MemberExpression exp, ExpTSC tsc)
|
||||
{
|
||||
if (exp.Expression == null)
|
||||
{
|
||||
switch (exp.Member.Name)
|
||||
{
|
||||
case "Now": return "now()";
|
||||
case "UtcNow": return "utc_timestamp()";
|
||||
case "Today": return "curdate()";
|
||||
case "MinValue": return "cast('0001/1/1 0:00:00' as datetime)";
|
||||
case "MaxValue": return "cast('9999/12/31 23:59:59' as datetime)";
|
||||
}
|
||||
return null;
|
||||
}
|
||||
var left = ExpressionLambdaToSql(exp.Expression, tsc);
|
||||
switch (exp.Member.Name)
|
||||
{
|
||||
case "Date": return $"cast(date_format({left},'%Y-%m-%d') as datetime)";
|
||||
case "TimeOfDay": return $"timestampdiff(microsecond, date_format({left},'%Y-%m-%d'), {left})";
|
||||
case "DayOfWeek": return $"(dayofweek({left})-1)";
|
||||
case "Day": return $"dayofmonth({left})";
|
||||
case "DayOfYear": return $"dayofyear({left})";
|
||||
case "Month": return $"month({left})";
|
||||
case "Year": return $"year({left})";
|
||||
case "Hour": return $"hour({left})";
|
||||
case "Minute": return $"minute({left})";
|
||||
case "Second": return $"second({left})";
|
||||
case "Millisecond": return $"floor(microsecond({left})/1000)";
|
||||
case "Ticks": return $"(timestampdiff(microsecond, '0001-1-1', {left})*10)";
|
||||
}
|
||||
return null;
|
||||
}
|
||||
public override string ExpressionLambdaToSqlMemberAccessTimeSpan(MemberExpression exp, ExpTSC tsc)
|
||||
{
|
||||
if (exp.Expression == null)
|
||||
{
|
||||
switch (exp.Member.Name)
|
||||
{
|
||||
case "Zero": return "0";
|
||||
case "MinValue": return "-922337203685477580"; //微秒 Ticks / 10
|
||||
case "MaxValue": return "922337203685477580";
|
||||
}
|
||||
return null;
|
||||
}
|
||||
var left = ExpressionLambdaToSql(exp.Expression, tsc);
|
||||
switch (exp.Member.Name)
|
||||
{
|
||||
case "Days": return $"(({left}) div {(long)1000000 * 60 * 60 * 24})";
|
||||
case "Hours": return $"(({left}) div {(long)1000000 * 60 * 60} mod 24)";
|
||||
case "Milliseconds": return $"(({left}) div 1000 mod 1000)";
|
||||
case "Minutes": return $"(({left}) div {(long)1000000 * 60} mod 60)";
|
||||
case "Seconds": return $"(({left}) div 1000000 mod 60)";
|
||||
case "Ticks": return $"(({left}) * 10)";
|
||||
case "TotalDays": return $"(({left}) / {(long)1000000 * 60 * 60 * 24})";
|
||||
case "TotalHours": return $"(({left}) / {(long)1000000 * 60 * 60})";
|
||||
case "TotalMilliseconds": return $"(({left}) / 1000)";
|
||||
case "TotalMinutes": return $"(({left}) / {(long)1000000 * 60})";
|
||||
case "TotalSeconds": return $"(({left}) / 1000000)";
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public override string ExpressionLambdaToSqlCallString(MethodCallExpression exp, ExpTSC tsc)
|
||||
{
|
||||
Func<Expression, string> getExp = exparg => ExpressionLambdaToSql(exparg, tsc);
|
||||
if (exp.Object == null)
|
||||
{
|
||||
switch (exp.Method.Name)
|
||||
{
|
||||
case "IsNullOrEmpty":
|
||||
var arg1 = getExp(exp.Arguments[0]);
|
||||
return $"({arg1} is null or {arg1} = '')";
|
||||
case "IsNullOrWhiteSpace":
|
||||
var arg2 = getExp(exp.Arguments[0]);
|
||||
return $"({arg2} is null or {arg2} = '' or ltrim({arg2}) = '')";
|
||||
case "Concat":
|
||||
return _common.StringConcat(exp.Arguments.Select(a => getExp(a)).ToArray(), null);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
var left = getExp(exp.Object);
|
||||
switch (exp.Method.Name)
|
||||
{
|
||||
case "StartsWith":
|
||||
case "EndsWith":
|
||||
case "Contains":
|
||||
var args0Value = getExp(exp.Arguments[0]);
|
||||
if (args0Value == "NULL") return $"({left}) IS NULL";
|
||||
if (exp.Method.Name == "StartsWith") return $"({left}) LIKE {(args0Value.EndsWith("'") ? args0Value.Insert(args0Value.Length - 1, "%") : $"concat({args0Value}, '%')")}";
|
||||
if (exp.Method.Name == "EndsWith") return $"({left}) LIKE {(args0Value.StartsWith("'") ? args0Value.Insert(1, "%") : $"concat('%', {args0Value})")}";
|
||||
if (args0Value.StartsWith("'") && args0Value.EndsWith("'")) return $"({left}) LIKE {args0Value.Insert(1, "%").Insert(args0Value.Length, "%")}";
|
||||
return $"({left}) LIKE concat('%', {args0Value}, '%')";
|
||||
case "ToLower": return $"lower({left})";
|
||||
case "ToUpper": return $"upper({left})";
|
||||
case "Substring":
|
||||
var substrArgs1 = getExp(exp.Arguments[0]);
|
||||
if (long.TryParse(substrArgs1, out var testtrylng1)) substrArgs1 = (testtrylng1 + 1).ToString();
|
||||
else substrArgs1 += "+1";
|
||||
if (exp.Arguments.Count == 1) return $"substr({left}, {substrArgs1})";
|
||||
return $"substr({left}, {substrArgs1}, {getExp(exp.Arguments[1])})";
|
||||
case "IndexOf":
|
||||
var indexOfFindStr = getExp(exp.Arguments[0]);
|
||||
if (exp.Arguments.Count > 1 && exp.Arguments[1].Type.FullName == "System.Int32")
|
||||
{
|
||||
var locateArgs1 = getExp(exp.Arguments[1]);
|
||||
if (long.TryParse(locateArgs1, out var testtrylng2)) locateArgs1 = (testtrylng2 + 1).ToString();
|
||||
else locateArgs1 += "+1";
|
||||
return $"(locate({left}, {indexOfFindStr}, {locateArgs1})-1)";
|
||||
}
|
||||
return $"(locate({left}, {indexOfFindStr})-1)";
|
||||
case "PadLeft":
|
||||
if (exp.Arguments.Count == 1) return $"lpad({left}, {getExp(exp.Arguments[0])})";
|
||||
return $"lpad({left}, {getExp(exp.Arguments[0])}, {getExp(exp.Arguments[1])})";
|
||||
case "PadRight":
|
||||
if (exp.Arguments.Count == 1) return $"rpad({left}, {getExp(exp.Arguments[0])})";
|
||||
return $"rpad({left}, {getExp(exp.Arguments[0])}, {getExp(exp.Arguments[1])})";
|
||||
case "Trim":
|
||||
case "TrimStart":
|
||||
case "TrimEnd":
|
||||
if (exp.Arguments.Count == 0)
|
||||
{
|
||||
if (exp.Method.Name == "Trim") return $"trim({left})";
|
||||
if (exp.Method.Name == "TrimStart") return $"ltrim({left})";
|
||||
if (exp.Method.Name == "TrimEnd") return $"rtrim({left})";
|
||||
}
|
||||
foreach (var argsTrim02 in exp.Arguments)
|
||||
{
|
||||
var argsTrim01s = new[] { argsTrim02 };
|
||||
if (argsTrim02.NodeType == ExpressionType.NewArrayInit)
|
||||
{
|
||||
var arritem = argsTrim02 as NewArrayExpression;
|
||||
argsTrim01s = arritem.Expressions.ToArray();
|
||||
}
|
||||
foreach (var argsTrim01 in argsTrim01s)
|
||||
{
|
||||
if (exp.Method.Name == "Trim") left = $"trim({getExp(argsTrim01)} from {left})";
|
||||
if (exp.Method.Name == "TrimStart") left = $"trim(leading {getExp(argsTrim01)} from {left})";
|
||||
if (exp.Method.Name == "TrimEnd") left = $"trim(trailing {getExp(argsTrim01)} from {left})";
|
||||
}
|
||||
}
|
||||
return left;
|
||||
case "Replace": return $"replace({left}, {getExp(exp.Arguments[0])}, {getExp(exp.Arguments[1])})";
|
||||
case "CompareTo": return $"strcmp({left}, {getExp(exp.Arguments[0])})";
|
||||
case "Equals": return $"({left} = {getExp(exp.Arguments[0])})";
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
public override string ExpressionLambdaToSqlCallMath(MethodCallExpression exp, ExpTSC tsc)
|
||||
{
|
||||
Func<Expression, string> getExp = exparg => ExpressionLambdaToSql(exparg, tsc);
|
||||
switch (exp.Method.Name)
|
||||
{
|
||||
case "Abs": return $"abs({getExp(exp.Arguments[0])})";
|
||||
case "Sign": return $"sign({getExp(exp.Arguments[0])})";
|
||||
case "Floor": return $"floor({getExp(exp.Arguments[0])})";
|
||||
case "Ceiling": return $"ceiling({getExp(exp.Arguments[0])})";
|
||||
case "Round":
|
||||
if (exp.Arguments.Count > 1 && exp.Arguments[1].Type.FullName == "System.Int32") return $"round({getExp(exp.Arguments[0])}, {getExp(exp.Arguments[1])})";
|
||||
return $"round({getExp(exp.Arguments[0])})";
|
||||
case "Exp": return $"exp({getExp(exp.Arguments[0])})";
|
||||
case "Log": return $"log({getExp(exp.Arguments[0])})";
|
||||
case "Log10": return $"log10({getExp(exp.Arguments[0])})";
|
||||
case "Pow": return $"pow({getExp(exp.Arguments[0])}, {getExp(exp.Arguments[1])})";
|
||||
case "Sqrt": return $"sqrt({getExp(exp.Arguments[0])})";
|
||||
case "Cos": return $"cos({getExp(exp.Arguments[0])})";
|
||||
case "Sin": return $"sin({getExp(exp.Arguments[0])})";
|
||||
case "Tan": return $"tan({getExp(exp.Arguments[0])})";
|
||||
case "Acos": return $"acos({getExp(exp.Arguments[0])})";
|
||||
case "Asin": return $"asin({getExp(exp.Arguments[0])})";
|
||||
case "Atan": return $"atan({getExp(exp.Arguments[0])})";
|
||||
case "Atan2": return $"atan2({getExp(exp.Arguments[0])}, {getExp(exp.Arguments[1])})";
|
||||
case "Truncate": return $"truncate({getExp(exp.Arguments[0])}, 0)";
|
||||
}
|
||||
return null;
|
||||
}
|
||||
public override string ExpressionLambdaToSqlCallDateTime(MethodCallExpression exp, ExpTSC tsc)
|
||||
{
|
||||
Func<Expression, string> getExp = exparg => ExpressionLambdaToSql(exparg, tsc);
|
||||
if (exp.Object == null)
|
||||
{
|
||||
switch (exp.Method.Name)
|
||||
{
|
||||
case "Compare": return $"({getExp(exp.Arguments[0])} - ({getExp(exp.Arguments[1])}))";
|
||||
case "DaysInMonth": return $"dayofmonth(last_day(concat({getExp(exp.Arguments[0])}, '-', {getExp(exp.Arguments[1])}, '-01')))";
|
||||
case "Equals": return $"({getExp(exp.Arguments[0])} = {getExp(exp.Arguments[1])})";
|
||||
|
||||
case "IsLeapYear":
|
||||
var isLeapYearArgs1 = getExp(exp.Arguments[0]);
|
||||
return $"(({isLeapYearArgs1})%4=0 AND ({isLeapYearArgs1})%100<>0 OR ({isLeapYearArgs1})%400=0)";
|
||||
|
||||
case "Parse": return $"cast({getExp(exp.Arguments[0])} as datetime)";
|
||||
case "ParseExact":
|
||||
case "TryParse":
|
||||
case "TryParseExact": return $"cast({getExp(exp.Arguments[0])} as datetime)";
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
var left = getExp(exp.Object);
|
||||
var args1 = exp.Arguments.Count == 0 ? null : getExp(exp.Arguments[0]);
|
||||
switch (exp.Method.Name)
|
||||
{
|
||||
case "Add": return $"date_add({left}, interval ({args1}) microsecond)";
|
||||
case "AddDays": return $"date_add({left}, interval ({args1}) day)";
|
||||
case "AddHours": return $"date_add({left}, interval ({args1}) hour)";
|
||||
case "AddMilliseconds": return $"date_add({left}, interval ({args1})*1000 microsecond)";
|
||||
case "AddMinutes": return $"date_add({left}, interval ({args1}) minute)";
|
||||
case "AddMonths": return $"date_add({left}, interval ({args1}) month)";
|
||||
case "AddSeconds": return $"date_add({left}, interval ({args1}) second)";
|
||||
case "AddTicks": return $"date_add({left}, interval ({args1})/10 microsecond)";
|
||||
case "AddYears": return $"date_add({left}, interval ({args1}) year)";
|
||||
case "Subtract":
|
||||
switch ((exp.Arguments[0].Type.IsNullableType() ? exp.Arguments[0].Type.GenericTypeArguments.FirstOrDefault() : exp.Arguments[0].Type).FullName)
|
||||
{
|
||||
case "System.DateTime": return $"timestampdiff(microsecond, {args1}, {left})";
|
||||
case "System.TimeSpan": return $"date_sub({left}, interval ({args1}) microsecond)";
|
||||
}
|
||||
break;
|
||||
case "Equals": return $"({left} = {getExp(exp.Arguments[0])})";
|
||||
case "CompareTo": return $"timestampdiff(microsecond,{args1},{left})";
|
||||
case "ToString": return exp.Arguments.Count == 0 ? $"date_format({left}, '%Y-%m-%d %H:%i:%s.%f')" : null;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
public override string ExpressionLambdaToSqlCallTimeSpan(MethodCallExpression exp, ExpTSC tsc)
|
||||
{
|
||||
Func<Expression, string> getExp = exparg => ExpressionLambdaToSql(exparg, tsc);
|
||||
if (exp.Object == null)
|
||||
{
|
||||
switch (exp.Method.Name)
|
||||
{
|
||||
case "Compare": return $"({getExp(exp.Arguments[0])}-({getExp(exp.Arguments[1])}))";
|
||||
case "Equals": return $"({getExp(exp.Arguments[0])} = {getExp(exp.Arguments[1])})";
|
||||
case "FromDays": return $"(({getExp(exp.Arguments[0])})*{(long)1000000 * 60 * 60 * 24})";
|
||||
case "FromHours": return $"(({getExp(exp.Arguments[0])})*{(long)1000000 * 60 * 60})";
|
||||
case "FromMilliseconds": return $"(({getExp(exp.Arguments[0])})*1000)";
|
||||
case "FromMinutes": return $"(({getExp(exp.Arguments[0])})*{(long)1000000 * 60})";
|
||||
case "FromSeconds": return $"(({getExp(exp.Arguments[0])})*1000000)";
|
||||
case "FromTicks": return $"(({getExp(exp.Arguments[0])})/10)";
|
||||
case "Parse": return $"cast({getExp(exp.Arguments[0])} as signed)";
|
||||
case "ParseExact":
|
||||
case "TryParse":
|
||||
case "TryParseExact": return $"cast({getExp(exp.Arguments[0])} as signed)";
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
var left = getExp(exp.Object);
|
||||
var args1 = exp.Arguments.Count == 0 ? null : getExp(exp.Arguments[0]);
|
||||
switch (exp.Method.Name)
|
||||
{
|
||||
case "Add": return $"({left}+{args1})";
|
||||
case "Subtract": return $"({left}-({args1}))";
|
||||
case "Equals": return $"({left} = {getExp(exp.Arguments[0])})";
|
||||
case "CompareTo": return $"({left}-({getExp(exp.Arguments[0])}))";
|
||||
case "ToString": return $"cast({left} as char)";
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
public override string ExpressionLambdaToSqlCallConvert(MethodCallExpression exp, ExpTSC tsc)
|
||||
{
|
||||
Func<Expression, string> getExp = exparg => ExpressionLambdaToSql(exparg, tsc);
|
||||
if (exp.Object == null)
|
||||
{
|
||||
switch (exp.Method.Name)
|
||||
{
|
||||
case "ToBoolean": return $"({getExp(exp.Arguments[0])} not in ('0','false'))";
|
||||
case "ToByte": return $"cast({getExp(exp.Arguments[0])} as unsigned)";
|
||||
case "ToChar": return $"substr(cast({getExp(exp.Arguments[0])} as char), 1, 1)";
|
||||
case "ToDateTime": return $"cast({getExp(exp.Arguments[0])} as datetime)";
|
||||
case "ToDecimal": return $"cast({getExp(exp.Arguments[0])} as decimal(36,18))";
|
||||
case "ToDouble": return $"cast({getExp(exp.Arguments[0])} as decimal(32,16))";
|
||||
case "ToInt16":
|
||||
case "ToInt32":
|
||||
case "ToInt64":
|
||||
case "ToSByte": return $"cast({getExp(exp.Arguments[0])} as signed)";
|
||||
case "ToSingle": return $"cast({getExp(exp.Arguments[0])} as decimal(14,7))";
|
||||
case "ToString": return $"cast({getExp(exp.Arguments[0])} as char)";
|
||||
case "ToUInt16":
|
||||
case "ToUInt32":
|
||||
case "ToUInt64": return $"cast({getExp(exp.Arguments[0])} as unsigned)";
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
63
Providers/FreeSql.Provider.Odbc/MySql/OdbcMySqlProvider.cs
Normal file
63
Providers/FreeSql.Provider.Odbc/MySql/OdbcMySqlProvider.cs
Normal file
@ -0,0 +1,63 @@
|
||||
using FreeSql.Internal;
|
||||
using FreeSql.Internal.CommonProvider;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data.Common;
|
||||
using System.Linq.Expressions;
|
||||
|
||||
namespace FreeSql.Odbc.MySql
|
||||
{
|
||||
|
||||
public class OdbcMySqlProvider<TMark> : IFreeSql<TMark>
|
||||
{
|
||||
|
||||
static OdbcMySqlProvider()
|
||||
{
|
||||
}
|
||||
|
||||
public ISelect<T1> Select<T1>() where T1 : class => new OdbcMySqlSelect<T1>(this, this.InternalCommonUtils, this.InternalCommonExpression, null);
|
||||
public ISelect<T1> Select<T1>(object dywhere) where T1 : class => new OdbcMySqlSelect<T1>(this, this.InternalCommonUtils, this.InternalCommonExpression, dywhere);
|
||||
public IInsert<T1> Insert<T1>() where T1 : class => new OdbcMySqlInsert<T1>(this, this.InternalCommonUtils, this.InternalCommonExpression);
|
||||
public IInsert<T1> Insert<T1>(T1 source) where T1 : class => this.Insert<T1>().AppendData(source);
|
||||
public IInsert<T1> Insert<T1>(T1[] source) where T1 : class => this.Insert<T1>().AppendData(source);
|
||||
public IInsert<T1> Insert<T1>(IEnumerable<T1> source) where T1 : class => this.Insert<T1>().AppendData(source);
|
||||
public IUpdate<T1> Update<T1>() where T1 : class => new OdbcMySqlUpdate<T1>(this, this.InternalCommonUtils, this.InternalCommonExpression, null);
|
||||
public IUpdate<T1> Update<T1>(object dywhere) where T1 : class => new OdbcMySqlUpdate<T1>(this, this.InternalCommonUtils, this.InternalCommonExpression, dywhere);
|
||||
public IDelete<T1> Delete<T1>() where T1 : class => new OdbcMySqlDelete<T1>(this, this.InternalCommonUtils, this.InternalCommonExpression, null);
|
||||
public IDelete<T1> Delete<T1>(object dywhere) where T1 : class => new OdbcMySqlDelete<T1>(this, this.InternalCommonUtils, this.InternalCommonExpression, dywhere);
|
||||
|
||||
public IAdo Ado { get; }
|
||||
public IAop Aop { get; }
|
||||
public ICodeFirst CodeFirst { get; }
|
||||
public IDbFirst DbFirst { get; }
|
||||
public OdbcMySqlProvider(string masterConnectionString, string[] slaveConnectionString)
|
||||
{
|
||||
this.InternalCommonUtils = new OdbcMySqlUtils(this);
|
||||
this.InternalCommonExpression = new OdbcMySqlExpression(this.InternalCommonUtils);
|
||||
|
||||
this.Ado = new OdbcMySqlAdo(this.InternalCommonUtils, masterConnectionString, slaveConnectionString);
|
||||
this.Aop = new AopProvider();
|
||||
|
||||
this.DbFirst = new OdbcMySqlDbFirst(this, this.InternalCommonUtils, this.InternalCommonExpression);
|
||||
this.CodeFirst = new OdbcMySqlCodeFirst(this, this.InternalCommonUtils, this.InternalCommonExpression);
|
||||
}
|
||||
|
||||
internal CommonUtils InternalCommonUtils { get; }
|
||||
internal CommonExpression InternalCommonExpression { get; }
|
||||
|
||||
public void Transaction(Action handler) => Ado.Transaction(handler);
|
||||
|
||||
public void Transaction(Action handler, TimeSpan timeout) => Ado.Transaction(handler, timeout);
|
||||
|
||||
~OdbcMySqlProvider()
|
||||
{
|
||||
this.Dispose();
|
||||
}
|
||||
bool _isdisposed = false;
|
||||
public void Dispose()
|
||||
{
|
||||
if (_isdisposed) return;
|
||||
(this.Ado as AdoProvider)?.Dispose();
|
||||
}
|
||||
}
|
||||
}
|
112
Providers/FreeSql.Provider.Odbc/MySql/OdbcMySqlUtils.cs
Normal file
112
Providers/FreeSql.Provider.Odbc/MySql/OdbcMySqlUtils.cs
Normal file
@ -0,0 +1,112 @@
|
||||
using FreeSql.Internal;
|
||||
using FreeSql.Internal.Model;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data.Common;
|
||||
using System.Data.Odbc;
|
||||
using System.Linq;
|
||||
using System.Linq.Expressions;
|
||||
using System.Reflection;
|
||||
using System.Text;
|
||||
|
||||
namespace FreeSql.Odbc.MySql
|
||||
{
|
||||
|
||||
class OdbcMySqlUtils : CommonUtils
|
||||
{
|
||||
public OdbcMySqlUtils(IFreeSql orm) : base(orm)
|
||||
{
|
||||
}
|
||||
|
||||
public override DbParameter AppendParamter(List<DbParameter> _params, string parameterName, Type type, object value)
|
||||
{
|
||||
if (string.IsNullOrEmpty(parameterName)) parameterName = $"p_{_params?.Count}";
|
||||
var ret = new OdbcParameter { ParameterName = QuoteParamterName(parameterName), Value = value };
|
||||
var tp = _orm.CodeFirst.GetDbInfo(type)?.type;
|
||||
if (tp != null)
|
||||
ret.OdbcType = (OdbcType)tp.Value;
|
||||
_params?.Add(ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
public override DbParameter[] GetDbParamtersByObject(string sql, object obj) =>
|
||||
Utils.GetDbParamtersByObject<OdbcParameter>(sql, obj, null, (name, type, value) =>
|
||||
{
|
||||
var ret = new OdbcParameter { ParameterName = $"?{name}", Value = value };
|
||||
var tp = _orm.CodeFirst.GetDbInfo(type)?.type;
|
||||
if (tp != null)
|
||||
ret.OdbcType = (OdbcType)tp.Value;
|
||||
return ret;
|
||||
});
|
||||
|
||||
public override string FormatSql(string sql, params object[] args) => sql?.FormatOdbcMySql(args);
|
||||
public override string QuoteSqlName(string name)
|
||||
{
|
||||
var nametrim = name.Trim();
|
||||
if (nametrim.StartsWith("(") && nametrim.EndsWith(")"))
|
||||
return nametrim; //原生SQL
|
||||
return $"`{nametrim.Trim('`').Replace(".", "`.`")}`";
|
||||
}
|
||||
public override string TrimQuoteSqlName(string name)
|
||||
{
|
||||
var nametrim = name.Trim();
|
||||
if (nametrim.StartsWith("(") && nametrim.EndsWith(")"))
|
||||
return nametrim; //原生SQL
|
||||
return $"{nametrim.Trim('`').Replace("`.`", ".").Replace(".`", ".")}";
|
||||
}
|
||||
public override string QuoteParamterName(string name) => $"?{(_orm.CodeFirst.IsSyncStructureToLower ? name.ToLower() : name)}";
|
||||
public override string IsNull(string sql, object value) => $"ifnull({sql}, {value})";
|
||||
public override string StringConcat(string[] objs, Type[] types) => $"concat({string.Join(", ", objs)})";
|
||||
public override string Mod(string left, string right, Type leftType, Type rightType) => $"{left} % {right}";
|
||||
public override string Div(string left, string right, Type leftType, Type rightType) => $"{left} div {right}";
|
||||
|
||||
public override string QuoteWriteParamter(Type type, string paramterName)
|
||||
{
|
||||
switch (type.FullName)
|
||||
{
|
||||
case "MygisPoint":
|
||||
case "MygisLineString":
|
||||
case "MygisPolygon":
|
||||
case "MygisMultiPoint":
|
||||
case "MygisMultiLineString":
|
||||
case "MygisMultiPolygon": return $"ST_GeomFromText({paramterName})";
|
||||
}
|
||||
return paramterName;
|
||||
}
|
||||
public override string QuoteReadColumn(Type type, string columnName)
|
||||
{
|
||||
switch (type.FullName)
|
||||
{
|
||||
case "MygisPoint":
|
||||
case "MygisLineString":
|
||||
case "MygisPolygon":
|
||||
case "MygisMultiPoint":
|
||||
case "MygisMultiLineString":
|
||||
case "MygisMultiPolygon": return $"ST_AsText({columnName})";
|
||||
}
|
||||
return columnName;
|
||||
}
|
||||
|
||||
public override string GetNoneParamaterSqlValue(List<DbParameter> specialParams, Type type, object value)
|
||||
{
|
||||
if (value == null) return "NULL";
|
||||
if (type == typeof(byte[]))
|
||||
{
|
||||
var bytes = value as byte[];
|
||||
var sb = new StringBuilder().Append("0x");
|
||||
foreach (var vc in bytes)
|
||||
{
|
||||
if (vc < 10) sb.Append("0");
|
||||
sb.Append(vc.ToString("X"));
|
||||
}
|
||||
return sb.ToString(); //val = Encoding.UTF8.GetString(val as byte[]);
|
||||
}
|
||||
else if (type == typeof(TimeSpan) || type == typeof(TimeSpan?))
|
||||
{
|
||||
var ts = (TimeSpan)value;
|
||||
value = $"{Math.Floor(ts.TotalHours)}:{ts.Minutes}:{ts.Seconds}";
|
||||
}
|
||||
return FormatSql("{0}", value, 1);
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,27 @@
|
||||
using FreeSql.Internal;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace FreeSql.Odbc.Oracle
|
||||
{
|
||||
|
||||
class OdbcOracleDelete<T1> : Internal.CommonProvider.DeleteProvider<T1> where T1 : class
|
||||
{
|
||||
public OdbcOracleDelete(IFreeSql orm, CommonUtils commonUtils, CommonExpression commonExpression, object dywhere)
|
||||
: base(orm, commonUtils, commonExpression, dywhere)
|
||||
{
|
||||
}
|
||||
|
||||
public override List<T1> ExecuteDeleted()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
public override Task<List<T1>> ExecuteDeletedAsync()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
}
|
211
Providers/FreeSql.Provider.Odbc/Oracle/Curd/OdbcOracleInsert.cs
Normal file
211
Providers/FreeSql.Provider.Odbc/Oracle/Curd/OdbcOracleInsert.cs
Normal file
@ -0,0 +1,211 @@
|
||||
using FreeSql.Internal;
|
||||
using FreeSql.Internal.Model;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
using System.Data.Common;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace FreeSql.Odbc.Oracle
|
||||
{
|
||||
|
||||
class OdbcOracleInsert<T1> : Internal.CommonProvider.InsertProvider<T1> where T1 : class
|
||||
{
|
||||
public OdbcOracleInsert(IFreeSql orm, CommonUtils commonUtils, CommonExpression commonExpression)
|
||||
: base(orm, commonUtils, commonExpression)
|
||||
{
|
||||
}
|
||||
|
||||
public override int ExecuteAffrows() => base.SplitExecuteAffrows(500, 999);
|
||||
public override Task<int> ExecuteAffrowsAsync() => base.SplitExecuteAffrowsAsync(500, 999);
|
||||
public override long ExecuteIdentity() => base.SplitExecuteIdentity(500, 999);
|
||||
public override Task<long> ExecuteIdentityAsync() => base.SplitExecuteIdentityAsync(500, 999);
|
||||
public override List<T1> ExecuteInserted() => base.SplitExecuteInserted(500, 999);
|
||||
public override Task<List<T1>> ExecuteInsertedAsync() => base.SplitExecuteInsertedAsync(500, 999);
|
||||
|
||||
|
||||
public override string ToSql()
|
||||
{
|
||||
if (_source == null || _source.Any() == false) return null;
|
||||
var sb = new StringBuilder();
|
||||
sb.Append("INSERT ");
|
||||
if (_source.Count > 1) sb.Append("ALL");
|
||||
|
||||
_identCol = null;
|
||||
var sbtb = new StringBuilder();
|
||||
sbtb.Append("INTO ");
|
||||
sbtb.Append(_commonUtils.QuoteSqlName(TableRuleInvoke())).Append("(");
|
||||
var colidx = 0;
|
||||
foreach (var col in _table.Columns.Values)
|
||||
{
|
||||
if (col.Attribute.IsIdentity) _identCol = col;
|
||||
if (_ignore.ContainsKey(col.Attribute.Name)) continue;
|
||||
if (col.Attribute.IsIdentity && _insertIdentity == false) continue;
|
||||
|
||||
if (colidx > 0) sbtb.Append(", ");
|
||||
sbtb.Append(_commonUtils.QuoteSqlName(col.Attribute.Name));
|
||||
++colidx;
|
||||
}
|
||||
sbtb.Append(") ");
|
||||
|
||||
_params = _noneParameter ? new DbParameter[0] : new DbParameter[colidx * _source.Count];
|
||||
var specialParams = new List<DbParameter>();
|
||||
var didx = 0;
|
||||
foreach (var d in _source)
|
||||
{
|
||||
if (_source.Count > 1) sb.Append("\r\n");
|
||||
sb.Append(sbtb);
|
||||
sb.Append("VALUES");
|
||||
sb.Append("(");
|
||||
var colidx2 = 0;
|
||||
foreach (var col in _table.Columns.Values)
|
||||
{
|
||||
if (_ignore.ContainsKey(col.Attribute.Name)) continue;
|
||||
if (col.Attribute.IsIdentity && _insertIdentity == false) continue;
|
||||
|
||||
if (colidx2 > 0) sb.Append(", ");
|
||||
object val = col.GetMapValue(d);
|
||||
if (_noneParameter)
|
||||
sb.Append(_commonUtils.GetNoneParamaterSqlValue(specialParams, col.Attribute.MapType, val));
|
||||
else
|
||||
{
|
||||
sb.Append(_commonUtils.QuoteWriteParamter(col.Attribute.MapType, _commonUtils.QuoteParamterName($"{col.CsName}_{didx}")));
|
||||
_params[didx * colidx + colidx2] = _commonUtils.AppendParamter(null, $"{col.CsName}_{didx}", col.Attribute.MapType, val);
|
||||
}
|
||||
++colidx2;
|
||||
}
|
||||
sb.Append(")");
|
||||
++didx;
|
||||
}
|
||||
if (_source.Count > 1) sb.Append("\r\n SELECT 1 FROM DUAL");
|
||||
return sb.ToString();
|
||||
}
|
||||
|
||||
ColumnInfo _identCol;
|
||||
protected override long RawExecuteIdentity()
|
||||
{
|
||||
var sql = this.ToSql();
|
||||
if (string.IsNullOrEmpty(sql)) return 0;
|
||||
|
||||
long ret = 0;
|
||||
Exception exception = null;
|
||||
Aop.CurdBeforeEventArgs before = null;
|
||||
|
||||
if (_identCol == null || _source.Count > 1)
|
||||
{
|
||||
before = new Aop.CurdBeforeEventArgs(_table.Type, Aop.CurdType.Insert, sql, _params);
|
||||
_orm.Aop.CurdBefore?.Invoke(this, before);
|
||||
try
|
||||
{
|
||||
ret = _orm.Ado.ExecuteNonQuery(_connection, _transaction, CommandType.Text, sql, _params);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
exception = ex;
|
||||
throw ex;
|
||||
}
|
||||
finally
|
||||
{
|
||||
var after = new Aop.CurdAfterEventArgs(before, exception, ret);
|
||||
_orm.Aop.CurdAfter?.Invoke(this, after);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
var identColName = _commonUtils.QuoteSqlName(_identCol.Attribute.Name);
|
||||
var identParam = _commonUtils.AppendParamter(null, $"{_identCol.CsName}99", _identCol.Attribute.MapType, 0);
|
||||
identParam.Direction = ParameterDirection.Output;
|
||||
sql = $"{sql} RETURNING {identColName} INTO {identParam.ParameterName}";
|
||||
var dbParms = _params.Concat(new[] { identParam }).ToArray();
|
||||
before = new Aop.CurdBeforeEventArgs(_table.Type, Aop.CurdType.Insert, sql, dbParms);
|
||||
_orm.Aop.CurdBefore?.Invoke(this, before);
|
||||
try
|
||||
{
|
||||
_orm.Ado.ExecuteNonQuery(_connection, _transaction, CommandType.Text, sql, dbParms);
|
||||
long.TryParse(string.Concat(identParam.Value), out ret);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
exception = ex;
|
||||
throw ex;
|
||||
}
|
||||
finally
|
||||
{
|
||||
var after = new Aop.CurdAfterEventArgs(before, exception, ret);
|
||||
_orm.Aop.CurdAfter?.Invoke(this, after);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
async protected override Task<long> RawExecuteIdentityAsync()
|
||||
{
|
||||
var sql = this.ToSql();
|
||||
if (string.IsNullOrEmpty(sql)) return 0;
|
||||
|
||||
long ret = 0;
|
||||
Exception exception = null;
|
||||
Aop.CurdBeforeEventArgs before = null;
|
||||
|
||||
if (_identCol == null || _source.Count > 1)
|
||||
{
|
||||
before = new Aop.CurdBeforeEventArgs(_table.Type, Aop.CurdType.Insert, sql, _params);
|
||||
_orm.Aop.CurdBefore?.Invoke(this, before);
|
||||
try
|
||||
{
|
||||
ret = await _orm.Ado.ExecuteNonQueryAsync(_connection, _transaction, CommandType.Text, sql, _params);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
exception = ex;
|
||||
throw ex;
|
||||
}
|
||||
finally
|
||||
{
|
||||
var after = new Aop.CurdAfterEventArgs(before, exception, ret);
|
||||
_orm.Aop.CurdAfter?.Invoke(this, after);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
var identColName = _commonUtils.QuoteSqlName(_identCol.Attribute.Name);
|
||||
var identParam = _commonUtils.AppendParamter(null, $"{_identCol.CsName}99", _identCol.Attribute.MapType, 0);
|
||||
identParam.Direction = ParameterDirection.Output;
|
||||
sql = $"{sql} RETURNING {identColName} INTO {identParam.ParameterName}";
|
||||
var dbParms = _params.Concat(new[] { identParam }).ToArray();
|
||||
before = new Aop.CurdBeforeEventArgs(_table.Type, Aop.CurdType.Insert, sql, dbParms);
|
||||
_orm.Aop.CurdBefore?.Invoke(this, before);
|
||||
try
|
||||
{
|
||||
await _orm.Ado.ExecuteNonQueryAsync(_connection, _transaction, CommandType.Text, sql, dbParms);
|
||||
long.TryParse(string.Concat(identParam.Value), out ret);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
exception = ex;
|
||||
throw ex;
|
||||
}
|
||||
finally
|
||||
{
|
||||
var after = new Aop.CurdAfterEventArgs(before, exception, ret);
|
||||
_orm.Aop.CurdAfter?.Invoke(this, after);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
protected override List<T1> RawExecuteInserted()
|
||||
{
|
||||
var sql = this.ToSql();
|
||||
if (string.IsNullOrEmpty(sql)) return new List<T1>();
|
||||
|
||||
this.RawExecuteAffrows();
|
||||
return _source;
|
||||
}
|
||||
async protected override Task<List<T1>> RawExecuteInsertedAsync()
|
||||
{
|
||||
var sql = this.ToSql();
|
||||
if (string.IsNullOrEmpty(sql)) return new List<T1>();
|
||||
|
||||
await this.RawExecuteAffrowsAsync();
|
||||
return _source;
|
||||
}
|
||||
}
|
||||
}
|
185
Providers/FreeSql.Provider.Odbc/Oracle/Curd/OdbcOracleSelect.cs
Normal file
185
Providers/FreeSql.Provider.Odbc/Oracle/Curd/OdbcOracleSelect.cs
Normal file
@ -0,0 +1,185 @@
|
||||
using FreeSql.Internal;
|
||||
using FreeSql.Internal.Model;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Linq.Expressions;
|
||||
using System.Text;
|
||||
|
||||
namespace FreeSql.Odbc.Oracle
|
||||
{
|
||||
|
||||
class OdbcOracleSelect<T1> : FreeSql.Internal.CommonProvider.Select1Provider<T1> where T1 : class
|
||||
{
|
||||
|
||||
internal static string ToSqlStatic(CommonUtils _commonUtils, CommonExpression _commonExpression, string _select, bool _distinct, string field, StringBuilder _join, StringBuilder _where, string _groupby, string _having, string _orderby, int _skip, int _limit, List<SelectTableInfo> _tables, List<Dictionary<Type, string>> tbUnions, List<LambdaExpression> _whereCascadeExpression, IFreeSql _orm)
|
||||
{
|
||||
if (_orm.CodeFirst.IsAutoSyncStructure)
|
||||
_orm.CodeFirst.SyncStructure(_tables.Select(a => a.Table.Type).ToArray());
|
||||
|
||||
if (_whereCascadeExpression.Any())
|
||||
foreach (var tb in _tables.Where(a => a.Type != SelectTableInfoType.Parent))
|
||||
tb.Cascade = _commonExpression.GetWhereCascadeSql(tb, _whereCascadeExpression);
|
||||
|
||||
var sb = new StringBuilder();
|
||||
var tbUnionsGt0 = tbUnions.Count > 1;
|
||||
for (var tbUnionsIdx = 0; tbUnionsIdx < tbUnions.Count; tbUnionsIdx++)
|
||||
{
|
||||
if (tbUnionsIdx > 0) sb.Append(" \r\n\r\nUNION ALL\r\n\r\n");
|
||||
if (tbUnionsGt0) sb.Append("select * from (");
|
||||
var tbUnion = tbUnions[tbUnionsIdx];
|
||||
|
||||
var sbnav = new StringBuilder();
|
||||
sb.Append(_select);
|
||||
if (_distinct) sb.Append("DISTINCT ");
|
||||
sb.Append(field);
|
||||
if (string.IsNullOrEmpty(_orderby) && _skip > 0) sb.Append(", ROWNUM AS \"__rownum__\"");
|
||||
sb.Append(" \r\nFROM ");
|
||||
var tbsjoin = _tables.Where(a => a.Type != SelectTableInfoType.From).ToArray();
|
||||
var tbsfrom = _tables.Where(a => a.Type == SelectTableInfoType.From).ToArray();
|
||||
for (var a = 0; a < tbsfrom.Length; a++)
|
||||
{
|
||||
sb.Append(_commonUtils.QuoteSqlName(tbUnion[tbsfrom[a].Table.Type])).Append(" ").Append(tbsfrom[a].Alias);
|
||||
if (tbsjoin.Length > 0)
|
||||
{
|
||||
//如果存在 join 查询,则处理 from t1, t2 改为 from t1 inner join t2 on 1 = 1
|
||||
for (var b = 1; b < tbsfrom.Length; b++)
|
||||
{
|
||||
sb.Append(" \r\nLEFT JOIN ").Append(_commonUtils.QuoteSqlName(tbUnion[tbsfrom[b].Table.Type])).Append(" ").Append(tbsfrom[b].Alias);
|
||||
|
||||
if (string.IsNullOrEmpty(tbsfrom[b].NavigateCondition) && string.IsNullOrEmpty(tbsfrom[b].On) && string.IsNullOrEmpty(tbsfrom[b].Cascade)) sb.Append(" ON 1 = 1");
|
||||
else
|
||||
{
|
||||
sb.Append(" ON ").Append(tbsfrom[b].NavigateCondition ?? tbsfrom[b].On);
|
||||
if (string.IsNullOrEmpty(tbsfrom[b].Cascade) == false) sb.Append(" AND (").Append(tbsfrom[b].Cascade).Append(")");
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!string.IsNullOrEmpty(tbsfrom[a].NavigateCondition)) sbnav.Append(" AND (").Append(tbsfrom[a].NavigateCondition).Append(")");
|
||||
if (!string.IsNullOrEmpty(tbsfrom[a].On)) sbnav.Append(" AND (").Append(tbsfrom[a].On).Append(")");
|
||||
if (a > 0 && !string.IsNullOrEmpty(tbsfrom[a].Cascade)) sbnav.Append(" AND (").Append(tbsfrom[a].Cascade).Append(")");
|
||||
}
|
||||
if (a < tbsfrom.Length - 1) sb.Append(", ");
|
||||
}
|
||||
foreach (var tb in tbsjoin)
|
||||
{
|
||||
if (tb.Type == SelectTableInfoType.Parent) continue;
|
||||
switch (tb.Type)
|
||||
{
|
||||
case SelectTableInfoType.LeftJoin:
|
||||
sb.Append(" \r\nLEFT JOIN ");
|
||||
break;
|
||||
case SelectTableInfoType.InnerJoin:
|
||||
sb.Append(" \r\nINNER JOIN ");
|
||||
break;
|
||||
case SelectTableInfoType.RightJoin:
|
||||
sb.Append(" \r\nRIGHT JOIN ");
|
||||
break;
|
||||
}
|
||||
sb.Append(_commonUtils.QuoteSqlName(tbUnion[tb.Table.Type])).Append(" ").Append(tb.Alias).Append(" ON ").Append(tb.On ?? tb.NavigateCondition);
|
||||
if (!string.IsNullOrEmpty(tb.Cascade)) sb.Append(" AND (").Append(tb.Cascade).Append(")");
|
||||
if (!string.IsNullOrEmpty(tb.On) && !string.IsNullOrEmpty(tb.NavigateCondition)) sbnav.Append(" AND (").Append(tb.NavigateCondition).Append(")");
|
||||
}
|
||||
if (_join.Length > 0) sb.Append(_join);
|
||||
|
||||
sbnav.Append(_where);
|
||||
if (!string.IsNullOrEmpty(_tables[0].Cascade))
|
||||
sbnav.Append(" AND (").Append(_tables[0].Cascade).Append(")");
|
||||
|
||||
foreach (var tb in _tables)
|
||||
{
|
||||
if (tb.Type == SelectTableInfoType.Parent) continue;
|
||||
if (string.IsNullOrEmpty(tb.Table.SelectFilter) == false)
|
||||
sbnav.Append(" AND (").Append(tb.Table.SelectFilter.Replace("a.", $"{tb.Alias}.")).Append(")");
|
||||
}
|
||||
if (string.IsNullOrEmpty(_orderby) && (_skip > 0 || _limit > 0))
|
||||
sbnav.Append(" AND ROWNUM < ").Append(_skip + _limit + 1);
|
||||
if (sbnav.Length > 0)
|
||||
sb.Append(" \r\nWHERE ").Append(sbnav.Remove(0, 5));
|
||||
if (string.IsNullOrEmpty(_groupby) == false)
|
||||
{
|
||||
sb.Append(_groupby);
|
||||
if (string.IsNullOrEmpty(_having) == false)
|
||||
sb.Append(" \r\nHAVING ").Append(_having.Substring(5));
|
||||
}
|
||||
sb.Append(_orderby);
|
||||
|
||||
if (string.IsNullOrEmpty(_orderby))
|
||||
{
|
||||
if (_skip > 0)
|
||||
sb.Insert(0, "SELECT t.* FROM (").Append(") t WHERE t.\"__rownum__\" > ").Append(_skip);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (_skip > 0 && _limit > 0) sb.Insert(0, "SELECT t.* FROM (SELECT rt.*, ROWNUM AS \"__rownum__\" FROM (").Append(") rt WHERE ROWNUM < ").Append(_skip + _limit + 1).Append(") t WHERE t.\"__rownum__\" > ").Append(_skip);
|
||||
else if (_skip > 0) sb.Insert(0, "SELECT t.* FROM (").Append(") t WHERE ROWNUM > ").Append(_skip);
|
||||
else if (_limit > 0) sb.Insert(0, "SELECT t.* FROM (").Append(") t WHERE ROWNUM < ").Append(_limit + 1);
|
||||
}
|
||||
|
||||
sbnav.Clear();
|
||||
if (tbUnionsGt0) sb.Append(") ftb");
|
||||
}
|
||||
return sb.ToString();
|
||||
}
|
||||
|
||||
public OdbcOracleSelect(IFreeSql orm, CommonUtils commonUtils, CommonExpression commonExpression, object dywhere) : base(orm, commonUtils, commonExpression, dywhere) { }
|
||||
public override ISelect<T1, T2> From<T2>(Expression<Func<ISelectFromExpression<T1>, T2, ISelectFromExpression<T1>>> exp) { this.InternalFrom(exp); var ret = new OracleSelect<T1, T2>(_orm, _commonUtils, _commonExpression, null); OdbcOracleSelect<T1>.CopyData(this, ret, exp?.Parameters); return ret; }
|
||||
public override ISelect<T1, T2, T3> From<T2, T3>(Expression<Func<ISelectFromExpression<T1>, T2, T3, ISelectFromExpression<T1>>> exp) { this.InternalFrom(exp); var ret = new OracleSelect<T1, T2, T3>(_orm, _commonUtils, _commonExpression, null); OdbcOracleSelect<T1>.CopyData(this, ret, exp?.Parameters); return ret; }
|
||||
public override ISelect<T1, T2, T3, T4> From<T2, T3, T4>(Expression<Func<ISelectFromExpression<T1>, T2, T3, T4, ISelectFromExpression<T1>>> exp) { this.InternalFrom(exp); var ret = new OracleSelect<T1, T2, T3, T4>(_orm, _commonUtils, _commonExpression, null); OdbcOracleSelect<T1>.CopyData(this, ret, exp?.Parameters); return ret; }
|
||||
public override ISelect<T1, T2, T3, T4, T5> From<T2, T3, T4, T5>(Expression<Func<ISelectFromExpression<T1>, T2, T3, T4, T5, ISelectFromExpression<T1>>> exp) { this.InternalFrom(exp); var ret = new OracleSelect<T1, T2, T3, T4, T5>(_orm, _commonUtils, _commonExpression, null); OdbcOracleSelect<T1>.CopyData(this, ret, exp?.Parameters); return ret; }
|
||||
public override ISelect<T1, T2, T3, T4, T5, T6> From<T2, T3, T4, T5, T6>(Expression<Func<ISelectFromExpression<T1>, T2, T3, T4, T5, T6, ISelectFromExpression<T1>>> exp) { this.InternalFrom(exp); var ret = new OracleSelect<T1, T2, T3, T4, T5, T6>(_orm, _commonUtils, _commonExpression, null); OdbcOracleSelect<T1>.CopyData(this, ret, exp?.Parameters); return ret; }
|
||||
public override ISelect<T1, T2, T3, T4, T5, T6, T7> From<T2, T3, T4, T5, T6, T7>(Expression<Func<ISelectFromExpression<T1>, T2, T3, T4, T5, T6, T7, ISelectFromExpression<T1>>> exp) { this.InternalFrom(exp); var ret = new OracleSelect<T1, T2, T3, T4, T5, T6, T7>(_orm, _commonUtils, _commonExpression, null); OdbcOracleSelect<T1>.CopyData(this, ret, exp?.Parameters); return ret; }
|
||||
public override ISelect<T1, T2, T3, T4, T5, T6, T7, T8> From<T2, T3, T4, T5, T6, T7, T8>(Expression<Func<ISelectFromExpression<T1>, T2, T3, T4, T5, T6, T7, T8, ISelectFromExpression<T1>>> exp) { this.InternalFrom(exp); var ret = new OracleSelect<T1, T2, T3, T4, T5, T6, T7, T8>(_orm, _commonUtils, _commonExpression, null); OdbcOracleSelect<T1>.CopyData(this, ret, exp?.Parameters); return ret; }
|
||||
public override ISelect<T1, T2, T3, T4, T5, T6, T7, T8, T9> From<T2, T3, T4, T5, T6, T7, T8, T9>(Expression<Func<ISelectFromExpression<T1>, T2, T3, T4, T5, T6, T7, T8, T9, ISelectFromExpression<T1>>> exp) { this.InternalFrom(exp); var ret = new OracleSelect<T1, T2, T3, T4, T5, T6, T7, T8, T9>(_orm, _commonUtils, _commonExpression, null); OdbcOracleSelect<T1>.CopyData(this, ret, exp?.Parameters); return ret; }
|
||||
public override ISelect<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10> From<T2, T3, T4, T5, T6, T7, T8, T9, T10>(Expression<Func<ISelectFromExpression<T1>, T2, T3, T4, T5, T6, T7, T8, T9, T10, ISelectFromExpression<T1>>> exp) { this.InternalFrom(exp); var ret = new OracleSelect<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10>(_orm, _commonUtils, _commonExpression, null); OdbcOracleSelect<T1>.CopyData(this, ret, exp?.Parameters); return ret; }
|
||||
public override string ToSql(string field = null) => ToSqlStatic(_commonUtils, _commonExpression, _select, _distinct, field ?? this.GetAllFieldExpressionTreeLevel2().Field, _join, _where, _groupby, _having, _orderby, _skip, _limit, _tables, this.GetTableRuleUnions(), _whereCascadeExpression, _orm);
|
||||
}
|
||||
class OracleSelect<T1, T2> : FreeSql.Internal.CommonProvider.Select2Provider<T1, T2> where T1 : class where T2 : class
|
||||
{
|
||||
public OracleSelect(IFreeSql orm, CommonUtils commonUtils, CommonExpression commonExpression, object dywhere) : base(orm, commonUtils, commonExpression, dywhere) { }
|
||||
public override string ToSql(string field = null) => OdbcOracleSelect<T1>.ToSqlStatic(_commonUtils, _commonExpression, _select, _distinct, field ?? this.GetAllFieldExpressionTreeLevel2().Field, _join, _where, _groupby, _having, _orderby, _skip, _limit, _tables, this.GetTableRuleUnions(), _whereCascadeExpression, _orm);
|
||||
}
|
||||
class OracleSelect<T1, T2, T3> : FreeSql.Internal.CommonProvider.Select3Provider<T1, T2, T3> where T1 : class where T2 : class where T3 : class
|
||||
{
|
||||
public OracleSelect(IFreeSql orm, CommonUtils commonUtils, CommonExpression commonExpression, object dywhere) : base(orm, commonUtils, commonExpression, dywhere) { }
|
||||
public override string ToSql(string field = null) => OdbcOracleSelect<T1>.ToSqlStatic(_commonUtils, _commonExpression, _select, _distinct, field ?? this.GetAllFieldExpressionTreeLevel2().Field, _join, _where, _groupby, _having, _orderby, _skip, _limit, _tables, this.GetTableRuleUnions(), _whereCascadeExpression, _orm);
|
||||
}
|
||||
class OracleSelect<T1, T2, T3, T4> : FreeSql.Internal.CommonProvider.Select4Provider<T1, T2, T3, T4> where T1 : class where T2 : class where T3 : class where T4 : class
|
||||
{
|
||||
public OracleSelect(IFreeSql orm, CommonUtils commonUtils, CommonExpression commonExpression, object dywhere) : base(orm, commonUtils, commonExpression, dywhere) { }
|
||||
public override string ToSql(string field = null) => OdbcOracleSelect<T1>.ToSqlStatic(_commonUtils, _commonExpression, _select, _distinct, field ?? this.GetAllFieldExpressionTreeLevel2().Field, _join, _where, _groupby, _having, _orderby, _skip, _limit, _tables, this.GetTableRuleUnions(), _whereCascadeExpression, _orm);
|
||||
}
|
||||
class OracleSelect<T1, T2, T3, T4, T5> : FreeSql.Internal.CommonProvider.Select5Provider<T1, T2, T3, T4, T5> where T1 : class where T2 : class where T3 : class where T4 : class where T5 : class
|
||||
{
|
||||
public OracleSelect(IFreeSql orm, CommonUtils commonUtils, CommonExpression commonExpression, object dywhere) : base(orm, commonUtils, commonExpression, dywhere) { }
|
||||
public override string ToSql(string field = null) => OdbcOracleSelect<T1>.ToSqlStatic(_commonUtils, _commonExpression, _select, _distinct, field ?? this.GetAllFieldExpressionTreeLevel2().Field, _join, _where, _groupby, _having, _orderby, _skip, _limit, _tables, this.GetTableRuleUnions(), _whereCascadeExpression, _orm);
|
||||
}
|
||||
class OracleSelect<T1, T2, T3, T4, T5, T6> : FreeSql.Internal.CommonProvider.Select6Provider<T1, T2, T3, T4, T5, T6> where T1 : class where T2 : class where T3 : class where T4 : class where T5 : class where T6 : class
|
||||
{
|
||||
public OracleSelect(IFreeSql orm, CommonUtils commonUtils, CommonExpression commonExpression, object dywhere) : base(orm, commonUtils, commonExpression, dywhere) { }
|
||||
public override string ToSql(string field = null) => OdbcOracleSelect<T1>.ToSqlStatic(_commonUtils, _commonExpression, _select, _distinct, field ?? this.GetAllFieldExpressionTreeLevel2().Field, _join, _where, _groupby, _having, _orderby, _skip, _limit, _tables, this.GetTableRuleUnions(), _whereCascadeExpression, _orm);
|
||||
}
|
||||
class OracleSelect<T1, T2, T3, T4, T5, T6, T7> : FreeSql.Internal.CommonProvider.Select7Provider<T1, T2, T3, T4, T5, T6, T7> where T1 : class where T2 : class where T3 : class where T4 : class where T5 : class where T6 : class where T7 : class
|
||||
{
|
||||
public OracleSelect(IFreeSql orm, CommonUtils commonUtils, CommonExpression commonExpression, object dywhere) : base(orm, commonUtils, commonExpression, dywhere) { }
|
||||
public override string ToSql(string field = null) => OdbcOracleSelect<T1>.ToSqlStatic(_commonUtils, _commonExpression, _select, _distinct, field ?? this.GetAllFieldExpressionTreeLevel2().Field, _join, _where, _groupby, _having, _orderby, _skip, _limit, _tables, this.GetTableRuleUnions(), _whereCascadeExpression, _orm);
|
||||
}
|
||||
class OracleSelect<T1, T2, T3, T4, T5, T6, T7, T8> : FreeSql.Internal.CommonProvider.Select8Provider<T1, T2, T3, T4, T5, T6, T7, T8> where T1 : class where T2 : class where T3 : class where T4 : class where T5 : class where T6 : class where T7 : class where T8 : class
|
||||
{
|
||||
public OracleSelect(IFreeSql orm, CommonUtils commonUtils, CommonExpression commonExpression, object dywhere) : base(orm, commonUtils, commonExpression, dywhere) { }
|
||||
public override string ToSql(string field = null) => OdbcOracleSelect<T1>.ToSqlStatic(_commonUtils, _commonExpression, _select, _distinct, field ?? this.GetAllFieldExpressionTreeLevel2().Field, _join, _where, _groupby, _having, _orderby, _skip, _limit, _tables, this.GetTableRuleUnions(), _whereCascadeExpression, _orm);
|
||||
}
|
||||
class OracleSelect<T1, T2, T3, T4, T5, T6, T7, T8, T9> : FreeSql.Internal.CommonProvider.Select9Provider<T1, T2, T3, T4, T5, T6, T7, T8, T9> where T1 : class where T2 : class where T3 : class where T4 : class where T5 : class where T6 : class where T7 : class where T8 : class where T9 : class
|
||||
{
|
||||
public OracleSelect(IFreeSql orm, CommonUtils commonUtils, CommonExpression commonExpression, object dywhere) : base(orm, commonUtils, commonExpression, dywhere) { }
|
||||
public override string ToSql(string field = null) => OdbcOracleSelect<T1>.ToSqlStatic(_commonUtils, _commonExpression, _select, _distinct, field ?? this.GetAllFieldExpressionTreeLevel2().Field, _join, _where, _groupby, _having, _orderby, _skip, _limit, _tables, this.GetTableRuleUnions(), _whereCascadeExpression, _orm);
|
||||
}
|
||||
class OracleSelect<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10> : FreeSql.Internal.CommonProvider.Select10Provider<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10> where T1 : class where T2 : class where T3 : class where T4 : class where T5 : class where T6 : class where T7 : class where T8 : class where T9 : class where T10 : class
|
||||
{
|
||||
public OracleSelect(IFreeSql orm, CommonUtils commonUtils, CommonExpression commonExpression, object dywhere) : base(orm, commonUtils, commonExpression, dywhere) { }
|
||||
public override string ToSql(string field = null) => OdbcOracleSelect<T1>.ToSqlStatic(_commonUtils, _commonExpression, _select, _distinct, field ?? this.GetAllFieldExpressionTreeLevel2().Field, _join, _where, _groupby, _having, _orderby, _skip, _limit, _tables, this.GetTableRuleUnions(), _whereCascadeExpression, _orm);
|
||||
}
|
||||
}
|
@ -0,0 +1,72 @@
|
||||
using FreeSql.Internal;
|
||||
using FreeSql.Internal.Model;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace FreeSql.Odbc.Oracle
|
||||
{
|
||||
|
||||
class OdbcOracleUpdate<T1> : Internal.CommonProvider.UpdateProvider<T1> where T1 : class
|
||||
{
|
||||
|
||||
public OdbcOracleUpdate(IFreeSql orm, CommonUtils commonUtils, CommonExpression commonExpression, object dywhere)
|
||||
: base(orm, commonUtils, commonExpression, dywhere)
|
||||
{
|
||||
}
|
||||
|
||||
public override int ExecuteAffrows() => base.SplitExecuteAffrows(200, 999);
|
||||
public override Task<int> ExecuteAffrowsAsync() => base.SplitExecuteAffrowsAsync(200, 999);
|
||||
public override List<T1> ExecuteUpdated() => base.SplitExecuteUpdated(200, 999);
|
||||
public override Task<List<T1>> ExecuteUpdatedAsync() => base.SplitExecuteUpdatedAsync(200, 999);
|
||||
|
||||
|
||||
protected override List<T1> RawExecuteUpdated()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
protected override Task<List<T1>> RawExecuteUpdatedAsync()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
protected override void ToSqlCase(StringBuilder caseWhen, ColumnInfo[] primarys)
|
||||
{
|
||||
if (_table.Primarys.Length == 1)
|
||||
{
|
||||
caseWhen.Append(_commonUtils.QuoteReadColumn(_table.Primarys.First().Attribute.MapType, _commonUtils.QuoteSqlName(_table.Primarys.First().Attribute.Name)));
|
||||
return;
|
||||
}
|
||||
caseWhen.Append("(");
|
||||
var pkidx = 0;
|
||||
foreach (var pk in _table.Primarys)
|
||||
{
|
||||
if (pkidx > 0) caseWhen.Append(" || ");
|
||||
caseWhen.Append(_commonUtils.QuoteReadColumn(pk.Attribute.MapType, _commonUtils.QuoteSqlName(pk.Attribute.Name)));
|
||||
++pkidx;
|
||||
}
|
||||
caseWhen.Append(")");
|
||||
}
|
||||
|
||||
protected override void ToSqlWhen(StringBuilder sb, ColumnInfo[] primarys, object d)
|
||||
{
|
||||
if (_table.Primarys.Length == 1)
|
||||
{
|
||||
sb.Append(_commonUtils.FormatSql("{0}", _table.Primarys.First().GetMapValue(d)));
|
||||
return;
|
||||
}
|
||||
sb.Append("(");
|
||||
var pkidx = 0;
|
||||
foreach (var pk in _table.Primarys)
|
||||
{
|
||||
if (pkidx > 0) sb.Append(" || ");
|
||||
sb.Append(_commonUtils.FormatSql("{0}", pk.GetMapValue(d)));
|
||||
++pkidx;
|
||||
}
|
||||
sb.Append(")");
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,70 @@
|
||||
using FreeSql.Internal;
|
||||
using SafeObjectPool;
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Data.Common;
|
||||
using System.Data.Odbc;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
|
||||
namespace FreeSql.Odbc.Oracle
|
||||
{
|
||||
class OdbcOracleAdo : FreeSql.Internal.CommonProvider.AdoProvider
|
||||
{
|
||||
public OdbcOracleAdo() : base(DataType.Oracle) { }
|
||||
public OdbcOracleAdo(CommonUtils util, string masterConnectionString, string[] slaveConnectionStrings) : base(DataType.Oracle)
|
||||
{
|
||||
base._util = util;
|
||||
if (!string.IsNullOrEmpty(masterConnectionString))
|
||||
MasterPool = new OdbcOracleConnectionPool("主库", masterConnectionString, null, null);
|
||||
if (slaveConnectionStrings != null)
|
||||
{
|
||||
foreach (var slaveConnectionString in slaveConnectionStrings)
|
||||
{
|
||||
var slavePool = new OdbcOracleConnectionPool($"从库{SlavePools.Count + 1}", slaveConnectionString, () => Interlocked.Decrement(ref slaveUnavailables), () => Interlocked.Increment(ref slaveUnavailables));
|
||||
SlavePools.Add(slavePool);
|
||||
}
|
||||
}
|
||||
}
|
||||
static DateTime dt1970 = new DateTime(1970, 1, 1);
|
||||
public override object AddslashesProcessParam(object param, Type mapType)
|
||||
{
|
||||
if (param == null) return "NULL";
|
||||
if (mapType != null && mapType != param.GetType())
|
||||
param = Utils.GetDataReaderValue(mapType, param);
|
||||
if (param is bool || param is bool?)
|
||||
return (bool)param ? 1 : 0;
|
||||
else if (param is string || param is char)
|
||||
return string.Concat("'", param.ToString().Replace("'", "''"), "'");
|
||||
else if (param is Enum)
|
||||
return ((Enum)param).ToInt64();
|
||||
else if (decimal.TryParse(string.Concat(param), out var trydec))
|
||||
return param;
|
||||
else if (param is DateTime || param is DateTime?)
|
||||
return string.Concat("to_timestamp('", ((DateTime)param).ToString("yyyy-MM-dd HH:mm:ss.ffffff"), "','YYYY-MM-DD HH24:MI:SS.FF6')");
|
||||
else if (param is TimeSpan || param is TimeSpan?)
|
||||
return $"numtodsinterval({((TimeSpan)param).Ticks * 1.0 / 10000000},'second')";
|
||||
else if (param is IEnumerable)
|
||||
{
|
||||
var sb = new StringBuilder();
|
||||
var ie = param as IEnumerable;
|
||||
foreach (var z in ie) sb.Append(",").Append(AddslashesProcessParam(z, mapType));
|
||||
return sb.Length == 0 ? "(NULL)" : sb.Remove(0, 1).Insert(0, "(").Append(")").ToString();
|
||||
}
|
||||
return string.Concat("'", param.ToString().Replace("'", "''"), "'");
|
||||
//if (param is string) return string.Concat('N', nparms[a]);
|
||||
}
|
||||
|
||||
protected override DbCommand CreateCommand()
|
||||
{
|
||||
return new OdbcCommand();
|
||||
}
|
||||
|
||||
protected override void ReturnConnection(ObjectPool<DbConnection> pool, Object<DbConnection> conn, Exception ex)
|
||||
{
|
||||
(pool as OdbcOracleConnectionPool).Return(conn, ex);
|
||||
}
|
||||
|
||||
protected override DbParameter[] GetDbParamtersByObject(string sql, object obj) => _util.GetDbParamtersByObject(sql, obj);
|
||||
}
|
||||
}
|
@ -0,0 +1,246 @@
|
||||
using SafeObjectPool;
|
||||
using System;
|
||||
using System.Collections.Concurrent;
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
using System.Data.Common;
|
||||
using System.Data.Odbc;
|
||||
using System.Text;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace FreeSql.Odbc.Oracle
|
||||
{
|
||||
|
||||
class OdbcOracleConnectionPool : ObjectPool<DbConnection>
|
||||
{
|
||||
|
||||
internal Action availableHandler;
|
||||
internal Action unavailableHandler;
|
||||
internal string UserId { get; set; }
|
||||
|
||||
public OdbcOracleConnectionPool(string name, string connectionString, Action availableHandler, Action unavailableHandler) : base(null)
|
||||
{
|
||||
var userIdMatch = Regex.Match(connectionString, @"(User\s+Id|Uid)\s*=\s*([^;]+)", RegexOptions.IgnoreCase);
|
||||
if (userIdMatch.Success == false) throw new Exception(@"从 ConnectionString 中无法匹配 (User\s+Id|Uid)\s*=\s*([^;]+)");
|
||||
this.UserId = userIdMatch.Groups[2].Value.Trim().ToUpper();
|
||||
|
||||
var policy = new OdbcOracleConnectionPoolPolicy
|
||||
{
|
||||
_pool = this,
|
||||
Name = name
|
||||
};
|
||||
this.Policy = policy;
|
||||
policy.ConnectionString = connectionString;
|
||||
|
||||
this.availableHandler = availableHandler;
|
||||
this.unavailableHandler = unavailableHandler;
|
||||
}
|
||||
|
||||
public void Return(Object<DbConnection> obj, Exception exception, bool isRecreate = false)
|
||||
{
|
||||
if (exception != null && exception is OdbcException)
|
||||
{
|
||||
|
||||
if (exception is System.IO.IOException)
|
||||
{
|
||||
|
||||
base.SetUnavailable(exception);
|
||||
|
||||
}
|
||||
else if (obj.Value.Ping() == false)
|
||||
{
|
||||
|
||||
base.SetUnavailable(exception);
|
||||
}
|
||||
}
|
||||
base.Return(obj, isRecreate);
|
||||
}
|
||||
}
|
||||
|
||||
class OdbcOracleConnectionPoolPolicy : IPolicy<DbConnection>
|
||||
{
|
||||
|
||||
internal OdbcOracleConnectionPool _pool;
|
||||
public string Name { get; set; } = "Oracle OdbcConnection 对象池";
|
||||
public int PoolSize { get; set; } = 100;
|
||||
public TimeSpan SyncGetTimeout { get; set; } = TimeSpan.FromSeconds(10);
|
||||
public TimeSpan IdleTimeout { get; set; } = TimeSpan.Zero;
|
||||
public int AsyncGetCapacity { get; set; } = 10000;
|
||||
public bool IsThrowGetTimeoutException { get; set; } = true;
|
||||
public int CheckAvailableInterval { get; set; } = 5;
|
||||
|
||||
static ConcurrentDictionary<string, int> dicConnStrIncr = new ConcurrentDictionary<string, int>(StringComparer.CurrentCultureIgnoreCase);
|
||||
private string _connectionString;
|
||||
public string ConnectionString
|
||||
{
|
||||
get => _connectionString;
|
||||
set
|
||||
{
|
||||
_connectionString = value ?? "";
|
||||
|
||||
var pattern = @"Max\s*pool\s*size\s*=\s*(\d+)";
|
||||
Match m = Regex.Match(_connectionString, pattern, RegexOptions.IgnoreCase);
|
||||
if (m.Success == false || int.TryParse(m.Groups[1].Value, out var poolsize) == false || poolsize <= 0) poolsize = 100;
|
||||
var connStrIncr = dicConnStrIncr.AddOrUpdate(_connectionString, 1, (oldkey, oldval) => oldval + 1);
|
||||
PoolSize = poolsize + connStrIncr;
|
||||
_connectionString = m.Success ?
|
||||
Regex.Replace(_connectionString, pattern, $"Max pool size={PoolSize}", RegexOptions.IgnoreCase) :
|
||||
$"{_connectionString};Max pool size={PoolSize}";
|
||||
|
||||
pattern = @"Connection\s*LifeTime\s*=\s*(\d+)";
|
||||
m = Regex.Match(_connectionString, pattern, RegexOptions.IgnoreCase);
|
||||
if (m.Success)
|
||||
{
|
||||
IdleTimeout = TimeSpan.FromSeconds(int.Parse(m.Groups[1].Value));
|
||||
_connectionString = Regex.Replace(_connectionString, pattern, "", RegexOptions.IgnoreCase);
|
||||
}
|
||||
|
||||
var minPoolSize = 0;
|
||||
pattern = @"Min\s*pool\s*size\s*=\s*(\d+)";
|
||||
m = Regex.Match(_connectionString, pattern, RegexOptions.IgnoreCase);
|
||||
if (m.Success)
|
||||
{
|
||||
minPoolSize = int.Parse(m.Groups[1].Value);
|
||||
_connectionString = Regex.Replace(_connectionString, pattern, "", RegexOptions.IgnoreCase);
|
||||
}
|
||||
|
||||
FreeSql.Internal.CommonUtils.PrevReheatConnectionPool(_pool, minPoolSize);
|
||||
}
|
||||
}
|
||||
|
||||
public bool OnCheckAvailable(Object<DbConnection> obj)
|
||||
{
|
||||
if (obj.Value.State == ConnectionState.Closed) obj.Value.Open();
|
||||
return obj.Value.Ping(true);
|
||||
}
|
||||
|
||||
public DbConnection OnCreate()
|
||||
{
|
||||
var conn = new OdbcConnection(_connectionString);
|
||||
return conn;
|
||||
}
|
||||
|
||||
public void OnDestroy(DbConnection obj)
|
||||
{
|
||||
if (obj.State != ConnectionState.Closed) obj.Close();
|
||||
obj.Dispose();
|
||||
}
|
||||
|
||||
public void OnGet(Object<DbConnection> obj)
|
||||
{
|
||||
|
||||
if (_pool.IsAvailable)
|
||||
{
|
||||
if (obj.Value == null)
|
||||
{
|
||||
if (_pool.SetUnavailable(new Exception("连接字符串错误")) == true)
|
||||
throw new Exception($"【{this.Name}】连接字符串错误,请检查。");
|
||||
return;
|
||||
}
|
||||
|
||||
if (obj.Value.State != ConnectionState.Open || DateTime.Now.Subtract(obj.LastReturnTime).TotalSeconds > 60 && obj.Value.Ping() == false)
|
||||
{
|
||||
|
||||
try
|
||||
{
|
||||
obj.Value.Open();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
if (_pool.SetUnavailable(ex) == true)
|
||||
throw new Exception($"【{this.Name}】状态不可用,等待后台检查程序恢复方可使用。{ex.Message}");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
async public Task OnGetAsync(Object<DbConnection> obj)
|
||||
{
|
||||
|
||||
if (_pool.IsAvailable)
|
||||
{
|
||||
if (obj.Value == null)
|
||||
{
|
||||
if (_pool.SetUnavailable(new Exception("连接字符串错误")) == true)
|
||||
throw new Exception($"【{this.Name}】连接字符串错误,请检查。");
|
||||
return;
|
||||
}
|
||||
|
||||
if (obj.Value.State != ConnectionState.Open || DateTime.Now.Subtract(obj.LastReturnTime).TotalSeconds > 60 && (await obj.Value.PingAsync()) == false)
|
||||
{
|
||||
|
||||
try
|
||||
{
|
||||
await obj.Value.OpenAsync();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
if (_pool.SetUnavailable(ex) == true)
|
||||
throw new Exception($"【{this.Name}】状态不可用,等待后台检查程序恢复方可使用。{ex.Message}");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void OnGetTimeout()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public void OnReturn(Object<DbConnection> obj)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public void OnAvailable()
|
||||
{
|
||||
_pool.availableHandler?.Invoke();
|
||||
}
|
||||
|
||||
public void OnUnavailable()
|
||||
{
|
||||
_pool.unavailableHandler?.Invoke();
|
||||
}
|
||||
}
|
||||
|
||||
static class DbConnectionExtensions
|
||||
{
|
||||
|
||||
static DbCommand PingCommand(DbConnection conn)
|
||||
{
|
||||
var cmd = conn.CreateCommand();
|
||||
cmd.CommandTimeout = 5;
|
||||
cmd.CommandText = "select 1 from dual";
|
||||
return cmd;
|
||||
}
|
||||
public static bool Ping(this DbConnection that, bool isThrow = false)
|
||||
{
|
||||
try
|
||||
{
|
||||
PingCommand(that).ExecuteNonQuery();
|
||||
return true;
|
||||
}
|
||||
catch
|
||||
{
|
||||
if (that.State != ConnectionState.Closed) try { that.Close(); } catch { }
|
||||
if (isThrow) throw;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
async public static Task<bool> PingAsync(this DbConnection that, bool isThrow = false)
|
||||
{
|
||||
try
|
||||
{
|
||||
await PingCommand(that).ExecuteNonQueryAsync();
|
||||
return true;
|
||||
}
|
||||
catch
|
||||
{
|
||||
if (that.State != ConnectionState.Closed) try { that.Close(); } catch { }
|
||||
if (isThrow) throw;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
412
Providers/FreeSql.Provider.Odbc/Oracle/OdbcOracleCodeFirst.cs
Normal file
412
Providers/FreeSql.Provider.Odbc/Oracle/OdbcOracleCodeFirst.cs
Normal file
@ -0,0 +1,412 @@
|
||||
using FreeSql.DataAnnotations;
|
||||
using FreeSql.DatabaseModel;
|
||||
using FreeSql.Internal;
|
||||
using FreeSql.Internal.Model;
|
||||
using System;
|
||||
using System.Collections.Concurrent;
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
using System.Data.Odbc;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Text;
|
||||
using System.Text.RegularExpressions;
|
||||
|
||||
namespace FreeSql.Odbc.Oracle
|
||||
{
|
||||
|
||||
class OdbcOracleCodeFirst : Internal.CommonProvider.CodeFirstProvider
|
||||
{
|
||||
public override bool IsNoneCommandParameter { get => true; set => base.IsNoneCommandParameter = true; }
|
||||
public OdbcOracleCodeFirst(IFreeSql orm, CommonUtils commonUtils, CommonExpression commonExpression) : base(orm, commonUtils, commonExpression) { }
|
||||
|
||||
static object _dicCsToDbLock = new object();
|
||||
static Dictionary<string, (OdbcType type, string dbtype, string dbtypeFull, bool? isUnsigned, bool? isnullable, object defaultValue)> _dicCsToDb = new Dictionary<string, (OdbcType type, string dbtype, string dbtypeFull, bool? isUnsigned, bool? isnullable, object defaultValue)>() {
|
||||
{ typeof(bool).FullName, (OdbcType.Bit, "number","number(1) NOT NULL", null, false, false) },{ typeof(bool?).FullName, (OdbcType.Bit, "number","number(1) NULL", null, true, null) },
|
||||
|
||||
{ typeof(sbyte).FullName, (OdbcType.SmallInt, "number", "number(4) NOT NULL", false, false, 0) },{ typeof(sbyte?).FullName, (OdbcType.SmallInt, "number", "number(4) NULL", false, true, null) },
|
||||
{ typeof(short).FullName, (OdbcType.SmallInt, "number","number(6) NOT NULL", false, false, 0) },{ typeof(short?).FullName, (OdbcType.SmallInt, "number", "number(6) NULL", false, true, null) },
|
||||
{ typeof(int).FullName, (OdbcType.Int, "number", "number(11) NOT NULL", false, false, 0) },{ typeof(int?).FullName, (OdbcType.Int, "number", "number(11) NULL", false, true, null) },
|
||||
{ typeof(long).FullName, (OdbcType.BigInt, "number","number(21) NOT NULL", false, false, 0) },{ typeof(long?).FullName, (OdbcType.BigInt, "number","number(21) NULL", false, true, null) },
|
||||
|
||||
{ typeof(byte).FullName, (OdbcType.TinyInt, "number","number(3) NOT NULL", true, false, 0) },{ typeof(byte?).FullName, (OdbcType.TinyInt, "number","number(3) NULL", true, true, null) },
|
||||
{ typeof(ushort).FullName, (OdbcType.Int, "number","number(5) NOT NULL", true, false, 0) },{ typeof(ushort?).FullName, (OdbcType.Int, "number", "number(5) NULL", true, true, null) },
|
||||
{ typeof(uint).FullName, (OdbcType.BigInt, "number", "number(10) NOT NULL", true, false, 0) },{ typeof(uint?).FullName, (OdbcType.BigInt, "number", "number(10) NULL", true, true, null) },
|
||||
{ typeof(ulong).FullName, (OdbcType.Decimal, "number", "number(20) NOT NULL", true, false, 0) },{ typeof(ulong?).FullName, (OdbcType.Decimal, "number", "number(20) NULL", true, true, null) },
|
||||
|
||||
{ typeof(double).FullName, (OdbcType.Double, "float", "float(126) NOT NULL", false, false, 0) },{ typeof(double?).FullName, (OdbcType.Double, "float", "float(126) NULL", false, true, null) },
|
||||
{ typeof(float).FullName, (OdbcType.Real, "float","float(63) NOT NULL", false, false, 0) },{ typeof(float?).FullName, (OdbcType.Real, "float","float(63) NULL", false, true, null) },
|
||||
{ typeof(decimal).FullName, (OdbcType.Decimal, "number", "number(10,2) NOT NULL", false, false, 0) },{ typeof(decimal?).FullName, (OdbcType.Decimal, "number", "number(10,2) NULL", false, true, null) },
|
||||
|
||||
//{ typeof(TimeSpan).FullName, (OdbcType.Time, "interval day to second","interval day(2) to second(6) NOT NULL", false, false, 0) },{ typeof(TimeSpan?).FullName, (OdbcType.Time, "interval day to second", "interval day(2) to second(6) NULL",false, true, null) },
|
||||
{ typeof(DateTime).FullName, (OdbcType.DateTime, "timestamp", "timestamp(6) NOT NULL", false, false, new DateTime(1970,1,1)) },{ typeof(DateTime?).FullName, (OdbcType.DateTime, "timestamp", "timestamp(6) NULL", false, true, null) },
|
||||
{ typeof(DateTimeOffset).FullName, (OdbcType.DateTime, "timestamp with local time zone", "timestamp(6) with local time zone NOT NULL", false, false, new DateTime(1970,1,1)) },{ typeof(DateTimeOffset?).FullName, (OdbcType.DateTime, "timestamp with local time zone", "timestamp(6) with local time zone NULL", false, true, null) },
|
||||
|
||||
{ typeof(byte[]).FullName, (OdbcType.VarBinary, "blob", "blob NULL", false, null, new byte[0]) },
|
||||
{ typeof(string).FullName, (OdbcType.NVarChar, "nvarchar2", "nvarchar2(255) NULL", false, null, "") },
|
||||
|
||||
{ typeof(Guid).FullName, (OdbcType.Char, "char", "char(36 CHAR) NOT NULL", false, false, Guid.Empty) },{ typeof(Guid?).FullName, (OdbcType.Char, "char", "char(36 CHAR) NULL", false, true, null) },
|
||||
};
|
||||
|
||||
public override (int type, string dbtype, string dbtypeFull, bool? isnullable, object defaultValue)? GetDbInfo(Type type)
|
||||
{
|
||||
if (_dicCsToDb.TryGetValue(type.FullName, out var trydc)) return new (int, string, string, bool?, object)?(((int)trydc.type, trydc.dbtype, trydc.dbtypeFull, trydc.isnullable, trydc.defaultValue));
|
||||
if (type.IsArray) return null;
|
||||
var enumType = type.IsEnum ? type : null;
|
||||
if (enumType == null && type.IsNullableType() && type.GenericTypeArguments.Length == 1 && type.GenericTypeArguments.First().IsEnum) enumType = type.GenericTypeArguments.First();
|
||||
if (enumType != null)
|
||||
{
|
||||
var newItem = enumType.GetCustomAttributes(typeof(FlagsAttribute), false).Any() ?
|
||||
(OdbcType.Int, "number", $"number(16){(type.IsEnum ? " NOT NULL" : "")}", false, type.IsEnum ? false : true, Enum.GetValues(enumType).GetValue(0)) :
|
||||
(OdbcType.BigInt, "number", $"number(32){(type.IsEnum ? " NOT NULL" : "")}", false, type.IsEnum ? false : true, Enum.GetValues(enumType).GetValue(0));
|
||||
if (_dicCsToDb.ContainsKey(type.FullName) == false)
|
||||
{
|
||||
lock (_dicCsToDbLock)
|
||||
{
|
||||
if (_dicCsToDb.ContainsKey(type.FullName) == false)
|
||||
_dicCsToDb.Add(type.FullName, newItem);
|
||||
}
|
||||
}
|
||||
return ((int)newItem.Item1, newItem.Item2, newItem.Item3, newItem.Item5, newItem.Item6);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public override string GetComparisonDDLStatements(params Type[] entityTypes)
|
||||
{
|
||||
var userId = (_orm.Ado.MasterPool as OdbcOracleConnectionPool).UserId;
|
||||
var seqcols = new List<(ColumnInfo, string[], bool)>(); //序列:列,表,自增
|
||||
var seqnameDel = new List<string>(); //要删除的序列+触发器
|
||||
|
||||
var sb = new StringBuilder();
|
||||
var sbDeclare = new StringBuilder();
|
||||
foreach (var entityType in entityTypes)
|
||||
{
|
||||
if (sb.Length > 0) sb.Append("\r\n");
|
||||
var tb = _commonUtils.GetTableByEntity(entityType);
|
||||
if (tb == null) throw new Exception($"类型 {entityType.FullName} 不可迁移");
|
||||
if (tb.Columns.Any() == false) throw new Exception($"类型 {entityType.FullName} 不可迁移,可迁移属性0个");
|
||||
var tbname = tb.DbName.Split(new[] { '.' }, 2);
|
||||
if (tbname?.Length == 1) tbname = new[] { userId, tbname[0] };
|
||||
|
||||
var tboldname = tb.DbOldName?.Split(new[] { '.' }, 2); //旧表名
|
||||
if (tboldname?.Length == 1) tboldname = new[] { userId, tboldname[0] };
|
||||
var primaryKeyName = entityType.GetCustomAttribute<OraclePrimaryKeyNameAttribute>()?.Name;
|
||||
|
||||
if (string.Compare(tbname[0], userId) != 0 && _orm.Ado.ExecuteScalar(CommandType.Text, _commonUtils.FormatSql(" select 1 from sys.dba_users where username={0}", tbname[0])) == null) //创建数据库
|
||||
throw new NotImplementedException($"Oracle CodeFirst 不支持代码创建 tablespace 与 schemas {tbname[0]}");
|
||||
|
||||
var sbalter = new StringBuilder();
|
||||
var istmpatler = false; //创建临时表,导入数据,删除旧表,修改
|
||||
if (_orm.Ado.ExecuteScalar(CommandType.Text, _commonUtils.FormatSql(" select 1 from all_tab_comments where owner={0} and table_name={1}", tbname)) == null)
|
||||
{ //表不存在
|
||||
if (tboldname != null)
|
||||
{
|
||||
if (_orm.Ado.ExecuteScalar(CommandType.Text, _commonUtils.FormatSql(" select 1 from all_tab_comments where owner={0} and table_name={1}", tboldname)) == null)
|
||||
//模式或表不存在
|
||||
tboldname = null;
|
||||
}
|
||||
if (tboldname == null)
|
||||
{
|
||||
//创建表
|
||||
sb.Append("execute immediate 'CREATE TABLE ").Append(_commonUtils.QuoteSqlName($"{tbname[0]}.{tbname[1]}")).Append(" ( ");
|
||||
foreach (var tbcol in tb.ColumnsByPosition)
|
||||
{
|
||||
sb.Append(" \r\n ").Append(_commonUtils.QuoteSqlName(tbcol.Attribute.Name)).Append(" ").Append(tbcol.Attribute.DbType).Append(",");
|
||||
if (tbcol.Attribute.IsIdentity == true) seqcols.Add((tbcol, tbname, true));
|
||||
}
|
||||
if (tb.Primarys.Any())
|
||||
{
|
||||
var pkname = primaryKeyName ?? $"{tbname[0]}_{tbname[1]}_pk1";
|
||||
sb.Append(" \r\n CONSTRAINT ").Append(pkname).Append(" PRIMARY KEY (");
|
||||
foreach (var tbcol in tb.Primarys) sb.Append(_commonUtils.QuoteSqlName(tbcol.Attribute.Name)).Append(", ");
|
||||
sb.Remove(sb.Length - 2, 2).Append("),");
|
||||
}
|
||||
foreach (var uk in tb.Uniques)
|
||||
{
|
||||
sb.Append(" \r\n CONSTRAINT ").Append(_commonUtils.QuoteSqlName(uk.Key)).Append(" UNIQUE (");
|
||||
foreach (var tbcol in uk.Value) sb.Append(_commonUtils.QuoteSqlName(tbcol.Attribute.Name)).Append(", ");
|
||||
sb.Remove(sb.Length - 2, 2).Append("),");
|
||||
}
|
||||
sb.Remove(sb.Length - 1, 1);
|
||||
sb.Append("\r\n) \r\nLOGGING \r\nNOCOMPRESS \r\nNOCACHE\r\n';\r\n");
|
||||
//备注
|
||||
foreach (var tbcol in tb.ColumnsByPosition)
|
||||
{
|
||||
if (string.IsNullOrEmpty(tbcol.Comment) == false)
|
||||
sb.Append("execute immediate 'COMMENT ON COLUMN ").Append(_commonUtils.QuoteSqlName($"{tbname[0]}.{tbname[1]}.{tbcol.Attribute.Name}")).Append(" IS ").Append(_commonUtils.FormatSql("{0}", tbcol.Comment).Replace("'", "''")).Append("';\r\n");
|
||||
}
|
||||
continue;
|
||||
}
|
||||
//如果新表,旧表在一个模式下,直接修改表名
|
||||
if (string.Compare(tbname[0], tboldname[0], true) == 0)
|
||||
sbalter.Append("execute immediate 'ALTER TABLE ").Append(_commonUtils.QuoteSqlName($"{tboldname[0]}.{tboldname[1]}")).Append(" RENAME TO ").Append(_commonUtils.QuoteSqlName($"{tbname[1]}")).Append("';\r\n");
|
||||
else
|
||||
{
|
||||
//如果新表,旧表不在一起,创建新表,导入数据,删除旧表
|
||||
istmpatler = true;
|
||||
}
|
||||
}
|
||||
else
|
||||
tboldname = null; //如果新表已经存在,不走改表名逻辑
|
||||
|
||||
//对比字段,只可以修改类型、增加字段、有限的修改字段名;保证安全不删除字段
|
||||
var sql = _commonUtils.FormatSql($@"
|
||||
select
|
||||
a.column_name,
|
||||
a.data_type,
|
||||
a.data_length,
|
||||
a.data_precision,
|
||||
a.data_scale,
|
||||
a.char_used,
|
||||
case when a.nullable = 'Y' then 1 else 0 end,
|
||||
nvl((select 1 from user_sequences where sequence_name='{Utils.GetCsName((tboldname ?? tbname).Last())}_seq_'||a.column_name), 0),
|
||||
nvl((select 1 from user_triggers where trigger_name='{Utils.GetCsName((tboldname ?? tbname).Last())}_seq_'||a.column_name||'TI'), 0),
|
||||
b.comments
|
||||
from all_tab_columns a
|
||||
left join all_col_comments b on b.owner = a.owner and b.table_name = a.table_name and b.column_name = a.column_name
|
||||
where a.owner={{0}} and a.table_name={{1}}", tboldname ?? tbname);
|
||||
var ds = _orm.Ado.ExecuteArray(CommandType.Text, sql);
|
||||
var tbstruct = ds.ToDictionary(a => string.Concat(a[0]), a =>
|
||||
{
|
||||
var sqlType = GetOracleSqlTypeFullName(a);
|
||||
return new
|
||||
{
|
||||
column = string.Concat(a[0]),
|
||||
sqlType,
|
||||
is_nullable = string.Concat(a[6]) == "1",
|
||||
is_identity = string.Concat(a[7]) == "1" && string.Concat(a[8]) == "1",
|
||||
comment = string.Concat(a[9])
|
||||
};
|
||||
}, StringComparer.CurrentCultureIgnoreCase);
|
||||
|
||||
if (istmpatler == false)
|
||||
{
|
||||
foreach (var tbcol in tb.ColumnsByPosition)
|
||||
{
|
||||
var dbtypeNoneNotNull = Regex.Replace(tbcol.Attribute.DbType, @"NOT\s+NULL", "NULL");
|
||||
if (tbstruct.TryGetValue(tbcol.Attribute.Name, out var tbstructcol) ||
|
||||
string.IsNullOrEmpty(tbcol.Attribute.OldName) == false && tbstruct.TryGetValue(tbcol.Attribute.OldName, out tbstructcol))
|
||||
{
|
||||
var isCommentChanged = tbstructcol.comment != (tbcol.Comment ?? "");
|
||||
if (tbcol.Attribute.DbType.StartsWith(tbstructcol.sqlType, StringComparison.CurrentCultureIgnoreCase) == false)
|
||||
istmpatler = true;
|
||||
//sbalter.Append("execute immediate 'ALTER TABLE ").Append(_commonUtils.QuoteSqlName($"{tbname[0]}.{tbname[1]}")).Append(" MODIFY (").Append(_commonUtils.QuoteSqlName(tbstructcol.column)).Append(" ").Append(dbtypeNoneNotNull).Append(")';\r\n");
|
||||
if (tbcol.Attribute.IsNullable != tbstructcol.is_nullable)
|
||||
{
|
||||
if (tbcol.Attribute.IsNullable == false)
|
||||
sbalter.Append("execute immediate 'UPDATE ").Append(_commonUtils.QuoteSqlName($"{tbname[0]}.{tbname[1]}")).Append(" SET ").Append(_commonUtils.QuoteSqlName(tbstructcol.column)).Append(" = ").Append(_commonUtils.FormatSql("{0}", tbcol.Attribute.DbDefautValue).Replace("'", "''")).Append(" WHERE ").Append(_commonUtils.QuoteSqlName(tbstructcol.column)).Append(" IS NULL';\r\n");
|
||||
sbalter.Append("execute immediate 'ALTER TABLE ").Append(_commonUtils.QuoteSqlName($"{tbname[0]}.{tbname[1]}")).Append(" MODIFY ").Append(_commonUtils.QuoteSqlName(tbstructcol.column)).Append(" ").Append(tbcol.Attribute.IsNullable == true ? "" : "NOT").Append(" NULL';\r\n");
|
||||
}
|
||||
if (string.Compare(tbstructcol.column, tbcol.Attribute.OldName, true) == 0)
|
||||
{
|
||||
if (tbstructcol.is_identity)
|
||||
seqnameDel.Add(Utils.GetCsName($"{tbname[1]}_seq_{tbstructcol.column}"));
|
||||
//修改列名
|
||||
sbalter.Append("execute immediate 'ALTER TABLE ").Append(_commonUtils.QuoteSqlName($"{tbname[0]}.{tbname[1]}")).Append(" RENAME COLUMN ").Append(_commonUtils.QuoteSqlName(tbstructcol.column)).Append(" TO ").Append(_commonUtils.QuoteSqlName(tbcol.Attribute.Name)).Append("';\r\n");
|
||||
if (tbcol.Attribute.IsIdentity)
|
||||
seqcols.Add((tbcol, tbname, tbcol.Attribute.IsIdentity == true));
|
||||
}
|
||||
else if (tbcol.Attribute.IsIdentity != tbstructcol.is_identity)
|
||||
seqcols.Add((tbcol, tbname, tbcol.Attribute.IsIdentity == true));
|
||||
if (isCommentChanged)
|
||||
sbalter.Append("execute immediate 'COMMENT ON COLUMN ").Append(_commonUtils.QuoteSqlName($"{tbname[0]}.{tbname[1]}.{tbcol.Attribute.Name}")).Append(" IS ").Append(_commonUtils.FormatSql("{0}", tbcol.Comment ?? "").Replace("'", "''")).Append("';\r\n");
|
||||
continue;
|
||||
}
|
||||
//添加列
|
||||
sbalter.Append("execute immediate 'ALTER TABLE ").Append(_commonUtils.QuoteSqlName($"{tbname[0]}.{tbname[1]}")).Append(" ADD (").Append(_commonUtils.QuoteSqlName(tbcol.Attribute.Name)).Append(" ").Append(dbtypeNoneNotNull).Append(")';\r\n");
|
||||
if (tbcol.Attribute.IsNullable == false)
|
||||
{
|
||||
sbalter.Append("execute immediate 'UPDATE ").Append(_commonUtils.QuoteSqlName($"{tbname[0]}.{tbname[1]}")).Append(" SET ").Append(_commonUtils.QuoteSqlName(tbcol.Attribute.Name)).Append(" = ").Append(_commonUtils.FormatSql("{0}", tbcol.Attribute.DbDefautValue).Replace("'", "''")).Append("';\r\n");
|
||||
sbalter.Append("execute immediate 'ALTER TABLE ").Append(_commonUtils.QuoteSqlName($"{tbname[0]}.{tbname[1]}")).Append(" MODIFY ").Append(_commonUtils.QuoteSqlName(tbcol.Attribute.Name)).Append(" NOT NULL';\r\n");
|
||||
}
|
||||
if (tbcol.Attribute.IsIdentity == true) seqcols.Add((tbcol, tbname, tbcol.Attribute.IsIdentity == true));
|
||||
if (string.IsNullOrEmpty(tbcol.Comment) == false) sbalter.Append("execute immediate 'COMMENT ON COLUMN ").Append(_commonUtils.QuoteSqlName($"{tbname[0]}.{tbname[1]}.{tbcol.Attribute.Name}")).Append(" IS ").Append(_commonUtils.FormatSql("{0}", tbcol.Comment ?? "").Replace("'", "''")).Append("';\r\n");
|
||||
}
|
||||
var dsuksql = _commonUtils.FormatSql(@"
|
||||
select
|
||||
c.column_name,
|
||||
c.constraint_name
|
||||
from
|
||||
all_constraints a,
|
||||
all_cons_columns c
|
||||
where
|
||||
a.constraint_name = c.constraint_name
|
||||
and a.owner = c.owner
|
||||
and a.table_name = c.table_name
|
||||
and a.constraint_type in ('U')
|
||||
and a.owner in ({0}) and a.table_name in ({1})", tboldname ?? tbname);
|
||||
var dsuk = _orm.Ado.ExecuteArray(CommandType.Text, dsuksql).Select(a => new[] { string.Concat(a[0]), string.Concat(a[1]) });
|
||||
foreach (var uk in tb.Uniques)
|
||||
{
|
||||
if (string.IsNullOrEmpty(uk.Key) || uk.Value.Any() == false) continue;
|
||||
var dsukfind1 = dsuk.Where(a => string.Compare(a[1], uk.Key, true) == 0).ToArray();
|
||||
if (dsukfind1.Any() == false || dsukfind1.Length != uk.Value.Count || dsukfind1.Where(a => uk.Value.Where(b => string.Compare(b.Attribute.Name, a[0], true) == 0).Any()).Count() != uk.Value.Count)
|
||||
{
|
||||
if (dsukfind1.Any()) sbalter.Append("execute immediate 'ALTER TABLE ").Append(_commonUtils.QuoteSqlName($"{tbname[0]}.{tbname[1]}")).Append(" DROP CONSTRAINT ").Append(_commonUtils.QuoteSqlName(uk.Key)).Append("';\r\n");
|
||||
sbalter.Append("execute immediate 'ALTER TABLE ").Append(_commonUtils.QuoteSqlName($"{tbname[0]}.{tbname[1]}")).Append(" ADD CONSTRAINT ").Append(_commonUtils.QuoteSqlName(uk.Key)).Append(" UNIQUE(");
|
||||
foreach (var tbcol in uk.Value) sbalter.Append(_commonUtils.QuoteSqlName(tbcol.Attribute.Name)).Append(", ");
|
||||
sbalter.Remove(sbalter.Length - 2, 2).Append(")';\r\n");
|
||||
}
|
||||
}
|
||||
}
|
||||
if (istmpatler == false)
|
||||
{
|
||||
sb.Append(sbalter);
|
||||
continue;
|
||||
}
|
||||
var oldpk = _orm.Ado.ExecuteScalar(CommandType.Text, _commonUtils.FormatSql(@"select constraint_name from user_constraints where owner={0} and table_name={1} and constraint_type='P'", tbname))?.ToString();
|
||||
if (string.IsNullOrEmpty(oldpk) == false)
|
||||
sb.Append("execute immediate 'ALTER TABLE ").Append(_commonUtils.QuoteSqlName($"{tbname[0]}.{tbname[1]}")).Append(" DROP CONSTRAINT ").Append(oldpk).Append("';\r\n");
|
||||
|
||||
//创建临时表,数据导进临时表,然后删除原表,将临时表改名为原表名
|
||||
var tablename = tboldname == null ? _commonUtils.QuoteSqlName($"{tbname[0]}.{tbname[1]}") : _commonUtils.QuoteSqlName($"{tboldname[0]}.{tboldname[1]}");
|
||||
var tmptablename = _commonUtils.QuoteSqlName($"{tbname[0]}.FTmp_{tbname[1]}");
|
||||
//创建临时表
|
||||
sb.Append("execute immediate 'CREATE TABLE ").Append(tmptablename).Append(" ( ");
|
||||
foreach (var tbcol in tb.ColumnsByPosition)
|
||||
{
|
||||
sb.Append(" \r\n ").Append(_commonUtils.QuoteSqlName(tbcol.Attribute.Name)).Append(" ").Append(tbcol.Attribute.DbType).Append(",");
|
||||
if (tbcol.Attribute.IsIdentity == true) seqcols.Add((tbcol, tbname, true));
|
||||
}
|
||||
if (tb.Primarys.Any())
|
||||
{
|
||||
var pkname = primaryKeyName ?? $"{tbname[0]}_{tbname[1]}_pk2";
|
||||
sb.Append(" \r\n CONSTRAINT ").Append(pkname).Append(" PRIMARY KEY (");
|
||||
foreach (var tbcol in tb.Primarys) sb.Append(_commonUtils.QuoteSqlName(tbcol.Attribute.Name)).Append(", ");
|
||||
sb.Remove(sb.Length - 2, 2).Append("),");
|
||||
}
|
||||
foreach (var uk in tb.Uniques)
|
||||
{
|
||||
sb.Append(" \r\n CONSTRAINT ").Append(_commonUtils.QuoteSqlName(uk.Key)).Append(" UNIQUE (");
|
||||
foreach (var tbcol in uk.Value) sb.Append(_commonUtils.QuoteSqlName(tbcol.Attribute.Name)).Append(", ");
|
||||
sb.Remove(sb.Length - 2, 2).Append("),");
|
||||
}
|
||||
sb.Remove(sb.Length - 1, 1);
|
||||
sb.Append("\r\n) LOGGING \r\nNOCOMPRESS \r\nNOCACHE\r\n';\r\n");
|
||||
//备注
|
||||
foreach (var tbcol in tb.ColumnsByPosition)
|
||||
{
|
||||
if (string.IsNullOrEmpty(tbcol.Comment) == false)
|
||||
sb.Append("execute immediate 'COMMENT ON COLUMN ").Append(_commonUtils.QuoteSqlName($"{tbname[0]}.FTmp_{tbname[1]}.{tbcol.Attribute.Name}")).Append(" IS ").Append(_commonUtils.FormatSql("{0}", tbcol.Comment).Replace("'", "''")).Append("';\r\n");
|
||||
}
|
||||
sb.Append("execute immediate 'INSERT INTO ").Append(tmptablename).Append(" (");
|
||||
foreach (var tbcol in tb.ColumnsByPosition)
|
||||
sb.Append(_commonUtils.QuoteSqlName(tbcol.Attribute.Name)).Append(", ");
|
||||
sb.Remove(sb.Length - 2, 2).Append(")\r\nSELECT ");
|
||||
foreach (var tbcol in tb.ColumnsByPosition)
|
||||
{
|
||||
var insertvalue = "NULL";
|
||||
if (tbstruct.TryGetValue(tbcol.Attribute.Name, out var tbstructcol) ||
|
||||
string.IsNullOrEmpty(tbcol.Attribute.OldName) == false && tbstruct.TryGetValue(tbcol.Attribute.OldName, out tbstructcol))
|
||||
{
|
||||
insertvalue = _commonUtils.QuoteSqlName(tbstructcol.column);
|
||||
if (tbcol.Attribute.DbType.StartsWith(tbstructcol.sqlType, StringComparison.CurrentCultureIgnoreCase) == false)
|
||||
{
|
||||
var dbtypeNoneNotNull = Regex.Replace(tbcol.Attribute.DbType, @"(NOT\s+)?NULL", "");
|
||||
insertvalue = $"cast({insertvalue} as {dbtypeNoneNotNull})";
|
||||
}
|
||||
if (tbcol.Attribute.IsNullable != tbstructcol.is_nullable)
|
||||
insertvalue = $"nvl({insertvalue},{_commonUtils.FormatSql("{0}", tbcol.Attribute.DbDefautValue)})";
|
||||
}
|
||||
else if (tbcol.Attribute.IsNullable == false)
|
||||
insertvalue = _commonUtils.FormatSql("{0}", tbcol.Attribute.DbDefautValue);
|
||||
sb.Append(insertvalue.Replace("'", "''")).Append(", ");
|
||||
}
|
||||
sb.Remove(sb.Length - 2, 2).Append(" FROM ").Append(tablename).Append("';\r\n");
|
||||
sb.Append("execute immediate 'DROP TABLE ").Append(tablename).Append("';\r\n");
|
||||
sb.Append("execute immediate 'ALTER TABLE ").Append(tmptablename).Append(" RENAME TO ").Append(_commonUtils.QuoteSqlName($"{tbname[1]}")).Append("';\r\n");
|
||||
}
|
||||
Dictionary<string, bool> dicDeclare = new Dictionary<string, bool>();
|
||||
Action<string> dropSequence = seqname =>
|
||||
{
|
||||
if (dicDeclare.ContainsKey(seqname) == false)
|
||||
{
|
||||
sbDeclare.Append("\r\n").Append(seqname).Append("IS NUMBER; \r\n");
|
||||
dicDeclare.Add(seqname, true);
|
||||
}
|
||||
sb.Append(seqname).Append("IS := 0; \r\n")
|
||||
.Append(" select count(1) into ").Append(seqname).Append(_commonUtils.FormatSql("IS from user_sequences where sequence_name={0}; \r\n", seqname))
|
||||
.Append("if ").Append(seqname).Append("IS > 0 then \r\n")
|
||||
.Append(" execute immediate 'DROP SEQUENCE ").Append(_commonUtils.QuoteSqlName(seqname)).Append("';\r\n")
|
||||
.Append("end if; \r\n");
|
||||
};
|
||||
Action<string> dropTrigger = tiggerName =>
|
||||
{
|
||||
if (dicDeclare.ContainsKey(tiggerName) == false)
|
||||
{
|
||||
sbDeclare.Append("\r\n").Append(tiggerName).Append("IS NUMBER; \r\n");
|
||||
dicDeclare.Add(tiggerName, true);
|
||||
}
|
||||
sb.Append(tiggerName).Append("IS := 0; \r\n")
|
||||
.Append(" select count(1) into ").Append(tiggerName).Append(_commonUtils.FormatSql("IS from user_triggers where trigger_name={0}; \r\n", tiggerName))
|
||||
.Append("if ").Append(tiggerName).Append("IS > 0 then \r\n")
|
||||
.Append(" execute immediate 'DROP TRIGGER ").Append(_commonUtils.QuoteSqlName(tiggerName)).Append("';\r\n")
|
||||
.Append("end if; \r\n");
|
||||
};
|
||||
foreach (var seqname in seqnameDel)
|
||||
{
|
||||
dropSequence(seqname);
|
||||
dropTrigger(seqname + "TI");
|
||||
}
|
||||
foreach (var seqcol in seqcols)
|
||||
{
|
||||
var tbname = seqcol.Item2;
|
||||
var seqname = Utils.GetCsName($"{tbname[1]}_seq_{seqcol.Item1.Attribute.Name}");
|
||||
var tiggerName = seqname + "TI";
|
||||
var tbname2 = _commonUtils.QuoteSqlName($"{tbname[0]}.{tbname[1]}");
|
||||
var colname2 = _commonUtils.QuoteSqlName(seqcol.Item1.Attribute.Name);
|
||||
dropSequence(seqname);
|
||||
if (seqcol.Item3)
|
||||
{
|
||||
var startWith = _orm.Ado.ExecuteScalar(CommandType.Text, _commonUtils.FormatSql(" select 1 from all_tab_columns where owner={0} and table_name={1} and column_name={2}", tbname[0], tbname[1], colname2)) == null ? 1 :
|
||||
_orm.Ado.ExecuteScalar(CommandType.Text, $" select nvl(max({colname2})+1,1) from {tbname2}");
|
||||
sb.Append("execute immediate 'CREATE SEQUENCE ").Append(_commonUtils.QuoteSqlName(seqname)).Append(" start with ").Append(startWith).Append("';\r\n");
|
||||
sb.Append("execute immediate 'CREATE OR REPLACE TRIGGER ").Append(_commonUtils.QuoteSqlName(tiggerName))
|
||||
.Append(" \r\nbefore insert on ").Append(tbname2)
|
||||
.Append(" \r\nfor each row \r\nbegin\r\nselect ").Append(_commonUtils.QuoteSqlName(seqname))
|
||||
.Append(".nextval into :new.").Append(colname2).Append(" from dual;\r\nend;';\r\n");
|
||||
}
|
||||
else
|
||||
dropTrigger(tiggerName);
|
||||
}
|
||||
if (sbDeclare.Length > 0) sbDeclare.Insert(0, "declare ");
|
||||
return sb.Length == 0 ? null : sb.Insert(0, "BEGIN \r\n").Insert(0, sbDeclare.ToString()).Append("END;").ToString();
|
||||
}
|
||||
|
||||
internal static string GetOracleSqlTypeFullName(object[] row)
|
||||
{
|
||||
var a = row;
|
||||
var sqlType = string.Concat(a[1]).ToUpper();
|
||||
var data_length = long.Parse(string.Concat(a[2]));
|
||||
long.TryParse(string.Concat(a[3]), out var data_precision);
|
||||
long.TryParse(string.Concat(a[4]), out var data_scale);
|
||||
var char_used = string.Concat(a[5]);
|
||||
if (Regex.IsMatch(sqlType, @"INTERVAL DAY\(\d+\) TO SECOND\(\d+\)", RegexOptions.IgnoreCase))
|
||||
{
|
||||
}
|
||||
else if (Regex.IsMatch(sqlType, @"INTERVAL YEAR\(\d+\) TO MONTH", RegexOptions.IgnoreCase))
|
||||
{
|
||||
}
|
||||
else if (sqlType.StartsWith("TIMESTAMP", StringComparison.CurrentCultureIgnoreCase))
|
||||
{
|
||||
}
|
||||
else if (sqlType.StartsWith("BLOB"))
|
||||
{
|
||||
}
|
||||
else if (char_used.ToLower() == "c")
|
||||
sqlType += sqlType.StartsWith("N") ? $"({data_length / 2})" : $"({data_length / 4} CHAR)";
|
||||
else if (char_used.ToLower() == "b")
|
||||
sqlType += $"({data_length} BYTE)";
|
||||
else if (sqlType.ToLower() == "float")
|
||||
sqlType += $"({data_precision})";
|
||||
else if (data_precision > 0 && data_scale > 0)
|
||||
sqlType += $"({data_precision},{data_scale})";
|
||||
else if (data_precision > 0)
|
||||
sqlType += $"({data_precision})";
|
||||
else
|
||||
sqlType += $"({data_length})";
|
||||
return sqlType;
|
||||
}
|
||||
}
|
||||
}
|
484
Providers/FreeSql.Provider.Odbc/Oracle/OdbcOracleDbFirst.cs
Normal file
484
Providers/FreeSql.Provider.Odbc/Oracle/OdbcOracleDbFirst.cs
Normal file
@ -0,0 +1,484 @@
|
||||
using FreeSql.DatabaseModel;
|
||||
using FreeSql.Internal;
|
||||
using System;
|
||||
using System.Collections.Concurrent;
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
using System.Data.Odbc;
|
||||
using System.Linq;
|
||||
using System.Text.RegularExpressions;
|
||||
|
||||
namespace FreeSql.Odbc.Oracle
|
||||
{
|
||||
class OdbcOracleDbFirst : IDbFirst
|
||||
{
|
||||
IFreeSql _orm;
|
||||
protected CommonUtils _commonUtils;
|
||||
protected CommonExpression _commonExpression;
|
||||
public OdbcOracleDbFirst(IFreeSql orm, CommonUtils commonUtils, CommonExpression commonExpression)
|
||||
{
|
||||
_orm = orm;
|
||||
_commonUtils = commonUtils;
|
||||
_commonExpression = commonExpression;
|
||||
}
|
||||
|
||||
public int GetDbType(DbColumnInfo column) => (int)GetSqlDbType(column);
|
||||
OdbcType GetSqlDbType(DbColumnInfo column)
|
||||
{
|
||||
var dbfull = column.DbTypeTextFull.ToLower();
|
||||
switch (dbfull)
|
||||
{
|
||||
case "number(1)": return OdbcType.Bit;
|
||||
|
||||
case "number(4)": return OdbcType.SmallInt;
|
||||
case "number(6)": return OdbcType.SmallInt;
|
||||
case "number(11)": return OdbcType.Int;
|
||||
case "number(21)": return OdbcType.BigInt;
|
||||
|
||||
case "number(3)": return OdbcType.TinyInt;
|
||||
case "number(5)": return OdbcType.SmallInt;
|
||||
case "number(10)": return OdbcType.BigInt;
|
||||
case "number(20)": return OdbcType.Decimal;
|
||||
|
||||
case "float(126)": return OdbcType.Double;
|
||||
case "float(63)": return OdbcType.Real;
|
||||
case "number(10,2)": return OdbcType.Decimal;
|
||||
|
||||
case "interval day(2) to second(6)": return OdbcType.Time;
|
||||
case "timestamp(6)": return OdbcType.DateTime;
|
||||
case "timestamp(6) with local time zone": return OdbcType.DateTime;
|
||||
|
||||
case "blob": return OdbcType.VarBinary;
|
||||
case "nvarchar2(255)": return OdbcType.NVarChar;
|
||||
|
||||
case "char(36 char)": return OdbcType.Char;
|
||||
}
|
||||
switch (column.DbTypeText.ToLower())
|
||||
{
|
||||
case "number":
|
||||
_dicDbToCs.TryAdd(dbfull, _dicDbToCs["number(10,2)"]);
|
||||
return OdbcType.Decimal;
|
||||
case "float":
|
||||
_dicDbToCs.TryAdd(dbfull, _dicDbToCs["float(126)"]);
|
||||
return OdbcType.Double;
|
||||
case "interval day to second":
|
||||
_dicDbToCs.TryAdd(dbfull, _dicDbToCs["interval day(2) to second(6)"]);
|
||||
return OdbcType.Time;
|
||||
case "date":
|
||||
_dicDbToCs.TryAdd(dbfull, _dicDbToCs["date(7)"]);
|
||||
return OdbcType.DateTime;
|
||||
case "timestamp":
|
||||
_dicDbToCs.TryAdd(dbfull, _dicDbToCs["timestamp(6)"]);
|
||||
return OdbcType.DateTime;
|
||||
case "timestamp with local time zone":
|
||||
_dicDbToCs.TryAdd(dbfull, _dicDbToCs["timestamp(6) with local time zone"]);
|
||||
return OdbcType.DateTime;
|
||||
case "blob":
|
||||
_dicDbToCs.TryAdd(dbfull, _dicDbToCs["blob"]);
|
||||
return OdbcType.VarBinary;
|
||||
case "nvarchar2":
|
||||
_dicDbToCs.TryAdd(dbfull, _dicDbToCs["nvarchar2(255)"]);
|
||||
return OdbcType.NVarChar;
|
||||
case "varchar2":
|
||||
_dicDbToCs.TryAdd(dbfull, _dicDbToCs["nvarchar2(255)"]);
|
||||
return OdbcType.NVarChar;
|
||||
case "char":
|
||||
_dicDbToCs.TryAdd(dbfull, _dicDbToCs["nvarchar2(255)"]);
|
||||
return OdbcType.Char;
|
||||
case "nchar":
|
||||
_dicDbToCs.TryAdd(dbfull, _dicDbToCs["nvarchar2(255)"]);
|
||||
return OdbcType.NChar;
|
||||
case "clob":
|
||||
_dicDbToCs.TryAdd(dbfull, _dicDbToCs["nvarchar2(255)"]);
|
||||
return OdbcType.NVarChar;
|
||||
case "nclob":
|
||||
_dicDbToCs.TryAdd(dbfull, _dicDbToCs["nvarchar2(255)"]);
|
||||
return OdbcType.NVarChar;
|
||||
case "raw":
|
||||
_dicDbToCs.TryAdd(dbfull, _dicDbToCs["blob"]);
|
||||
return OdbcType.VarBinary;
|
||||
case "long raw":
|
||||
_dicDbToCs.TryAdd(dbfull, _dicDbToCs["blob"]);
|
||||
return OdbcType.VarBinary;
|
||||
case "binary_float":
|
||||
_dicDbToCs.TryAdd(dbfull, _dicDbToCs["float(63)"]);
|
||||
return OdbcType.Real;
|
||||
case "binary_double":
|
||||
_dicDbToCs.TryAdd(dbfull, _dicDbToCs["float(126)"]);
|
||||
return OdbcType.Double;
|
||||
case "rowid":
|
||||
default:
|
||||
_dicDbToCs.TryAdd(dbfull, _dicDbToCs["nvarchar2(255)"]);
|
||||
return OdbcType.NVarChar;
|
||||
}
|
||||
throw new NotImplementedException($"未实现 {column.DbTypeTextFull} 类型映射");
|
||||
}
|
||||
|
||||
static ConcurrentDictionary<string, (string csConvert, string csParse, string csStringify, string csType, Type csTypeInfo, Type csNullableTypeInfo, string csTypeValue, string dataReaderMethod)> _dicDbToCs = new ConcurrentDictionary<string, (string csConvert, string csParse, string csStringify, string csType, Type csTypeInfo, Type csNullableTypeInfo, string csTypeValue, string dataReaderMethod)>(StringComparer.CurrentCultureIgnoreCase);
|
||||
static OdbcOracleDbFirst()
|
||||
{
|
||||
var defaultDbToCs = new Dictionary<string, (string csConvert, string csParse, string csStringify, string csType, Type csTypeInfo, Type csNullableTypeInfo, string csTypeValue, string dataReaderMethod)>() {
|
||||
{ "number(1)", ("(bool?)", "{0} == \"1\"", "{0} == true ? \"1\" : \"0\"", "bool?", typeof(bool), typeof(bool?), "{0}.Value", "GetBoolean") },
|
||||
|
||||
{ "number(4)", ("(sbyte?)", "sbyte.Parse({0})", "{0}.ToString()", "sbyte?", typeof(sbyte), typeof(sbyte?), "{0}.Value", "GetInt16") },
|
||||
{ "number(6)", ("(short?)", "short.Parse({0})", "{0}.ToString()", "short?", typeof(short), typeof(short?), "{0}.Value", "GetInt16") },
|
||||
{ "number(11)", ("(int?)", "int.Parse({0})", "{0}.ToString()", "int?", typeof(int), typeof(int?), "{0}.Value", "GetInt32") },
|
||||
{ "number(21)", ("(long?)", "long.Parse({0})", "{0}.ToString()", "long?", typeof(long), typeof(long?), "{0}.Value", "GetInt64") },
|
||||
|
||||
{ "number(3)", ("(byte?)", "byte.Parse({0})", "{0}.ToString()", "byte?", typeof(byte), typeof(byte?), "{0}.Value", "GetByte") },
|
||||
{ "number(5)", ("(ushort?)", "ushort.Parse({0})", "{0}.ToString()", "ushort?", typeof(ushort), typeof(ushort?), "{0}.Value", "GetInt32") },
|
||||
{ "number(10)", ("(uint?)", "uint.Parse({0})", "{0}.ToString()", "uint?", typeof(uint), typeof(uint?), "{0}.Value", "GetInt64") },
|
||||
{ "number(20)", ("(ulong?)", "ulong.Parse({0})", "{0}.ToString()", "ulong?", typeof(ulong), typeof(ulong?), "{0}.Value", "GetDecimal") },
|
||||
|
||||
{ "float(126)", ("(double?)", "double.Parse({0})", "{0}.ToString()", "double?", typeof(double), typeof(double?), "{0}.Value", "GetDouble") },
|
||||
{ "float(63)", ("(float?)", "float.Parse({0})", "{0}.ToString()", "float?", typeof(float), typeof(float?), "{0}.Value", "GetFloat") },
|
||||
{ "number(10,2)", ("(decimal?)", "decimal.Parse({0})", "{0}.ToString()", "decimal?", typeof(decimal), typeof(decimal?), "{0}.Value", "GetDecimal") },
|
||||
|
||||
{ "interval day(2) to second(6)", ("(TimeSpan?)", "TimeSpan.Parse(double.Parse({0}))", "{0}.Ticks.ToString()", "TimeSpan?", typeof(TimeSpan), typeof(TimeSpan?), "{0}.Value", "GetValue") },
|
||||
{ "date(7)", ("(DateTime?)", "new DateTime(long.Parse({0}))", "{0}.Ticks.ToString()", "DateTime?", typeof(DateTime), typeof(DateTime?), "{0}.Value", "GetValue") },
|
||||
{ "timestamp(6)", ("(DateTime?)", "new DateTime(long.Parse({0}))", "{0}.Ticks.ToString()", "DateTime?", typeof(DateTime), typeof(DateTime?), "{0}.Value", "GetValue") },
|
||||
{ "timestamp(6) with local time zone", ("(DateTime?)", "new DateTime(long.Parse({0}))", "{0}.Ticks.ToString()", "DateTime?", typeof(DateTime), typeof(DateTime?), "{0}.Value", "GetValue") },
|
||||
|
||||
{ "blob", ("(byte[])", "Convert.FromBase64String({0})", "Convert.ToBase64String({0})", "byte[]", typeof(byte[]), typeof(byte[]), "{0}", "GetValue") },
|
||||
|
||||
{ "nvarchar2(255)", ("", "{0}.Replace(StringifySplit, \"|\")", "{0}.Replace(\"|\", StringifySplit)", "string", typeof(string), typeof(string), "{0}", "GetString") },
|
||||
{ "char(36 char)", ("(Guid?)", "Guid.Parse({0})", "{0}.ToString()", "Guid?", typeof(Guid), typeof(Guid?), "{0}.Value", "GetGuid") },
|
||||
};
|
||||
foreach (var kv in defaultDbToCs)
|
||||
_dicDbToCs.TryAdd(kv.Key, kv.Value);
|
||||
}
|
||||
|
||||
|
||||
public string GetCsConvert(DbColumnInfo column) => _dicDbToCs.TryGetValue(column.DbTypeTextFull, out var trydc) ? (column.IsNullable ? trydc.csConvert : trydc.csConvert.Replace("?", "")) : null;
|
||||
public string GetCsParse(DbColumnInfo column) => _dicDbToCs.TryGetValue(column.DbTypeTextFull, out var trydc) ? trydc.csParse : null;
|
||||
public string GetCsStringify(DbColumnInfo column) => _dicDbToCs.TryGetValue(column.DbTypeTextFull, out var trydc) ? trydc.csStringify : null;
|
||||
public string GetCsType(DbColumnInfo column) => _dicDbToCs.TryGetValue(column.DbTypeTextFull, out var trydc) ? (column.IsNullable ? trydc.csType : trydc.csType.Replace("?", "")) : null;
|
||||
public Type GetCsTypeInfo(DbColumnInfo column) => _dicDbToCs.TryGetValue(column.DbTypeTextFull, out var trydc) ? trydc.csTypeInfo : null;
|
||||
public string GetCsTypeValue(DbColumnInfo column) => _dicDbToCs.TryGetValue(column.DbTypeTextFull, out var trydc) ? trydc.csTypeValue : null;
|
||||
public string GetDataReaderMethod(DbColumnInfo column) => _dicDbToCs.TryGetValue(column.DbTypeTextFull, out var trydc) ? trydc.dataReaderMethod : null;
|
||||
|
||||
public List<string> GetDatabases()
|
||||
{
|
||||
var sql = @" select username from all_users";
|
||||
var ds = _orm.Ado.ExecuteArray(CommandType.Text, sql);
|
||||
return ds.Select(a => a.FirstOrDefault()?.ToString()).ToList();
|
||||
}
|
||||
|
||||
public List<DbTableInfo> GetTablesByDatabase(params string[] database2)
|
||||
{
|
||||
var loc1 = new List<DbTableInfo>();
|
||||
var loc2 = new Dictionary<string, DbTableInfo>();
|
||||
var loc3 = new Dictionary<string, Dictionary<string, DbColumnInfo>>();
|
||||
var database = database2?.ToArray();
|
||||
|
||||
if (database == null || database.Any() == false)
|
||||
{
|
||||
var userUsers = _orm.Ado.ExecuteScalar("select username from user_users")?.ToString();
|
||||
if (string.IsNullOrEmpty(userUsers)) return loc1;
|
||||
database = new[] { userUsers };
|
||||
}
|
||||
var databaseIn = string.Join(",", database.Select(a => _commonUtils.FormatSql("{0}", a)));
|
||||
var sql = string.Format(@"
|
||||
select
|
||||
a.owner || '.' || a.table_name,
|
||||
a.owner,
|
||||
a.table_name,
|
||||
b.comments,
|
||||
'TABLE'
|
||||
from all_tables a
|
||||
left join all_tab_comments b on b.owner = a.owner and b.table_name = a.table_name and b.table_type = 'TABLE'
|
||||
where a.owner in ({0})", databaseIn);
|
||||
var ds = _orm.Ado.ExecuteArray(CommandType.Text, sql);
|
||||
if (ds == null) return loc1;
|
||||
|
||||
var loc6 = new List<string>();
|
||||
var loc66 = new List<string>();
|
||||
foreach (var row in ds)
|
||||
{
|
||||
var table_id = string.Concat(row[0]);
|
||||
var schema = string.Concat(row[1]);
|
||||
var table = string.Concat(row[2]);
|
||||
var comment = string.Concat(row[3]);
|
||||
var type = string.Concat(row[4]) == "VIEW" ? DbTableType.VIEW : DbTableType.TABLE;
|
||||
if (database.Length == 1)
|
||||
{
|
||||
table_id = table_id.Substring(table_id.IndexOf('.') + 1);
|
||||
schema = "";
|
||||
}
|
||||
loc2.Add(table_id, new DbTableInfo { Id = table_id, Schema = schema, Name = table, Comment = comment, Type = type });
|
||||
loc3.Add(table_id, new Dictionary<string, DbColumnInfo>());
|
||||
switch (type)
|
||||
{
|
||||
case DbTableType.TABLE:
|
||||
case DbTableType.VIEW:
|
||||
loc6.Add(table.Replace("'", "''"));
|
||||
break;
|
||||
case DbTableType.StoreProcedure:
|
||||
loc66.Add(table.Replace("'", "''"));
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (loc6.Count == 0) return loc1;
|
||||
var loc8 = "'" + string.Join("','", loc6.ToArray()) + "'";
|
||||
var loc88 = "'" + string.Join("','", loc66.ToArray()) + "'";
|
||||
|
||||
sql = string.Format(@"
|
||||
select
|
||||
a.owner || '.' || a.table_name,
|
||||
a.column_name,
|
||||
a.data_type,
|
||||
a.data_length,
|
||||
a.data_precision,
|
||||
a.data_scale,
|
||||
a.char_used,
|
||||
case when a.nullable = 'Y' then 1 else 0 end,
|
||||
nvl((select 1 from user_sequences where upper(sequence_name)=upper(a.table_name||'_seq_'||a.column_name)), 0),
|
||||
b.comments
|
||||
from all_tab_cols a
|
||||
left join all_col_comments b on b.owner = a.owner and b.table_name = a.table_name and b.column_name = a.column_name
|
||||
where a.owner in ({1}) and a.table_name in ({0})
|
||||
", loc8, databaseIn);
|
||||
ds = _orm.Ado.ExecuteArray(CommandType.Text, sql);
|
||||
if (ds == null) return loc1;
|
||||
|
||||
var ds2 = new List<object[]>();
|
||||
foreach (var row in ds)
|
||||
{
|
||||
var ds2item = new object[8];
|
||||
ds2item[0] = row[0];
|
||||
ds2item[1] = row[1];
|
||||
ds2item[2] = Regex.Replace(string.Concat(row[2]), @"\(\d+\)", "");
|
||||
ds2item[4] = OdbcOracleCodeFirst.GetOracleSqlTypeFullName(new object[] { row[1], row[2], row[3], row[4], row[5], row[6] });
|
||||
ds2item[5] = string.Concat(row[7]) == "1";
|
||||
ds2item[6] = string.Concat(row[8]) == "1";
|
||||
ds2item[7] = string.Concat(row[9]);
|
||||
ds2.Add(ds2item);
|
||||
}
|
||||
foreach (var row in ds2)
|
||||
{
|
||||
string table_id = string.Concat(row[0]);
|
||||
string column = string.Concat(row[1]);
|
||||
string type = string.Concat(row[2]);
|
||||
//long max_length = long.Parse(string.Concat(row[3]));
|
||||
string sqlType = string.Concat(row[4]);
|
||||
var m_len = Regex.Match(sqlType, @"\w+\((\d+)");
|
||||
int max_length = m_len.Success ? int.Parse(m_len.Groups[1].Value) : -1;
|
||||
bool is_nullable = string.Concat(row[5]) == "1";
|
||||
bool is_identity = string.Concat(row[6]) == "1";
|
||||
string comment = string.Concat(row[7]);
|
||||
if (max_length == 0) max_length = -1;
|
||||
if (database.Length == 1)
|
||||
{
|
||||
table_id = table_id.Substring(table_id.IndexOf('.') + 1);
|
||||
}
|
||||
loc3[table_id].Add(column, new DbColumnInfo
|
||||
{
|
||||
Name = column,
|
||||
MaxLength = max_length,
|
||||
IsIdentity = is_identity,
|
||||
IsNullable = is_nullable,
|
||||
IsPrimary = false,
|
||||
DbTypeText = type,
|
||||
DbTypeTextFull = sqlType,
|
||||
Table = loc2[table_id],
|
||||
Coment = comment
|
||||
});
|
||||
loc3[table_id][column].DbType = this.GetDbType(loc3[table_id][column]);
|
||||
loc3[table_id][column].CsType = this.GetCsTypeInfo(loc3[table_id][column]);
|
||||
}
|
||||
|
||||
sql = string.Format(@"
|
||||
select
|
||||
a.owner || '.' || a.table_name,
|
||||
c.column_name,
|
||||
c.constraint_name,
|
||||
case when a.constraint_type = 'U' then 1 else 0 end,
|
||||
case when a.constraint_type = 'P' then 1 else 0 end,
|
||||
0,
|
||||
0
|
||||
from
|
||||
all_constraints a,
|
||||
all_cons_columns c
|
||||
where
|
||||
a.constraint_name = c.constraint_name
|
||||
and a.owner = c.owner
|
||||
and a.table_name = c.table_name
|
||||
and a.constraint_type in ('P', 'U')
|
||||
and a.owner in ({1}) and a.table_name in ({0})
|
||||
", loc8, databaseIn);
|
||||
ds = _orm.Ado.ExecuteArray(CommandType.Text, sql);
|
||||
if (ds == null) return loc1;
|
||||
|
||||
var indexColumns = new Dictionary<string, Dictionary<string, List<DbColumnInfo>>>();
|
||||
var uniqueColumns = new Dictionary<string, Dictionary<string, List<DbColumnInfo>>>();
|
||||
foreach (var row in ds)
|
||||
{
|
||||
string table_id = string.Concat(row[0]);
|
||||
string column = string.Concat(row[1]);
|
||||
string index_id = string.Concat(row[2]);
|
||||
bool is_unique = string.Concat(row[3]) == "1";
|
||||
bool is_primary_key = string.Concat(row[4]) == "1";
|
||||
bool is_clustered = string.Concat(row[5]) == "1";
|
||||
int is_desc = int.Parse(string.Concat(row[6]));
|
||||
if (database.Length == 1)
|
||||
{
|
||||
table_id = table_id.Substring(table_id.IndexOf('.') + 1);
|
||||
}
|
||||
if (loc3.ContainsKey(table_id) == false || loc3[table_id].ContainsKey(column) == false) continue;
|
||||
var loc9 = loc3[table_id][column];
|
||||
if (loc9.IsPrimary == false && is_primary_key) loc9.IsPrimary = is_primary_key;
|
||||
|
||||
Dictionary<string, List<DbColumnInfo>> loc10 = null;
|
||||
List<DbColumnInfo> loc11 = null;
|
||||
if (!indexColumns.TryGetValue(table_id, out loc10))
|
||||
indexColumns.Add(table_id, loc10 = new Dictionary<string, List<DbColumnInfo>>());
|
||||
if (!loc10.TryGetValue(index_id, out loc11))
|
||||
loc10.Add(index_id, loc11 = new List<DbColumnInfo>());
|
||||
loc11.Add(loc9);
|
||||
if (is_unique && !is_primary_key)
|
||||
{
|
||||
if (!uniqueColumns.TryGetValue(table_id, out loc10))
|
||||
uniqueColumns.Add(table_id, loc10 = new Dictionary<string, List<DbColumnInfo>>());
|
||||
if (!loc10.TryGetValue(index_id, out loc11))
|
||||
loc10.Add(index_id, loc11 = new List<DbColumnInfo>());
|
||||
loc11.Add(loc9);
|
||||
}
|
||||
}
|
||||
foreach (string table_id in indexColumns.Keys)
|
||||
{
|
||||
foreach (var column in indexColumns[table_id])
|
||||
loc2[table_id].IndexesDict.Add(column.Key, column.Value);
|
||||
}
|
||||
foreach (string table_id in uniqueColumns.Keys)
|
||||
{
|
||||
foreach (var column in uniqueColumns[table_id])
|
||||
{
|
||||
column.Value.Sort((c1, c2) => c1.Name.CompareTo(c2.Name));
|
||||
loc2[table_id].UniquesDict.Add(column.Key, column.Value);
|
||||
}
|
||||
}
|
||||
|
||||
sql = string.Format(@"
|
||||
select
|
||||
a.owner || '.' || a.table_name,
|
||||
c.column_name,
|
||||
c.constraint_name,
|
||||
b.owner || '.' || b.table_name,
|
||||
1,
|
||||
d.column_name
|
||||
|
||||
-- a.owner 外键拥有者,
|
||||
-- a.table_name 外键表,
|
||||
-- c.column_name 外键列,
|
||||
-- b.owner 主键拥有者,
|
||||
-- b.table_name 主键表,
|
||||
-- d.column_name 主键列,
|
||||
-- c.constraint_name 外键名,
|
||||
-- d.constraint_name 主键名
|
||||
|
||||
from
|
||||
all_constraints a,
|
||||
all_constraints b,
|
||||
all_cons_columns c, --外键表
|
||||
all_cons_columns d --主键表
|
||||
where
|
||||
a.r_constraint_name = b.constraint_name
|
||||
and a.constraint_type = 'R'
|
||||
and b.constraint_type = 'P'
|
||||
and a.r_owner = b.owner
|
||||
and a.constraint_name = c.constraint_name
|
||||
and b.constraint_name = d.constraint_name
|
||||
and a.owner = c.owner
|
||||
and a.table_name = c.table_name
|
||||
and b.owner = d.owner
|
||||
and b.table_name = d.table_name
|
||||
and a.owner in ({1}) and a.table_name in ({0})
|
||||
", loc8, databaseIn);
|
||||
ds = _orm.Ado.ExecuteArray(CommandType.Text, sql);
|
||||
if (ds == null) return loc1;
|
||||
|
||||
var fkColumns = new Dictionary<string, Dictionary<string, DbForeignInfo>>();
|
||||
foreach (var row in ds)
|
||||
{
|
||||
string table_id = string.Concat(row[0]);
|
||||
string column = string.Concat(row[1]);
|
||||
string fk_id = string.Concat(row[2]);
|
||||
string ref_table_id = string.Concat(row[3]);
|
||||
bool is_foreign_key = string.Concat(row[4]) == "1";
|
||||
string referenced_column = string.Concat(row[5]);
|
||||
if (database.Length == 1)
|
||||
{
|
||||
table_id = table_id.Substring(table_id.IndexOf('.') + 1);
|
||||
ref_table_id = ref_table_id.Substring(ref_table_id.IndexOf('.') + 1);
|
||||
}
|
||||
if (loc3.ContainsKey(table_id) == false || loc3[table_id].ContainsKey(column) == false) continue;
|
||||
var loc9 = loc3[table_id][column];
|
||||
if (loc2.ContainsKey(ref_table_id) == false) continue;
|
||||
var loc10 = loc2[ref_table_id];
|
||||
var loc11 = loc3[ref_table_id][referenced_column];
|
||||
|
||||
Dictionary<string, DbForeignInfo> loc12 = null;
|
||||
DbForeignInfo loc13 = null;
|
||||
if (!fkColumns.TryGetValue(table_id, out loc12))
|
||||
fkColumns.Add(table_id, loc12 = new Dictionary<string, DbForeignInfo>());
|
||||
if (!loc12.TryGetValue(fk_id, out loc13))
|
||||
loc12.Add(fk_id, loc13 = new DbForeignInfo { Table = loc2[table_id], ReferencedTable = loc10 });
|
||||
loc13.Columns.Add(loc9);
|
||||
loc13.ReferencedColumns.Add(loc11);
|
||||
}
|
||||
foreach (var table_id in fkColumns.Keys)
|
||||
foreach (var fk in fkColumns[table_id])
|
||||
loc2[table_id].ForeignsDict.Add(fk.Key, fk.Value);
|
||||
|
||||
foreach (var table_id in loc3.Keys)
|
||||
{
|
||||
foreach (var loc5 in loc3[table_id].Values)
|
||||
{
|
||||
loc2[table_id].Columns.Add(loc5);
|
||||
if (loc5.IsIdentity) loc2[table_id].Identitys.Add(loc5);
|
||||
if (loc5.IsPrimary) loc2[table_id].Primarys.Add(loc5);
|
||||
}
|
||||
}
|
||||
foreach (var loc4 in loc2.Values)
|
||||
{
|
||||
if (loc4.Primarys.Count == 0 && loc4.UniquesDict.Count > 0)
|
||||
{
|
||||
foreach (var loc5 in loc4.UniquesDict.First().Value)
|
||||
{
|
||||
loc5.IsPrimary = true;
|
||||
loc4.Primarys.Add(loc5);
|
||||
}
|
||||
}
|
||||
loc4.Primarys.Sort((c1, c2) => c1.Name.CompareTo(c2.Name));
|
||||
loc4.Columns.Sort((c1, c2) =>
|
||||
{
|
||||
int compare = c2.IsPrimary.CompareTo(c1.IsPrimary);
|
||||
if (compare == 0)
|
||||
{
|
||||
bool b1 = loc4.ForeignsDict.Values.Where(fk => fk.Columns.Where(c3 => c3.Name == c1.Name).Any()).Any();
|
||||
bool b2 = loc4.ForeignsDict.Values.Where(fk => fk.Columns.Where(c3 => c3.Name == c2.Name).Any()).Any();
|
||||
compare = b2.CompareTo(b1);
|
||||
}
|
||||
if (compare == 0) compare = c1.Name.CompareTo(c2.Name);
|
||||
return compare;
|
||||
});
|
||||
loc1.Add(loc4);
|
||||
}
|
||||
loc1.Sort((t1, t2) =>
|
||||
{
|
||||
var ret = t1.Schema.CompareTo(t2.Schema);
|
||||
if (ret == 0) ret = t1.Name.CompareTo(t2.Name);
|
||||
return ret;
|
||||
});
|
||||
|
||||
loc2.Clear();
|
||||
loc3.Clear();
|
||||
return loc1;
|
||||
}
|
||||
|
||||
public List<DbEnumInfo> GetEnumsByDatabase(params string[] database)
|
||||
{
|
||||
return new List<DbEnumInfo>();
|
||||
}
|
||||
}
|
||||
}
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
x
Reference in New Issue
Block a user