mirror of
https://github.com/nsnail/FreeSql.git
synced 2025-06-17 19:43:21 +08:00
- 增加 所有国产数据库支持 CustomMySql、CustomPostgreSQL、CustomOracle、CustomSqlServer 自定义适配;
This commit is contained in:
parent
3ec8e2118d
commit
b7e96620a7
@ -18,7 +18,7 @@
|
||||
<SignAssembly>true</SignAssembly>
|
||||
<AssemblyOriginatorKeyFile>key.snk</AssemblyOriginatorKeyFile>
|
||||
<DelaySign>false</DelaySign>
|
||||
<Version>1.0.0</Version>
|
||||
<Version>1.0.1</Version>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
@ -800,14 +800,5 @@
|
||||
<param name="that"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:Microsoft.Extensions.DependencyInjection.FreeSqlRepositoryDependencyInjection.AddFreeRepository(Microsoft.Extensions.DependencyInjection.IServiceCollection,System.Action{FreeSql.FluentDataFilter},System.Reflection.Assembly[])">
|
||||
<summary>
|
||||
批量注入 Repository,可以参考代码自行调整
|
||||
</summary>
|
||||
<param name="services"></param>
|
||||
<param name="globalDataFilter"></param>
|
||||
<param name="assemblies"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
</members>
|
||||
</doc>
|
||||
|
@ -0,0 +1,34 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net6.0</TargetFramework>
|
||||
<IsPackable>false</IsPackable>
|
||||
</PropertyGroup>
|
||||
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
|
||||
<DocumentationFile>FreeSql.Tests.Provider.Custom.xml</DocumentationFile>
|
||||
<WarningLevel>3</WarningLevel>
|
||||
<NoWarn>1701;1702;1591</NoWarn>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.8.0" />
|
||||
<PackageReference Include="MySqlConnector" Version="2.1.13" />
|
||||
<PackageReference Include="Npgsql" Version="6.0.6" />
|
||||
<PackageReference Include="Oracle.ManagedDataAccess.Core" Version="3.21.70" />
|
||||
<PackageReference Include="System.Data.SqlClient" Version="4.8.3" />
|
||||
<PackageReference Include="xunit" Version="2.4.1" />
|
||||
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.3">
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
</PackageReference>
|
||||
</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.Custom\FreeSql.Provider.Custom.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
@ -0,0 +1,113 @@
|
||||
<?xml version="1.0"?>
|
||||
<doc>
|
||||
<assembly>
|
||||
<name>FreeSql.Tests.Provider.Custom</name>
|
||||
</assembly>
|
||||
<members>
|
||||
<member name="M:FreeSql.Tests.Custom.MySql.MySqlCodeFirstTest.Tb_alltype.Save">
|
||||
<summary>
|
||||
保存或添加,如果主键有值则尝试 Update,如果影响的行为 0 则尝试 Insert
|
||||
</summary>
|
||||
</member>
|
||||
<member name="T:FreeSql.Tests.Custom.SqlServer.SqlServerCodeFirstTest.tbdot01">
|
||||
<summary>
|
||||
表中带点
|
||||
</summary>
|
||||
</member>
|
||||
<member name="P:FreeSql.Tests.Custom.SqlServer.SqlServerCodeFirstTest.tbdot01.id">
|
||||
<summary>
|
||||
主键
|
||||
</summary>
|
||||
</member>
|
||||
<member name="T:FreeSql.Tests.Custom.UnitTest1.NewsArticle">
|
||||
<summary>
|
||||
|
||||
</summary>
|
||||
</member>
|
||||
<member name="P:FreeSql.Tests.Custom.UnitTest1.NewsArticle.ArticleId">
|
||||
<summary>
|
||||
|
||||
</summary>
|
||||
</member>
|
||||
<member name="P:FreeSql.Tests.Custom.UnitTest1.NewsArticle.ArticleTitle">
|
||||
<summary>
|
||||
|
||||
</summary>
|
||||
</member>
|
||||
<member name="P:FreeSql.Tests.Custom.UnitTest1.NewsArticle.CategoryId">
|
||||
<summary>
|
||||
|
||||
</summary>
|
||||
</member>
|
||||
<member name="P:FreeSql.Tests.Custom.UnitTest1.NewsArticle.ChannelId">
|
||||
<summary>
|
||||
|
||||
</summary>
|
||||
</member>
|
||||
<member name="P:FreeSql.Tests.Custom.UnitTest1.NewsArticle.TypeId">
|
||||
<summary>
|
||||
类型
|
||||
</summary>
|
||||
</member>
|
||||
<member name="P:FreeSql.Tests.Custom.UnitTest1.NewsArticle.Summary">
|
||||
<summary>
|
||||
内容简介
|
||||
</summary>
|
||||
</member>
|
||||
<member name="P:FreeSql.Tests.Custom.UnitTest1.NewsArticle.Thumbnail">
|
||||
<summary>
|
||||
缩略图
|
||||
</summary>
|
||||
</member>
|
||||
<member name="P:FreeSql.Tests.Custom.UnitTest1.NewsArticle.Hits">
|
||||
<summary>
|
||||
点击量
|
||||
</summary>
|
||||
</member>
|
||||
<member name="P:FreeSql.Tests.Custom.UnitTest1.NewsArticle.IsDisplay">
|
||||
<summary>
|
||||
|
||||
</summary>
|
||||
</member>
|
||||
<member name="P:FreeSql.Tests.Custom.UnitTest1.NewsArticle.Status">
|
||||
<summary>
|
||||
|
||||
</summary>
|
||||
</member>
|
||||
<member name="P:FreeSql.Tests.Custom.UnitTest1.NewsArticle.CreateTime">
|
||||
<summary>
|
||||
|
||||
</summary>
|
||||
</member>
|
||||
<member name="P:FreeSql.Tests.Custom.UnitTest1.NewsArticle.ReleaseTime">
|
||||
<summary>
|
||||
|
||||
</summary>
|
||||
</member>
|
||||
<member name="P:FreeSql.Tests.Custom.UnitTest1.Templates.Id2">
|
||||
<summary>
|
||||
测试中文重命名id
|
||||
</summary>
|
||||
</member>
|
||||
<member name="P:FreeSql.Tests.Custom.UnitTest1.Class1.name">
|
||||
<summary>
|
||||
姓名
|
||||
</summary>
|
||||
</member>
|
||||
<member name="T:FreeSql.Tests.Custom.ExamPaper">
|
||||
<summary>
|
||||
试卷表
|
||||
</summary>
|
||||
</member>
|
||||
<member name="P:FreeSql.Tests.Custom.ExamPaper.AssessmentPlanId">
|
||||
<summary>
|
||||
考核计划ID
|
||||
</summary>
|
||||
</member>
|
||||
<member name="P:FreeSql.Tests.Custom.ExamPaper.TotalScore">
|
||||
<summary>
|
||||
总分
|
||||
</summary>
|
||||
</member>
|
||||
</members>
|
||||
</doc>
|
@ -0,0 +1,104 @@
|
||||
using FreeSql.DataAnnotations;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Xunit;
|
||||
|
||||
namespace FreeSql.Tests.Custom.MySql
|
||||
{
|
||||
public class MySqlDeleteTest
|
||||
{
|
||||
|
||||
IDelete<Topic> delete => g.mysql.Delete<Topic>(); //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
|
||||
[Table(Name = "tb_topic_delete")]
|
||||
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_delete` WHERE (`Id` IN (1,2))", sql);
|
||||
|
||||
sql = g.mysql.Delete<Topic>(new Topic { Id = 1, Title = "test" }).ToSql();
|
||||
Assert.Equal("DELETE FROM `tb_topic_delete` 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_delete` WHERE (`Id` IN (1,2))", sql);
|
||||
|
||||
sql = g.mysql.Delete<Topic>(new { id = 1 }).ToSql();
|
||||
Assert.Equal("DELETE FROM `tb_topic_delete` WHERE (`Id` = 1)", sql);
|
||||
|
||||
sql = g.mysql.Delete<MultiPkTopic>(new[] { new { Id1 = 1, Id2 = 10 }, new { Id1 = 2, Id2 = 20 } }).ToSql();
|
||||
Assert.Equal("DELETE FROM `MultiPkTopic` WHERE (`Id1` = 1 AND `Id2` = 10 OR `Id1` = 2 AND `Id2` = 20)", sql);
|
||||
}
|
||||
class MultiPkTopic
|
||||
{
|
||||
[Column(IsPrimary = true)]
|
||||
public int Id1 { get; set; }
|
||||
[Column(IsPrimary = true)]
|
||||
public int Id2 { get; set; }
|
||||
public int Clicks { get; set; }
|
||||
public string Title { get; set; }
|
||||
public DateTime CreateTime { get; set; }
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Where()
|
||||
{
|
||||
var sql = delete.Where(a => a.Id == 1).ToSql().Replace("\r\n", "");
|
||||
Assert.Equal("DELETE FROM `tb_topic_delete` WHERE (`Id` = 1)", sql);
|
||||
|
||||
sql = delete.Where("id = @id", new { id = 1 }).ToSql().Replace("\r\n", "");
|
||||
Assert.Equal("DELETE FROM `tb_topic_delete` 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_delete` 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_delete` WHERE (`Id` IN (1,2,3,4,5,6,7,8,9,10))", sql);
|
||||
}
|
||||
[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` IN (1,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` IN (1,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,453 @@
|
||||
using FreeSql.DataAnnotations;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Xunit;
|
||||
|
||||
namespace FreeSql.Tests.Custom.MySql
|
||||
{
|
||||
public class MySqlInsertOrUpdateIfExistsDoNothingTest
|
||||
{
|
||||
|
||||
IFreeSql fsql => g.mysql;
|
||||
|
||||
[Fact]
|
||||
public void InsertOrUpdate_OnePrimary()
|
||||
{
|
||||
fsql.Delete<tbioudb02>().Where("1=1").ExecuteAffrows();
|
||||
var iou = fsql.InsertOrUpdate<tbioudb02>().IfExistsDoNothing().SetSource(new tbioudb02 { id = 1, name = "01" });
|
||||
var sql = iou.ToSql();
|
||||
Assert.Equal(@"INSERT INTO `tbioudb02`(`id`, `name`) SELECT 1, '01'
|
||||
FROM dual WHERE NOT EXISTS(SELECT 1
|
||||
FROM `tbioudb02` a
|
||||
WHERE (a.`id` = 1)
|
||||
limit 0,1)", sql);
|
||||
Assert.Equal(1, iou.ExecuteAffrows());
|
||||
|
||||
iou = fsql.InsertOrUpdate<tbioudb02>().IfExistsDoNothing().SetSource(new tbioudb02 { id = 1, name = "011" });
|
||||
sql = iou.ToSql();
|
||||
Assert.Equal(@"INSERT INTO `tbioudb02`(`id`, `name`) SELECT 1, '011'
|
||||
FROM dual WHERE NOT EXISTS(SELECT 1
|
||||
FROM `tbioudb02` a
|
||||
WHERE (a.`id` = 1)
|
||||
limit 0,1)", sql);
|
||||
Assert.Equal(0, iou.ExecuteAffrows());
|
||||
|
||||
iou = fsql.InsertOrUpdate<tbioudb02>().IfExistsDoNothing().SetSource(new tbioudb02 { id = 2, name = "02" });
|
||||
sql = iou.ToSql();
|
||||
Assert.Equal(@"INSERT INTO `tbioudb02`(`id`, `name`) SELECT 2, '02'
|
||||
FROM dual WHERE NOT EXISTS(SELECT 1
|
||||
FROM `tbioudb02` a
|
||||
WHERE (a.`id` = 2)
|
||||
limit 0,1)", sql);
|
||||
Assert.Equal(1, iou.ExecuteAffrows());
|
||||
|
||||
iou = fsql.InsertOrUpdate<tbioudb02>().IfExistsDoNothing().SetSource(new[] { new tbioudb02 { id = 1, name = "01" }, new tbioudb02 { id = 2, name = "02" }, new tbioudb02 { id = 3, name = "03" }, new tbioudb02 { id = 4, name = "04" } });
|
||||
sql = iou.ToSql();
|
||||
Assert.Equal(@"INSERT INTO `tbioudb02`(`id`, `name`) SELECT 1, '01'
|
||||
FROM dual WHERE NOT EXISTS(SELECT 1
|
||||
FROM `tbioudb02` a
|
||||
WHERE (a.`id` = 1)
|
||||
limit 0,1)
|
||||
UNION ALL
|
||||
SELECT 2, '02'
|
||||
FROM dual WHERE NOT EXISTS(SELECT 1
|
||||
FROM `tbioudb02` a
|
||||
WHERE (a.`id` = 2)
|
||||
limit 0,1)
|
||||
UNION ALL
|
||||
SELECT 3, '03'
|
||||
FROM dual WHERE NOT EXISTS(SELECT 1
|
||||
FROM `tbioudb02` a
|
||||
WHERE (a.`id` = 3)
|
||||
limit 0,1)
|
||||
UNION ALL
|
||||
SELECT 4, '04'
|
||||
FROM dual WHERE NOT EXISTS(SELECT 1
|
||||
FROM `tbioudb02` a
|
||||
WHERE (a.`id` = 4)
|
||||
limit 0,1)", sql);
|
||||
Assert.Equal(2, iou.ExecuteAffrows());
|
||||
|
||||
iou = fsql.InsertOrUpdate<tbioudb02>().IfExistsDoNothing().SetSource(new[] { new tbioudb02 { id = 1, name = "001" }, new tbioudb02 { id = 2, name = "002" }, new tbioudb02 { id = 3, name = "003" }, new tbioudb02 { id = 4, name = "004" } });
|
||||
sql = iou.ToSql();
|
||||
Assert.Equal(@"INSERT INTO `tbioudb02`(`id`, `name`) SELECT 1, '001'
|
||||
FROM dual WHERE NOT EXISTS(SELECT 1
|
||||
FROM `tbioudb02` a
|
||||
WHERE (a.`id` = 1)
|
||||
limit 0,1)
|
||||
UNION ALL
|
||||
SELECT 2, '002'
|
||||
FROM dual WHERE NOT EXISTS(SELECT 1
|
||||
FROM `tbioudb02` a
|
||||
WHERE (a.`id` = 2)
|
||||
limit 0,1)
|
||||
UNION ALL
|
||||
SELECT 3, '003'
|
||||
FROM dual WHERE NOT EXISTS(SELECT 1
|
||||
FROM `tbioudb02` a
|
||||
WHERE (a.`id` = 3)
|
||||
limit 0,1)
|
||||
UNION ALL
|
||||
SELECT 4, '004'
|
||||
FROM dual WHERE NOT EXISTS(SELECT 1
|
||||
FROM `tbioudb02` a
|
||||
WHERE (a.`id` = 4)
|
||||
limit 0,1)", sql);
|
||||
Assert.Equal(0, iou.ExecuteAffrows());
|
||||
var lst = fsql.Select<tbioudb02>().Where(a => new[] { 1, 2, 3, 4 }.Contains(a.id)).ToList();
|
||||
Assert.Equal(4, lst.Where(a => a.name == "0" + a.id).Count());
|
||||
}
|
||||
class tbioudb02
|
||||
{
|
||||
public int id { get; set; }
|
||||
public string name { get; set; }
|
||||
}
|
||||
[Fact]
|
||||
public void InsertOrUpdate_OnePrimaryAndIdentity()
|
||||
{
|
||||
fsql.Delete<tbioudb022>().Where("1=1").ExecuteAffrows();
|
||||
var iou = fsql.InsertOrUpdate<tbioudb022>().IfExistsDoNothing().SetSource(new tbioudb022 { id = 1, name = "01" });
|
||||
var sql = iou.ToSql();
|
||||
Assert.Equal(@"INSERT INTO `tbioudb022`(`id`, `name`) SELECT 1, '01'
|
||||
FROM dual WHERE NOT EXISTS(SELECT 1
|
||||
FROM `tbioudb022` a
|
||||
WHERE (a.`id` = 1)
|
||||
limit 0,1)", sql);
|
||||
Assert.Equal(1, iou.ExecuteAffrows());
|
||||
|
||||
iou = fsql.InsertOrUpdate<tbioudb022>().IfExistsDoNothing().SetSource(new tbioudb022 { id = 1, name = "011" });
|
||||
sql = iou.ToSql();
|
||||
Assert.Equal(@"INSERT INTO `tbioudb022`(`id`, `name`) SELECT 1, '011'
|
||||
FROM dual WHERE NOT EXISTS(SELECT 1
|
||||
FROM `tbioudb022` a
|
||||
WHERE (a.`id` = 1)
|
||||
limit 0,1)", sql);
|
||||
Assert.Equal(0, iou.ExecuteAffrows());
|
||||
|
||||
iou = fsql.InsertOrUpdate<tbioudb022>().IfExistsDoNothing().SetSource(new tbioudb022 { id = 2, name = "02" });
|
||||
sql = iou.ToSql();
|
||||
Assert.Equal(@"INSERT INTO `tbioudb022`(`id`, `name`) SELECT 2, '02'
|
||||
FROM dual WHERE NOT EXISTS(SELECT 1
|
||||
FROM `tbioudb022` a
|
||||
WHERE (a.`id` = 2)
|
||||
limit 0,1)", sql);
|
||||
Assert.Equal(1, iou.ExecuteAffrows());
|
||||
|
||||
iou = fsql.InsertOrUpdate<tbioudb022>().IfExistsDoNothing().SetSource(new[] { new tbioudb022 { id = 1, name = "01" }, new tbioudb022 { id = 2, name = "02" }, new tbioudb022 { id = 3, name = "03" }, new tbioudb022 { id = 4, name = "04" } });
|
||||
sql = iou.ToSql();
|
||||
Assert.Equal(@"INSERT INTO `tbioudb022`(`id`, `name`) SELECT 1, '01'
|
||||
FROM dual WHERE NOT EXISTS(SELECT 1
|
||||
FROM `tbioudb022` a
|
||||
WHERE (a.`id` = 1)
|
||||
limit 0,1)
|
||||
UNION ALL
|
||||
SELECT 2, '02'
|
||||
FROM dual WHERE NOT EXISTS(SELECT 1
|
||||
FROM `tbioudb022` a
|
||||
WHERE (a.`id` = 2)
|
||||
limit 0,1)
|
||||
UNION ALL
|
||||
SELECT 3, '03'
|
||||
FROM dual WHERE NOT EXISTS(SELECT 1
|
||||
FROM `tbioudb022` a
|
||||
WHERE (a.`id` = 3)
|
||||
limit 0,1)
|
||||
UNION ALL
|
||||
SELECT 4, '04'
|
||||
FROM dual WHERE NOT EXISTS(SELECT 1
|
||||
FROM `tbioudb022` a
|
||||
WHERE (a.`id` = 4)
|
||||
limit 0,1)", sql);
|
||||
Assert.Equal(2, iou.ExecuteAffrows());
|
||||
|
||||
iou = fsql.InsertOrUpdate<tbioudb022>().IfExistsDoNothing().SetSource(new[] { new tbioudb022 { id = 1, name = "001" }, new tbioudb022 { id = 2, name = "002" }, new tbioudb022 { id = 3, name = "003" }, new tbioudb022 { id = 4, name = "004" } });
|
||||
sql = iou.ToSql();
|
||||
Assert.Equal(@"INSERT INTO `tbioudb022`(`id`, `name`) SELECT 1, '001'
|
||||
FROM dual WHERE NOT EXISTS(SELECT 1
|
||||
FROM `tbioudb022` a
|
||||
WHERE (a.`id` = 1)
|
||||
limit 0,1)
|
||||
UNION ALL
|
||||
SELECT 2, '002'
|
||||
FROM dual WHERE NOT EXISTS(SELECT 1
|
||||
FROM `tbioudb022` a
|
||||
WHERE (a.`id` = 2)
|
||||
limit 0,1)
|
||||
UNION ALL
|
||||
SELECT 3, '003'
|
||||
FROM dual WHERE NOT EXISTS(SELECT 1
|
||||
FROM `tbioudb022` a
|
||||
WHERE (a.`id` = 3)
|
||||
limit 0,1)
|
||||
UNION ALL
|
||||
SELECT 4, '004'
|
||||
FROM dual WHERE NOT EXISTS(SELECT 1
|
||||
FROM `tbioudb022` a
|
||||
WHERE (a.`id` = 4)
|
||||
limit 0,1)", sql);
|
||||
Assert.Equal(0, iou.ExecuteAffrows());
|
||||
var lst = fsql.Select<tbioudb022>().Where(a => new[] { 1, 2, 3, 4 }.Contains(a.id)).ToList();
|
||||
Assert.Equal(4, lst.Where(a => a.name == "0" + a.id).Count());
|
||||
|
||||
//--no primary
|
||||
iou = fsql.InsertOrUpdate<tbioudb022>().IfExistsDoNothing().SetSource(new tbioudb022 { name = "01" });
|
||||
sql = iou.ToSql();
|
||||
Assert.Equal(@"INSERT INTO `tbioudb022`(`name`) VALUES('01')", sql);
|
||||
Assert.Equal(1, iou.ExecuteAffrows());
|
||||
|
||||
iou = fsql.InsertOrUpdate<tbioudb022>().IfExistsDoNothing().SetSource(new tbioudb022 { name = "011" });
|
||||
sql = iou.ToSql();
|
||||
Assert.Equal(@"INSERT INTO `tbioudb022`(`name`) VALUES('011')", sql);
|
||||
Assert.Equal(1, iou.ExecuteAffrows());
|
||||
|
||||
iou = fsql.InsertOrUpdate<tbioudb022>().IfExistsDoNothing().SetSource(new tbioudb022 { name = "02" });
|
||||
sql = iou.ToSql();
|
||||
Assert.Equal(@"INSERT INTO `tbioudb022`(`name`) VALUES('02')", sql);
|
||||
Assert.Equal(1, iou.ExecuteAffrows());
|
||||
|
||||
iou = fsql.InsertOrUpdate<tbioudb022>().IfExistsDoNothing().SetSource(new[] { new tbioudb022 { name = "01" }, new tbioudb022 { name = "02" }, new tbioudb022 { name = "03" }, new tbioudb022 { name = "04" } });
|
||||
sql = iou.ToSql();
|
||||
Assert.Equal(@"INSERT INTO `tbioudb022`(`name`) VALUES('01'), ('02'), ('03'), ('04')", sql);
|
||||
Assert.Equal(4, iou.ExecuteAffrows());
|
||||
|
||||
iou = fsql.InsertOrUpdate<tbioudb022>().IfExistsDoNothing().SetSource(new[] { new tbioudb022 { name = "001" }, new tbioudb022 { name = "002" }, new tbioudb022 { name = "003" }, new tbioudb022 { name = "004" } });
|
||||
sql = iou.ToSql();
|
||||
Assert.Equal(@"INSERT INTO `tbioudb022`(`name`) VALUES('001'), ('002'), ('003'), ('004')", sql);
|
||||
Assert.Equal(4, iou.ExecuteAffrows());
|
||||
|
||||
//--no primary and yes
|
||||
iou = fsql.InsertOrUpdate<tbioudb022>().IfExistsDoNothing().SetSource(new[] { new tbioudb022 { id = 1, name = "100001" }, new tbioudb022 { name = "00001" }, new tbioudb022 { id = 2, name = "100002" }, new tbioudb022 { name = "00002" }, new tbioudb022 { id = 3, name = "100003" }, new tbioudb022 { name = "00003" }, new tbioudb022 { id = 4, name = "100004" }, new tbioudb022 { name = "00004" } });
|
||||
sql = iou.ToSql();
|
||||
Assert.Equal(@"INSERT INTO `tbioudb022`(`id`, `name`) SELECT 1, '100001'
|
||||
FROM dual WHERE NOT EXISTS(SELECT 1
|
||||
FROM `tbioudb022` a
|
||||
WHERE (a.`id` = 1)
|
||||
limit 0,1)
|
||||
UNION ALL
|
||||
SELECT 2, '100002'
|
||||
FROM dual WHERE NOT EXISTS(SELECT 1
|
||||
FROM `tbioudb022` a
|
||||
WHERE (a.`id` = 2)
|
||||
limit 0,1)
|
||||
UNION ALL
|
||||
SELECT 3, '100003'
|
||||
FROM dual WHERE NOT EXISTS(SELECT 1
|
||||
FROM `tbioudb022` a
|
||||
WHERE (a.`id` = 3)
|
||||
limit 0,1)
|
||||
UNION ALL
|
||||
SELECT 4, '100004'
|
||||
FROM dual WHERE NOT EXISTS(SELECT 1
|
||||
FROM `tbioudb022` a
|
||||
WHERE (a.`id` = 4)
|
||||
limit 0,1)
|
||||
|
||||
;
|
||||
|
||||
INSERT INTO `tbioudb022`(`name`) VALUES('00001'), ('00002'), ('00003'), ('00004')", sql);
|
||||
Assert.Equal(4, iou.ExecuteAffrows());
|
||||
lst = fsql.Select<tbioudb022>().Where(a => new[] { 1, 2, 3, 4 }.Contains(a.id)).ToList();
|
||||
Assert.Equal(4, lst.Where(a => a.name == "0" + a.id).Count());
|
||||
}
|
||||
class tbioudb022
|
||||
{
|
||||
[Column(IsIdentity = true)]
|
||||
public int id { get; set; }
|
||||
public string name { get; set; }
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void InsertOrUpdate_TwoPrimary()
|
||||
{
|
||||
fsql.Delete<tbioudb03>().Where("1=1").ExecuteAffrows();
|
||||
var iou = fsql.InsertOrUpdate<tbioudb03>().IfExistsDoNothing().SetSource(new tbioudb03 { id1 = 1, id2 = "01", name = "01" });
|
||||
var sql = iou.ToSql();
|
||||
Assert.Equal(@"INSERT INTO `tbioudb03`(`id1`, `id2`, `name`) SELECT 1, '01', '01'
|
||||
FROM dual WHERE NOT EXISTS(SELECT 1
|
||||
FROM `tbioudb03` a
|
||||
WHERE (a.`id1` = 1 AND a.`id2` = '01')
|
||||
limit 0,1)", sql);
|
||||
Assert.Equal(1, iou.ExecuteAffrows());
|
||||
|
||||
iou = fsql.InsertOrUpdate<tbioudb03>().IfExistsDoNothing().SetSource(new tbioudb03 { id1 = 1, id2 = "01", name = "011" });
|
||||
sql = iou.ToSql();
|
||||
Assert.Equal(@"INSERT INTO `tbioudb03`(`id1`, `id2`, `name`) SELECT 1, '01', '011'
|
||||
FROM dual WHERE NOT EXISTS(SELECT 1
|
||||
FROM `tbioudb03` a
|
||||
WHERE (a.`id1` = 1 AND a.`id2` = '01')
|
||||
limit 0,1)", sql);
|
||||
Assert.Equal(0, iou.ExecuteAffrows());
|
||||
|
||||
iou = fsql.InsertOrUpdate<tbioudb03>().IfExistsDoNothing().SetSource(new tbioudb03 { id1 = 2, id2 = "02", name = "02" });
|
||||
sql = iou.ToSql();
|
||||
Assert.Equal(@"INSERT INTO `tbioudb03`(`id1`, `id2`, `name`) SELECT 2, '02', '02'
|
||||
FROM dual WHERE NOT EXISTS(SELECT 1
|
||||
FROM `tbioudb03` a
|
||||
WHERE (a.`id1` = 2 AND a.`id2` = '02')
|
||||
limit 0,1)", sql);
|
||||
Assert.Equal(1, iou.ExecuteAffrows());
|
||||
|
||||
iou = fsql.InsertOrUpdate<tbioudb03>().IfExistsDoNothing().SetSource(new[] { new tbioudb03 { id1 = 1, id2 = "01", name = "01" }, new tbioudb03 { id1 = 2, id2 = "02", name = "02" }, new tbioudb03 { id1 = 3, id2 = "03", name = "03" }, new tbioudb03 { id1 = 4, id2 = "04", name = "04" } });
|
||||
sql = iou.ToSql();
|
||||
Assert.Equal(@"INSERT INTO `tbioudb03`(`id1`, `id2`, `name`) SELECT 1, '01', '01'
|
||||
FROM dual WHERE NOT EXISTS(SELECT 1
|
||||
FROM `tbioudb03` a
|
||||
WHERE (a.`id1` = 1 AND a.`id2` = '01')
|
||||
limit 0,1)
|
||||
UNION ALL
|
||||
SELECT 2, '02', '02'
|
||||
FROM dual WHERE NOT EXISTS(SELECT 1
|
||||
FROM `tbioudb03` a
|
||||
WHERE (a.`id1` = 2 AND a.`id2` = '02')
|
||||
limit 0,1)
|
||||
UNION ALL
|
||||
SELECT 3, '03', '03'
|
||||
FROM dual WHERE NOT EXISTS(SELECT 1
|
||||
FROM `tbioudb03` a
|
||||
WHERE (a.`id1` = 3 AND a.`id2` = '03')
|
||||
limit 0,1)
|
||||
UNION ALL
|
||||
SELECT 4, '04', '04'
|
||||
FROM dual WHERE NOT EXISTS(SELECT 1
|
||||
FROM `tbioudb03` a
|
||||
WHERE (a.`id1` = 4 AND a.`id2` = '04')
|
||||
limit 0,1)", sql);
|
||||
Assert.Equal(2, iou.ExecuteAffrows());
|
||||
|
||||
iou = fsql.InsertOrUpdate<tbioudb03>().IfExistsDoNothing().SetSource(new[] { new tbioudb03 { id1 = 1, id2 = "01", name = "001" }, new tbioudb03 { id1 = 2, id2 = "02", name = "002" }, new tbioudb03 { id1 = 3, id2 = "03", name = "003" }, new tbioudb03 { id1 = 4, id2 = "04", name = "004" } });
|
||||
sql = iou.ToSql();
|
||||
Assert.Equal(@"INSERT INTO `tbioudb03`(`id1`, `id2`, `name`) SELECT 1, '01', '001'
|
||||
FROM dual WHERE NOT EXISTS(SELECT 1
|
||||
FROM `tbioudb03` a
|
||||
WHERE (a.`id1` = 1 AND a.`id2` = '01')
|
||||
limit 0,1)
|
||||
UNION ALL
|
||||
SELECT 2, '02', '002'
|
||||
FROM dual WHERE NOT EXISTS(SELECT 1
|
||||
FROM `tbioudb03` a
|
||||
WHERE (a.`id1` = 2 AND a.`id2` = '02')
|
||||
limit 0,1)
|
||||
UNION ALL
|
||||
SELECT 3, '03', '003'
|
||||
FROM dual WHERE NOT EXISTS(SELECT 1
|
||||
FROM `tbioudb03` a
|
||||
WHERE (a.`id1` = 3 AND a.`id2` = '03')
|
||||
limit 0,1)
|
||||
UNION ALL
|
||||
SELECT 4, '04', '004'
|
||||
FROM dual WHERE NOT EXISTS(SELECT 1
|
||||
FROM `tbioudb03` a
|
||||
WHERE (a.`id1` = 4 AND a.`id2` = '04')
|
||||
limit 0,1)", sql);
|
||||
Assert.Equal(0, iou.ExecuteAffrows());
|
||||
var lst = fsql.Select<tbioudb03>().Where(a => a.id1 == 1 && a.id2 == "01" || a.id1 == 2 && a.id2 == "02" || a.id1 == 3 && a.id2 == "03" || a.id1 == 4 && a.id2 == "04").ToList();
|
||||
Assert.Equal(4, lst.Where(a => a.name == "0" + a.id1).Count());
|
||||
}
|
||||
class tbioudb03
|
||||
{
|
||||
[Column(IsPrimary = true)]
|
||||
public int id1 { get; set; }
|
||||
[Column(IsPrimary = true)]
|
||||
public string id2 { get; set; }
|
||||
public string name { get; set; }
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void InsertOrUpdate_OnePrimaryAndVersionAndCanUpdate()
|
||||
{
|
||||
fsql.Delete<tbioudb04>().Where("1=1").ExecuteAffrows();
|
||||
var iou = fsql.InsertOrUpdate<tbioudb04>().IfExistsDoNothing().SetSource(new tbioudb04 { id = 1, name = "01" });
|
||||
var sql = iou.ToSql();
|
||||
Assert.Equal(@"INSERT INTO `tbioudb04`(`id`, `name`, `version`, `CreateTime`) SELECT 1, '01', 0, now(3)
|
||||
FROM dual WHERE NOT EXISTS(SELECT 1
|
||||
FROM `tbioudb04` a
|
||||
WHERE (a.`id` = 1)
|
||||
limit 0,1)", sql);
|
||||
Assert.Equal(1, iou.ExecuteAffrows());
|
||||
|
||||
iou = fsql.InsertOrUpdate<tbioudb04>().IfExistsDoNothing().SetSource(new tbioudb04 { id = 1, name = "011" });
|
||||
sql = iou.ToSql();
|
||||
Assert.Equal(@"INSERT INTO `tbioudb04`(`id`, `name`, `version`, `CreateTime`) SELECT 1, '011', 0, now(3)
|
||||
FROM dual WHERE NOT EXISTS(SELECT 1
|
||||
FROM `tbioudb04` a
|
||||
WHERE (a.`id` = 1)
|
||||
limit 0,1)", sql);
|
||||
Assert.Equal(0, iou.ExecuteAffrows());
|
||||
|
||||
iou = fsql.InsertOrUpdate<tbioudb04>().IfExistsDoNothing().SetSource(new tbioudb04 { id = 2, name = "02" });
|
||||
sql = iou.ToSql();
|
||||
Assert.Equal(@"INSERT INTO `tbioudb04`(`id`, `name`, `version`, `CreateTime`) SELECT 2, '02', 0, now(3)
|
||||
FROM dual WHERE NOT EXISTS(SELECT 1
|
||||
FROM `tbioudb04` a
|
||||
WHERE (a.`id` = 2)
|
||||
limit 0,1)", sql);
|
||||
Assert.Equal(1, iou.ExecuteAffrows());
|
||||
|
||||
iou = fsql.InsertOrUpdate<tbioudb04>().IfExistsDoNothing().SetSource(new[] { new tbioudb04 { id = 1, name = "01" }, new tbioudb04 { id = 2, name = "02" }, new tbioudb04 { id = 3, name = "03" }, new tbioudb04 { id = 4, name = "04" } });
|
||||
sql = iou.ToSql();
|
||||
Assert.Equal(@"INSERT INTO `tbioudb04`(`id`, `name`, `version`, `CreateTime`) SELECT 1, '01', 0, now(3)
|
||||
FROM dual WHERE NOT EXISTS(SELECT 1
|
||||
FROM `tbioudb04` a
|
||||
WHERE (a.`id` = 1)
|
||||
limit 0,1)
|
||||
UNION ALL
|
||||
SELECT 2, '02', 0, now(3)
|
||||
FROM dual WHERE NOT EXISTS(SELECT 1
|
||||
FROM `tbioudb04` a
|
||||
WHERE (a.`id` = 2)
|
||||
limit 0,1)
|
||||
UNION ALL
|
||||
SELECT 3, '03', 0, now(3)
|
||||
FROM dual WHERE NOT EXISTS(SELECT 1
|
||||
FROM `tbioudb04` a
|
||||
WHERE (a.`id` = 3)
|
||||
limit 0,1)
|
||||
UNION ALL
|
||||
SELECT 4, '04', 0, now(3)
|
||||
FROM dual WHERE NOT EXISTS(SELECT 1
|
||||
FROM `tbioudb04` a
|
||||
WHERE (a.`id` = 4)
|
||||
limit 0,1)", sql);
|
||||
Assert.Equal(2, iou.ExecuteAffrows());
|
||||
|
||||
iou = fsql.InsertOrUpdate<tbioudb04>().IfExistsDoNothing().SetSource(new[] { new tbioudb04 { id = 1, name = "001" }, new tbioudb04 { id = 2, name = "002" }, new tbioudb04 { id = 3, name = "003" }, new tbioudb04 { id = 4, name = "004" } });
|
||||
sql = iou.ToSql();
|
||||
Assert.Equal(@"INSERT INTO `tbioudb04`(`id`, `name`, `version`, `CreateTime`) SELECT 1, '001', 0, now(3)
|
||||
FROM dual WHERE NOT EXISTS(SELECT 1
|
||||
FROM `tbioudb04` a
|
||||
WHERE (a.`id` = 1)
|
||||
limit 0,1)
|
||||
UNION ALL
|
||||
SELECT 2, '002', 0, now(3)
|
||||
FROM dual WHERE NOT EXISTS(SELECT 1
|
||||
FROM `tbioudb04` a
|
||||
WHERE (a.`id` = 2)
|
||||
limit 0,1)
|
||||
UNION ALL
|
||||
SELECT 3, '003', 0, now(3)
|
||||
FROM dual WHERE NOT EXISTS(SELECT 1
|
||||
FROM `tbioudb04` a
|
||||
WHERE (a.`id` = 3)
|
||||
limit 0,1)
|
||||
UNION ALL
|
||||
SELECT 4, '004', 0, now(3)
|
||||
FROM dual WHERE NOT EXISTS(SELECT 1
|
||||
FROM `tbioudb04` a
|
||||
WHERE (a.`id` = 4)
|
||||
limit 0,1)", sql);
|
||||
Assert.Equal(0, iou.ExecuteAffrows());
|
||||
var lst = fsql.Select<tbioudb04>().Where(a => new[] { 1, 2, 3, 4 }.Contains(a.id)).ToList();
|
||||
Assert.Equal(4, lst.Where(a => a.name == "0" + a.id).Count());
|
||||
}
|
||||
class tbioudb04
|
||||
{
|
||||
public int id { get; set; }
|
||||
public string name { get; set; }
|
||||
[Column(IsVersion = true)]
|
||||
public int version { get; set; }
|
||||
[Column(CanUpdate = false, ServerTime = DateTimeKind.Local)]
|
||||
public DateTime CreateTime { get; set; }
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,254 @@
|
||||
using FreeSql.DataAnnotations;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Xunit;
|
||||
|
||||
namespace FreeSql.Tests.Custom.MySql
|
||||
{
|
||||
public class MySqlInsertOrUpdateTest
|
||||
{
|
||||
|
||||
IFreeSql fsql => g.mysql;
|
||||
|
||||
[Fact]
|
||||
public void InsertOrUpdate_OnePrimary()
|
||||
{
|
||||
fsql.Delete<tbiou02>().Where("1=1").ExecuteAffrows();
|
||||
var iou = fsql.InsertOrUpdate<tbiou02>().SetSource(new tbiou02 { id = 1, name = "01" });
|
||||
var sql = iou.ToSql();
|
||||
Assert.Equal(@"INSERT INTO `tbiou02`(`id`, `name`) VALUES(1, '01')
|
||||
ON DUPLICATE KEY UPDATE
|
||||
`name` = VALUES(`name`)", sql);
|
||||
iou.ExecuteAffrows();
|
||||
|
||||
iou = fsql.InsertOrUpdate<tbiou02>().SetSource(new tbiou02 { id = 1, name = "011" });
|
||||
sql = iou.ToSql();
|
||||
Assert.Equal(@"INSERT INTO `tbiou02`(`id`, `name`) VALUES(1, '011')
|
||||
ON DUPLICATE KEY UPDATE
|
||||
`name` = VALUES(`name`)", sql);
|
||||
iou.ExecuteAffrows();
|
||||
|
||||
iou = fsql.InsertOrUpdate<tbiou02>().SetSource(new tbiou02 { id = 2, name = "02" });
|
||||
sql = iou.ToSql();
|
||||
Assert.Equal(@"INSERT INTO `tbiou02`(`id`, `name`) VALUES(2, '02')
|
||||
ON DUPLICATE KEY UPDATE
|
||||
`name` = VALUES(`name`)", sql);
|
||||
iou.ExecuteAffrows();
|
||||
|
||||
iou = fsql.InsertOrUpdate<tbiou02>().SetSource(new[] { new tbiou02 { id = 1, name = "01" }, new tbiou02 { id = 2, name = "02" }, new tbiou02 { id = 3, name = "03" }, new tbiou02 { id = 4, name = "04" } });
|
||||
sql = iou.ToSql();
|
||||
Assert.Equal(@"INSERT INTO `tbiou02`(`id`, `name`) VALUES(1, '01'), (2, '02'), (3, '03'), (4, '04')
|
||||
ON DUPLICATE KEY UPDATE
|
||||
`name` = VALUES(`name`)", sql);
|
||||
iou.ExecuteAffrows();
|
||||
|
||||
iou = fsql.InsertOrUpdate<tbiou02>().SetSource(new[] { new tbiou02 { id = 1, name = "001" }, new tbiou02 { id = 2, name = "002" }, new tbiou02 { id = 3, name = "003" }, new tbiou02 { id = 4, name = "004" } });
|
||||
sql = iou.ToSql();
|
||||
Assert.Equal(@"INSERT INTO `tbiou02`(`id`, `name`) VALUES(1, '001'), (2, '002'), (3, '003'), (4, '004')
|
||||
ON DUPLICATE KEY UPDATE
|
||||
`name` = VALUES(`name`)", sql);
|
||||
iou.ExecuteAffrows();
|
||||
var lst = fsql.Select<tbiou02>().Where(a => new[] { 1, 2, 3, 4 }.Contains(a.id)).ToList();
|
||||
Assert.Equal(4, lst.Where(a => a.name == "00" + a.id).Count());
|
||||
}
|
||||
class tbiou02
|
||||
{
|
||||
public int id { get; set; }
|
||||
public string name { get; set; }
|
||||
}
|
||||
[Fact]
|
||||
public void InsertOrUpdate_OnePrimaryAndIdentity()
|
||||
{
|
||||
fsql.Delete<tbiou022>().Where("1=1").ExecuteAffrows();
|
||||
var iou = fsql.InsertOrUpdate<tbiou022>().SetSource(new tbiou022 { id = 1, name = "01" });
|
||||
var sql = iou.ToSql();
|
||||
Assert.Equal(@"INSERT INTO `tbiou022`(`id`, `name`) VALUES(1, '01')
|
||||
ON DUPLICATE KEY UPDATE
|
||||
`name` = VALUES(`name`)", sql);
|
||||
Assert.Equal(1, iou.ExecuteAffrows());
|
||||
|
||||
iou = fsql.InsertOrUpdate<tbiou022>().SetSource(new tbiou022 { id = 1, name = "011" });
|
||||
sql = iou.ToSql();
|
||||
Assert.Equal(@"INSERT INTO `tbiou022`(`id`, `name`) VALUES(1, '011')
|
||||
ON DUPLICATE KEY UPDATE
|
||||
`name` = VALUES(`name`)", sql);
|
||||
Assert.Equal(2, iou.ExecuteAffrows());
|
||||
|
||||
iou = fsql.InsertOrUpdate<tbiou022>().SetSource(new tbiou022 { id = 2, name = "02" });
|
||||
sql = iou.ToSql();
|
||||
Assert.Equal(@"INSERT INTO `tbiou022`(`id`, `name`) VALUES(2, '02')
|
||||
ON DUPLICATE KEY UPDATE
|
||||
`name` = VALUES(`name`)", sql);
|
||||
Assert.Equal(1, iou.ExecuteAffrows());
|
||||
|
||||
iou = fsql.InsertOrUpdate<tbiou022>().SetSource(new[] { new tbiou022 { id = 1, name = "01" }, new tbiou022 { id = 2, name = "02" }, new tbiou022 { id = 3, name = "03" }, new tbiou022 { id = 4, name = "04" } });
|
||||
sql = iou.ToSql();
|
||||
Assert.Equal(@"INSERT INTO `tbiou022`(`id`, `name`) VALUES(1, '01'), (2, '02'), (3, '03'), (4, '04')
|
||||
ON DUPLICATE KEY UPDATE
|
||||
`name` = VALUES(`name`)", sql);
|
||||
Assert.Equal(4, iou.ExecuteAffrows());
|
||||
|
||||
iou = fsql.InsertOrUpdate<tbiou022>().SetSource(new[] { new tbiou022 { id = 1, name = "001" }, new tbiou022 { id = 2, name = "002" }, new tbiou022 { id = 3, name = "003" }, new tbiou022 { id = 4, name = "004" } });
|
||||
sql = iou.ToSql();
|
||||
Assert.Equal(@"INSERT INTO `tbiou022`(`id`, `name`) VALUES(1, '001'), (2, '002'), (3, '003'), (4, '004')
|
||||
ON DUPLICATE KEY UPDATE
|
||||
`name` = VALUES(`name`)", sql);
|
||||
Assert.Equal(8, iou.ExecuteAffrows());
|
||||
var lst = fsql.Select<tbiou022>().Where(a => new[] { 1, 2, 3, 4 }.Contains(a.id)).ToList();
|
||||
Assert.Equal(4, lst.Where(a => a.name == "00" + a.id).Count());
|
||||
|
||||
//--no primary
|
||||
iou = fsql.InsertOrUpdate<tbiou022>().SetSource(new tbiou022 { name = "01" });
|
||||
sql = iou.ToSql();
|
||||
Assert.Equal(@"INSERT INTO `tbiou022`(`name`) VALUES('01')", sql);
|
||||
Assert.Equal(1, iou.ExecuteAffrows());
|
||||
|
||||
iou = fsql.InsertOrUpdate<tbiou022>().SetSource(new tbiou022 { name = "011" });
|
||||
sql = iou.ToSql();
|
||||
Assert.Equal(@"INSERT INTO `tbiou022`(`name`) VALUES('011')", sql);
|
||||
Assert.Equal(1, iou.ExecuteAffrows());
|
||||
|
||||
iou = fsql.InsertOrUpdate<tbiou022>().SetSource(new tbiou022 { name = "02" });
|
||||
sql = iou.ToSql();
|
||||
Assert.Equal(@"INSERT INTO `tbiou022`(`name`) VALUES('02')", sql);
|
||||
Assert.Equal(1, iou.ExecuteAffrows());
|
||||
|
||||
iou = fsql.InsertOrUpdate<tbiou022>().SetSource(new[] { new tbiou022 { name = "01" }, new tbiou022 { name = "02" }, new tbiou022 { name = "03" }, new tbiou022 { name = "04" } });
|
||||
sql = iou.ToSql();
|
||||
Assert.Equal(@"INSERT INTO `tbiou022`(`name`) VALUES('01'), ('02'), ('03'), ('04')", sql);
|
||||
Assert.Equal(4, iou.ExecuteAffrows());
|
||||
|
||||
iou = fsql.InsertOrUpdate<tbiou022>().SetSource(new[] { new tbiou022 { name = "001" }, new tbiou022 { name = "002" }, new tbiou022 { name = "003" }, new tbiou022 { name = "004" } });
|
||||
sql = iou.ToSql();
|
||||
Assert.Equal(@"INSERT INTO `tbiou022`(`name`) VALUES('001'), ('002'), ('003'), ('004')", sql);
|
||||
Assert.Equal(4, iou.ExecuteAffrows());
|
||||
|
||||
//--no primary and yes
|
||||
iou = fsql.InsertOrUpdate<tbiou022>().SetSource(new[] { new tbiou022 { id = 1, name = "100001" }, new tbiou022 { name = "00001" }, new tbiou022 { id = 2, name = "100002" }, new tbiou022 { name = "00002" }, new tbiou022 { id = 3, name = "100003" }, new tbiou022 { name = "00003" }, new tbiou022 { id = 4, name = "100004" }, new tbiou022 { name = "00004" } });
|
||||
sql = iou.ToSql();
|
||||
Assert.Equal(@"INSERT INTO `tbiou022`(`id`, `name`) VALUES(1, '100001'), (2, '100002'), (3, '100003'), (4, '100004')
|
||||
ON DUPLICATE KEY UPDATE
|
||||
`name` = VALUES(`name`)
|
||||
|
||||
;
|
||||
|
||||
INSERT INTO `tbiou022`(`name`) VALUES('00001'), ('00002'), ('00003'), ('00004')", sql);
|
||||
Assert.Equal(12, iou.ExecuteAffrows());
|
||||
lst = fsql.Select<tbiou022>().Where(a => new[] { 1, 2, 3, 4 }.Contains(a.id)).ToList();
|
||||
Assert.Equal(4, lst.Where(a => a.name == "10000" + a.id).Count());
|
||||
}
|
||||
class tbiou022
|
||||
{
|
||||
[Column(IsIdentity = true)]
|
||||
public int id { get; set; }
|
||||
public string name { get; set; }
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void InsertOrUpdate_TwoPrimary()
|
||||
{
|
||||
fsql.Delete<tbiou03>().Where("1=1").ExecuteAffrows();
|
||||
var iou = fsql.InsertOrUpdate<tbiou03>().SetSource(new tbiou03 { id1 = 1, id2 = "01", name = "01" });
|
||||
var sql = iou.ToSql();
|
||||
Assert.Equal(@"INSERT INTO `tbiou03`(`id1`, `id2`, `name`) VALUES(1, '01', '01')
|
||||
ON DUPLICATE KEY UPDATE
|
||||
`name` = VALUES(`name`)", sql);
|
||||
iou.ExecuteAffrows();
|
||||
|
||||
iou = fsql.InsertOrUpdate<tbiou03>().SetSource(new tbiou03 { id1 = 1, id2 = "01", name = "011" });
|
||||
sql = iou.ToSql();
|
||||
Assert.Equal(@"INSERT INTO `tbiou03`(`id1`, `id2`, `name`) VALUES(1, '01', '011')
|
||||
ON DUPLICATE KEY UPDATE
|
||||
`name` = VALUES(`name`)", sql);
|
||||
iou.ExecuteAffrows();
|
||||
|
||||
iou = fsql.InsertOrUpdate<tbiou03>().SetSource(new tbiou03 { id1 = 2, id2 = "02", name = "02" });
|
||||
sql = iou.ToSql();
|
||||
Assert.Equal(@"INSERT INTO `tbiou03`(`id1`, `id2`, `name`) VALUES(2, '02', '02')
|
||||
ON DUPLICATE KEY UPDATE
|
||||
`name` = VALUES(`name`)", sql);
|
||||
iou.ExecuteAffrows();
|
||||
|
||||
iou = fsql.InsertOrUpdate<tbiou03>().SetSource(new[] { new tbiou03 { id1 = 1, id2 = "01", name = "01" }, new tbiou03 { id1 = 2, id2 = "02", name = "02" }, new tbiou03 { id1 = 3, id2 = "03", name = "03" }, new tbiou03 { id1 = 4, id2 = "04", name = "04" } });
|
||||
sql = iou.ToSql();
|
||||
Assert.Equal(@"INSERT INTO `tbiou03`(`id1`, `id2`, `name`) VALUES(1, '01', '01'), (2, '02', '02'), (3, '03', '03'), (4, '04', '04')
|
||||
ON DUPLICATE KEY UPDATE
|
||||
`name` = VALUES(`name`)", sql);
|
||||
iou.ExecuteAffrows();
|
||||
|
||||
iou = fsql.InsertOrUpdate<tbiou03>().SetSource(new[] { new tbiou03 { id1 = 1, id2 = "01", name = "001" }, new tbiou03 { id1 = 2, id2 = "02", name = "002" }, new tbiou03 { id1 = 3, id2 = "03", name = "003" }, new tbiou03 { id1 = 4, id2 = "04", name = "004" } });
|
||||
sql = iou.ToSql();
|
||||
Assert.Equal(@"INSERT INTO `tbiou03`(`id1`, `id2`, `name`) VALUES(1, '01', '001'), (2, '02', '002'), (3, '03', '003'), (4, '04', '004')
|
||||
ON DUPLICATE KEY UPDATE
|
||||
`name` = VALUES(`name`)", sql);
|
||||
iou.ExecuteAffrows();
|
||||
var lst = fsql.Select<tbiou03>().Where(a => a.id1 == 1 && a.id2 == "01" || a.id1 == 2 && a.id2 == "02" || a.id1 == 3 && a.id2 == "03" || a.id1 == 4 && a.id2 == "04").ToList();
|
||||
Assert.Equal(4, lst.Where(a => a.name == "00" + a.id1).Count());
|
||||
}
|
||||
class tbiou03
|
||||
{
|
||||
[Column(IsPrimary = true)]
|
||||
public int id1 { get; set; }
|
||||
[Column(IsPrimary = true)]
|
||||
public string id2 { get; set; }
|
||||
public string name { get; set; }
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void InsertOrUpdate_OnePrimaryAndVersionAndCanUpdate()
|
||||
{
|
||||
fsql.Delete<tbiou04>().Where("1=1").ExecuteAffrows();
|
||||
var iou = fsql.InsertOrUpdate<tbiou04>().SetSource(new tbiou04 { id = 1, name = "01" });
|
||||
var sql = iou.ToSql();
|
||||
Assert.Equal(@"INSERT INTO `tbiou04`(`id`, `name`, `version`, `CreateTime`) VALUES(1, '01', 0, now(3))
|
||||
ON DUPLICATE KEY UPDATE
|
||||
`name` = VALUES(`name`),
|
||||
`version` = `version` + 1", sql);
|
||||
iou.ExecuteAffrows();
|
||||
|
||||
iou = fsql.InsertOrUpdate<tbiou04>().SetSource(new tbiou04 { id = 1, name = "011" });
|
||||
sql = iou.ToSql();
|
||||
Assert.Equal(@"INSERT INTO `tbiou04`(`id`, `name`, `version`, `CreateTime`) VALUES(1, '011', 0, now(3))
|
||||
ON DUPLICATE KEY UPDATE
|
||||
`name` = VALUES(`name`),
|
||||
`version` = `version` + 1", sql);
|
||||
iou.ExecuteAffrows();
|
||||
|
||||
iou = fsql.InsertOrUpdate<tbiou04>().SetSource(new tbiou04 { id = 2, name = "02" });
|
||||
sql = iou.ToSql();
|
||||
Assert.Equal(@"INSERT INTO `tbiou04`(`id`, `name`, `version`, `CreateTime`) VALUES(2, '02', 0, now(3))
|
||||
ON DUPLICATE KEY UPDATE
|
||||
`name` = VALUES(`name`),
|
||||
`version` = `version` + 1", sql);
|
||||
iou.ExecuteAffrows();
|
||||
|
||||
iou = fsql.InsertOrUpdate<tbiou04>().SetSource(new[] { new tbiou04 { id = 1, name = "01" }, new tbiou04 { id = 2, name = "02" }, new tbiou04 { id = 3, name = "03" }, new tbiou04 { id = 4, name = "04" } });
|
||||
sql = iou.ToSql();
|
||||
Assert.Equal(@"INSERT INTO `tbiou04`(`id`, `name`, `version`, `CreateTime`) VALUES(1, '01', 0, now(3)), (2, '02', 0, now(3)), (3, '03', 0, now(3)), (4, '04', 0, now(3))
|
||||
ON DUPLICATE KEY UPDATE
|
||||
`name` = VALUES(`name`),
|
||||
`version` = `version` + 1", sql);
|
||||
iou.ExecuteAffrows();
|
||||
|
||||
iou = fsql.InsertOrUpdate<tbiou04>().SetSource(new[] { new tbiou04 { id = 1, name = "001" }, new tbiou04 { id = 2, name = "002" }, new tbiou04 { id = 3, name = "003" }, new tbiou04 { id = 4, name = "004" } });
|
||||
sql = iou.ToSql();
|
||||
Assert.Equal(@"INSERT INTO `tbiou04`(`id`, `name`, `version`, `CreateTime`) VALUES(1, '001', 0, now(3)), (2, '002', 0, now(3)), (3, '003', 0, now(3)), (4, '004', 0, now(3))
|
||||
ON DUPLICATE KEY UPDATE
|
||||
`name` = VALUES(`name`),
|
||||
`version` = `version` + 1", sql);
|
||||
iou.ExecuteAffrows();
|
||||
var lst = fsql.Select<tbiou04>().Where(a => new[] { 1, 2, 3, 4 }.Contains(a.id)).ToList();
|
||||
Assert.Equal(4, lst.Where(a => a.name == "00" + a.id).Count());
|
||||
}
|
||||
class tbiou04
|
||||
{
|
||||
public int id { get; set; }
|
||||
public string name { get; set; }
|
||||
[Column(IsVersion = true)]
|
||||
public int version { get; set; }
|
||||
[Column(CanUpdate = false, ServerTime = DateTimeKind.Local)]
|
||||
public DateTime CreateTime { get; set; }
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,162 @@
|
||||
using FreeSql.DataAnnotations;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Xunit;
|
||||
|
||||
namespace FreeSql.Tests.Custom.MySql
|
||||
{
|
||||
public class MySqlInsertTest
|
||||
{
|
||||
|
||||
IInsert<Topic> insert => g.mysql.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 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_insert`(`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_insert`(`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_insert`(`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_insert`(`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_insert`(`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_insert`(`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_insert`(`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_insert`(`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_topic_insertIgnoreColumns")]
|
||||
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,317 @@
|
||||
using FreeSql.DataAnnotations;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Xunit;
|
||||
|
||||
namespace FreeSql.Tests.Custom.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` IN (1,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` IN (1,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);
|
||||
|
||||
sql = g.mysql.Update<ts_source_mpk>().SetSource(new[] {
|
||||
new ts_source_mpk { id1 = 1, id2 = 7, xx = "a1" },
|
||||
new ts_source_mpk { id1 = 1, id2 = 8, xx = "b122" }
|
||||
}).NoneParameter().ToSql().Replace("\r\n", "");
|
||||
}
|
||||
public class ts_source_mpk
|
||||
{
|
||||
[Column(IsPrimary = true)]
|
||||
public int id1 { get; set; }
|
||||
[Column(IsPrimary = true)]
|
||||
public int id2 { get; set; }
|
||||
public string xx { get; set; }
|
||||
}
|
||||
[Fact]
|
||||
public void SetSourceIgnore()
|
||||
{
|
||||
Assert.Equal("UPDATE `tssi01` SET `tint` = 10 WHERE (`id` = '00000000-0000-0000-0000-000000000000')",
|
||||
g.mysql.Update<tssi01>().NoneParameter()
|
||||
.SetSourceIgnore(new tssi01 { id = Guid.Empty, tint = 10 }, col => col == null).ToSql().Replace("\r\n", ""));
|
||||
}
|
||||
public class tssi01
|
||||
{
|
||||
[Column(CanUpdate = false)]
|
||||
public Guid id { get; set; }
|
||||
public int tint { get; set; }
|
||||
public string title { get; set; }
|
||||
}
|
||||
[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);
|
||||
|
||||
var dt2000 = DateTime.Parse("2000-01-01");
|
||||
sql = update.Set(a => a.Clicks == (a.CreateTime > dt2000 ? 1 : 2)).Where(a => a.Id == 1).ToSql().Replace("\r\n", "");
|
||||
Assert.Equal("UPDATE `tb_topic` SET `Clicks` = case when `CreateTime` > '2000-01-01 00:00:00.000' then 1 else 2 end 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);
|
||||
|
||||
sql = update.Set(a => a.Clicks == null).Where(a => a.Id == 1).ToSql().Replace("\r\n", "");
|
||||
Assert.Equal("UPDATE `tb_topic` SET `Clicks` = NULL 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);
|
||||
}
|
||||
public class tenumcls
|
||||
{
|
||||
public Guid id { get; set; }
|
||||
public tenum status { get; set; }
|
||||
}
|
||||
public enum tenum
|
||||
{
|
||||
WaitPay = 1,
|
||||
Pay = 3,
|
||||
Finsh = 8,
|
||||
Cacel = 16,
|
||||
Refunding = 32
|
||||
}
|
||||
[Fact]
|
||||
public void SetEnum()
|
||||
{
|
||||
var fsql = g.mysql;
|
||||
//#184
|
||||
fsql.Delete<tenumcls>(Guid.Parse("5e83a910-672f-847c-00c1-316b71d153fb")).ExecuteAffrows();
|
||||
var item = new tenumcls { id = Guid.Parse("5e83a910-672f-847c-00c1-316b71d153fb"), status = tenum.Finsh };
|
||||
Assert.Equal("INSERT INTO `tenumcls`(`id`, `status`) VALUES('5e83a910-672f-847c-00c1-316b71d153fb', 'Finsh')",
|
||||
fsql.Insert<tenumcls>().NoneParameter().AppendData(item).ToSql());
|
||||
Assert.Equal(1, fsql.Insert<tenumcls>().NoneParameter().AppendData(item).ExecuteAffrows());
|
||||
var item2 = fsql.Select<tenumcls>().Where(a => a.id == item.id).First();
|
||||
Assert.Equal(item.id, item2.id);
|
||||
Assert.Equal(tenum.Finsh, item2.status);
|
||||
|
||||
Assert.Equal(@"UPDATE `tenumcls` SET `status` = case when `id` = '5e83a910-672f-847c-00c1-316b71d153fb' then 'Pay' else 'Refunding' end
|
||||
WHERE (`id` = '5e83a910-672f-847c-00c1-316b71d153fb')",
|
||||
fsql.Update<tenumcls>(item).NoneParameter().Set(a => a.status == (a.id == item.id ? tenum.Pay : tenum.Refunding)).ToSql());
|
||||
Assert.Equal(1, fsql.Update<tenumcls>(item).NoneParameter().Set(a => a.status == (a.id == item.id ? tenum.Pay : tenum.Refunding)).ExecuteAffrows());
|
||||
item2 = fsql.Select<tenumcls>().Where(a => a.id == item.id).First();
|
||||
Assert.Equal(item.id, item2.id);
|
||||
Assert.Equal(tenum.Pay, item2.status);
|
||||
|
||||
Assert.Equal(@"UPDATE `tenumcls` SET `status` = 'Finsh'
|
||||
WHERE (`id` = '5e83a910-672f-847c-00c1-316b71d153fb')",
|
||||
fsql.Update<tenumcls>(item).NoneParameter().Set(a => a.status == tenum.Finsh).ToSql());
|
||||
Assert.Equal(1, fsql.Update<tenumcls>(item).NoneParameter().Set(a => a.status == tenum.Finsh).ExecuteAffrows());
|
||||
item2 = fsql.Select<tenumcls>().Where(a => a.id == item.id).First();
|
||||
Assert.Equal(item.id, item2.id);
|
||||
Assert.Equal(tenum.Finsh, item2.status);
|
||||
|
||||
Assert.Equal(@"UPDATE `tenumcls` SET `status` = 'Pay'
|
||||
WHERE (`id` = '5e83a910-672f-847c-00c1-316b71d153fb')",
|
||||
fsql.Update<tenumcls>(item).NoneParameter().Set(a => a.status == tenum.Pay).ToSql());
|
||||
Assert.Equal(1, fsql.Update<tenumcls>(item).NoneParameter().Set(a => a.status == tenum.Pay).ExecuteAffrows());
|
||||
item2 = fsql.Select<tenumcls>().Where(a => a.id == item.id).First();
|
||||
Assert.Equal(item.id, item2.id);
|
||||
Assert.Equal(tenum.Pay, item2.status);
|
||||
|
||||
Assert.Equal(@"UPDATE `tenumcls` SET `status` = 'Finsh'
|
||||
WHERE (`id` = '5e83a910-672f-847c-00c1-316b71d153fb')",
|
||||
fsql.Update<tenumcls>(item).NoneParameter().Set(a => a.status, tenum.Finsh).ToSql());
|
||||
Assert.Equal(1, fsql.Update<tenumcls>(item).NoneParameter().Set(a => a.status, tenum.Finsh).ExecuteAffrows());
|
||||
item2 = fsql.Select<tenumcls>().Where(a => a.id == item.id).First();
|
||||
Assert.Equal(item.id, item2.id);
|
||||
Assert.Equal(tenum.Finsh, item2.status);
|
||||
|
||||
Assert.Equal(@"UPDATE `tenumcls` SET `status` = 'Pay'
|
||||
WHERE (`id` = '5e83a910-672f-847c-00c1-316b71d153fb')",
|
||||
fsql.Update<tenumcls>(item).NoneParameter().Set(a => a.status, tenum.Pay).ToSql());
|
||||
Assert.Equal(1, fsql.Update<tenumcls>(item).NoneParameter().Set(a => a.status, tenum.Pay).ExecuteAffrows());
|
||||
|
||||
Assert.Equal(@"SELECT a.`id`, a.`status`
|
||||
FROM `tenumcls` a
|
||||
WHERE (a.`id` = '5e83a910-672f-847c-00c1-316b71d153fb' AND a.`status` = case when a.`id` = '5e83a910-672f-847c-00c1-316b71d153fb' then 'Pay' else 'Refunding' end)
|
||||
limit 0,1", fsql.Select<tenumcls>().Where(a => a.id == item.id && a.status == (a.id == item.id ? tenum.Pay : tenum.Refunding)).Limit(1).ToSql());
|
||||
item2 = fsql.Select<tenumcls>().Where(a => a.id == item.id && a.status == (a.id == item.id ? tenum.Pay : tenum.Refunding)).First();
|
||||
Assert.Equal(item.id, item2.id);
|
||||
Assert.Equal(tenum.Pay, item2.status);
|
||||
}
|
||||
[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 SetDto()
|
||||
{
|
||||
var sql = update.SetDto(new { clicks = 1, title = "xxx" }).Where(a => a.Id == 1).ToSql().Replace("\r\n", "");
|
||||
Assert.Equal("UPDATE `tb_topic` SET `Clicks` = 1, `Title` = 'xxx' WHERE (`Id` = 1)", sql);
|
||||
|
||||
sql = update.SetDto(new Dictionary<string, object> { ["clicks"] = 1, ["title"] = "xxx" }).Where(a => a.Id == 1).ToSql().Replace("\r\n", "");
|
||||
Assert.Equal("UPDATE `tb_topic` SET `Clicks` = 1, `Title` = 'xxx' 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);
|
||||
|
||||
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 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` IN (1,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` IN (1,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());
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,195 @@
|
||||
using FreeSql.DataAnnotations;
|
||||
using FreeSql.Custom.MySql;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Xunit;
|
||||
|
||||
namespace FreeSql.Tests.Custom.MySql
|
||||
{
|
||||
public class OnDuplicateKeyUpdateTest
|
||||
{
|
||||
class TestOnDuplicateKeyUpdateInfo
|
||||
{
|
||||
[Column(IsIdentity = true)]
|
||||
public int id { get; set; }
|
||||
public string title { get; set; }
|
||||
public DateTime? time { get; set; }
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ExecuteAffrows()
|
||||
{
|
||||
g.mysql.Delete<TestOnDuplicateKeyUpdateInfo>(new[] { 100, 101, 102 }).ExecuteAffrows();
|
||||
var odku1 = new CustomMySqlOnDuplicateKeyUpdate<TestOnDuplicateKeyUpdateInfo>(g.mysql.Insert(new TestOnDuplicateKeyUpdateInfo { id = 100, title = "title-100", time = DateTime.Parse("2000-01-01") }).NoneParameter().InsertIdentity());
|
||||
Assert.Equal(@"INSERT INTO `TestOnDuplicateKeyUpdateInfo`(`id`, `title`, `time`) VALUES(100, 'title-100', '2000-01-01 00:00:00.000')
|
||||
ON DUPLICATE KEY UPDATE
|
||||
`title` = VALUES(`title`),
|
||||
`time` = VALUES(`time`)", odku1.ToSql());
|
||||
Assert.Equal(1, odku1.ExecuteAffrows());
|
||||
|
||||
var odku2 = new CustomMySqlOnDuplicateKeyUpdate<TestOnDuplicateKeyUpdateInfo>(g.mysql.Insert(new[] {
|
||||
new TestOnDuplicateKeyUpdateInfo { id = 100, title = "title-100", time = DateTime.Parse("2000-01-01") },
|
||||
new TestOnDuplicateKeyUpdateInfo { id = 101, title = "title-101", time = DateTime.Parse("2000-01-01") },
|
||||
new TestOnDuplicateKeyUpdateInfo { id = 102, title = "title-102", time = DateTime.Parse("2000-01-01") }
|
||||
}).NoneParameter().InsertIdentity());
|
||||
Assert.Equal(@"INSERT INTO `TestOnDuplicateKeyUpdateInfo`(`id`, `title`, `time`) VALUES(100, 'title-100', '2000-01-01 00:00:00.000'), (101, 'title-101', '2000-01-01 00:00:00.000'), (102, 'title-102', '2000-01-01 00:00:00.000')
|
||||
ON DUPLICATE KEY UPDATE
|
||||
`title` = VALUES(`title`),
|
||||
`time` = VALUES(`time`)", odku2.ToSql());
|
||||
odku2.ExecuteAffrows();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void IgnoreColumns()
|
||||
{
|
||||
g.mysql.Delete<TestOnDuplicateKeyUpdateInfo>(new[] { 200, 201, 202 }).ExecuteAffrows();
|
||||
var odku1 = new CustomMySqlOnDuplicateKeyUpdate<TestOnDuplicateKeyUpdateInfo>(g.mysql.Insert(new TestOnDuplicateKeyUpdateInfo { id = 200, title = "title-200", time = DateTime.Parse("2000-01-01") }).IgnoreColumns(a => a.time).NoneParameter().InsertIdentity());
|
||||
Assert.Equal(@"INSERT INTO `TestOnDuplicateKeyUpdateInfo`(`id`, `title`) VALUES(200, 'title-200')
|
||||
ON DUPLICATE KEY UPDATE
|
||||
`title` = VALUES(`title`),
|
||||
`time` = '2000-01-01 00:00:00.000'", odku1.ToSql());
|
||||
Assert.Equal(1, odku1.ExecuteAffrows());
|
||||
|
||||
var odku2 = new CustomMySqlOnDuplicateKeyUpdate<TestOnDuplicateKeyUpdateInfo>(g.mysql.Insert(new[] {
|
||||
new TestOnDuplicateKeyUpdateInfo { id = 200, title = "title-200", time = DateTime.Parse("2000-01-01") },
|
||||
new TestOnDuplicateKeyUpdateInfo { id = 201, title = "title-201", time = DateTime.Parse("2000-01-01") },
|
||||
new TestOnDuplicateKeyUpdateInfo { id = 202, title = "title-202", time = DateTime.Parse("2000-01-01") }
|
||||
}).IgnoreColumns(a => a.time).NoneParameter().InsertIdentity());
|
||||
Assert.Equal(@"INSERT INTO `TestOnDuplicateKeyUpdateInfo`(`id`, `title`) VALUES(200, 'title-200'), (201, 'title-201'), (202, 'title-202')
|
||||
ON DUPLICATE KEY UPDATE
|
||||
`title` = VALUES(`title`),
|
||||
`time` = CASE `id`
|
||||
WHEN 200 THEN '2000-01-01 00:00:00.000'
|
||||
WHEN 201 THEN '2000-01-01 00:00:00.000'
|
||||
WHEN 202 THEN '2000-01-01 00:00:00.000' END", odku2.ToSql());
|
||||
odku2.ExecuteAffrows();
|
||||
|
||||
|
||||
g.mysql.Delete<TestOnDuplicateKeyUpdateInfo>(new[] { 200, 201, 202 }).ExecuteAffrows();
|
||||
odku1 = new CustomMySqlOnDuplicateKeyUpdate<TestOnDuplicateKeyUpdateInfo>(g.mysql.Insert(new TestOnDuplicateKeyUpdateInfo { id = 200, title = "title-200", time = DateTime.Parse("2000-01-01") }).IgnoreColumns(a => a.time).NoneParameter().InsertIdentity()).IgnoreColumns(a => a.title);
|
||||
Assert.Equal(@"INSERT INTO `TestOnDuplicateKeyUpdateInfo`(`id`, `title`) VALUES(200, 'title-200')
|
||||
ON DUPLICATE KEY UPDATE
|
||||
`time` = '2000-01-01 00:00:00.000'", odku1.ToSql());
|
||||
Assert.Equal(1, odku1.ExecuteAffrows());
|
||||
|
||||
odku2 = new CustomMySqlOnDuplicateKeyUpdate<TestOnDuplicateKeyUpdateInfo>(g.mysql.Insert(new[] {
|
||||
new TestOnDuplicateKeyUpdateInfo { id = 200, title = "title-200", time = DateTime.Parse("2000-01-01") },
|
||||
new TestOnDuplicateKeyUpdateInfo { id = 201, title = "title-201", time = DateTime.Parse("2000-01-01") },
|
||||
new TestOnDuplicateKeyUpdateInfo { id = 202, title = "title-202", time = DateTime.Parse("2000-01-01") }
|
||||
}).IgnoreColumns(a => a.time).NoneParameter().InsertIdentity()).IgnoreColumns(a => a.title);
|
||||
Assert.Equal(@"INSERT INTO `TestOnDuplicateKeyUpdateInfo`(`id`, `title`) VALUES(200, 'title-200'), (201, 'title-201'), (202, 'title-202')
|
||||
ON DUPLICATE KEY UPDATE
|
||||
`time` = CASE `id`
|
||||
WHEN 200 THEN '2000-01-01 00:00:00.000'
|
||||
WHEN 201 THEN '2000-01-01 00:00:00.000'
|
||||
WHEN 202 THEN '2000-01-01 00:00:00.000' END", odku2.ToSql());
|
||||
odku2.ExecuteAffrows();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void UpdateColumns()
|
||||
{
|
||||
g.mysql.Delete<TestOnDuplicateKeyUpdateInfo>(new[] { 300, 301, 302 }).ExecuteAffrows();
|
||||
var odku1 = new CustomMySqlOnDuplicateKeyUpdate<TestOnDuplicateKeyUpdateInfo>(g.mysql.Insert(new TestOnDuplicateKeyUpdateInfo { id = 300, title = "title-300", time = DateTime.Parse("2000-01-01") }).InsertColumns(a => a.title).NoneParameter().InsertIdentity());
|
||||
Assert.Equal(@"INSERT INTO `TestOnDuplicateKeyUpdateInfo`(`id`, `title`) VALUES(300, 'title-300')
|
||||
ON DUPLICATE KEY UPDATE
|
||||
`title` = VALUES(`title`),
|
||||
`time` = '2000-01-01 00:00:00.000'", odku1.ToSql());
|
||||
Assert.Equal(1, odku1.ExecuteAffrows());
|
||||
|
||||
var odku2 = new CustomMySqlOnDuplicateKeyUpdate<TestOnDuplicateKeyUpdateInfo>(g.mysql.Insert(new[] {
|
||||
new TestOnDuplicateKeyUpdateInfo { id = 300, title = "title-300", time = DateTime.Parse("2000-01-01") },
|
||||
new TestOnDuplicateKeyUpdateInfo { id = 301, title = "title-301", time = DateTime.Parse("2000-01-01") },
|
||||
new TestOnDuplicateKeyUpdateInfo { id = 302, title = "title-302", time = DateTime.Parse("2000-01-01") }
|
||||
}).InsertColumns(a => a.title).NoneParameter().InsertIdentity());
|
||||
Assert.Equal(@"INSERT INTO `TestOnDuplicateKeyUpdateInfo`(`id`, `title`) VALUES(300, 'title-300'), (301, 'title-301'), (302, 'title-302')
|
||||
ON DUPLICATE KEY UPDATE
|
||||
`title` = VALUES(`title`),
|
||||
`time` = CASE `id`
|
||||
WHEN 300 THEN '2000-01-01 00:00:00.000'
|
||||
WHEN 301 THEN '2000-01-01 00:00:00.000'
|
||||
WHEN 302 THEN '2000-01-01 00:00:00.000' END", odku2.ToSql());
|
||||
odku2.ExecuteAffrows();
|
||||
|
||||
|
||||
g.mysql.Delete<TestOnDuplicateKeyUpdateInfo>(new[] { 300, 301, 302 }).ExecuteAffrows();
|
||||
odku1 = new CustomMySqlOnDuplicateKeyUpdate<TestOnDuplicateKeyUpdateInfo>(g.mysql.Insert(new TestOnDuplicateKeyUpdateInfo { id = 300, title = "title-300", time = DateTime.Parse("2000-01-01") }).InsertColumns(a => a.title).NoneParameter().InsertIdentity()).UpdateColumns(a => a.time);
|
||||
Assert.Equal(@"INSERT INTO `TestOnDuplicateKeyUpdateInfo`(`id`, `title`) VALUES(300, 'title-300')
|
||||
ON DUPLICATE KEY UPDATE
|
||||
`time` = '2000-01-01 00:00:00.000'", odku1.ToSql());
|
||||
Assert.Equal(1, odku1.ExecuteAffrows());
|
||||
|
||||
odku2 = new CustomMySqlOnDuplicateKeyUpdate<TestOnDuplicateKeyUpdateInfo>(g.mysql.Insert(new[] {
|
||||
new TestOnDuplicateKeyUpdateInfo { id = 300, title = "title-300", time = DateTime.Parse("2000-01-01") },
|
||||
new TestOnDuplicateKeyUpdateInfo { id = 301, title = "title-301", time = DateTime.Parse("2000-01-01") },
|
||||
new TestOnDuplicateKeyUpdateInfo { id = 302, title = "title-302", time = DateTime.Parse("2000-01-01") }
|
||||
}).InsertColumns(a => a.title).NoneParameter().InsertIdentity()).UpdateColumns(a => a.time);
|
||||
Assert.Equal(@"INSERT INTO `TestOnDuplicateKeyUpdateInfo`(`id`, `title`) VALUES(300, 'title-300'), (301, 'title-301'), (302, 'title-302')
|
||||
ON DUPLICATE KEY UPDATE
|
||||
`time` = CASE `id`
|
||||
WHEN 300 THEN '2000-01-01 00:00:00.000'
|
||||
WHEN 301 THEN '2000-01-01 00:00:00.000'
|
||||
WHEN 302 THEN '2000-01-01 00:00:00.000' END", odku2.ToSql());
|
||||
odku2.ExecuteAffrows();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Set()
|
||||
{
|
||||
g.mysql.Delete<TestOnDuplicateKeyUpdateInfo>(new[] { 400, 401, 402 }).ExecuteAffrows();
|
||||
var odku1 = new CustomMySqlOnDuplicateKeyUpdate<TestOnDuplicateKeyUpdateInfo>(g.mysql.Insert(new TestOnDuplicateKeyUpdateInfo { id = 400, title = "title-400", time = DateTime.Parse("2000-01-01") }).NoneParameter().InsertIdentity()).Set(a => a.time, DateTime.Parse("2020-1-1"));
|
||||
Assert.Equal(@"INSERT INTO `TestOnDuplicateKeyUpdateInfo`(`id`, `title`, `time`) VALUES(400, 'title-400', '2000-01-01 00:00:00.000')
|
||||
ON DUPLICATE KEY UPDATE
|
||||
`time` = '2020-01-01 00:00:00.000'", odku1.ToSql());
|
||||
Assert.Equal(1, odku1.ExecuteAffrows());
|
||||
|
||||
var odku2 = new CustomMySqlOnDuplicateKeyUpdate<TestOnDuplicateKeyUpdateInfo>(g.mysql.Insert(new[] {
|
||||
new TestOnDuplicateKeyUpdateInfo { id = 400, title = "title-400", time = DateTime.Parse("2000-01-01") },
|
||||
new TestOnDuplicateKeyUpdateInfo { id = 401, title = "title-401", time = DateTime.Parse("2000-01-01") },
|
||||
new TestOnDuplicateKeyUpdateInfo { id = 402, title = "title-402", time = DateTime.Parse("2000-01-01") }
|
||||
}).NoneParameter().InsertIdentity()).Set(a => a.time, DateTime.Parse("2020-1-1"));
|
||||
Assert.Equal(@"INSERT INTO `TestOnDuplicateKeyUpdateInfo`(`id`, `title`, `time`) VALUES(400, 'title-400', '2000-01-01 00:00:00.000'), (401, 'title-401', '2000-01-01 00:00:00.000'), (402, 'title-402', '2000-01-01 00:00:00.000')
|
||||
ON DUPLICATE KEY UPDATE
|
||||
`time` = '2020-01-01 00:00:00.000'", odku2.ToSql());
|
||||
odku2.ExecuteAffrows();
|
||||
|
||||
|
||||
var dt2020 = DateTime.Parse("2020-1-1");
|
||||
g.mysql.Delete<TestOnDuplicateKeyUpdateInfo>(new[] { 400, 401, 402 }).ExecuteAffrows();
|
||||
odku1 = new CustomMySqlOnDuplicateKeyUpdate<TestOnDuplicateKeyUpdateInfo>(g.mysql.Insert(new TestOnDuplicateKeyUpdateInfo { id = 400, title = "title-400", time = DateTime.Parse("2000-01-01") }).NoneParameter().InsertIdentity()).Set(a => a.time == dt2020);
|
||||
Assert.Equal(@"INSERT INTO `TestOnDuplicateKeyUpdateInfo`(`id`, `title`, `time`) VALUES(400, 'title-400', '2000-01-01 00:00:00.000')
|
||||
ON DUPLICATE KEY UPDATE
|
||||
`time` = '2020-01-01 00:00:00.000'", odku1.ToSql());
|
||||
Assert.Equal(1, odku1.ExecuteAffrows());
|
||||
|
||||
odku2 = new CustomMySqlOnDuplicateKeyUpdate<TestOnDuplicateKeyUpdateInfo>(g.mysql.Insert(new[] {
|
||||
new TestOnDuplicateKeyUpdateInfo { id = 400, title = "title-400", time = DateTime.Parse("2000-01-01") },
|
||||
new TestOnDuplicateKeyUpdateInfo { id = 401, title = "title-401", time = DateTime.Parse("2000-01-01") },
|
||||
new TestOnDuplicateKeyUpdateInfo { id = 402, title = "title-402", time = DateTime.Parse("2000-01-01") }
|
||||
}).NoneParameter().InsertIdentity()).Set(a => a.time == dt2020);
|
||||
Assert.Equal(@"INSERT INTO `TestOnDuplicateKeyUpdateInfo`(`id`, `title`, `time`) VALUES(400, 'title-400', '2000-01-01 00:00:00.000'), (401, 'title-401', '2000-01-01 00:00:00.000'), (402, 'title-402', '2000-01-01 00:00:00.000')
|
||||
ON DUPLICATE KEY UPDATE
|
||||
`time` = '2020-01-01 00:00:00.000'", odku2.ToSql());
|
||||
odku2.ExecuteAffrows();
|
||||
|
||||
|
||||
g.mysql.Delete<TestOnDuplicateKeyUpdateInfo>(new[] { 400, 401, 402 }).ExecuteAffrows();
|
||||
odku1 = new CustomMySqlOnDuplicateKeyUpdate<TestOnDuplicateKeyUpdateInfo>(g.mysql.Insert(new TestOnDuplicateKeyUpdateInfo { id = 400, title = "title-400", time = DateTime.Parse("2000-01-01") }).NoneParameter().InsertIdentity()).Set(a => new { time = dt2020, title = a.title + "123" });
|
||||
Assert.Equal(@"INSERT INTO `TestOnDuplicateKeyUpdateInfo`(`id`, `title`, `time`) VALUES(400, 'title-400', '2000-01-01 00:00:00.000')
|
||||
ON DUPLICATE KEY UPDATE
|
||||
`time` = '2020-01-01 00:00:00.000', `title` = concat(`title`, '123')", odku1.ToSql());
|
||||
Assert.Equal(1, odku1.ExecuteAffrows());
|
||||
|
||||
odku2 = new CustomMySqlOnDuplicateKeyUpdate<TestOnDuplicateKeyUpdateInfo>(g.mysql.Insert(new[] {
|
||||
new TestOnDuplicateKeyUpdateInfo { id = 400, title = "title-400", time = DateTime.Parse("2000-01-01") },
|
||||
new TestOnDuplicateKeyUpdateInfo { id = 401, title = "title-401", time = DateTime.Parse("2000-01-01") },
|
||||
new TestOnDuplicateKeyUpdateInfo { id = 402, title = "title-402", time = DateTime.Parse("2000-01-01") }
|
||||
}).NoneParameter().InsertIdentity()).Set(a => new { time = dt2020, title = a.title + "123" });
|
||||
Assert.Equal(@"INSERT INTO `TestOnDuplicateKeyUpdateInfo`(`id`, `title`, `time`) VALUES(400, 'title-400', '2000-01-01 00:00:00.000'), (401, 'title-401', '2000-01-01 00:00:00.000'), (402, 'title-402', '2000-01-01 00:00:00.000')
|
||||
ON DUPLICATE KEY UPDATE
|
||||
`time` = '2020-01-01 00:00:00.000', `title` = concat(`title`, '123')", odku2.ToSql());
|
||||
odku2.ExecuteAffrows();
|
||||
}
|
||||
}
|
||||
}
|
File diff suppressed because it is too large
Load Diff
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.Custom.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.Custom.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.Custom.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,71 @@
|
||||
using FreeSql.DataAnnotations;
|
||||
using System;
|
||||
using System.Data.Odbc;
|
||||
using Xunit;
|
||||
|
||||
namespace FreeSql.Tests.Custom.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 ExecuteTest()
|
||||
{
|
||||
Assert.True(g.mysql.Ado.ExecuteConnectTest());
|
||||
}
|
||||
[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<Exception>(() => 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.Custom.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,577 @@
|
||||
using FreeSql.DataAnnotations;
|
||||
using Newtonsoft.Json;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using Xunit;
|
||||
|
||||
namespace FreeSql.Tests.Custom.MySql
|
||||
{
|
||||
public class MySqlCodeFirstTest
|
||||
{
|
||||
[Fact]
|
||||
public void Test_0String()
|
||||
{
|
||||
var fsql = g.mysql;
|
||||
fsql.Delete<test_0string01>().Where("1=1").ExecuteAffrows();
|
||||
|
||||
Assert.Equal(1, fsql.Insert(new test_0string01 { name = @"1.0000\0.0000\0.0000\0.0000\1.0000\0.0000" }).ExecuteAffrows());
|
||||
Assert.Equal(1, fsql.Insert(new test_0string01 { name = @"1.0000\0.0000\0.0000\0.0000\1.0000\0.0000" }).NoneParameter().ExecuteAffrows());
|
||||
|
||||
var list = fsql.Select<test_0string01>().ToList();
|
||||
Assert.Equal(2, list.Count);
|
||||
Assert.Equal(@"1.0000\0.0000\0.0000\0.0000\1.0000\0.0000", list[0].name);
|
||||
Assert.Equal(@"1.0000\0.0000\0.0000\0.0000\1.0000\0.0000", list[1].name);
|
||||
}
|
||||
class test_0string01
|
||||
{
|
||||
public Guid id { get; set; }
|
||||
public string name { get; set; }
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void EnumStartValue1()
|
||||
{
|
||||
var fsql = g.mysql;
|
||||
fsql.Delete<TS_ESV1>().Where("1=1").ExecuteAffrows();
|
||||
|
||||
var repo = fsql.GetRepository<TS_ESV1>();
|
||||
var item1 = repo.Insert(new TS_ESV1 { Status = TS_TSV1_Status.Status1 });
|
||||
Assert.True(fsql.Select<TS_ESV1>().Where(a => a.Id == item1.Id).Any());
|
||||
Assert.Equal(TS_TSV1_Status.Status1, fsql.Select<TS_ESV1>().Where(a => a.Id == item1.Id).First().Status);
|
||||
Assert.Equal(TS_TSV1_Status.Status1, fsql.Select<TS_ESV1>().Where(a => a.Id == item1.Id).First(a => a.Status));
|
||||
Assert.True(repo.Select.Where(a => a.Id == item1.Id).Any());
|
||||
Assert.Equal(TS_TSV1_Status.Status1, repo.Select.Where(a => a.Id == item1.Id).First().Status);
|
||||
Assert.Equal(TS_TSV1_Status.Status1, repo.Select.Where(a => a.Id == item1.Id).First(a => a.Status));
|
||||
|
||||
Assert.Equal($"UPDATE `TS_ESV1` SET `Status` = 'Status1' WHERE (`Id` = '{item1.Id}')", fsql.Update<TS_ESV1>().Where(a => a.Id == item1.Id).NoneParameter().Set(a => a.Status, TS_TSV1_Status.Status1).ToSql().Replace("\r\n", ""));
|
||||
Assert.Equal($"UPDATE `TS_ESV1` SET `Status` = 'Status2' WHERE (`Id` = '{item1.Id}')", fsql.Update<TS_ESV1>().Where(a => a.Id == item1.Id).NoneParameter().Set(a => a.Status, TS_TSV1_Status.Status2).ToSql().Replace("\r\n", ""));
|
||||
Assert.Equal($"UPDATE `TS_ESV1` SET `Status` = 'Status3' WHERE (`Id` = '{item1.Id}')", fsql.Update<TS_ESV1>().Where(a => a.Id == item1.Id).NoneParameter().Set(a => a.Status, TS_TSV1_Status.Status3).ToSql().Replace("\r\n", ""));
|
||||
Assert.Equal($"UPDATE `TS_ESV1` SET `Status` = 'Status1' WHERE (`Id` = '{item1.Id}')", fsql.Update<TS_ESV1>().Where(a => a.Id == item1.Id).NoneParameter().Set(a => a.Status == TS_TSV1_Status.Status1).ToSql().Replace("\r\n", ""));
|
||||
Assert.Equal($"UPDATE `TS_ESV1` SET `Status` = 'Status2' WHERE (`Id` = '{item1.Id}')", fsql.Update<TS_ESV1>().Where(a => a.Id == item1.Id).NoneParameter().Set(a => a.Status == TS_TSV1_Status.Status2).ToSql().Replace("\r\n", ""));
|
||||
Assert.Equal($"UPDATE `TS_ESV1` SET `Status` = 'Status3' WHERE (`Id` = '{item1.Id}')", fsql.Update<TS_ESV1>().Where(a => a.Id == item1.Id).NoneParameter().Set(a => a.Status == TS_TSV1_Status.Status3).ToSql().Replace("\r\n", ""));
|
||||
|
||||
item1.Status = TS_TSV1_Status.Status1;
|
||||
repo.Update(item1);
|
||||
Assert.True(fsql.Select<TS_ESV1>().Where(a => a.Id == item1.Id).Any());
|
||||
Assert.Equal(TS_TSV1_Status.Status1, fsql.Select<TS_ESV1>().Where(a => a.Id == item1.Id).First().Status);
|
||||
Assert.Equal(TS_TSV1_Status.Status1, fsql.Select<TS_ESV1>().Where(a => a.Id == item1.Id).First(a => a.Status));
|
||||
Assert.True(repo.Select.Where(a => a.Id == item1.Id).Any());
|
||||
Assert.Equal(TS_TSV1_Status.Status1, repo.Select.Where(a => a.Id == item1.Id).First().Status);
|
||||
Assert.Equal(TS_TSV1_Status.Status1, repo.Select.Where(a => a.Id == item1.Id).First(a => a.Status));
|
||||
|
||||
item1.Status = TS_TSV1_Status.Status2;
|
||||
repo.Update(item1);
|
||||
Assert.True(fsql.Select<TS_ESV1>().Where(a => a.Id == item1.Id).Any());
|
||||
Assert.Equal(TS_TSV1_Status.Status2, fsql.Select<TS_ESV1>().Where(a => a.Id == item1.Id).First().Status);
|
||||
Assert.Equal(TS_TSV1_Status.Status2, fsql.Select<TS_ESV1>().Where(a => a.Id == item1.Id).First(a => a.Status));
|
||||
Assert.True(repo.Select.Where(a => a.Id == item1.Id).Any());
|
||||
Assert.Equal(TS_TSV1_Status.Status2, repo.Select.Where(a => a.Id == item1.Id).First().Status);
|
||||
Assert.Equal(TS_TSV1_Status.Status2, repo.Select.Where(a => a.Id == item1.Id).First(a => a.Status));
|
||||
|
||||
item1.Status = TS_TSV1_Status.Status3;
|
||||
repo.Update(item1);
|
||||
Assert.True(fsql.Select<TS_ESV1>().Where(a => a.Id == item1.Id).Any());
|
||||
Assert.Equal(TS_TSV1_Status.Status3, fsql.Select<TS_ESV1>().Where(a => a.Id == item1.Id).First().Status);
|
||||
Assert.Equal(TS_TSV1_Status.Status3, fsql.Select<TS_ESV1>().Where(a => a.Id == item1.Id).First(a => a.Status));
|
||||
Assert.True(repo.Select.Where(a => a.Id == item1.Id).Any());
|
||||
Assert.Equal(TS_TSV1_Status.Status3, repo.Select.Where(a => a.Id == item1.Id).First().Status);
|
||||
Assert.Equal(TS_TSV1_Status.Status3, repo.Select.Where(a => a.Id == item1.Id).First(a => a.Status));
|
||||
|
||||
item1.Status = TS_TSV1_Status.Status3;
|
||||
fsql.GetRepository<TS_ESV1>().Update(item1);
|
||||
Assert.True(fsql.Select<TS_ESV1>().Where(a => a.Id == item1.Id).Any());
|
||||
Assert.Equal(TS_TSV1_Status.Status3, fsql.Select<TS_ESV1>().Where(a => a.Id == item1.Id).First().Status);
|
||||
Assert.Equal(TS_TSV1_Status.Status3, fsql.Select<TS_ESV1>().Where(a => a.Id == item1.Id).First(a => a.Status));
|
||||
Assert.True(repo.Select.Where(a => a.Id == item1.Id).Any());
|
||||
Assert.Equal(TS_TSV1_Status.Status3, repo.Select.Where(a => a.Id == item1.Id).First().Status);
|
||||
Assert.Equal(TS_TSV1_Status.Status3, repo.Select.Where(a => a.Id == item1.Id).First(a => a.Status));
|
||||
|
||||
item1.Status = TS_TSV1_Status.Status2;
|
||||
fsql.GetRepository<TS_ESV1>().Update(item1);
|
||||
Assert.True(fsql.Select<TS_ESV1>().Where(a => a.Id == item1.Id).Any());
|
||||
Assert.Equal(TS_TSV1_Status.Status2, fsql.Select<TS_ESV1>().Where(a => a.Id == item1.Id).First().Status);
|
||||
Assert.Equal(TS_TSV1_Status.Status2, fsql.Select<TS_ESV1>().Where(a => a.Id == item1.Id).First(a => a.Status));
|
||||
Assert.True(repo.Select.Where(a => a.Id == item1.Id).Any());
|
||||
Assert.Equal(TS_TSV1_Status.Status2, repo.Select.Where(a => a.Id == item1.Id).First().Status);
|
||||
Assert.Equal(TS_TSV1_Status.Status2, repo.Select.Where(a => a.Id == item1.Id).First(a => a.Status));
|
||||
}
|
||||
public class TS_ESV1
|
||||
{
|
||||
public Guid Id { get; set; }
|
||||
public TS_TSV1_Status Status { get; set; }
|
||||
}
|
||||
public enum TS_TSV1_Status
|
||||
{
|
||||
Status1 = 1,
|
||||
Status2 = 3,
|
||||
Status3 = 5
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void StringLength()
|
||||
{
|
||||
var dll = g.mysql.CodeFirst.GetComparisonDDLStatements<TS_SLTB>();
|
||||
g.mysql.CodeFirst.SyncStructure<TS_SLTB>();
|
||||
}
|
||||
class TS_SLTB
|
||||
{
|
||||
public Guid Id { get; set; }
|
||||
[Column(StringLength = 50)]
|
||||
public string Title { get; set; }
|
||||
|
||||
[Column(IsNullable = false, StringLength = 50)]
|
||||
public string TitleSub { get; set; }
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void 表名中有点()
|
||||
{
|
||||
var item = new tbdot01 { name = "insert" };
|
||||
g.mysql.Insert(item).ExecuteAffrows();
|
||||
|
||||
var find = g.mysql.Select<tbdot01>().Where(a => a.id == item.id).First();
|
||||
Assert.NotNull(find);
|
||||
Assert.Equal(item.id, find.id);
|
||||
Assert.Equal("insert", find.name);
|
||||
|
||||
Assert.Equal(1, g.mysql.Update<tbdot01>().Set(a => a.name == "update").Where(a => a.id == item.id).ExecuteAffrows());
|
||||
find = g.mysql.Select<tbdot01>().Where(a => a.id == item.id).First();
|
||||
Assert.NotNull(find);
|
||||
Assert.Equal(item.id, find.id);
|
||||
Assert.Equal("update", find.name);
|
||||
|
||||
Assert.Equal(1, g.mysql.Delete<tbdot01>().Where(a => a.id == item.id).ExecuteAffrows());
|
||||
find = g.mysql.Select<tbdot01>().Where(a => a.id == item.id).First();
|
||||
Assert.Null(find);
|
||||
}
|
||||
[Table(Name = "`sys.tbdot01`")]
|
||||
class tbdot01
|
||||
{
|
||||
public Guid id { get; set; }
|
||||
public string name { get; set; }
|
||||
}
|
||||
|
||||
[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.标题);
|
||||
|
||||
item.标题 = "测试标题更新";
|
||||
Assert.Equal(1, g.mysql.Update<测试中文表2>().SetSource(item).ExecuteAffrows());
|
||||
item2 = g.mysql.Select<测试中文表2>().Where(a => a.编号 == item.编号).First();
|
||||
Assert.NotNull(item2);
|
||||
Assert.Equal(item.编号, item2.编号);
|
||||
Assert.Equal(item.标题, item2.标题);
|
||||
|
||||
item.标题 = "测试标题更新_repo";
|
||||
var repo = g.mysql.GetRepository<测试中文表2>();
|
||||
Assert.Equal(1, repo.Update(item));
|
||||
item2 = g.mysql.Select<测试中文表2>().Where(a => a.编号 == item.编号).First();
|
||||
Assert.NotNull(item2);
|
||||
Assert.Equal(item.编号, item2.编号);
|
||||
Assert.Equal(item.标题, item2.标题);
|
||||
|
||||
item.标题 = "测试标题更新_repo22";
|
||||
Assert.Equal(1, repo.Update(item));
|
||||
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>();
|
||||
g.mysql.CodeFirst.SyncStructure(typeof(AddUniquesInfo), "AddUniquesInfo1");
|
||||
}
|
||||
[Table(Name = "AddUniquesInfo", OldName = "AddUniquesInfo2")]
|
||||
[Index("uk_phone", "phone", true)]
|
||||
class AddUniquesInfo
|
||||
{
|
||||
public Guid id { get; set; }
|
||||
public string phone { get; set; }
|
||||
|
||||
public string group { get; set; }
|
||||
public int index { get; set; }
|
||||
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>();
|
||||
Assert.True(string.IsNullOrEmpty(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'\\?!@#$%^&*()_+{}}{~?><<>",
|
||||
testFieldChar = 'X',
|
||||
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();
|
||||
Assert.Equal(item2.testFieldString, newitem2.testFieldString);
|
||||
Assert.Equal(item2.testFieldChar, newitem2.testFieldChar);
|
||||
|
||||
item2.Id = (int)insert.NoneParameter().AppendData(item2).ExecuteIdentity();
|
||||
newitem2 = select.Where(a => a.Id == item2.Id).ToOne();
|
||||
Assert.Equal(item2.testFieldString, newitem2.testFieldString);
|
||||
Assert.Equal(item2.testFieldChar, newitem2.testFieldChar);
|
||||
|
||||
var items = select.ToList();
|
||||
var itemstb = select.ToDataTable();
|
||||
}
|
||||
|
||||
|
||||
[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 = "testFieldChar", DbType = "char(1)", IsNullable = true)]
|
||||
public char testFieldChar { 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 char testFieldChar { 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,64 @@
|
||||
using FreeSql.DataAnnotations;
|
||||
using System;
|
||||
using Xunit;
|
||||
|
||||
namespace FreeSql.Tests.Custom.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]);
|
||||
Assert.True(t2.Count > 0);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void GetTableByName()
|
||||
{
|
||||
var fsql = g.mysql;
|
||||
var t1 = fsql.DbFirst.GetTableByName("tb_alltype");
|
||||
var t2 = fsql.DbFirst.GetTableByName("cccddd_odbc.tb_alltype");
|
||||
Assert.NotNull(t1);
|
||||
Assert.NotNull(t2);
|
||||
Assert.True(t1.Columns.Count > 0);
|
||||
Assert.True(t2.Columns.Count > 0);
|
||||
Assert.Equal(t1.Columns.Count, t2.Columns.Count);
|
||||
var t3 = fsql.DbFirst.GetTableByName("notexists_tb");
|
||||
Assert.Null(t3);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ExistsTable()
|
||||
{
|
||||
var fsql = g.mysql;
|
||||
Assert.False(fsql.DbFirst.ExistsTable("test_existstb01"));
|
||||
Assert.False(fsql.DbFirst.ExistsTable("cccddd_odbc.test_existstb01"));
|
||||
Assert.False(fsql.DbFirst.ExistsTable("test_existstb01", false));
|
||||
Assert.False(fsql.DbFirst.ExistsTable("cccddd_odbc.test_existstb01", false));
|
||||
fsql.CodeFirst.SyncStructure(typeof(test_existstb01));
|
||||
Assert.True(fsql.DbFirst.ExistsTable("test_existstb01"));
|
||||
Assert.True(fsql.DbFirst.ExistsTable("cccddd_odbc.test_existstb01"));
|
||||
Assert.True(fsql.DbFirst.ExistsTable("Test_existstb01", false));
|
||||
Assert.True(fsql.DbFirst.ExistsTable("cccddd_odbc.Test_existstb01", false));
|
||||
fsql.Ado.ExecuteNonQuery("drop table test_existstb01");
|
||||
|
||||
Assert.False(fsql.DbFirst.ExistsTable("cccddd_odbc.test_existstb01"));
|
||||
Assert.False(fsql.DbFirst.ExistsTable("cccddd_odbc.test_existstb01", false));
|
||||
fsql.CodeFirst.SyncStructure(typeof(test_existstb01), "cccddd_odbc.test_existstb01");
|
||||
Assert.True(fsql.DbFirst.ExistsTable("cccddd_odbc.test_existstb01"));
|
||||
Assert.True(fsql.DbFirst.ExistsTable("cccddd_odbc.Test_existstb01", false));
|
||||
fsql.Ado.ExecuteNonQuery("drop table cccddd_odbc.test_existstb01");
|
||||
}
|
||||
class test_existstb01
|
||||
{
|
||||
public Guid id { get; set; }
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,169 @@
|
||||
using FreeSql.DataAnnotations;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Xunit;
|
||||
|
||||
namespace FreeSql.Tests.Custom.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,720 @@
|
||||
using FreeSql.DataAnnotations;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Xunit;
|
||||
|
||||
namespace FreeSql.Tests.Custom.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 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()))
|
||||
|
||||
g.mysql.Insert(new Topic()).ExecuteAffrows();
|
||||
var dtn = DateTime.Parse("2020-1-1 0:0:0");
|
||||
var dts = Enumerable.Range(1, 12).Select(a => dtn.AddMonths(a))
|
||||
.Concat(Enumerable.Range(1, 31).Select(a => dtn.AddDays(a)))
|
||||
.Concat(Enumerable.Range(1, 24).Select(a => dtn.AddHours(a)))
|
||||
.Concat(Enumerable.Range(1, 60).Select(a => dtn.AddMinutes(a)))
|
||||
.Concat(Enumerable.Range(1, 60).Select(a => dtn.AddSeconds(a)));
|
||||
foreach (var dt in dts)
|
||||
{
|
||||
Assert.Equal(dt.ToString("yyyy-MM-dd HH:mm:ss.ffffff"), select.First(a => dt.ToString()));
|
||||
Assert.Equal(dt.ToString("yyyy-MM-dd HH:mm:ss"), select.First(a => dt.ToString("yyyy-MM-dd HH:mm:ss")));
|
||||
Assert.Equal(dt.ToString("yyyy-MM-dd HH:mm"), select.First(a => dt.ToString("yyyy-MM-dd HH:mm")));
|
||||
Assert.Equal(dt.ToString("yyyy-MM-dd HH"), select.First(a => dt.ToString("yyyy-MM-dd HH")));
|
||||
Assert.Equal(dt.ToString("yyyy-MM-dd"), select.First(a => dt.ToString("yyyy-MM-dd")));
|
||||
Assert.Equal(dt.ToString("yyyy-MM"), select.First(a => dt.ToString("yyyy-MM")));
|
||||
Assert.Equal(dt.ToString("yyyyMMddHHmmss"), select.First(a => dt.ToString("yyyyMMddHHmmss")));
|
||||
Assert.Equal(dt.ToString("yyyyMMddHHmm"), select.First(a => dt.ToString("yyyyMMddHHmm")));
|
||||
Assert.Equal(dt.ToString("yyyyMMddHH"), select.First(a => dt.ToString("yyyyMMddHH")));
|
||||
Assert.Equal(dt.ToString("yyyyMMdd"), select.First(a => dt.ToString("yyyyMMdd")));
|
||||
Assert.Equal(dt.ToString("yyyyMM"), select.First(a => dt.ToString("yyyyMM")));
|
||||
Assert.Equal(dt.ToString("yyyy"), select.First(a => dt.ToString("yyyy")));
|
||||
Assert.Equal(dt.ToString("HH:mm:ss"), select.First(a => dt.ToString("HH:mm:ss")));
|
||||
Assert.Equal(dt.ToString("yyyy MM dd HH mm ss yy M d H hh h"), select.First(a => dt.ToString("yyyy MM dd HH mm ss yy M d H hh h")));
|
||||
Assert.Equal(dt.ToString("yyyy MM dd HH mm ss yy M d H hh h m s tt t").Replace("上午", "AM").Replace("下午", "PM").Replace("上", "A").Replace("下", "P"), select.First(a => dt.ToString("yyyy MM dd HH mm ss yy M d H hh h m s tt t")));
|
||||
}
|
||||
}
|
||||
[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 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.Custom.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,166 @@
|
||||
using FreeSql.DataAnnotations;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data.Odbc;
|
||||
using System.Linq;
|
||||
using Xunit;
|
||||
|
||||
namespace FreeSql.Tests.Custom.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 t51 = select.WhereCascade(a => a.testFieldBool).Limit(10).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();
|
||||
|
||||
var t111 = select.Where(a => a.testFieldBool == true && a.Id > 0).ToList();
|
||||
var t222 = select.Where(a => a.testFieldBool != true && a.Id > 0).ToList();
|
||||
var t333 = select.Where(a => a.testFieldBool == false && a.Id > 0).ToList();
|
||||
var t444 = select.Where(a => !a.testFieldBool && a.Id > 0).ToList();
|
||||
var t555 = select.Where(a => a.testFieldBool && a.Id > 0).ToList();
|
||||
|
||||
var t1111 = select.Where(a => a.testFieldBoolNullable == true && a.Id > 0).ToList();
|
||||
var t2222 = select.Where(a => a.testFieldBoolNullable != true && a.Id > 0).ToList();
|
||||
var t3333 = select.Where(a => a.testFieldBoolNullable == false && a.Id > 0).ToList();
|
||||
var t4444 = select.Where(a => !a.testFieldBoolNullable.Value && a.Id > 0).ToList();
|
||||
var t5555 = select.Where(a => a.testFieldBoolNullable.Value && a.Id > 0).ToList();
|
||||
|
||||
var t11111 = select.Where(a => a.testFieldBool == true && a.Id > 0 && a.testFieldBool == true).ToList();
|
||||
var t22222 = select.Where(a => a.testFieldBool != true && a.Id > 0 && a.testFieldBool != true).ToList();
|
||||
var t33333 = select.Where(a => a.testFieldBool == false && a.Id > 0 && a.testFieldBool == false).ToList();
|
||||
var t44444 = select.Where(a => !a.testFieldBool && a.Id > 0 && !a.testFieldBool).ToList();
|
||||
var t55555 = select.Where(a => a.testFieldBool && a.Id > 0 && a.testFieldBool).ToList();
|
||||
|
||||
var t111111 = select.Where(a => a.testFieldBoolNullable == true && a.Id > 0 && a.testFieldBoolNullable == true).ToList();
|
||||
var t222222 = select.Where(a => a.testFieldBoolNullable != true && a.Id > 0 && a.testFieldBoolNullable != true).ToList();
|
||||
var t333333 = select.Where(a => a.testFieldBoolNullable == false && a.Id > 0 && a.testFieldBoolNullable == false).ToList();
|
||||
var t444444 = select.Where(a => !a.testFieldBoolNullable.Value && a.Id > 0 && !a.testFieldBoolNullable.Value).ToList();
|
||||
var t555555 = select.Where(a => a.testFieldBoolNullable.Value && a.Id > 0 && a.testFieldBoolNullable.Value).ToList();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Array()
|
||||
{
|
||||
int[] nullarr = null;
|
||||
Assert.Throws<Exception>(() => { select.Where(a => nullarr.Contains(a.testFieldInt)).ToList(); });
|
||||
Assert.Throws<Exception>(() => { 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();
|
||||
|
||||
var inarray2n = Enumerable.Range(1, 3333).ToArray();
|
||||
var sql1111111 = select.Where(a => inarray2n.Contains(a.testFieldInt)).ToList();
|
||||
var sql1122222 = select.Where(a => inarray2n.Contains(a.testFieldInt) == false).ToList();
|
||||
var sql1133333 = select.Where(a => !inarray2n.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,831 @@
|
||||
using FreeSql.DataAnnotations;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Xunit;
|
||||
|
||||
namespace FreeSql.Tests.Custom.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 StringJoin()
|
||||
{
|
||||
var fsql = g.mysql;
|
||||
fsql.Delete<StringJoin01>().Where("1=1").ExecuteAffrows();
|
||||
fsql.Insert(new[] { new StringJoin01 { name = "北京" }, new StringJoin01 { name = "上海" }, new StringJoin01 { name = "深圳" }, }).ExecuteAffrows();
|
||||
|
||||
var val1 = string.Join(",", fsql.Select<StringJoin01>().ToList(a => a.name));
|
||||
var val2 = fsql.Select<StringJoin01>().ToList(a => string.Join(",", fsql.Select<StringJoin01>().As("b").ToList(b => b.name)));
|
||||
Assert.Equal(val1, val2[0]);
|
||||
|
||||
val1 = string.Join("**", fsql.Select<StringJoin01>().ToList(a => a.name));
|
||||
val2 = fsql.Select<StringJoin01>().ToList(a => string.Join("**", fsql.Select<StringJoin01>().As("b").ToList(b => b.name)));
|
||||
Assert.Equal(val1, val2[0]);
|
||||
|
||||
val1 = string.Join(",", fsql.Select<StringJoin01>().ToList(a => a.id));
|
||||
val2 = fsql.Select<StringJoin01>().ToList(a => string.Join(",", fsql.Select<StringJoin01>().As("b").ToList(b => b.id)));
|
||||
Assert.Equal(val1, val2[0]);
|
||||
|
||||
val1 = string.Join("**", fsql.Select<StringJoin01>().ToList(a => a.id));
|
||||
val2 = fsql.Select<StringJoin01>().ToList(a => string.Join("**", fsql.Select<StringJoin01>().As("b").ToList(b => b.id)));
|
||||
Assert.Equal(val1, val2[0]);
|
||||
}
|
||||
class StringJoin01
|
||||
{
|
||||
[Column(IsIdentity = true)]
|
||||
public int id { get; set; }
|
||||
public string name { get; set; }
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void First()
|
||||
{
|
||||
Assert.Equal('x', select.First(a => "x1".First()));
|
||||
Assert.Equal('z', select.First(a => "z1".First()));
|
||||
}
|
||||
[Fact]
|
||||
public void FirstOrDefault()
|
||||
{
|
||||
Assert.Equal('x', select.First(a => "x1".FirstOrDefault()));
|
||||
Assert.Equal('z', select.First(a => "z1".FirstOrDefault()));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Format()
|
||||
{
|
||||
var item = g.mysql.GetRepository<Topic>().Insert(new Topic { Clicks = 101, Title = "我是中国人101", CreateTime = DateTime.Parse("2020-7-5") });
|
||||
var sql = select.WhereDynamic(item).ToSql(a => new
|
||||
{
|
||||
str = $"x{a.Id + 1}z-{a.CreateTime.ToString("yyyyMM")}{a.Title}",
|
||||
str2 = string.Format("{0}x{0}z-{1}{2}", a.Id + 1, a.CreateTime.ToString("yyyyMM"), a.Title)
|
||||
});
|
||||
Assert.Equal($@"SELECT concat('x',ifnull((a.`Id` + 1), ''),'z-',ifnull(date_format(a.`CreateTime`,'%Y%m'), ''),'',ifnull(a.`Title`, ''),'') as1, concat('',ifnull((a.`Id` + 1), ''),'x',ifnull((a.`Id` + 1), ''),'z-',ifnull(date_format(a.`CreateTime`,'%Y%m'), ''),'',ifnull(a.`Title`, ''),'') as2
|
||||
FROM `tb_topic` a
|
||||
WHERE (a.`Id` = {item.Id})", sql);
|
||||
|
||||
var item2 = select.WhereDynamic(item).First(a => new
|
||||
{
|
||||
str = $"x{a.Id + 1}z-{a.CreateTime.ToString("yyyyMM")}{a.Title}",
|
||||
str2 = string.Format("{0}x{0}z-{1}{2}", a.Id + 1, a.CreateTime.ToString("yyyyMM"), a.Title)
|
||||
});
|
||||
Assert.NotNull(item2);
|
||||
Assert.Equal($"x{item.Id + 1}z-{item.CreateTime.ToString("yyyyMM")}{item.Title}", item2.str);
|
||||
Assert.Equal(string.Format("{0}x{0}z-{1}{2}", item.Id + 1, item.CreateTime.ToString("yyyyMM"), item.Title), item2.str2);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Format4()
|
||||
{
|
||||
//3个 {} 时,Arguments 解析出来是分开的
|
||||
//4个 {} 时,Arguments[1] 只能解析这个出来,然后里面是 NewArray []
|
||||
var item = g.mysql.GetRepository<Topic>().Insert(new Topic { Clicks = 101, Title = "我是中国人101", CreateTime = DateTime.Parse("2020-7-5") });
|
||||
var sql = select.WhereDynamic(item).ToSql(a => new
|
||||
{
|
||||
str = $"x{a.Id + 1}z-{a.CreateTime.ToString("yyyyMM")}{a.Title}{a.Title}",
|
||||
str2 = string.Format("{0}x{0}z-{1}{2}{3}", a.Id + 1, a.CreateTime.ToString("yyyyMM"), a.Title, a.Title)
|
||||
});
|
||||
Assert.Equal($@"SELECT concat('x',ifnull((a.`Id` + 1), ''),'z-',ifnull(date_format(a.`CreateTime`,'%Y%m'), ''),'',ifnull(a.`Title`, ''),'',ifnull(a.`Title`, ''),'') as1, concat('',ifnull((a.`Id` + 1), ''),'x',ifnull((a.`Id` + 1), ''),'z-',ifnull(date_format(a.`CreateTime`,'%Y%m'), ''),'',ifnull(a.`Title`, ''),'',ifnull(a.`Title`, ''),'') as2
|
||||
FROM `tb_topic` a
|
||||
WHERE (a.`Id` = {item.Id})", sql);
|
||||
|
||||
var item2 = select.WhereDynamic(item).First(a => new
|
||||
{
|
||||
str = $"x{a.Id + 1}z-{a.CreateTime.ToString("yyyyMM")}{a.Title}{a.Title}",
|
||||
str2 = string.Format("{0}x{0}z-{1}{2}{3}", a.Id + 1, a.CreateTime.ToString("yyyyMM"), a.Title, a.Title)
|
||||
});
|
||||
Assert.NotNull(item2);
|
||||
Assert.Equal($"x{item.Id + 1}z-{item.CreateTime.ToString("yyyyMM")}{item.Title}{item.Title}", item2.str);
|
||||
Assert.Equal(string.Format("{0}x{0}z-{1}{2}{3}", item.Id + 1, item.CreateTime.ToString("yyyyMM"), item.Title, item.Title), item2.str2);
|
||||
}
|
||||
|
||||
[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`, '%'))
|
||||
|
||||
|
||||
list.Add(select.Where(a => a.Title.Contains("%")).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());
|
||||
//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.Custom.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,106 @@
|
||||
using FreeSql.DataAnnotations;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Xunit;
|
||||
|
||||
namespace FreeSql.Tests.Custom.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\" IN (1,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\" IN (1,2))", sql);
|
||||
|
||||
sql = g.oracle.Delete<Topic>(new { id = 1 }).ToSql();
|
||||
Assert.Equal("DELETE FROM \"TB_TOPIC22211\" WHERE (\"ID\" = 1)", sql);
|
||||
|
||||
sql = g.oracle.Delete<MultiPkTopic>(new[] { new { Id1 = 1, Id2 = 10 }, new { Id1 = 2, Id2 = 20 } }).ToSql();
|
||||
Assert.Equal("DELETE FROM \"MULTIPKTOPIC\" WHERE (\"ID1\" = 1 AND \"ID2\" = 10 OR \"ID1\" = 2 AND \"ID2\" = 20)", sql);
|
||||
}
|
||||
class MultiPkTopic
|
||||
{
|
||||
[Column(IsPrimary = true)]
|
||||
public int Id1 { get; set; }
|
||||
[Column(IsPrimary = true)]
|
||||
public int Id2 { get; set; }
|
||||
public int Clicks { get; set; }
|
||||
public string Title { get; set; }
|
||||
public DateTime CreateTime { get; set; }
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Where()
|
||||
{
|
||||
var sql = delete.Where(a => a.Id == 1).ToSql().Replace("\r\n", "");
|
||||
Assert.Equal("DELETE FROM \"TB_TOPIC22211\" WHERE (\"ID\" = 1)", sql);
|
||||
|
||||
sql = delete.Where("id = :id", new { id = 1 }).ToSql().Replace("\r\n", "");
|
||||
Assert.Equal("DELETE FROM \"TB_TOPIC22211\" WHERE (id = :id)", sql);
|
||||
|
||||
var item = new Topic { Id = 1, Title = "newtitle" };
|
||||
sql = delete.Where(item).ToSql().Replace("\r\n", "");
|
||||
Assert.Equal("DELETE FROM \"TB_TOPIC22211\" WHERE (\"ID\" = 1)", sql);
|
||||
|
||||
var items = new List<Topic>();
|
||||
for (var a = 0; a < 10; a++) items.Add(new Topic { Id = a + 1, Title = $"newtitle{a}", Clicks = a * 100 });
|
||||
|
||||
sql = delete.Where(items).ToSql().Replace("\r\n", "");
|
||||
Assert.Equal("DELETE FROM \"TB_TOPIC22211\" WHERE (\"ID\" IN (1,2,3,4,5,6,7,8,9,10))", sql);
|
||||
}
|
||||
[Fact]
|
||||
public void ExecuteAffrows()
|
||||
{
|
||||
|
||||
var id = g.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\" IN (1,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\" IN (1,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,425 @@
|
||||
using FreeSql.DataAnnotations;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Xunit;
|
||||
|
||||
namespace FreeSql.Tests.Custom.Oracle
|
||||
{
|
||||
public class OracleInsertOrUpdateIfExistsDoNothingTest
|
||||
{
|
||||
IFreeSql fsql => g.oracle;
|
||||
|
||||
[Fact]
|
||||
public void InsertOrUpdate_OnlyPrimary()
|
||||
{
|
||||
fsql.Delete<tbioudb01>().Where("1=1").ExecuteAffrows();
|
||||
var iou = fsql.InsertOrUpdate<tbioudb01>().IfExistsDoNothing().SetSource(new tbioudb01 { id = 1 });
|
||||
var sql = iou.ToSql();
|
||||
Assert.Equal(@"MERGE INTO ""TBIOUDB01"" t1
|
||||
USING (SELECT 1 as ""ID"" FROM dual ) t2 ON (t1.""ID"" = t2.""ID"")
|
||||
WHEN NOT MATCHED THEN
|
||||
insert (""ID"")
|
||||
values (t2.""ID"")", sql);
|
||||
iou.ExecuteAffrows();
|
||||
|
||||
iou = fsql.InsertOrUpdate<tbioudb01>().IfExistsDoNothing().SetSource(new tbioudb01 { id = 1 });
|
||||
sql = iou.ToSql();
|
||||
Assert.Equal(@"MERGE INTO ""TBIOUDB01"" t1
|
||||
USING (SELECT 1 as ""ID"" FROM dual ) t2 ON (t1.""ID"" = t2.""ID"")
|
||||
WHEN NOT MATCHED THEN
|
||||
insert (""ID"")
|
||||
values (t2.""ID"")", sql);
|
||||
iou.ExecuteAffrows();
|
||||
|
||||
iou = fsql.InsertOrUpdate<tbioudb01>().IfExistsDoNothing().SetSource(new tbioudb01 { id = 2 });
|
||||
sql = iou.ToSql();
|
||||
Assert.Equal(@"MERGE INTO ""TBIOUDB01"" t1
|
||||
USING (SELECT 2 as ""ID"" FROM dual ) t2 ON (t1.""ID"" = t2.""ID"")
|
||||
WHEN NOT MATCHED THEN
|
||||
insert (""ID"")
|
||||
values (t2.""ID"")", sql);
|
||||
iou.ExecuteAffrows();
|
||||
|
||||
iou = fsql.InsertOrUpdate<tbioudb01>().IfExistsDoNothing().SetSource(new[] { new tbioudb01 { id = 1 }, new tbioudb01 { id = 2 }, new tbioudb01 { id = 3 }, new tbioudb01 { id = 4 } });
|
||||
sql = iou.ToSql();
|
||||
Assert.Equal(@"MERGE INTO ""TBIOUDB01"" t1
|
||||
USING (SELECT 1 as ""ID"" FROM dual
|
||||
UNION ALL
|
||||
SELECT 2 FROM dual
|
||||
UNION ALL
|
||||
SELECT 3 FROM dual
|
||||
UNION ALL
|
||||
SELECT 4 FROM dual ) t2 ON (t1.""ID"" = t2.""ID"")
|
||||
WHEN NOT MATCHED THEN
|
||||
insert (""ID"")
|
||||
values (t2.""ID"")", sql);
|
||||
iou.ExecuteAffrows();
|
||||
|
||||
iou = fsql.InsertOrUpdate<tbioudb01>().IfExistsDoNothing().SetSource(new[] { new tbioudb01 { id = 1 }, new tbioudb01 { id = 2 }, new tbioudb01 { id = 3 }, new tbioudb01 { id = 4 } });
|
||||
sql = iou.ToSql();
|
||||
Assert.Equal(@"MERGE INTO ""TBIOUDB01"" t1
|
||||
USING (SELECT 1 as ""ID"" FROM dual
|
||||
UNION ALL
|
||||
SELECT 2 FROM dual
|
||||
UNION ALL
|
||||
SELECT 3 FROM dual
|
||||
UNION ALL
|
||||
SELECT 4 FROM dual ) t2 ON (t1.""ID"" = t2.""ID"")
|
||||
WHEN NOT MATCHED THEN
|
||||
insert (""ID"")
|
||||
values (t2.""ID"")", sql);
|
||||
iou.ExecuteAffrows();
|
||||
}
|
||||
class tbioudb01
|
||||
{
|
||||
public int id { get; set; }
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void InsertOrUpdate_OnePrimary()
|
||||
{
|
||||
fsql.Delete<tbioudb02>().Where("1=1").ExecuteAffrows();
|
||||
var iou = fsql.InsertOrUpdate<tbioudb02>().IfExistsDoNothing().SetSource(new tbioudb02 { id = 1, name = "01" });
|
||||
var sql = iou.ToSql();
|
||||
Assert.Equal(@"MERGE INTO ""TBIOUDB02"" t1
|
||||
USING (SELECT 1 as ""ID"", '01' as ""NAME"" FROM dual ) t2 ON (t1.""ID"" = t2.""ID"")
|
||||
WHEN NOT MATCHED THEN
|
||||
insert (""ID"", ""NAME"")
|
||||
values (t2.""ID"", t2.""NAME"")", sql);
|
||||
iou.ExecuteAffrows();
|
||||
|
||||
iou = fsql.InsertOrUpdate<tbioudb02>().IfExistsDoNothing().SetSource(new tbioudb02 { id = 1, name = "011" });
|
||||
sql = iou.ToSql();
|
||||
Assert.Equal(@"MERGE INTO ""TBIOUDB02"" t1
|
||||
USING (SELECT 1 as ""ID"", '011' as ""NAME"" FROM dual ) t2 ON (t1.""ID"" = t2.""ID"")
|
||||
WHEN NOT MATCHED THEN
|
||||
insert (""ID"", ""NAME"")
|
||||
values (t2.""ID"", t2.""NAME"")", sql);
|
||||
iou.ExecuteAffrows();
|
||||
|
||||
iou = fsql.InsertOrUpdate<tbioudb02>().IfExistsDoNothing().SetSource(new tbioudb02 { id = 2, name = "02" });
|
||||
sql = iou.ToSql();
|
||||
Assert.Equal(@"MERGE INTO ""TBIOUDB02"" t1
|
||||
USING (SELECT 2 as ""ID"", '02' as ""NAME"" FROM dual ) t2 ON (t1.""ID"" = t2.""ID"")
|
||||
WHEN NOT MATCHED THEN
|
||||
insert (""ID"", ""NAME"")
|
||||
values (t2.""ID"", t2.""NAME"")", sql);
|
||||
iou.ExecuteAffrows();
|
||||
|
||||
iou = fsql.InsertOrUpdate<tbioudb02>().IfExistsDoNothing().SetSource(new[] { new tbioudb02 { id = 1, name = "01" }, new tbioudb02 { id = 2, name = "02" }, new tbioudb02 { id = 3, name = "03" }, new tbioudb02 { id = 4, name = "04" } });
|
||||
sql = iou.ToSql();
|
||||
Assert.Equal(@"MERGE INTO ""TBIOUDB02"" t1
|
||||
USING (SELECT 1 as ""ID"", '01' as ""NAME"" FROM dual
|
||||
UNION ALL
|
||||
SELECT 2, '02' FROM dual
|
||||
UNION ALL
|
||||
SELECT 3, '03' FROM dual
|
||||
UNION ALL
|
||||
SELECT 4, '04' FROM dual ) t2 ON (t1.""ID"" = t2.""ID"")
|
||||
WHEN NOT MATCHED THEN
|
||||
insert (""ID"", ""NAME"")
|
||||
values (t2.""ID"", t2.""NAME"")", sql);
|
||||
iou.ExecuteAffrows();
|
||||
|
||||
iou = fsql.InsertOrUpdate<tbioudb02>().IfExistsDoNothing().SetSource(new[] { new tbioudb02 { id = 1, name = "001" }, new tbioudb02 { id = 2, name = "002" }, new tbioudb02 { id = 3, name = "003" }, new tbioudb02 { id = 4, name = "004" } });
|
||||
sql = iou.ToSql();
|
||||
Assert.Equal(@"MERGE INTO ""TBIOUDB02"" t1
|
||||
USING (SELECT 1 as ""ID"", '001' as ""NAME"" FROM dual
|
||||
UNION ALL
|
||||
SELECT 2, '002' FROM dual
|
||||
UNION ALL
|
||||
SELECT 3, '003' FROM dual
|
||||
UNION ALL
|
||||
SELECT 4, '004' FROM dual ) t2 ON (t1.""ID"" = t2.""ID"")
|
||||
WHEN NOT MATCHED THEN
|
||||
insert (""ID"", ""NAME"")
|
||||
values (t2.""ID"", t2.""NAME"")", sql);
|
||||
iou.ExecuteAffrows();
|
||||
var lst = fsql.Select<tbioudb02>().Where(a => new[] { 1, 2, 3, 4 }.Contains(a.id)).ToList();
|
||||
Assert.Equal(4, lst.Where(a => a.name == "0" + a.id).Count());
|
||||
}
|
||||
class tbioudb02
|
||||
{
|
||||
public int id { get; set; }
|
||||
public string name { get; set; }
|
||||
}
|
||||
[Fact]
|
||||
public void InsertOrUpdate_OnePrimaryAndIdentity()
|
||||
{
|
||||
fsql.Delete<tbioudb022>().Where("1=1").ExecuteAffrows();
|
||||
var iou = fsql.InsertOrUpdate<tbioudb022>().IfExistsDoNothing().SetSource(new tbioudb022 { id = 1, name = "01" });
|
||||
var sql = iou.ToSql();
|
||||
Assert.Equal(@"MERGE INTO ""TBIOUDB022"" t1
|
||||
USING (SELECT 1 as ""ID"", '01' as ""NAME"" FROM dual ) t2 ON (t1.""ID"" = t2.""ID"")
|
||||
WHEN NOT MATCHED THEN
|
||||
insert (""ID"", ""NAME"")
|
||||
values (t2.""ID"", t2.""NAME"")", sql);
|
||||
iou.ExecuteAffrows();
|
||||
|
||||
iou = fsql.InsertOrUpdate<tbioudb022>().IfExistsDoNothing().SetSource(new tbioudb022 { id = 1, name = "011" });
|
||||
sql = iou.ToSql();
|
||||
Assert.Equal(@"MERGE INTO ""TBIOUDB022"" t1
|
||||
USING (SELECT 1 as ""ID"", '011' as ""NAME"" FROM dual ) t2 ON (t1.""ID"" = t2.""ID"")
|
||||
WHEN NOT MATCHED THEN
|
||||
insert (""ID"", ""NAME"")
|
||||
values (t2.""ID"", t2.""NAME"")", sql);
|
||||
iou.ExecuteAffrows();
|
||||
|
||||
iou = fsql.InsertOrUpdate<tbioudb022>().IfExistsDoNothing().SetSource(new tbioudb022 { id = 2, name = "02" });
|
||||
sql = iou.ToSql();
|
||||
Assert.Equal(@"MERGE INTO ""TBIOUDB022"" t1
|
||||
USING (SELECT 2 as ""ID"", '02' as ""NAME"" FROM dual ) t2 ON (t1.""ID"" = t2.""ID"")
|
||||
WHEN NOT MATCHED THEN
|
||||
insert (""ID"", ""NAME"")
|
||||
values (t2.""ID"", t2.""NAME"")", sql);
|
||||
iou.ExecuteAffrows();
|
||||
|
||||
iou = fsql.InsertOrUpdate<tbioudb022>().IfExistsDoNothing().SetSource(new[] { new tbioudb022 { id = 1, name = "01" }, new tbioudb022 { id = 2, name = "02" }, new tbioudb022 { id = 3, name = "03" }, new tbioudb022 { id = 4, name = "04" } });
|
||||
sql = iou.ToSql();
|
||||
Assert.Equal(@"MERGE INTO ""TBIOUDB022"" t1
|
||||
USING (SELECT 1 as ""ID"", '01' as ""NAME"" FROM dual
|
||||
UNION ALL
|
||||
SELECT 2, '02' FROM dual
|
||||
UNION ALL
|
||||
SELECT 3, '03' FROM dual
|
||||
UNION ALL
|
||||
SELECT 4, '04' FROM dual ) t2 ON (t1.""ID"" = t2.""ID"")
|
||||
WHEN NOT MATCHED THEN
|
||||
insert (""ID"", ""NAME"")
|
||||
values (t2.""ID"", t2.""NAME"")", sql);
|
||||
iou.ExecuteAffrows();
|
||||
|
||||
iou = fsql.InsertOrUpdate<tbioudb022>().IfExistsDoNothing().SetSource(new[] { new tbioudb022 { id = 1, name = "001" }, new tbioudb022 { id = 2, name = "002" }, new tbioudb022 { id = 3, name = "003" }, new tbioudb022 { id = 4, name = "004" } });
|
||||
sql = iou.ToSql();
|
||||
Assert.Equal(@"MERGE INTO ""TBIOUDB022"" t1
|
||||
USING (SELECT 1 as ""ID"", '001' as ""NAME"" FROM dual
|
||||
UNION ALL
|
||||
SELECT 2, '002' FROM dual
|
||||
UNION ALL
|
||||
SELECT 3, '003' FROM dual
|
||||
UNION ALL
|
||||
SELECT 4, '004' FROM dual ) t2 ON (t1.""ID"" = t2.""ID"")
|
||||
WHEN NOT MATCHED THEN
|
||||
insert (""ID"", ""NAME"")
|
||||
values (t2.""ID"", t2.""NAME"")", sql);
|
||||
iou.ExecuteAffrows();
|
||||
var lst = fsql.Select<tbioudb022>().Where(a => new[] { 1, 2, 3, 4 }.Contains(a.id)).ToList();
|
||||
//Assert.Equal(4, lst.Where(a => a.name == "00" + a.id).Count());
|
||||
|
||||
//--no primary
|
||||
iou = fsql.InsertOrUpdate<tbioudb022>().IfExistsDoNothing().SetSource(new tbioudb022 { name = "01" });
|
||||
sql = iou.ToSql();
|
||||
Assert.Equal(@"INSERT INTO ""TBIOUDB022""(""NAME"") VALUES('01')", sql);
|
||||
iou.ExecuteAffrows();
|
||||
|
||||
iou = fsql.InsertOrUpdate<tbioudb022>().IfExistsDoNothing().SetSource(new tbioudb022 { name = "011" });
|
||||
sql = iou.ToSql();
|
||||
Assert.Equal(@"INSERT INTO ""TBIOUDB022""(""NAME"") VALUES('011')", sql);
|
||||
iou.ExecuteAffrows();
|
||||
|
||||
iou = fsql.InsertOrUpdate<tbioudb022>().IfExistsDoNothing().SetSource(new tbioudb022 { name = "02" });
|
||||
sql = iou.ToSql();
|
||||
Assert.Equal(@"INSERT INTO ""TBIOUDB022""(""NAME"") VALUES('02')", sql);
|
||||
iou.ExecuteAffrows();
|
||||
|
||||
iou = fsql.InsertOrUpdate<tbioudb022>().IfExistsDoNothing().SetSource(new[] { new tbioudb022 { name = "01" }, new tbioudb022 { name = "02" }, new tbioudb022 { name = "03" }, new tbioudb022 { name = "04" } });
|
||||
sql = iou.ToSql();
|
||||
Assert.Equal(@"INSERT ALL
|
||||
INTO ""TBIOUDB022""(""NAME"") VALUES('01')
|
||||
INTO ""TBIOUDB022""(""NAME"") VALUES('02')
|
||||
INTO ""TBIOUDB022""(""NAME"") VALUES('03')
|
||||
INTO ""TBIOUDB022""(""NAME"") VALUES('04')
|
||||
SELECT 1 FROM DUAL", sql);
|
||||
iou.ExecuteAffrows();
|
||||
|
||||
iou = fsql.InsertOrUpdate<tbioudb022>().IfExistsDoNothing().SetSource(new[] { new tbioudb022 { name = "001" }, new tbioudb022 { name = "002" }, new tbioudb022 { name = "003" }, new tbioudb022 { name = "004" } });
|
||||
sql = iou.ToSql();
|
||||
Assert.Equal(@"INSERT ALL
|
||||
INTO ""TBIOUDB022""(""NAME"") VALUES('001')
|
||||
INTO ""TBIOUDB022""(""NAME"") VALUES('002')
|
||||
INTO ""TBIOUDB022""(""NAME"") VALUES('003')
|
||||
INTO ""TBIOUDB022""(""NAME"") VALUES('004')
|
||||
SELECT 1 FROM DUAL", sql);
|
||||
iou.ExecuteAffrows();
|
||||
|
||||
//--no primary and yes
|
||||
iou = fsql.InsertOrUpdate<tbioudb022>().IfExistsDoNothing().SetSource(new[] { new tbioudb022 { id = 1, name = "100001" }, new tbioudb022 { name = "00001" }, new tbioudb022 { id = 2, name = "100002" }, new tbioudb022 { name = "00002" }, new tbioudb022 { id = 3, name = "100003" }, new tbioudb022 { name = "00003" }, new tbioudb022 { id = 4, name = "100004" }, new tbioudb022 { name = "00004" } });
|
||||
sql = iou.ToSql();
|
||||
Assert.Equal(@"MERGE INTO ""TBIOUDB022"" t1
|
||||
USING (SELECT 1 as ""ID"", '100001' as ""NAME"" FROM dual
|
||||
UNION ALL
|
||||
SELECT 2, '100002' FROM dual
|
||||
UNION ALL
|
||||
SELECT 3, '100003' FROM dual
|
||||
UNION ALL
|
||||
SELECT 4, '100004' FROM dual ) t2 ON (t1.""ID"" = t2.""ID"")
|
||||
WHEN NOT MATCHED THEN
|
||||
insert (""ID"", ""NAME"")
|
||||
values (t2.""ID"", t2.""NAME"")
|
||||
|
||||
;
|
||||
|
||||
INSERT ALL
|
||||
INTO ""TBIOUDB022""(""NAME"") VALUES('00001')
|
||||
INTO ""TBIOUDB022""(""NAME"") VALUES('00002')
|
||||
INTO ""TBIOUDB022""(""NAME"") VALUES('00003')
|
||||
INTO ""TBIOUDB022""(""NAME"") VALUES('00004')
|
||||
SELECT 1 FROM DUAL", sql);
|
||||
iou.ExecuteAffrows();
|
||||
lst = fsql.Select<tbioudb022>().Where(a => new[] { 1, 2, 3, 4 }.Contains(a.id)).ToList();
|
||||
//Assert.Equal(4, lst.Where(a => a.name == "10000" + a.id).Count());
|
||||
}
|
||||
class tbioudb022
|
||||
{
|
||||
[Column(IsIdentity = true)]
|
||||
public int id { get; set; }
|
||||
public string name { get; set; }
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void InsertOrUpdate_TwoPrimary()
|
||||
{
|
||||
fsql.Delete<tbioudb03>().Where("1=1").ExecuteAffrows();
|
||||
var iou = fsql.InsertOrUpdate<tbioudb03>().IfExistsDoNothing().SetSource(new tbioudb03 { id1 = 1, id2 = "01", name = "01" });
|
||||
var sql = iou.ToSql();
|
||||
Assert.Equal(@"MERGE INTO ""TBIOUDB03"" t1
|
||||
USING (SELECT 1 as ""ID1"", '01' as ""ID2"", '01' as ""NAME"" FROM dual ) t2 ON (t1.""ID1"" = t2.""ID1"" AND t1.""ID2"" = t2.""ID2"")
|
||||
WHEN NOT MATCHED THEN
|
||||
insert (""ID1"", ""ID2"", ""NAME"")
|
||||
values (t2.""ID1"", t2.""ID2"", t2.""NAME"")", sql);
|
||||
iou.ExecuteAffrows();
|
||||
|
||||
iou = fsql.InsertOrUpdate<tbioudb03>().IfExistsDoNothing().SetSource(new tbioudb03 { id1 = 1, id2 = "01", name = "011" });
|
||||
sql = iou.ToSql();
|
||||
Assert.Equal(@"MERGE INTO ""TBIOUDB03"" t1
|
||||
USING (SELECT 1 as ""ID1"", '01' as ""ID2"", '011' as ""NAME"" FROM dual ) t2 ON (t1.""ID1"" = t2.""ID1"" AND t1.""ID2"" = t2.""ID2"")
|
||||
WHEN NOT MATCHED THEN
|
||||
insert (""ID1"", ""ID2"", ""NAME"")
|
||||
values (t2.""ID1"", t2.""ID2"", t2.""NAME"")", sql);
|
||||
iou.ExecuteAffrows();
|
||||
|
||||
iou = fsql.InsertOrUpdate<tbioudb03>().IfExistsDoNothing().SetSource(new tbioudb03 { id1 = 2, id2 = "02", name = "02" });
|
||||
sql = iou.ToSql();
|
||||
Assert.Equal(@"MERGE INTO ""TBIOUDB03"" t1
|
||||
USING (SELECT 2 as ""ID1"", '02' as ""ID2"", '02' as ""NAME"" FROM dual ) t2 ON (t1.""ID1"" = t2.""ID1"" AND t1.""ID2"" = t2.""ID2"")
|
||||
WHEN NOT MATCHED THEN
|
||||
insert (""ID1"", ""ID2"", ""NAME"")
|
||||
values (t2.""ID1"", t2.""ID2"", t2.""NAME"")", sql);
|
||||
iou.ExecuteAffrows();
|
||||
|
||||
iou = fsql.InsertOrUpdate<tbioudb03>().IfExistsDoNothing().SetSource(new[] { new tbioudb03 { id1 = 1, id2 = "01", name = "01" }, new tbioudb03 { id1 = 2, id2 = "02", name = "02" }, new tbioudb03 { id1 = 3, id2 = "03", name = "03" }, new tbioudb03 { id1 = 4, id2 = "04", name = "04" } });
|
||||
sql = iou.ToSql();
|
||||
Assert.Equal(@"MERGE INTO ""TBIOUDB03"" t1
|
||||
USING (SELECT 1 as ""ID1"", '01' as ""ID2"", '01' as ""NAME"" FROM dual
|
||||
UNION ALL
|
||||
SELECT 2, '02', '02' FROM dual
|
||||
UNION ALL
|
||||
SELECT 3, '03', '03' FROM dual
|
||||
UNION ALL
|
||||
SELECT 4, '04', '04' FROM dual ) t2 ON (t1.""ID1"" = t2.""ID1"" AND t1.""ID2"" = t2.""ID2"")
|
||||
WHEN NOT MATCHED THEN
|
||||
insert (""ID1"", ""ID2"", ""NAME"")
|
||||
values (t2.""ID1"", t2.""ID2"", t2.""NAME"")", sql);
|
||||
iou.ExecuteAffrows();
|
||||
|
||||
iou = fsql.InsertOrUpdate<tbioudb03>().IfExistsDoNothing().SetSource(new[] { new tbioudb03 { id1 = 1, id2 = "01", name = "001" }, new tbioudb03 { id1 = 2, id2 = "02", name = "002" }, new tbioudb03 { id1 = 3, id2 = "03", name = "003" }, new tbioudb03 { id1 = 4, id2 = "04", name = "004" } });
|
||||
sql = iou.ToSql();
|
||||
Assert.Equal(@"MERGE INTO ""TBIOUDB03"" t1
|
||||
USING (SELECT 1 as ""ID1"", '01' as ""ID2"", '001' as ""NAME"" FROM dual
|
||||
UNION ALL
|
||||
SELECT 2, '02', '002' FROM dual
|
||||
UNION ALL
|
||||
SELECT 3, '03', '003' FROM dual
|
||||
UNION ALL
|
||||
SELECT 4, '04', '004' FROM dual ) t2 ON (t1.""ID1"" = t2.""ID1"" AND t1.""ID2"" = t2.""ID2"")
|
||||
WHEN NOT MATCHED THEN
|
||||
insert (""ID1"", ""ID2"", ""NAME"")
|
||||
values (t2.""ID1"", t2.""ID2"", t2.""NAME"")", sql);
|
||||
iou.ExecuteAffrows();
|
||||
var lst = fsql.Select<tbioudb03>().Where(a => a.id1 == 1 && a.id2 == "01" || a.id1 == 2 && a.id2 == "02" || a.id1 == 3 && a.id2 == "03" || a.id1 == 4 && a.id2 == "04").ToList();
|
||||
Assert.Equal(4, lst.Where(a => a.name == "0" + a.id1).Count());
|
||||
}
|
||||
class tbioudb03
|
||||
{
|
||||
[Column(IsPrimary = true)]
|
||||
public int id1 { get; set; }
|
||||
[Column(IsPrimary = true)]
|
||||
public string id2 { get; set; }
|
||||
public string name { get; set; }
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void InsertOrUpdate_OnePrimaryAndVersionAndCanUpdate()
|
||||
{
|
||||
fsql.Delete<tbioudb04>().Where("1=1").ExecuteAffrows();
|
||||
var iou = fsql.InsertOrUpdate<tbioudb04>().IfExistsDoNothing().SetSource(new tbioudb04 { id = 1, name = "01" });
|
||||
var sql = iou.ToSql();
|
||||
Assert.Equal(@"MERGE INTO ""TBIOUDB04"" t1
|
||||
USING (SELECT 1 as ""ID"", '01' as ""NAME"", 0 as ""VERSION"", systimestamp as ""CREATETIME"" FROM dual ) t2 ON (t1.""ID"" = t2.""ID"")
|
||||
WHEN NOT MATCHED THEN
|
||||
insert (""ID"", ""NAME"", ""VERSION"", ""CREATETIME"")
|
||||
values (t2.""ID"", t2.""NAME"", t2.""VERSION"", t2.""CREATETIME"")", sql);
|
||||
iou.ExecuteAffrows();
|
||||
|
||||
iou = fsql.InsertOrUpdate<tbioudb04>().IfExistsDoNothing().SetSource(new tbioudb04 { id = 1, name = "011" });
|
||||
sql = iou.ToSql();
|
||||
Assert.Equal(@"MERGE INTO ""TBIOUDB04"" t1
|
||||
USING (SELECT 1 as ""ID"", '011' as ""NAME"", 0 as ""VERSION"", systimestamp as ""CREATETIME"" FROM dual ) t2 ON (t1.""ID"" = t2.""ID"")
|
||||
WHEN NOT MATCHED THEN
|
||||
insert (""ID"", ""NAME"", ""VERSION"", ""CREATETIME"")
|
||||
values (t2.""ID"", t2.""NAME"", t2.""VERSION"", t2.""CREATETIME"")", sql);
|
||||
iou.ExecuteAffrows();
|
||||
|
||||
iou = fsql.InsertOrUpdate<tbioudb04>().IfExistsDoNothing().SetSource(new tbioudb04 { id = 2, name = "02" });
|
||||
sql = iou.ToSql();
|
||||
Assert.Equal(@"MERGE INTO ""TBIOUDB04"" t1
|
||||
USING (SELECT 2 as ""ID"", '02' as ""NAME"", 0 as ""VERSION"", systimestamp as ""CREATETIME"" FROM dual ) t2 ON (t1.""ID"" = t2.""ID"")
|
||||
WHEN NOT MATCHED THEN
|
||||
insert (""ID"", ""NAME"", ""VERSION"", ""CREATETIME"")
|
||||
values (t2.""ID"", t2.""NAME"", t2.""VERSION"", t2.""CREATETIME"")", sql);
|
||||
iou.ExecuteAffrows();
|
||||
|
||||
iou = fsql.InsertOrUpdate<tbioudb04>().IfExistsDoNothing().SetSource(new[] { new tbioudb04 { id = 1, name = "01" }, new tbioudb04 { id = 2, name = "02" }, new tbioudb04 { id = 3, name = "03" }, new tbioudb04 { id = 4, name = "04" } });
|
||||
sql = iou.ToSql();
|
||||
Assert.Equal(@"MERGE INTO ""TBIOUDB04"" t1
|
||||
USING (SELECT 1 as ""ID"", '01' as ""NAME"", 0 as ""VERSION"", systimestamp as ""CREATETIME"" FROM dual
|
||||
UNION ALL
|
||||
SELECT 2, '02', 0, systimestamp FROM dual
|
||||
UNION ALL
|
||||
SELECT 3, '03', 0, systimestamp FROM dual
|
||||
UNION ALL
|
||||
SELECT 4, '04', 0, systimestamp FROM dual ) t2 ON (t1.""ID"" = t2.""ID"")
|
||||
WHEN NOT MATCHED THEN
|
||||
insert (""ID"", ""NAME"", ""VERSION"", ""CREATETIME"")
|
||||
values (t2.""ID"", t2.""NAME"", t2.""VERSION"", t2.""CREATETIME"")", sql);
|
||||
iou.ExecuteAffrows();
|
||||
|
||||
iou = fsql.InsertOrUpdate<tbioudb04>().IfExistsDoNothing().SetSource(new[] { new tbioudb04 { id = 1, name = "001" }, new tbioudb04 { id = 2, name = "002" }, new tbioudb04 { id = 3, name = "003" }, new tbioudb04 { id = 4, name = "004" } });
|
||||
sql = iou.ToSql();
|
||||
Assert.Equal(@"MERGE INTO ""TBIOUDB04"" t1
|
||||
USING (SELECT 1 as ""ID"", '001' as ""NAME"", 0 as ""VERSION"", systimestamp as ""CREATETIME"" FROM dual
|
||||
UNION ALL
|
||||
SELECT 2, '002', 0, systimestamp FROM dual
|
||||
UNION ALL
|
||||
SELECT 3, '003', 0, systimestamp FROM dual
|
||||
UNION ALL
|
||||
SELECT 4, '004', 0, systimestamp FROM dual ) t2 ON (t1.""ID"" = t2.""ID"")
|
||||
WHEN NOT MATCHED THEN
|
||||
insert (""ID"", ""NAME"", ""VERSION"", ""CREATETIME"")
|
||||
values (t2.""ID"", t2.""NAME"", t2.""VERSION"", t2.""CREATETIME"")", sql);
|
||||
iou.ExecuteAffrows();
|
||||
var lst = fsql.Select<tbioudb04>().Where(a => new[] { 1, 2, 3, 4 }.Contains(a.id)).ToList();
|
||||
Assert.Equal(4, lst.Where(a => a.name == "0" + a.id).Count());
|
||||
}
|
||||
class tbioudb04
|
||||
{
|
||||
public int id { get; set; }
|
||||
public string name { get; set; }
|
||||
[Column(IsVersion = true)]
|
||||
public int version { get; set; }
|
||||
[Column(CanUpdate = false, ServerTime = DateTimeKind.Local)]
|
||||
public DateTime CreateTime { get; set; }
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,467 @@
|
||||
using FreeSql.DataAnnotations;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Xunit;
|
||||
|
||||
namespace FreeSql.Tests.Custom.Oracle
|
||||
{
|
||||
public class OracleInsertOrUpdateTest
|
||||
{
|
||||
IFreeSql fsql => g.oracle;
|
||||
|
||||
[Fact]
|
||||
public void InsertOrUpdate_OnlyPrimary()
|
||||
{
|
||||
fsql.Delete<tbiou01>().Where("1=1").ExecuteAffrows();
|
||||
var iou = fsql.InsertOrUpdate<tbiou01>().SetSource(new tbiou01 { id = 1 });
|
||||
var sql = iou.ToSql();
|
||||
Assert.Equal(@"MERGE INTO ""TBIOU01"" t1
|
||||
USING (SELECT 1 as ""ID"" FROM dual ) t2 ON (t1.""ID"" = t2.""ID"")
|
||||
WHEN NOT MATCHED THEN
|
||||
insert (""ID"")
|
||||
values (t2.""ID"")", sql);
|
||||
iou.ExecuteAffrows();
|
||||
|
||||
iou = fsql.InsertOrUpdate<tbiou01>().SetSource(new tbiou01 { id = 1 });
|
||||
sql = iou.ToSql();
|
||||
Assert.Equal(@"MERGE INTO ""TBIOU01"" t1
|
||||
USING (SELECT 1 as ""ID"" FROM dual ) t2 ON (t1.""ID"" = t2.""ID"")
|
||||
WHEN NOT MATCHED THEN
|
||||
insert (""ID"")
|
||||
values (t2.""ID"")", sql);
|
||||
iou.ExecuteAffrows();
|
||||
|
||||
iou = fsql.InsertOrUpdate<tbiou01>().SetSource(new tbiou01 { id = 2 });
|
||||
sql = iou.ToSql();
|
||||
Assert.Equal(@"MERGE INTO ""TBIOU01"" t1
|
||||
USING (SELECT 2 as ""ID"" FROM dual ) t2 ON (t1.""ID"" = t2.""ID"")
|
||||
WHEN NOT MATCHED THEN
|
||||
insert (""ID"")
|
||||
values (t2.""ID"")", sql);
|
||||
iou.ExecuteAffrows();
|
||||
|
||||
iou = fsql.InsertOrUpdate<tbiou01>().SetSource(new[] { new tbiou01 { id = 1 }, new tbiou01 { id = 2 }, new tbiou01 { id = 3 }, new tbiou01 { id = 4 } });
|
||||
sql = iou.ToSql();
|
||||
Assert.Equal(@"MERGE INTO ""TBIOU01"" t1
|
||||
USING (SELECT 1 as ""ID"" FROM dual
|
||||
UNION ALL
|
||||
SELECT 2 FROM dual
|
||||
UNION ALL
|
||||
SELECT 3 FROM dual
|
||||
UNION ALL
|
||||
SELECT 4 FROM dual ) t2 ON (t1.""ID"" = t2.""ID"")
|
||||
WHEN NOT MATCHED THEN
|
||||
insert (""ID"")
|
||||
values (t2.""ID"")", sql);
|
||||
iou.ExecuteAffrows();
|
||||
|
||||
iou = fsql.InsertOrUpdate<tbiou01>().SetSource(new[] { new tbiou01 { id = 1 }, new tbiou01 { id = 2 }, new tbiou01 { id = 3 }, new tbiou01 { id = 4 } });
|
||||
sql = iou.ToSql();
|
||||
Assert.Equal(@"MERGE INTO ""TBIOU01"" t1
|
||||
USING (SELECT 1 as ""ID"" FROM dual
|
||||
UNION ALL
|
||||
SELECT 2 FROM dual
|
||||
UNION ALL
|
||||
SELECT 3 FROM dual
|
||||
UNION ALL
|
||||
SELECT 4 FROM dual ) t2 ON (t1.""ID"" = t2.""ID"")
|
||||
WHEN NOT MATCHED THEN
|
||||
insert (""ID"")
|
||||
values (t2.""ID"")", sql);
|
||||
iou.ExecuteAffrows();
|
||||
}
|
||||
class tbiou01
|
||||
{
|
||||
public int id { get; set; }
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void InsertOrUpdate_OnePrimary()
|
||||
{
|
||||
fsql.Delete<tbiou02>().Where("1=1").ExecuteAffrows();
|
||||
var iou = fsql.InsertOrUpdate<tbiou02>().SetSource(new tbiou02 { id = 1, name = "01" });
|
||||
var sql = iou.ToSql();
|
||||
Assert.Equal(@"MERGE INTO ""TBIOU02"" t1
|
||||
USING (SELECT 1 as ""ID"", '01' as ""NAME"" FROM dual ) t2 ON (t1.""ID"" = t2.""ID"")
|
||||
WHEN MATCHED THEN
|
||||
update set ""NAME"" = t2.""NAME""
|
||||
WHEN NOT MATCHED THEN
|
||||
insert (""ID"", ""NAME"")
|
||||
values (t2.""ID"", t2.""NAME"")", sql);
|
||||
iou.ExecuteAffrows();
|
||||
|
||||
iou = fsql.InsertOrUpdate<tbiou02>().SetSource(new tbiou02 { id = 1, name = "011" });
|
||||
sql = iou.ToSql();
|
||||
Assert.Equal(@"MERGE INTO ""TBIOU02"" t1
|
||||
USING (SELECT 1 as ""ID"", '011' as ""NAME"" FROM dual ) t2 ON (t1.""ID"" = t2.""ID"")
|
||||
WHEN MATCHED THEN
|
||||
update set ""NAME"" = t2.""NAME""
|
||||
WHEN NOT MATCHED THEN
|
||||
insert (""ID"", ""NAME"")
|
||||
values (t2.""ID"", t2.""NAME"")", sql);
|
||||
iou.ExecuteAffrows();
|
||||
|
||||
iou = fsql.InsertOrUpdate<tbiou02>().SetSource(new tbiou02 { id = 2, name = "02" });
|
||||
sql = iou.ToSql();
|
||||
Assert.Equal(@"MERGE INTO ""TBIOU02"" t1
|
||||
USING (SELECT 2 as ""ID"", '02' as ""NAME"" FROM dual ) t2 ON (t1.""ID"" = t2.""ID"")
|
||||
WHEN MATCHED THEN
|
||||
update set ""NAME"" = t2.""NAME""
|
||||
WHEN NOT MATCHED THEN
|
||||
insert (""ID"", ""NAME"")
|
||||
values (t2.""ID"", t2.""NAME"")", sql);
|
||||
iou.ExecuteAffrows();
|
||||
|
||||
iou = fsql.InsertOrUpdate<tbiou02>().SetSource(new[] { new tbiou02 { id = 1, name = "01" }, new tbiou02 { id = 2, name = "02" }, new tbiou02 { id = 3, name = "03" }, new tbiou02 { id = 4, name = "04" } });
|
||||
sql = iou.ToSql();
|
||||
Assert.Equal(@"MERGE INTO ""TBIOU02"" t1
|
||||
USING (SELECT 1 as ""ID"", '01' as ""NAME"" FROM dual
|
||||
UNION ALL
|
||||
SELECT 2, '02' FROM dual
|
||||
UNION ALL
|
||||
SELECT 3, '03' FROM dual
|
||||
UNION ALL
|
||||
SELECT 4, '04' FROM dual ) t2 ON (t1.""ID"" = t2.""ID"")
|
||||
WHEN MATCHED THEN
|
||||
update set ""NAME"" = t2.""NAME""
|
||||
WHEN NOT MATCHED THEN
|
||||
insert (""ID"", ""NAME"")
|
||||
values (t2.""ID"", t2.""NAME"")", sql);
|
||||
iou.ExecuteAffrows();
|
||||
|
||||
iou = fsql.InsertOrUpdate<tbiou02>().SetSource(new[] { new tbiou02 { id = 1, name = "001" }, new tbiou02 { id = 2, name = "002" }, new tbiou02 { id = 3, name = "003" }, new tbiou02 { id = 4, name = "004" } });
|
||||
sql = iou.ToSql();
|
||||
Assert.Equal(@"MERGE INTO ""TBIOU02"" t1
|
||||
USING (SELECT 1 as ""ID"", '001' as ""NAME"" FROM dual
|
||||
UNION ALL
|
||||
SELECT 2, '002' FROM dual
|
||||
UNION ALL
|
||||
SELECT 3, '003' FROM dual
|
||||
UNION ALL
|
||||
SELECT 4, '004' FROM dual ) t2 ON (t1.""ID"" = t2.""ID"")
|
||||
WHEN MATCHED THEN
|
||||
update set ""NAME"" = t2.""NAME""
|
||||
WHEN NOT MATCHED THEN
|
||||
insert (""ID"", ""NAME"")
|
||||
values (t2.""ID"", t2.""NAME"")", sql);
|
||||
iou.ExecuteAffrows();
|
||||
var lst = fsql.Select<tbiou02>().Where(a => new[] { 1, 2, 3, 4 }.Contains(a.id)).ToList();
|
||||
Assert.Equal(4, lst.Where(a => a.name == "00" + a.id).Count());
|
||||
}
|
||||
class tbiou02
|
||||
{
|
||||
public int id { get; set; }
|
||||
public string name { get; set; }
|
||||
}
|
||||
[Fact]
|
||||
public void InsertOrUpdate_OnePrimaryAndIdentity()
|
||||
{
|
||||
fsql.Delete<tbiou022>().Where("1=1").ExecuteAffrows();
|
||||
var iou = fsql.InsertOrUpdate<tbiou022>().SetSource(new tbiou022 { id = 1, name = "01" });
|
||||
var sql = iou.ToSql();
|
||||
Assert.Equal(@"MERGE INTO ""TBIOU022"" t1
|
||||
USING (SELECT 1 as ""ID"", '01' as ""NAME"" FROM dual ) t2 ON (t1.""ID"" = t2.""ID"")
|
||||
WHEN MATCHED THEN
|
||||
update set ""NAME"" = t2.""NAME""
|
||||
WHEN NOT MATCHED THEN
|
||||
insert (""ID"", ""NAME"")
|
||||
values (t2.""ID"", t2.""NAME"")", sql);
|
||||
iou.ExecuteAffrows();
|
||||
|
||||
iou = fsql.InsertOrUpdate<tbiou022>().SetSource(new tbiou022 { id = 1, name = "011" });
|
||||
sql = iou.ToSql();
|
||||
Assert.Equal(@"MERGE INTO ""TBIOU022"" t1
|
||||
USING (SELECT 1 as ""ID"", '011' as ""NAME"" FROM dual ) t2 ON (t1.""ID"" = t2.""ID"")
|
||||
WHEN MATCHED THEN
|
||||
update set ""NAME"" = t2.""NAME""
|
||||
WHEN NOT MATCHED THEN
|
||||
insert (""ID"", ""NAME"")
|
||||
values (t2.""ID"", t2.""NAME"")", sql);
|
||||
iou.ExecuteAffrows();
|
||||
|
||||
iou = fsql.InsertOrUpdate<tbiou022>().SetSource(new tbiou022 { id = 2, name = "02" });
|
||||
sql = iou.ToSql();
|
||||
Assert.Equal(@"MERGE INTO ""TBIOU022"" t1
|
||||
USING (SELECT 2 as ""ID"", '02' as ""NAME"" FROM dual ) t2 ON (t1.""ID"" = t2.""ID"")
|
||||
WHEN MATCHED THEN
|
||||
update set ""NAME"" = t2.""NAME""
|
||||
WHEN NOT MATCHED THEN
|
||||
insert (""ID"", ""NAME"")
|
||||
values (t2.""ID"", t2.""NAME"")", sql);
|
||||
iou.ExecuteAffrows();
|
||||
|
||||
iou = fsql.InsertOrUpdate<tbiou022>().SetSource(new[] { new tbiou022 { id = 1, name = "01" }, new tbiou022 { id = 2, name = "02" }, new tbiou022 { id = 3, name = "03" }, new tbiou022 { id = 4, name = "04" } });
|
||||
sql = iou.ToSql();
|
||||
Assert.Equal(@"MERGE INTO ""TBIOU022"" t1
|
||||
USING (SELECT 1 as ""ID"", '01' as ""NAME"" FROM dual
|
||||
UNION ALL
|
||||
SELECT 2, '02' FROM dual
|
||||
UNION ALL
|
||||
SELECT 3, '03' FROM dual
|
||||
UNION ALL
|
||||
SELECT 4, '04' FROM dual ) t2 ON (t1.""ID"" = t2.""ID"")
|
||||
WHEN MATCHED THEN
|
||||
update set ""NAME"" = t2.""NAME""
|
||||
WHEN NOT MATCHED THEN
|
||||
insert (""ID"", ""NAME"")
|
||||
values (t2.""ID"", t2.""NAME"")", sql);
|
||||
iou.ExecuteAffrows();
|
||||
|
||||
iou = fsql.InsertOrUpdate<tbiou022>().SetSource(new[] { new tbiou022 { id = 1, name = "001" }, new tbiou022 { id = 2, name = "002" }, new tbiou022 { id = 3, name = "003" }, new tbiou022 { id = 4, name = "004" } });
|
||||
sql = iou.ToSql();
|
||||
Assert.Equal(@"MERGE INTO ""TBIOU022"" t1
|
||||
USING (SELECT 1 as ""ID"", '001' as ""NAME"" FROM dual
|
||||
UNION ALL
|
||||
SELECT 2, '002' FROM dual
|
||||
UNION ALL
|
||||
SELECT 3, '003' FROM dual
|
||||
UNION ALL
|
||||
SELECT 4, '004' FROM dual ) t2 ON (t1.""ID"" = t2.""ID"")
|
||||
WHEN MATCHED THEN
|
||||
update set ""NAME"" = t2.""NAME""
|
||||
WHEN NOT MATCHED THEN
|
||||
insert (""ID"", ""NAME"")
|
||||
values (t2.""ID"", t2.""NAME"")", sql);
|
||||
iou.ExecuteAffrows();
|
||||
var lst = fsql.Select<tbiou022>().Where(a => new[] { 1, 2, 3, 4 }.Contains(a.id)).ToList();
|
||||
//Assert.Equal(4, lst.Where(a => a.name == "00" + a.id).Count());
|
||||
|
||||
//--no primary
|
||||
iou = fsql.InsertOrUpdate<tbiou022>().SetSource(new tbiou022 { name = "01" });
|
||||
sql = iou.ToSql();
|
||||
Assert.Equal(@"INSERT INTO ""TBIOU022""(""NAME"") VALUES('01')", sql);
|
||||
iou.ExecuteAffrows();
|
||||
|
||||
iou = fsql.InsertOrUpdate<tbiou022>().SetSource(new tbiou022 { name = "011" });
|
||||
sql = iou.ToSql();
|
||||
Assert.Equal(@"INSERT INTO ""TBIOU022""(""NAME"") VALUES('011')", sql);
|
||||
iou.ExecuteAffrows();
|
||||
|
||||
iou = fsql.InsertOrUpdate<tbiou022>().SetSource(new tbiou022 { name = "02" });
|
||||
sql = iou.ToSql();
|
||||
Assert.Equal(@"INSERT INTO ""TBIOU022""(""NAME"") VALUES('02')", sql);
|
||||
iou.ExecuteAffrows();
|
||||
|
||||
iou = fsql.InsertOrUpdate<tbiou022>().SetSource(new[] { new tbiou022 { name = "01" }, new tbiou022 { name = "02" }, new tbiou022 { name = "03" }, new tbiou022 { name = "04" } });
|
||||
sql = iou.ToSql();
|
||||
Assert.Equal(@"INSERT ALL
|
||||
INTO ""TBIOU022""(""NAME"") VALUES('01')
|
||||
INTO ""TBIOU022""(""NAME"") VALUES('02')
|
||||
INTO ""TBIOU022""(""NAME"") VALUES('03')
|
||||
INTO ""TBIOU022""(""NAME"") VALUES('04')
|
||||
SELECT 1 FROM DUAL", sql);
|
||||
iou.ExecuteAffrows();
|
||||
|
||||
iou = fsql.InsertOrUpdate<tbiou022>().SetSource(new[] { new tbiou022 { name = "001" }, new tbiou022 { name = "002" }, new tbiou022 { name = "003" }, new tbiou022 { name = "004" } });
|
||||
sql = iou.ToSql();
|
||||
Assert.Equal(@"INSERT ALL
|
||||
INTO ""TBIOU022""(""NAME"") VALUES('001')
|
||||
INTO ""TBIOU022""(""NAME"") VALUES('002')
|
||||
INTO ""TBIOU022""(""NAME"") VALUES('003')
|
||||
INTO ""TBIOU022""(""NAME"") VALUES('004')
|
||||
SELECT 1 FROM DUAL", sql);
|
||||
iou.ExecuteAffrows();
|
||||
|
||||
//--no primary and yes
|
||||
iou = fsql.InsertOrUpdate<tbiou022>().SetSource(new[] { new tbiou022 { id = 1, name = "100001" }, new tbiou022 { name = "00001" }, new tbiou022 { id = 2, name = "100002" }, new tbiou022 { name = "00002" }, new tbiou022 { id = 3, name = "100003" }, new tbiou022 { name = "00003" }, new tbiou022 { id = 4, name = "100004" }, new tbiou022 { name = "00004" } });
|
||||
sql = iou.ToSql();
|
||||
Assert.Equal(@"MERGE INTO ""TBIOU022"" t1
|
||||
USING (SELECT 1 as ""ID"", '100001' as ""NAME"" FROM dual
|
||||
UNION ALL
|
||||
SELECT 2, '100002' FROM dual
|
||||
UNION ALL
|
||||
SELECT 3, '100003' FROM dual
|
||||
UNION ALL
|
||||
SELECT 4, '100004' FROM dual ) t2 ON (t1.""ID"" = t2.""ID"")
|
||||
WHEN MATCHED THEN
|
||||
update set ""NAME"" = t2.""NAME""
|
||||
WHEN NOT MATCHED THEN
|
||||
insert (""ID"", ""NAME"")
|
||||
values (t2.""ID"", t2.""NAME"")
|
||||
|
||||
;
|
||||
|
||||
INSERT ALL
|
||||
INTO ""TBIOU022""(""NAME"") VALUES('00001')
|
||||
INTO ""TBIOU022""(""NAME"") VALUES('00002')
|
||||
INTO ""TBIOU022""(""NAME"") VALUES('00003')
|
||||
INTO ""TBIOU022""(""NAME"") VALUES('00004')
|
||||
SELECT 1 FROM DUAL", sql);
|
||||
iou.ExecuteAffrows();
|
||||
lst = fsql.Select<tbiou022>().Where(a => new[] { 1, 2, 3, 4 }.Contains(a.id)).ToList();
|
||||
//Assert.Equal(4, lst.Where(a => a.name == "10000" + a.id).Count());
|
||||
}
|
||||
class tbiou022
|
||||
{
|
||||
[Column(IsIdentity = true)]
|
||||
public int id { get; set; }
|
||||
public string name { get; set; }
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void InsertOrUpdate_TwoPrimary()
|
||||
{
|
||||
fsql.Delete<tbiou03>().Where("1=1").ExecuteAffrows();
|
||||
var iou = fsql.InsertOrUpdate<tbiou03>().SetSource(new tbiou03 { id1 = 1, id2 = "01", name = "01" });
|
||||
var sql = iou.ToSql();
|
||||
Assert.Equal(@"MERGE INTO ""TBIOU03"" t1
|
||||
USING (SELECT 1 as ""ID1"", '01' as ""ID2"", '01' as ""NAME"" FROM dual ) t2 ON (t1.""ID1"" = t2.""ID1"" AND t1.""ID2"" = t2.""ID2"")
|
||||
WHEN MATCHED THEN
|
||||
update set ""NAME"" = t2.""NAME""
|
||||
WHEN NOT MATCHED THEN
|
||||
insert (""ID1"", ""ID2"", ""NAME"")
|
||||
values (t2.""ID1"", t2.""ID2"", t2.""NAME"")", sql);
|
||||
iou.ExecuteAffrows();
|
||||
|
||||
iou = fsql.InsertOrUpdate<tbiou03>().SetSource(new tbiou03 { id1 = 1, id2 = "01", name = "011" });
|
||||
sql = iou.ToSql();
|
||||
Assert.Equal(@"MERGE INTO ""TBIOU03"" t1
|
||||
USING (SELECT 1 as ""ID1"", '01' as ""ID2"", '011' as ""NAME"" FROM dual ) t2 ON (t1.""ID1"" = t2.""ID1"" AND t1.""ID2"" = t2.""ID2"")
|
||||
WHEN MATCHED THEN
|
||||
update set ""NAME"" = t2.""NAME""
|
||||
WHEN NOT MATCHED THEN
|
||||
insert (""ID1"", ""ID2"", ""NAME"")
|
||||
values (t2.""ID1"", t2.""ID2"", t2.""NAME"")", sql);
|
||||
iou.ExecuteAffrows();
|
||||
|
||||
iou = fsql.InsertOrUpdate<tbiou03>().SetSource(new tbiou03 { id1 = 2, id2 = "02", name = "02" });
|
||||
sql = iou.ToSql();
|
||||
Assert.Equal(@"MERGE INTO ""TBIOU03"" t1
|
||||
USING (SELECT 2 as ""ID1"", '02' as ""ID2"", '02' as ""NAME"" FROM dual ) t2 ON (t1.""ID1"" = t2.""ID1"" AND t1.""ID2"" = t2.""ID2"")
|
||||
WHEN MATCHED THEN
|
||||
update set ""NAME"" = t2.""NAME""
|
||||
WHEN NOT MATCHED THEN
|
||||
insert (""ID1"", ""ID2"", ""NAME"")
|
||||
values (t2.""ID1"", t2.""ID2"", t2.""NAME"")", sql);
|
||||
iou.ExecuteAffrows();
|
||||
|
||||
iou = fsql.InsertOrUpdate<tbiou03>().SetSource(new[] { new tbiou03 { id1 = 1, id2 = "01", name = "01" }, new tbiou03 { id1 = 2, id2 = "02", name = "02" }, new tbiou03 { id1 = 3, id2 = "03", name = "03" }, new tbiou03 { id1 = 4, id2 = "04", name = "04" } });
|
||||
sql = iou.ToSql();
|
||||
Assert.Equal(@"MERGE INTO ""TBIOU03"" t1
|
||||
USING (SELECT 1 as ""ID1"", '01' as ""ID2"", '01' as ""NAME"" FROM dual
|
||||
UNION ALL
|
||||
SELECT 2, '02', '02' FROM dual
|
||||
UNION ALL
|
||||
SELECT 3, '03', '03' FROM dual
|
||||
UNION ALL
|
||||
SELECT 4, '04', '04' FROM dual ) t2 ON (t1.""ID1"" = t2.""ID1"" AND t1.""ID2"" = t2.""ID2"")
|
||||
WHEN MATCHED THEN
|
||||
update set ""NAME"" = t2.""NAME""
|
||||
WHEN NOT MATCHED THEN
|
||||
insert (""ID1"", ""ID2"", ""NAME"")
|
||||
values (t2.""ID1"", t2.""ID2"", t2.""NAME"")", sql);
|
||||
iou.ExecuteAffrows();
|
||||
|
||||
iou = fsql.InsertOrUpdate<tbiou03>().SetSource(new[] { new tbiou03 { id1 = 1, id2 = "01", name = "001" }, new tbiou03 { id1 = 2, id2 = "02", name = "002" }, new tbiou03 { id1 = 3, id2 = "03", name = "003" }, new tbiou03 { id1 = 4, id2 = "04", name = "004" } });
|
||||
sql = iou.ToSql();
|
||||
Assert.Equal(@"MERGE INTO ""TBIOU03"" t1
|
||||
USING (SELECT 1 as ""ID1"", '01' as ""ID2"", '001' as ""NAME"" FROM dual
|
||||
UNION ALL
|
||||
SELECT 2, '02', '002' FROM dual
|
||||
UNION ALL
|
||||
SELECT 3, '03', '003' FROM dual
|
||||
UNION ALL
|
||||
SELECT 4, '04', '004' FROM dual ) t2 ON (t1.""ID1"" = t2.""ID1"" AND t1.""ID2"" = t2.""ID2"")
|
||||
WHEN MATCHED THEN
|
||||
update set ""NAME"" = t2.""NAME""
|
||||
WHEN NOT MATCHED THEN
|
||||
insert (""ID1"", ""ID2"", ""NAME"")
|
||||
values (t2.""ID1"", t2.""ID2"", t2.""NAME"")", sql);
|
||||
iou.ExecuteAffrows();
|
||||
var lst = fsql.Select<tbiou03>().Where(a => a.id1 == 1 && a.id2 == "01" || a.id1 == 2 && a.id2 == "02" || a.id1 == 3 && a.id2 == "03" || a.id1 == 4 && a.id2 == "04").ToList();
|
||||
Assert.Equal(4, lst.Where(a => a.name == "00" + a.id1).Count());
|
||||
}
|
||||
class tbiou03
|
||||
{
|
||||
[Column(IsPrimary = true)]
|
||||
public int id1 { get; set; }
|
||||
[Column(IsPrimary = true)]
|
||||
public string id2 { get; set; }
|
||||
public string name { get; set; }
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void InsertOrUpdate_OnePrimaryAndVersionAndCanUpdate()
|
||||
{
|
||||
fsql.Delete<tbiou04>().Where("1=1").ExecuteAffrows();
|
||||
var iou = fsql.InsertOrUpdate<tbiou04>().SetSource(new tbiou04 { id = 1, name = "01" });
|
||||
var sql = iou.ToSql();
|
||||
Assert.Equal(@"MERGE INTO ""TBIOU04"" t1
|
||||
USING (SELECT 1 as ""ID"", '01' as ""NAME"", 0 as ""VERSION"", systimestamp as ""CREATETIME"" FROM dual ) t2 ON (t1.""ID"" = t2.""ID"")
|
||||
WHEN MATCHED THEN
|
||||
update set ""NAME"" = t2.""NAME"", ""VERSION"" = t1.""VERSION"" + 1
|
||||
WHEN NOT MATCHED THEN
|
||||
insert (""ID"", ""NAME"", ""VERSION"", ""CREATETIME"")
|
||||
values (t2.""ID"", t2.""NAME"", t2.""VERSION"", t2.""CREATETIME"")", sql);
|
||||
iou.ExecuteAffrows();
|
||||
|
||||
iou = fsql.InsertOrUpdate<tbiou04>().SetSource(new tbiou04 { id = 1, name = "011" });
|
||||
sql = iou.ToSql();
|
||||
Assert.Equal(@"MERGE INTO ""TBIOU04"" t1
|
||||
USING (SELECT 1 as ""ID"", '011' as ""NAME"", 0 as ""VERSION"", systimestamp as ""CREATETIME"" FROM dual ) t2 ON (t1.""ID"" = t2.""ID"")
|
||||
WHEN MATCHED THEN
|
||||
update set ""NAME"" = t2.""NAME"", ""VERSION"" = t1.""VERSION"" + 1
|
||||
WHEN NOT MATCHED THEN
|
||||
insert (""ID"", ""NAME"", ""VERSION"", ""CREATETIME"")
|
||||
values (t2.""ID"", t2.""NAME"", t2.""VERSION"", t2.""CREATETIME"")", sql);
|
||||
iou.ExecuteAffrows();
|
||||
|
||||
iou = fsql.InsertOrUpdate<tbiou04>().SetSource(new tbiou04 { id = 2, name = "02" });
|
||||
sql = iou.ToSql();
|
||||
Assert.Equal(@"MERGE INTO ""TBIOU04"" t1
|
||||
USING (SELECT 2 as ""ID"", '02' as ""NAME"", 0 as ""VERSION"", systimestamp as ""CREATETIME"" FROM dual ) t2 ON (t1.""ID"" = t2.""ID"")
|
||||
WHEN MATCHED THEN
|
||||
update set ""NAME"" = t2.""NAME"", ""VERSION"" = t1.""VERSION"" + 1
|
||||
WHEN NOT MATCHED THEN
|
||||
insert (""ID"", ""NAME"", ""VERSION"", ""CREATETIME"")
|
||||
values (t2.""ID"", t2.""NAME"", t2.""VERSION"", t2.""CREATETIME"")", sql);
|
||||
iou.ExecuteAffrows();
|
||||
|
||||
iou = fsql.InsertOrUpdate<tbiou04>().SetSource(new[] { new tbiou04 { id = 1, name = "01" }, new tbiou04 { id = 2, name = "02" }, new tbiou04 { id = 3, name = "03" }, new tbiou04 { id = 4, name = "04" } });
|
||||
sql = iou.ToSql();
|
||||
Assert.Equal(@"MERGE INTO ""TBIOU04"" t1
|
||||
USING (SELECT 1 as ""ID"", '01' as ""NAME"", 0 as ""VERSION"", systimestamp as ""CREATETIME"" FROM dual
|
||||
UNION ALL
|
||||
SELECT 2, '02', 0, systimestamp FROM dual
|
||||
UNION ALL
|
||||
SELECT 3, '03', 0, systimestamp FROM dual
|
||||
UNION ALL
|
||||
SELECT 4, '04', 0, systimestamp FROM dual ) t2 ON (t1.""ID"" = t2.""ID"")
|
||||
WHEN MATCHED THEN
|
||||
update set ""NAME"" = t2.""NAME"", ""VERSION"" = t1.""VERSION"" + 1
|
||||
WHEN NOT MATCHED THEN
|
||||
insert (""ID"", ""NAME"", ""VERSION"", ""CREATETIME"")
|
||||
values (t2.""ID"", t2.""NAME"", t2.""VERSION"", t2.""CREATETIME"")", sql);
|
||||
iou.ExecuteAffrows();
|
||||
|
||||
iou = fsql.InsertOrUpdate<tbiou04>().SetSource(new[] { new tbiou04 { id = 1, name = "001" }, new tbiou04 { id = 2, name = "002" }, new tbiou04 { id = 3, name = "003" }, new tbiou04 { id = 4, name = "004" } });
|
||||
sql = iou.ToSql();
|
||||
Assert.Equal(@"MERGE INTO ""TBIOU04"" t1
|
||||
USING (SELECT 1 as ""ID"", '001' as ""NAME"", 0 as ""VERSION"", systimestamp as ""CREATETIME"" FROM dual
|
||||
UNION ALL
|
||||
SELECT 2, '002', 0, systimestamp FROM dual
|
||||
UNION ALL
|
||||
SELECT 3, '003', 0, systimestamp FROM dual
|
||||
UNION ALL
|
||||
SELECT 4, '004', 0, systimestamp FROM dual ) t2 ON (t1.""ID"" = t2.""ID"")
|
||||
WHEN MATCHED THEN
|
||||
update set ""NAME"" = t2.""NAME"", ""VERSION"" = t1.""VERSION"" + 1
|
||||
WHEN NOT MATCHED THEN
|
||||
insert (""ID"", ""NAME"", ""VERSION"", ""CREATETIME"")
|
||||
values (t2.""ID"", t2.""NAME"", t2.""VERSION"", t2.""CREATETIME"")", sql);
|
||||
iou.ExecuteAffrows();
|
||||
var lst = fsql.Select<tbiou04>().Where(a => new[] { 1, 2, 3, 4 }.Contains(a.id)).ToList();
|
||||
Assert.Equal(4, lst.Where(a => a.name == "00" + a.id).Count());
|
||||
}
|
||||
class tbiou04
|
||||
{
|
||||
public int id { get; set; }
|
||||
public string name { get; set; }
|
||||
[Column(IsVersion = true)]
|
||||
public int version { get; set; }
|
||||
[Column(CanUpdate = false, ServerTime = DateTimeKind.Local)]
|
||||
public DateTime CreateTime { get; set; }
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,278 @@
|
||||
using FreeSql.DataAnnotations;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Xunit;
|
||||
|
||||
namespace FreeSql.Tests.Custom.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,191 @@
|
||||
using FreeSql.DataAnnotations;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Xunit;
|
||||
|
||||
namespace FreeSql.Tests.Custom.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\" IN (1,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\" IN (1,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);
|
||||
|
||||
sql = g.oracle.Update<ts_source_mpk>().SetSource(new[] {
|
||||
new ts_source_mpk { id1 = 1, id2 = 7, xx = "a1" },
|
||||
new ts_source_mpk { id1 = 1, id2 = 8, xx = "b122" }
|
||||
}).NoneParameter().ToSql().Replace("\r\n", "");
|
||||
|
||||
var uuids = new[]
|
||||
{
|
||||
new tssi01{tint = 1, title = "title01"},
|
||||
new tssi01{tint = 2, title = "title02"},
|
||||
new tssi01{tint = 3, title = "title03"},
|
||||
};
|
||||
g.oracle.Insert(uuids).ExecuteAffrows();
|
||||
g.oracle.Update<tssi01>().SetSource(uuids).ExecuteAffrows();
|
||||
|
||||
var tssi01tb = g.oracle.DbFirst.GetTableByName("tssi01");
|
||||
}
|
||||
public class ts_source_mpk
|
||||
{
|
||||
[Column(IsPrimary = true)]
|
||||
public int id1 { get; set; }
|
||||
[Column(IsPrimary = true)]
|
||||
public int id2 { get; set; }
|
||||
public string xx { get; set; }
|
||||
}
|
||||
[Fact]
|
||||
public void SetSourceIgnore()
|
||||
{
|
||||
Assert.Equal("UPDATE \"TSSI01\" SET \"TINT\" = 10 WHERE (\"ID\" = '00000000-0000-0000-0000-000000000000')",
|
||||
g.oracle.Update<tssi01>().NoneParameter()
|
||||
.SetSourceIgnore(new tssi01 { id = Guid.Empty, tint = 10 }, col => col == null).ToSql().Replace("\r\n", ""));
|
||||
}
|
||||
public class tssi01
|
||||
{
|
||||
[Column(CanUpdate = false, DbType = "nvarchar2(36)")]
|
||||
public Guid id { get; set; }
|
||||
public int tint { get; set; }
|
||||
public string title { get; set; }
|
||||
}
|
||||
[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);
|
||||
|
||||
var dt2000 = DateTime.Parse("2000-01-01");
|
||||
sql = update.Set(a => a.Clicks == (a.CreateTime > dt2000 ? 1 : 2)).Where(a => a.Id == 1).ToSql().Replace("\r\n", "");
|
||||
Assert.Equal("UPDATE \"TB_TOPIC\" SET \"CLICKS\" = case when \"CREATETIME\" > to_timestamp('2000-01-01 00:00:00.000000','YYYY-MM-DD HH24:MI:SS.FF6') then 1 else 2 end 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);
|
||||
|
||||
sql = update.Set(a => a.Clicks == null).Where(a => a.Id == 1).ToSql().Replace("\r\n", "");
|
||||
Assert.Equal("UPDATE \"TB_TOPIC\" SET \"CLICKS\" = NULL 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 SetDto()
|
||||
{
|
||||
var sql = update.SetDto(new { clicks = 1, title = "xxx" }).Where(a => a.Id == 1).ToSql().Replace("\r\n", "");
|
||||
Assert.Equal("UPDATE \"TB_TOPIC\" SET \"CLICKS\" = 1, \"TITLE\" = 'xxx' WHERE (\"ID\" = 1)", sql);
|
||||
|
||||
sql = update.SetDto(new Dictionary<string, object> { ["clicks"] = 1, ["title"] = "xxx" }).Where(a => a.Id == 1).ToSql().Replace("\r\n", "");
|
||||
Assert.Equal("UPDATE \"TB_TOPIC\" SET \"CLICKS\" = 1, \"TITLE\" = 'xxx' 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 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\" IN (1,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\" IN (1,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
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.Custom.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.Custom.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.Custom.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,71 @@
|
||||
using FreeSql.DataAnnotations;
|
||||
using System;
|
||||
using Xunit;
|
||||
|
||||
namespace FreeSql.Tests.Custom.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 ExecuteTest()
|
||||
{
|
||||
Assert.True(g.oracle.Ado.ExecuteConnectTest());
|
||||
}
|
||||
[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.Custom.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,336 @@
|
||||
using FreeSql.DataAnnotations;
|
||||
using Newtonsoft.Json;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using Xunit;
|
||||
|
||||
namespace FreeSql.Tests.Custom.Oracle
|
||||
{
|
||||
public class OracleCodeFirstTest
|
||||
{
|
||||
[Fact]
|
||||
public void Test_0String()
|
||||
{
|
||||
var fsql = g.oracle;
|
||||
fsql.Delete<test_0string01>().Where("1=1").ExecuteAffrows();
|
||||
|
||||
Assert.Equal(1, fsql.Insert(new test_0string01 { name = @"1.0000\0.0000\0.0000\0.0000\1.0000\0.0000" }).ExecuteAffrows());
|
||||
Assert.Equal(1, fsql.Insert(new test_0string01 { name = @"1.0000\0.0000\0.0000\0.0000\1.0000\0.0000" }).NoneParameter().ExecuteAffrows());
|
||||
|
||||
var list = fsql.Select<test_0string01>().ToList();
|
||||
Assert.Equal(2, list.Count);
|
||||
Assert.Equal(@"1.0000\0.0000\0.0000\0.0000\1.0000\0.0000", list[0].name);
|
||||
Assert.Equal(@"1.0000\0.0000\0.0000\0.0000\1.0000\0.0000", list[1].name);
|
||||
}
|
||||
class test_0string01
|
||||
{
|
||||
public Guid id { get; set; }
|
||||
public string name { get; set; }
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void StringLength()
|
||||
{
|
||||
var dll = g.oracle.CodeFirst.GetComparisonDDLStatements<TS_SLTB>();
|
||||
g.oracle.CodeFirst.SyncStructure<TS_SLTB>();
|
||||
}
|
||||
class TS_SLTB
|
||||
{
|
||||
public Guid Id { get; set; }
|
||||
[Column(StringLength = 50)]
|
||||
public string Title { get; set; }
|
||||
|
||||
[Column(IsNullable = false, StringLength = 50)]
|
||||
public string TitleSub { get; set; }
|
||||
}
|
||||
|
||||
[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.标题);
|
||||
|
||||
item.标题 = "测试标题更新";
|
||||
Assert.Equal(1, g.oracle.Update<测试数字表>().SetSource(item).ExecuteAffrows());
|
||||
item2 = g.oracle.Select<测试数字表>().Where(a => a.编号 == item.编号).First();
|
||||
Assert.NotNull(item2);
|
||||
Assert.Equal(item.编号, item2.编号);
|
||||
Assert.Equal(item.标题, item2.标题);
|
||||
|
||||
item.标题 = "测试标题更新_repo";
|
||||
var repo = g.oracle.GetRepository<测试数字表>();
|
||||
Assert.Equal(1, repo.Update(item));
|
||||
item2 = g.oracle.Select<测试数字表>().Where(a => a.编号 == item.编号).First();
|
||||
Assert.NotNull(item2);
|
||||
Assert.Equal(item.编号, item2.编号);
|
||||
Assert.Equal(item.标题, item2.标题);
|
||||
|
||||
item.标题 = "测试标题更新_repo22";
|
||||
Assert.Equal(1, repo.Update(item));
|
||||
item2 = g.oracle.Select<测试数字表>().Where(a => a.编号 == item.编号).First();
|
||||
Assert.NotNull(item2);
|
||||
Assert.Equal(item.编号, item2.编号);
|
||||
Assert.Equal(item.标题, item2.标题);
|
||||
}
|
||||
[Table(Name = "123tb")]
|
||||
class 测试数字表
|
||||
{
|
||||
[Column(IsPrimary = true, Name = "123id")]
|
||||
public Guid 编号 { get; set; }
|
||||
|
||||
[Column(Name = "123title")]
|
||||
public string 标题 { get; set; }
|
||||
|
||||
[Column(Name = "123time")]
|
||||
public DateTime 创建时间 { get; set; }
|
||||
}
|
||||
|
||||
[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.标题);
|
||||
|
||||
item.标题 = "测试标题更新";
|
||||
Assert.Equal(1, g.oracle.Update<测试中文表>().SetSource(item).ExecuteAffrows());
|
||||
item2 = g.oracle.Select<测试中文表>().Where(a => a.编号 == item.编号).First();
|
||||
Assert.NotNull(item2);
|
||||
Assert.Equal(item.编号, item2.编号);
|
||||
Assert.Equal(item.标题, item2.标题);
|
||||
|
||||
item.标题 = "测试标题更新_repo";
|
||||
var repo = g.oracle.GetRepository<测试中文表>();
|
||||
Assert.Equal(1, repo.Update(item));
|
||||
item2 = g.oracle.Select<测试中文表>().Where(a => a.编号 == item.编号).First();
|
||||
Assert.NotNull(item2);
|
||||
Assert.Equal(item.编号, item2.编号);
|
||||
Assert.Equal(item.标题, item2.标题);
|
||||
|
||||
item.标题 = "测试标题更新_repo22";
|
||||
Assert.Equal(1, repo.Update(item));
|
||||
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")]
|
||||
[Index("uk_phone", "phone", true)]
|
||||
[Index("uk_group_index", "group,index", true)]
|
||||
[Index("uk_group_index22", "group, index22", true)]
|
||||
class AddUniquesInfo
|
||||
{
|
||||
public Guid id { get; set; }
|
||||
public string phone { get; set; }
|
||||
|
||||
public string group { get; set; }
|
||||
public int index { get; set; }
|
||||
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>();
|
||||
Assert.True(string.IsNullOrEmpty(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 { };
|
||||
for (var a = 0; a < 100; a++)
|
||||
{
|
||||
try //ERROR [23000] [Oracle][ODBC][Ora]ORA-00001: 违反唯一约束条件 (1ODBC.1ODBC_TB_ALLTYPE_pk2)
|
||||
{
|
||||
item.Id = (int)insert.AppendData(item).ExecuteIdentity();
|
||||
break;
|
||||
}
|
||||
catch
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
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'\\?!@#$%^&*()_+{}}{~?><<>",
|
||||
Char = 'X',
|
||||
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();
|
||||
Assert.Equal(item2.String, newitem2.String);
|
||||
Assert.Equal(item2.Char, newitem2.Char);
|
||||
|
||||
item2.Id = (int)insert.NoneParameter().AppendData(item2).ExecuteIdentity();
|
||||
newitem2 = select.Where(a => a.Id == item2.Id).ToOne();
|
||||
Assert.Equal(item2.String, newitem2.String);
|
||||
Assert.Equal(item2.Char, newitem2.Char);
|
||||
|
||||
var items = select.ToList();
|
||||
var itemstb = select.ToDataTable();
|
||||
}
|
||||
|
||||
[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 char Char { 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,65 @@
|
||||
using FreeSql.DataAnnotations;
|
||||
using System;
|
||||
using Xunit;
|
||||
|
||||
namespace FreeSql.Tests.Custom.Oracle
|
||||
{
|
||||
public class OracleDbFirstTest
|
||||
{
|
||||
[Fact]
|
||||
public void GetDatabases()
|
||||
{
|
||||
var t1 = g.oracle.DbFirst.GetDatabases();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void GetTablesByDatabase()
|
||||
{
|
||||
var t2 = g.oracle.DbFirst.GetTablesByDatabase();
|
||||
Assert.True(t2.Count > 0);
|
||||
//var tb = g.oracle.Ado.ExecuteArray(System.Data.CommandType.Text, "select * from \"tb_dbfirst\"");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void GetTableByName()
|
||||
{
|
||||
var fsql = g.oracle;
|
||||
var t1 = fsql.DbFirst.GetTableByName("tb_alltype");
|
||||
var t2 = fsql.DbFirst.GetTableByName("1odbc.tb_alltype");
|
||||
Assert.NotNull(t1);
|
||||
Assert.NotNull(t2);
|
||||
Assert.True(t1.Columns.Count > 0);
|
||||
Assert.True(t2.Columns.Count > 0);
|
||||
Assert.Equal(t1.Columns.Count, t2.Columns.Count);
|
||||
var t3 = fsql.DbFirst.GetTableByName("notexists_tb");
|
||||
Assert.Null(t3);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ExistsTable()
|
||||
{
|
||||
var fsql = g.oracle;
|
||||
Assert.False(fsql.DbFirst.ExistsTable("test_existstb01"));
|
||||
Assert.False(fsql.DbFirst.ExistsTable("1odbc.test_existstb01"));
|
||||
Assert.False(fsql.DbFirst.ExistsTable("test_existstb01", false));
|
||||
Assert.False(fsql.DbFirst.ExistsTable("1odbc.test_existstb01", false));
|
||||
fsql.CodeFirst.SyncStructure(typeof(test_existstb01));
|
||||
Assert.True(fsql.DbFirst.ExistsTable("test_existstb01"));
|
||||
Assert.True(fsql.DbFirst.ExistsTable("1odbc.test_existstb01"));
|
||||
Assert.False(fsql.DbFirst.ExistsTable("test_existstb01", false));
|
||||
Assert.False(fsql.DbFirst.ExistsTable("11odbcuser.test_existstb01", false));
|
||||
fsql.Ado.ExecuteNonQuery("drop table test_existstb01");
|
||||
|
||||
Assert.False(fsql.DbFirst.ExistsTable("1odbc.test_existstb01"));
|
||||
Assert.False(fsql.DbFirst.ExistsTable("1odbc.test_existstb01", false));
|
||||
fsql.CodeFirst.SyncStructure(typeof(test_existstb01), "1odbc.test_existstb01");
|
||||
Assert.True(fsql.DbFirst.ExistsTable("1odbc.test_existstb01"));
|
||||
Assert.False(fsql.DbFirst.ExistsTable("1odbc.test_existstb01", false));
|
||||
fsql.Ado.ExecuteNonQuery("drop table \"1ODBC\".test_existstb01");
|
||||
}
|
||||
class test_existstb01
|
||||
{
|
||||
public Guid id { get; set; }
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,169 @@
|
||||
using FreeSql.DataAnnotations;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Xunit;
|
||||
|
||||
namespace FreeSql.Tests.Custom.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,732 @@
|
||||
using FreeSql.DataAnnotations;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Xunit;
|
||||
|
||||
namespace FreeSql.Tests.Custom.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; } = DateTime.Now;
|
||||
}
|
||||
[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 this_ToString()
|
||||
{
|
||||
var data = new List<object>();
|
||||
data.Add(select.Where(a => a.CreateTime.ToString().Equals(DateTime.Now.ToString())).ToList());
|
||||
data.Add(select.Where(a => a.Type.Time.AddYears(1).ToString().Equals(DateTime.Now.ToString())).ToList());
|
||||
data.Add(select.Where(a => a.Type.Parent.Time2.AddYears(1).ToString().Equals(DateTime.Now.ToString())).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()))
|
||||
|
||||
//g.oracle.Insert(new Topic()).ExecuteAffrows();
|
||||
//var dtn = DateTime.Parse("2020-1-1 0:0:0");
|
||||
//var dts = Enumerable.Range(1, 12).Select(a => dtn.AddMonths(a))
|
||||
// .Concat(Enumerable.Range(1, 31).Select(a => dtn.AddDays(a)))
|
||||
// .Concat(Enumerable.Range(1, 24).Select(a => dtn.AddHours(a)))
|
||||
// .Concat(Enumerable.Range(1, 60).Select(a => dtn.AddMinutes(a)))
|
||||
// .Concat(Enumerable.Range(1, 60).Select(a => dtn.AddSeconds(a)));
|
||||
//foreach (var dt in dts)
|
||||
//{
|
||||
// Assert.Equal(dt.ToString("yyyy-MM-dd HH:mm:ss.ffffff"), select.First(a => dt.ToString()));
|
||||
// Assert.Equal(dt.ToString("yyyy-MM-dd HH:mm:ss"), select.First(a => dt.ToString("yyyy-MM-dd HH:mm:ss")));
|
||||
// Assert.Equal(dt.ToString("yyyy-MM-dd HH:mm"), select.First(a => dt.ToString("yyyy-MM-dd HH:mm")));
|
||||
// Assert.Equal(dt.ToString("yyyy-MM-dd HH"), select.First(a => dt.ToString("yyyy-MM-dd HH")));
|
||||
// Assert.Equal(dt.ToString("yyyy-MM-dd"), select.First(a => dt.ToString("yyyy-MM-dd")));
|
||||
// Assert.Equal(dt.ToString("yyyy-MM"), select.First(a => dt.ToString("yyyy-MM")));
|
||||
// Assert.Equal(dt.ToString("yyyyMMddHHmmss"), select.First(a => dt.ToString("yyyyMMddHHmmss")));
|
||||
// Assert.Equal(dt.ToString("yyyyMMddHHmm"), select.First(a => dt.ToString("yyyyMMddHHmm")));
|
||||
// Assert.Equal(dt.ToString("yyyyMMddHH"), select.First(a => dt.ToString("yyyyMMddHH")));
|
||||
// Assert.Equal(dt.ToString("yyyyMMdd"), select.First(a => dt.ToString("yyyyMMdd")));
|
||||
// Assert.Equal(dt.ToString("yyyyMM"), select.First(a => dt.ToString("yyyyMM")));
|
||||
// Assert.Equal(dt.ToString("yyyy"), select.First(a => dt.ToString("yyyy")));
|
||||
// Assert.Equal(dt.ToString("HH:mm:ss"), select.First(a => dt.ToString("HH:mm:ss")));
|
||||
// Assert.Equal(dt.ToString("yyyy MM dd HH mm ss yy M d H hh h"), select.First(a => dt.ToString("yyyy MM dd HH mm ss yy M d H hh h")));
|
||||
// Assert.Equal(dt.ToString("yyyy MM dd HH mm ss yy M d H hh h m s"), select.First(a => dt.ToString("yyyy MM dd HH mm ss yy M d H hh h m s")));
|
||||
//}
|
||||
}
|
||||
[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 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.Custom.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,165 @@
|
||||
using FreeSql.DataAnnotations;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Xunit;
|
||||
|
||||
namespace FreeSql.Tests.Custom.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 t51 = select.WhereCascade(a => a.Bool).Limit(10).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();
|
||||
|
||||
var t111 = select.Where(a => a.Bool == true && a.Id > 0).ToList();
|
||||
var t222 = select.Where(a => a.Bool != true && a.Id > 0).ToList();
|
||||
var t333 = select.Where(a => a.Bool == false && a.Id > 0).ToList();
|
||||
var t444 = select.Where(a => !a.Bool && a.Id > 0).ToList();
|
||||
var t555 = select.Where(a => a.Bool && a.Id > 0).ToList();
|
||||
|
||||
var t1111 = select.Where(a => a.BoolNullable == true && a.Id > 0).ToList();
|
||||
var t2222 = select.Where(a => a.BoolNullable != true && a.Id > 0).ToList();
|
||||
var t3333 = select.Where(a => a.BoolNullable == false && a.Id > 0).ToList();
|
||||
var t4444 = select.Where(a => !a.BoolNullable.Value && a.Id > 0).ToList();
|
||||
var t5555 = select.Where(a => a.BoolNullable.Value && a.Id > 0).ToList();
|
||||
|
||||
var t11111 = select.Where(a => a.Bool == true && a.Id > 0 && a.Bool == true).ToList();
|
||||
var t22222 = select.Where(a => a.Bool != true && a.Id > 0 && a.Bool != true).ToList();
|
||||
var t33333 = select.Where(a => a.Bool == false && a.Id > 0 && a.Bool == false).ToList();
|
||||
var t44444 = select.Where(a => !a.Bool && a.Id > 0 && !a.Bool).ToList();
|
||||
var t55555 = select.Where(a => a.Bool && a.Id > 0 && a.Bool).ToList();
|
||||
|
||||
var t111111 = select.Where(a => a.BoolNullable == true && a.Id > 0 && a.BoolNullable == true).ToList();
|
||||
var t222222 = select.Where(a => a.BoolNullable != true && a.Id > 0 && a.BoolNullable != true).ToList();
|
||||
var t333333 = select.Where(a => a.BoolNullable == false && a.Id > 0 && a.BoolNullable == false).ToList();
|
||||
var t444444 = select.Where(a => !a.BoolNullable.Value && a.Id > 0 && !a.BoolNullable.Value).ToList();
|
||||
var t555555 = select.Where(a => a.BoolNullable.Value && a.Id > 0 && 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();
|
||||
|
||||
var inarray2n = Enumerable.Range(1, 3333).ToArray();
|
||||
var sql1111111 = select.Where(a => inarray2n.Contains(a.Int)).ToList();
|
||||
var sql1122222 = select.Where(a => inarray2n.Contains(a.Int) == false).ToList();
|
||||
var sql1133333 = select.Where(a => !inarray2n.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,827 @@
|
||||
using FreeSql.DataAnnotations;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Xunit;
|
||||
|
||||
namespace FreeSql.Tests.Custom.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 StringJoin()
|
||||
{
|
||||
var fsql = g.oracle;
|
||||
fsql.Delete<StringJoin01>().Where("1=1").ExecuteAffrows();
|
||||
fsql.Insert(new[] { new StringJoin01 { name = "北京" }, new StringJoin01 { name = "上海" }, new StringJoin01 { name = "深圳" }, }).ExecuteAffrows();
|
||||
|
||||
var val1 = string.Join(",", fsql.Select<StringJoin01>().ToList(a => a.name));
|
||||
var val2 = fsql.Select<StringJoin01>().ToList(a => string.Join(",", fsql.Select<StringJoin01>().As("b").ToList(b => b.name)));
|
||||
Assert.Equal(val1, val2[0]);
|
||||
|
||||
val1 = string.Join("**", fsql.Select<StringJoin01>().ToList(a => a.name));
|
||||
val2 = fsql.Select<StringJoin01>().ToList(a => string.Join("**", fsql.Select<StringJoin01>().As("b").ToList(b => b.name)));
|
||||
Assert.Equal(val1, val2[0]);
|
||||
|
||||
val1 = string.Join(",", fsql.Select<StringJoin01>().ToList(a => a.id));
|
||||
val2 = fsql.Select<StringJoin01>().ToList(a => string.Join(",", fsql.Select<StringJoin01>().As("b").ToList(b => b.id)));
|
||||
Assert.Equal(val1, val2[0]);
|
||||
|
||||
val1 = string.Join("**", fsql.Select<StringJoin01>().ToList(a => a.id));
|
||||
val2 = fsql.Select<StringJoin01>().ToList(a => string.Join("**", fsql.Select<StringJoin01>().As("b").ToList(b => b.id)));
|
||||
Assert.Equal(val1, val2[0]);
|
||||
}
|
||||
class StringJoin01
|
||||
{
|
||||
[Column(IsIdentity = true)]
|
||||
public int id { get; set; }
|
||||
public string name { get; set; }
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void First()
|
||||
{
|
||||
Assert.Equal('x', select.First(a => "x1".First()));
|
||||
Assert.Equal('z', select.First(a => "z1".First()));
|
||||
}
|
||||
[Fact]
|
||||
public void FirstOrDefault()
|
||||
{
|
||||
Assert.Equal('x', select.First(a => "x1".FirstOrDefault()));
|
||||
Assert.Equal('z', select.First(a => "z1".FirstOrDefault()));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Format()
|
||||
{
|
||||
var item = g.oracle.GetRepository<Topic>().Insert(new Topic { Clicks = 101, Title = "我是中国人101", CreateTime = DateTime.Parse("2020-7-5") });
|
||||
var sql = select.WhereDynamic(item).ToSql(a => new
|
||||
{
|
||||
str = $"x{a.Id + 1}z-{a.CreateTime.ToString("yyyyMM")}{a.Title}",
|
||||
str2 = string.Format("{0}x{0}z-{1}{2}", a.Id + 1, a.CreateTime.ToString("yyyyMM"), a.Title)
|
||||
});
|
||||
Assert.Equal($@"SELECT 'x'||nvl((a.""ID"" + 1), '')||'z-'||nvl(to_char(a.""CREATETIME"",'YYYYMM'), '')||''||nvl(a.""TITLE"", '')||'' as1, ''||nvl((a.""ID"" + 1), '')||'x'||nvl((a.""ID"" + 1), '')||'z-'||nvl(to_char(a.""CREATETIME"",'YYYYMM'), '')||''||nvl(a.""TITLE"", '')||'' as2
|
||||
FROM ""TB_TOPIC"" a
|
||||
WHERE (a.""ID"" = {item.Id})", sql);
|
||||
|
||||
var item2 = select.WhereDynamic(item).First(a => new
|
||||
{
|
||||
str = $"x{a.Id + 1}z-{a.CreateTime.ToString("yyyyMM")}{a.Title}",
|
||||
str2 = string.Format("{0}x{0}z-{1}{2}", a.Id + 1, a.CreateTime.ToString("yyyyMM"), a.Title)
|
||||
});
|
||||
Assert.NotNull(item2);
|
||||
Assert.Equal($"x{item.Id + 1}z-{item.CreateTime.ToString("yyyyMM")}{item.Title}", item2.str);
|
||||
Assert.Equal(string.Format("{0}x{0}z-{1}{2}", item.Id + 1, item.CreateTime.ToString("yyyyMM"), item.Title), item2.str2);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Format4()
|
||||
{
|
||||
//3个 {} 时,Arguments 解析出来是分开的
|
||||
//4个 {} 时,Arguments[1] 只能解析这个出来,然后里面是 NewArray []
|
||||
var item = g.oracle.GetRepository<Topic>().Insert(new Topic { Clicks = 101, Title = "我是中国人101", CreateTime = DateTime.Parse("2020-7-5") });
|
||||
var sql = select.WhereDynamic(item).ToSql(a => new
|
||||
{
|
||||
str = $"x{a.Id + 1}z-{a.CreateTime.ToString("yyyyMM")}{a.Title}{a.Title}",
|
||||
str2 = string.Format("{0}x{0}z-{1}{2}{3}", a.Id + 1, a.CreateTime.ToString("yyyyMM"), a.Title, a.Title)
|
||||
});
|
||||
Assert.Equal($@"SELECT 'x'||nvl((a.""ID"" + 1), '')||'z-'||nvl(to_char(a.""CREATETIME"",'YYYYMM'), '')||''||nvl(a.""TITLE"", '')||''||nvl(a.""TITLE"", '')||'' as1, ''||nvl((a.""ID"" + 1), '')||'x'||nvl((a.""ID"" + 1), '')||'z-'||nvl(to_char(a.""CREATETIME"",'YYYYMM'), '')||''||nvl(a.""TITLE"", '')||''||nvl(a.""TITLE"", '')||'' as2
|
||||
FROM ""TB_TOPIC"" a
|
||||
WHERE (a.""ID"" = {item.Id})", sql);
|
||||
|
||||
var item2 = select.WhereDynamic(item).First(a => new
|
||||
{
|
||||
str = $"x{a.Id + 1}z-{a.CreateTime.ToString("yyyyMM")}{a.Title}{a.Title}",
|
||||
str2 = string.Format("{0}x{0}z-{1}{2}{3}", a.Id + 1, a.CreateTime.ToString("yyyyMM"), a.Title, a.Title)
|
||||
});
|
||||
Assert.NotNull(item2);
|
||||
Assert.Equal($"x{item.Id + 1}z-{item.CreateTime.ToString("yyyyMM")}{item.Title}{item.Title}", item2.str);
|
||||
Assert.Equal(string.Format("{0}x{0}z-{1}{2}{3}", item.Id + 1, item.CreateTime.ToString("yyyyMM"), item.Title, item.Title), item2.str2);
|
||||
}
|
||||
|
||||
[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`, '%'))
|
||||
|
||||
|
||||
list.Add(select.Where(a => a.Title.Contains("%")).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());
|
||||
//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.Custom.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,158 @@
|
||||
using FreeSql.DataAnnotations;
|
||||
using FreeSql.Custom.PostgreSQL;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Xunit;
|
||||
|
||||
namespace FreeSql.Tests.Custom.PostgreSQL
|
||||
{
|
||||
public class OnConflictDoUpdateTest
|
||||
{
|
||||
class TestOnConflictDoUpdateInfo
|
||||
{
|
||||
[Column(IsIdentity = true)]
|
||||
public int id { get; set; }
|
||||
public string title { get; set; }
|
||||
public DateTime? time { get; set; }
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ExecuteAffrows()
|
||||
{
|
||||
g.pgsql.Delete<TestOnConflictDoUpdateInfo>(new[] { 100, 101, 102 }).ExecuteAffrows();
|
||||
var odku1 = new CustomPostgreSQLOnConflictDoUpdate<TestOnConflictDoUpdateInfo>(g.pgsql.Insert(new TestOnConflictDoUpdateInfo { id = 100, title = "title-100", time = DateTime.Parse("2000-01-01") }).NoneParameter().InsertIdentity());
|
||||
Assert.Equal(@"INSERT INTO ""testonconflictdoupdateinfo""(""id"", ""title"", ""time"") VALUES(100, 'title-100', '2000-01-01 00:00:00.000000')
|
||||
ON CONFLICT(""id"") DO UPDATE SET
|
||||
""title"" = EXCLUDED.""title"",
|
||||
""time"" = EXCLUDED.""time""", odku1.ToSql());
|
||||
Assert.Equal(1, odku1.ExecuteAffrows());
|
||||
|
||||
var odku2 = new CustomPostgreSQLOnConflictDoUpdate<TestOnConflictDoUpdateInfo>(g.pgsql.Insert(new[] {
|
||||
new TestOnConflictDoUpdateInfo { id = 100, title = "title-100", time = DateTime.Parse("2000-01-01") },
|
||||
new TestOnConflictDoUpdateInfo { id = 101, title = "title-101", time = DateTime.Parse("2000-01-01") },
|
||||
new TestOnConflictDoUpdateInfo { id = 102, title = "title-102", time = DateTime.Parse("2000-01-01") }
|
||||
}).NoneParameter().InsertIdentity());
|
||||
Assert.Equal(@"INSERT INTO ""testonconflictdoupdateinfo""(""id"", ""title"", ""time"") VALUES(100, 'title-100', '2000-01-01 00:00:00.000000'), (101, 'title-101', '2000-01-01 00:00:00.000000'), (102, 'title-102', '2000-01-01 00:00:00.000000')
|
||||
ON CONFLICT(""id"") DO UPDATE SET
|
||||
""title"" = EXCLUDED.""title"",
|
||||
""time"" = EXCLUDED.""time""", odku2.ToSql());
|
||||
odku2.ExecuteAffrows();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void IgnoreColumns()
|
||||
{
|
||||
g.pgsql.Delete<TestOnConflictDoUpdateInfo>(new[] { 200, 201, 202 }).ExecuteAffrows();
|
||||
var odku1 = new CustomPostgreSQLOnConflictDoUpdate<TestOnConflictDoUpdateInfo>(g.pgsql.Insert(new TestOnConflictDoUpdateInfo { id = 200, title = "title-200", time = DateTime.Parse("2000-01-01") }).IgnoreColumns(a => a.time).NoneParameter().InsertIdentity());
|
||||
Assert.Equal(@"INSERT INTO ""testonconflictdoupdateinfo""(""id"", ""title"") VALUES(200, 'title-200')
|
||||
ON CONFLICT(""id"") DO UPDATE SET
|
||||
""title"" = EXCLUDED.""title"",
|
||||
""time"" = '2000-01-01 00:00:00.000000'", odku1.ToSql());
|
||||
Assert.Equal(1, odku1.ExecuteAffrows());
|
||||
|
||||
var odku2 = new CustomPostgreSQLOnConflictDoUpdate<TestOnConflictDoUpdateInfo>(g.pgsql.Insert(new[] {
|
||||
new TestOnConflictDoUpdateInfo { id = 200, title = "title-200", time = DateTime.Parse("2000-01-01") },
|
||||
new TestOnConflictDoUpdateInfo { id = 201, title = "title-201", time = DateTime.Parse("2000-01-01") },
|
||||
new TestOnConflictDoUpdateInfo { id = 202, title = "title-202", time = DateTime.Parse("2000-01-01") }
|
||||
}).IgnoreColumns(a => a.time).NoneParameter().InsertIdentity());
|
||||
Assert.Equal(@"INSERT INTO ""testonconflictdoupdateinfo""(""id"", ""title"") VALUES(200, 'title-200'), (201, 'title-201'), (202, 'title-202')
|
||||
ON CONFLICT(""id"") DO UPDATE SET
|
||||
""title"" = EXCLUDED.""title"",
|
||||
""time"" = CASE EXCLUDED.""id""
|
||||
WHEN 200 THEN '2000-01-01 00:00:00.000000'
|
||||
WHEN 201 THEN '2000-01-01 00:00:00.000000'
|
||||
WHEN 202 THEN '2000-01-01 00:00:00.000000' END::timestamp", odku2.ToSql());
|
||||
odku2.ExecuteAffrows();
|
||||
|
||||
|
||||
g.pgsql.Delete<TestOnConflictDoUpdateInfo>(new[] { 200, 201, 202 }).ExecuteAffrows();
|
||||
odku1 = new CustomPostgreSQLOnConflictDoUpdate<TestOnConflictDoUpdateInfo>(g.pgsql.Insert(new TestOnConflictDoUpdateInfo { id = 200, title = "title-200", time = DateTime.Parse("2000-01-01") }).IgnoreColumns(a => a.time).NoneParameter().InsertIdentity()).IgnoreColumns(a => a.title);
|
||||
Assert.Equal(@"INSERT INTO ""testonconflictdoupdateinfo""(""id"", ""title"") VALUES(200, 'title-200')
|
||||
ON CONFLICT(""id"") DO UPDATE SET
|
||||
""time"" = '2000-01-01 00:00:00.000000'", odku1.ToSql());
|
||||
Assert.Equal(1, odku1.ExecuteAffrows());
|
||||
|
||||
odku2 = new CustomPostgreSQLOnConflictDoUpdate<TestOnConflictDoUpdateInfo>(g.pgsql.Insert(new[] {
|
||||
new TestOnConflictDoUpdateInfo { id = 200, title = "title-200", time = DateTime.Parse("2000-01-01") },
|
||||
new TestOnConflictDoUpdateInfo { id = 201, title = "title-201", time = DateTime.Parse("2000-01-01") },
|
||||
new TestOnConflictDoUpdateInfo { id = 202, title = "title-202", time = DateTime.Parse("2000-01-01") }
|
||||
}).IgnoreColumns(a => a.time).NoneParameter().InsertIdentity()).IgnoreColumns(a => a.title);
|
||||
Assert.Equal(@"INSERT INTO ""testonconflictdoupdateinfo""(""id"", ""title"") VALUES(200, 'title-200'), (201, 'title-201'), (202, 'title-202')
|
||||
ON CONFLICT(""id"") DO UPDATE SET
|
||||
""time"" = CASE EXCLUDED.""id""
|
||||
WHEN 200 THEN '2000-01-01 00:00:00.000000'
|
||||
WHEN 201 THEN '2000-01-01 00:00:00.000000'
|
||||
WHEN 202 THEN '2000-01-01 00:00:00.000000' END::timestamp", odku2.ToSql());
|
||||
odku2.ExecuteAffrows();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void UpdateColumns()
|
||||
{
|
||||
g.pgsql.Delete<TestOnConflictDoUpdateInfo>(new[] { 300, 301, 302 }).ExecuteAffrows();
|
||||
var odku1 = new CustomPostgreSQLOnConflictDoUpdate<TestOnConflictDoUpdateInfo>(g.pgsql.Insert(new TestOnConflictDoUpdateInfo { id = 300, title = "title-300", time = DateTime.Parse("2000-01-01") }).InsertColumns(a => a.title).NoneParameter().InsertIdentity());
|
||||
Assert.Equal(@"INSERT INTO ""testonconflictdoupdateinfo""(""id"", ""title"") VALUES(300, 'title-300')
|
||||
ON CONFLICT(""id"") DO UPDATE SET
|
||||
""title"" = EXCLUDED.""title"",
|
||||
""time"" = '2000-01-01 00:00:00.000000'", odku1.ToSql());
|
||||
Assert.Equal(1, odku1.ExecuteAffrows());
|
||||
|
||||
var odku2 = new CustomPostgreSQLOnConflictDoUpdate<TestOnConflictDoUpdateInfo>(g.pgsql.Insert(new[] {
|
||||
new TestOnConflictDoUpdateInfo { id = 300, title = "title-300", time = DateTime.Parse("2000-01-01") },
|
||||
new TestOnConflictDoUpdateInfo { id = 301, title = "title-301", time = DateTime.Parse("2000-01-01") },
|
||||
new TestOnConflictDoUpdateInfo { id = 302, title = "title-302", time = DateTime.Parse("2000-01-01") }
|
||||
}).InsertColumns(a => a.title).NoneParameter().InsertIdentity());
|
||||
Assert.Equal(@"INSERT INTO ""testonconflictdoupdateinfo""(""id"", ""title"") VALUES(300, 'title-300'), (301, 'title-301'), (302, 'title-302')
|
||||
ON CONFLICT(""id"") DO UPDATE SET
|
||||
""title"" = EXCLUDED.""title"",
|
||||
""time"" = CASE EXCLUDED.""id""
|
||||
WHEN 300 THEN '2000-01-01 00:00:00.000000'
|
||||
WHEN 301 THEN '2000-01-01 00:00:00.000000'
|
||||
WHEN 302 THEN '2000-01-01 00:00:00.000000' END::timestamp", odku2.ToSql());
|
||||
odku2.ExecuteAffrows();
|
||||
|
||||
|
||||
g.pgsql.Delete<TestOnConflictDoUpdateInfo>(new[] { 300, 301, 302 }).ExecuteAffrows();
|
||||
odku1 = new CustomPostgreSQLOnConflictDoUpdate<TestOnConflictDoUpdateInfo>(g.pgsql.Insert(new TestOnConflictDoUpdateInfo { id = 300, title = "title-300", time = DateTime.Parse("2000-01-01") }).InsertColumns(a => a.title).NoneParameter().InsertIdentity()).UpdateColumns(a => a.time);
|
||||
Assert.Equal(@"INSERT INTO ""testonconflictdoupdateinfo""(""id"", ""title"") VALUES(300, 'title-300')
|
||||
ON CONFLICT(""id"") DO UPDATE SET
|
||||
""time"" = '2000-01-01 00:00:00.000000'", odku1.ToSql());
|
||||
Assert.Equal(1, odku1.ExecuteAffrows());
|
||||
|
||||
odku2 = new CustomPostgreSQLOnConflictDoUpdate<TestOnConflictDoUpdateInfo>(g.pgsql.Insert(new[] {
|
||||
new TestOnConflictDoUpdateInfo { id = 300, title = "title-300", time = DateTime.Parse("2000-01-01") },
|
||||
new TestOnConflictDoUpdateInfo { id = 301, title = "title-301", time = DateTime.Parse("2000-01-01") },
|
||||
new TestOnConflictDoUpdateInfo { id = 302, title = "title-302", time = DateTime.Parse("2000-01-01") }
|
||||
}).InsertColumns(a => a.title).NoneParameter().InsertIdentity()).UpdateColumns(a => a.time);
|
||||
Assert.Equal(@"INSERT INTO ""testonconflictdoupdateinfo""(""id"", ""title"") VALUES(300, 'title-300'), (301, 'title-301'), (302, 'title-302')
|
||||
ON CONFLICT(""id"") DO UPDATE SET
|
||||
""time"" = CASE EXCLUDED.""id""
|
||||
WHEN 300 THEN '2000-01-01 00:00:00.000000'
|
||||
WHEN 301 THEN '2000-01-01 00:00:00.000000'
|
||||
WHEN 302 THEN '2000-01-01 00:00:00.000000' END::timestamp", odku2.ToSql());
|
||||
odku2.ExecuteAffrows();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Set()
|
||||
{
|
||||
g.pgsql.Delete<TestOnConflictDoUpdateInfo>(new[] { 400, 401, 402 }).ExecuteAffrows();
|
||||
var odku1 = new CustomPostgreSQLOnConflictDoUpdate<TestOnConflictDoUpdateInfo>(g.pgsql.Insert(new TestOnConflictDoUpdateInfo { id = 400, title = "title-400", time = DateTime.Parse("2000-01-01") }).NoneParameter().InsertIdentity()).Set(a => a.time, DateTime.Parse("2020-1-1"));
|
||||
Assert.Equal(@"INSERT INTO ""testonconflictdoupdateinfo""(""id"", ""title"", ""time"") VALUES(400, 'title-400', '2000-01-01 00:00:00.000000')
|
||||
ON CONFLICT(""id"") DO UPDATE SET
|
||||
""time"" = '2020-01-01 00:00:00.000000'", odku1.ToSql());
|
||||
Assert.Equal(1, odku1.ExecuteAffrows());
|
||||
|
||||
var odku2 = new CustomPostgreSQLOnConflictDoUpdate<TestOnConflictDoUpdateInfo>(g.pgsql.Insert(new[] {
|
||||
new TestOnConflictDoUpdateInfo { id = 400, title = "title-400", time = DateTime.Parse("2000-01-01") },
|
||||
new TestOnConflictDoUpdateInfo { id = 401, title = "title-401", time = DateTime.Parse("2000-01-01") },
|
||||
new TestOnConflictDoUpdateInfo { id = 402, title = "title-402", time = DateTime.Parse("2000-01-01") }
|
||||
}).NoneParameter().InsertIdentity()).Set(a => a.time, DateTime.Parse("2020-1-1"));
|
||||
Assert.Equal(@"INSERT INTO ""testonconflictdoupdateinfo""(""id"", ""title"", ""time"") VALUES(400, 'title-400', '2000-01-01 00:00:00.000000'), (401, 'title-401', '2000-01-01 00:00:00.000000'), (402, 'title-402', '2000-01-01 00:00:00.000000')
|
||||
ON CONFLICT(""id"") DO UPDATE SET
|
||||
""time"" = '2020-01-01 00:00:00.000000'", odku2.ToSql());
|
||||
odku2.ExecuteAffrows();
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,105 @@
|
||||
using FreeSql.DataAnnotations;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Xunit;
|
||||
|
||||
namespace FreeSql.Tests.Custom.PostgreSQL
|
||||
{
|
||||
public class PostgreSQLDeleteTest
|
||||
{
|
||||
|
||||
IDelete<Topic> delete => g.pgsql.Delete<Topic>();
|
||||
|
||||
[Table(Name = "tb_topic_del")]
|
||||
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.pgsql.Delete<Topic>().ToSql());
|
||||
var sql = g.pgsql.Delete<Topic>(new[] { 1, 2 }).ToSql();
|
||||
Assert.Equal("DELETE FROM \"tb_topic_del\" WHERE (\"id\" IN (1,2))", sql);
|
||||
|
||||
sql = g.pgsql.Delete<Topic>(new Topic { Id = 1, Title = "test" }).ToSql();
|
||||
Assert.Equal("DELETE FROM \"tb_topic_del\" WHERE (\"id\" = 1)", sql);
|
||||
|
||||
sql = g.pgsql.Delete<Topic>(new[] { new Topic { Id = 1, Title = "test" }, new Topic { Id = 2, Title = "test" } }).ToSql();
|
||||
Assert.Equal("DELETE FROM \"tb_topic_del\" WHERE (\"id\" IN (1,2))", sql);
|
||||
|
||||
sql = g.pgsql.Delete<Topic>(new { id = 1 }).ToSql();
|
||||
Assert.Equal("DELETE FROM \"tb_topic_del\" WHERE (\"id\" = 1)", sql);
|
||||
|
||||
sql = g.pgsql.Delete<MultiPkTopic>(new[] { new { Id1 = 1, Id2 = 10 }, new { Id1 = 2, Id2 = 20 } }).ToSql();
|
||||
Assert.Equal("DELETE FROM \"multipktopic\" WHERE (\"id1\" = 1 AND \"id2\" = 10 OR \"id1\" = 2 AND \"id2\" = 20)", sql);
|
||||
}
|
||||
class MultiPkTopic
|
||||
{
|
||||
[Column(IsPrimary = true)]
|
||||
public int Id1 { get; set; }
|
||||
[Column(IsPrimary = true)]
|
||||
public int Id2 { get; set; }
|
||||
public int Clicks { get; set; }
|
||||
public string Title { get; set; }
|
||||
public DateTime CreateTime { get; set; }
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Where()
|
||||
{
|
||||
var sql = delete.Where(a => a.Id == 1).ToSql().Replace("\r\n", "");
|
||||
Assert.Equal("DELETE FROM \"tb_topic_del\" WHERE (\"id\" = 1)", sql);
|
||||
|
||||
sql = delete.Where("id = @id", new { id = 1 }).ToSql().Replace("\r\n", "");
|
||||
Assert.Equal("DELETE FROM \"tb_topic_del\" 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_del\" 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_del\" WHERE (\"id\" IN (1,2,3,4,5,6,7,8,9,10))", sql);
|
||||
}
|
||||
[Fact]
|
||||
public void ExecuteAffrows()
|
||||
{
|
||||
|
||||
var id = g.pgsql.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.pgsql.Delete<Topic>().ToSql());
|
||||
var sql = g.pgsql.Delete<Topic>(new[] { 1, 2 }).AsTable(a => "TopicAsTable").ToSql();
|
||||
Assert.Equal("DELETE FROM \"topicastable\" WHERE (\"id\" IN (1,2))", sql);
|
||||
|
||||
sql = g.pgsql.Delete<Topic>(new Topic { Id = 1, Title = "test" }).AsTable(a => "TopicAsTable").ToSql();
|
||||
Assert.Equal("DELETE FROM \"topicastable\" WHERE (\"id\" = 1)", sql);
|
||||
|
||||
sql = g.pgsql.Delete<Topic>(new[] { new Topic { Id = 1, Title = "test" }, new Topic { Id = 2, Title = "test" } }).AsTable(a => "TopicAsTable").ToSql();
|
||||
Assert.Equal("DELETE FROM \"topicastable\" WHERE (\"id\" IN (1,2))", sql);
|
||||
|
||||
sql = g.pgsql.Delete<Topic>(new { id = 1 }).AsTable(a => "TopicAsTable").ToSql();
|
||||
Assert.Equal("DELETE FROM \"topicastable\" WHERE (\"id\" = 1)", sql);
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,266 @@
|
||||
using FreeSql.DataAnnotations;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Xunit;
|
||||
|
||||
namespace FreeSql.Tests.Custom.PostgreSQL
|
||||
{
|
||||
public class PostgreSQLInsertOrUpdateIfExistsDoNotingTest
|
||||
{
|
||||
IFreeSql fsql => g.pgsql;
|
||||
|
||||
[Fact]
|
||||
public void InsertOrUpdate_OnlyPrimary()
|
||||
{
|
||||
fsql.Delete<tbioudb01>().Where("1=1").ExecuteAffrows();
|
||||
var iou = fsql.InsertOrUpdate<tbioudb01>().IfExistsDoNothing().SetSource(new tbioudb01 { id = 1 });
|
||||
var sql = iou.ToSql();
|
||||
Assert.Equal(@"INSERT INTO ""tbioudb01""(""id"") VALUES(1)
|
||||
ON CONFLICT(""id"") DO NOTHING", sql);
|
||||
Assert.Equal(1, iou.ExecuteAffrows());
|
||||
|
||||
iou = fsql.InsertOrUpdate<tbioudb01>().IfExistsDoNothing().SetSource(new tbioudb01 { id = 1 });
|
||||
sql = iou.ToSql();
|
||||
Assert.Equal(@"INSERT INTO ""tbioudb01""(""id"") VALUES(1)
|
||||
ON CONFLICT(""id"") DO NOTHING", sql);
|
||||
Assert.Equal(0, iou.ExecuteAffrows());
|
||||
|
||||
iou = fsql.InsertOrUpdate<tbioudb01>().IfExistsDoNothing().SetSource(new tbioudb01 { id = 2 });
|
||||
sql = iou.ToSql();
|
||||
Assert.Equal(@"INSERT INTO ""tbioudb01""(""id"") VALUES(2)
|
||||
ON CONFLICT(""id"") DO NOTHING", sql);
|
||||
Assert.Equal(1, iou.ExecuteAffrows());
|
||||
|
||||
iou = fsql.InsertOrUpdate<tbioudb01>().IfExistsDoNothing().SetSource(new[] { new tbioudb01 { id = 1 }, new tbioudb01 { id = 2 }, new tbioudb01 { id = 3 }, new tbioudb01 { id = 4 } });
|
||||
sql = iou.ToSql();
|
||||
Assert.Equal(@"INSERT INTO ""tbioudb01""(""id"") VALUES(1), (2), (3), (4)
|
||||
ON CONFLICT(""id"") DO NOTHING", sql);
|
||||
Assert.Equal(2, iou.ExecuteAffrows());
|
||||
|
||||
iou = fsql.InsertOrUpdate<tbioudb01>().IfExistsDoNothing().SetSource(new[] { new tbioudb01 { id = 1 }, new tbioudb01 { id = 2 }, new tbioudb01 { id = 3 }, new tbioudb01 { id = 4 } });
|
||||
sql = iou.ToSql();
|
||||
Assert.Equal(@"INSERT INTO ""tbioudb01""(""id"") VALUES(1), (2), (3), (4)
|
||||
ON CONFLICT(""id"") DO NOTHING", sql);
|
||||
Assert.Equal(0, iou.ExecuteAffrows());
|
||||
}
|
||||
class tbioudb01
|
||||
{
|
||||
public int id { get; set; }
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void InsertOrUpdate_OnePrimary()
|
||||
{
|
||||
fsql.Delete<tbioudb02>().Where("1=1").ExecuteAffrows();
|
||||
var iou = fsql.InsertOrUpdate<tbioudb02>().IfExistsDoNothing().SetSource(new tbioudb02 { id = 1, name = "01" });
|
||||
var sql = iou.ToSql();
|
||||
Assert.Equal(@"INSERT INTO ""tbioudb02""(""id"", ""name"") VALUES(1, '01')
|
||||
ON CONFLICT(""id"") DO NOTHING", sql);
|
||||
Assert.Equal(1, iou.ExecuteAffrows());
|
||||
|
||||
iou = fsql.InsertOrUpdate<tbioudb02>().IfExistsDoNothing().SetSource(new tbioudb02 { id = 1, name = "011" });
|
||||
sql = iou.ToSql();
|
||||
Assert.Equal(@"INSERT INTO ""tbioudb02""(""id"", ""name"") VALUES(1, '011')
|
||||
ON CONFLICT(""id"") DO NOTHING", sql);
|
||||
Assert.Equal(0, iou.ExecuteAffrows());
|
||||
|
||||
iou = fsql.InsertOrUpdate<tbioudb02>().IfExistsDoNothing().SetSource(new tbioudb02 { id = 2, name = "02" });
|
||||
sql = iou.ToSql();
|
||||
Assert.Equal(@"INSERT INTO ""tbioudb02""(""id"", ""name"") VALUES(2, '02')
|
||||
ON CONFLICT(""id"") DO NOTHING", sql);
|
||||
Assert.Equal(1, iou.ExecuteAffrows());
|
||||
|
||||
iou = fsql.InsertOrUpdate<tbioudb02>().IfExistsDoNothing().SetSource(new[] { new tbioudb02 { id = 1, name = "01" }, new tbioudb02 { id = 2, name = "02" }, new tbioudb02 { id = 3, name = "03" }, new tbioudb02 { id = 4, name = "04" } });
|
||||
sql = iou.ToSql();
|
||||
Assert.Equal(@"INSERT INTO ""tbioudb02""(""id"", ""name"") VALUES(1, '01'), (2, '02'), (3, '03'), (4, '04')
|
||||
ON CONFLICT(""id"") DO NOTHING", sql);
|
||||
Assert.Equal(2, iou.ExecuteAffrows());
|
||||
|
||||
iou = fsql.InsertOrUpdate<tbioudb02>().IfExistsDoNothing().SetSource(new[] { new tbioudb02 { id = 1, name = "001" }, new tbioudb02 { id = 2, name = "002" }, new tbioudb02 { id = 3, name = "003" }, new tbioudb02 { id = 4, name = "004" } });
|
||||
sql = iou.ToSql();
|
||||
Assert.Equal(@"INSERT INTO ""tbioudb02""(""id"", ""name"") VALUES(1, '001'), (2, '002'), (3, '003'), (4, '004')
|
||||
ON CONFLICT(""id"") DO NOTHING", sql);
|
||||
Assert.Equal(0, iou.ExecuteAffrows());
|
||||
var lst = fsql.Select<tbioudb02>().Where(a => new[] { 1, 2, 3, 4 }.Contains(a.id)).ToList();
|
||||
Assert.Equal(4, lst.Where(a => a.name == "0" + a.id).Count());
|
||||
}
|
||||
class tbioudb02
|
||||
{
|
||||
public int id { get; set; }
|
||||
public string name { get; set; }
|
||||
}
|
||||
[Fact]
|
||||
public void InsertOrUpdate_OnePrimaryAndIdentity()
|
||||
{
|
||||
fsql.Delete<tbioudb022>().Where("1=1").ExecuteAffrows();
|
||||
var iou = fsql.InsertOrUpdate<tbioudb022>().IfExistsDoNothing().SetSource(new tbioudb022 { id = 1, name = "01" });
|
||||
var sql = iou.ToSql();
|
||||
Assert.Equal(@"INSERT INTO ""tbioudb022""(""id"", ""name"") VALUES(1, '01')
|
||||
ON CONFLICT(""id"") DO NOTHING", sql);
|
||||
Assert.Equal(1, iou.ExecuteAffrows());
|
||||
|
||||
iou = fsql.InsertOrUpdate<tbioudb022>().IfExistsDoNothing().SetSource(new tbioudb022 { id = 1, name = "011" });
|
||||
sql = iou.ToSql();
|
||||
Assert.Equal(@"INSERT INTO ""tbioudb022""(""id"", ""name"") VALUES(1, '011')
|
||||
ON CONFLICT(""id"") DO NOTHING", sql);
|
||||
Assert.Equal(0, iou.ExecuteAffrows());
|
||||
|
||||
iou = fsql.InsertOrUpdate<tbioudb022>().IfExistsDoNothing().SetSource(new tbioudb022 { id = 2, name = "02" });
|
||||
sql = iou.ToSql();
|
||||
Assert.Equal(@"INSERT INTO ""tbioudb022""(""id"", ""name"") VALUES(2, '02')
|
||||
ON CONFLICT(""id"") DO NOTHING", sql);
|
||||
Assert.Equal(1, iou.ExecuteAffrows());
|
||||
|
||||
iou = fsql.InsertOrUpdate<tbioudb022>().IfExistsDoNothing().SetSource(new[] { new tbioudb022 { id = 1, name = "01" }, new tbioudb022 { id = 2, name = "02" }, new tbioudb022 { id = 3, name = "03" }, new tbioudb022 { id = 4, name = "04" } });
|
||||
sql = iou.ToSql();
|
||||
Assert.Equal(@"INSERT INTO ""tbioudb022""(""id"", ""name"") VALUES(1, '01'), (2, '02'), (3, '03'), (4, '04')
|
||||
ON CONFLICT(""id"") DO NOTHING", sql);
|
||||
Assert.Equal(2, iou.ExecuteAffrows());
|
||||
|
||||
iou = fsql.InsertOrUpdate<tbioudb022>().IfExistsDoNothing().SetSource(new[] { new tbioudb022 { id = 1, name = "001" }, new tbioudb022 { id = 2, name = "002" }, new tbioudb022 { id = 3, name = "003" }, new tbioudb022 { id = 4, name = "004" } });
|
||||
sql = iou.ToSql();
|
||||
Assert.Equal(@"INSERT INTO ""tbioudb022""(""id"", ""name"") VALUES(1, '001'), (2, '002'), (3, '003'), (4, '004')
|
||||
ON CONFLICT(""id"") DO NOTHING", sql);
|
||||
Assert.Equal(0, iou.ExecuteAffrows());
|
||||
var lst = fsql.Select<tbioudb022>().Where(a => new[] { 1, 2, 3, 4 }.Contains(a.id)).ToList();
|
||||
Assert.Equal(4, lst.Where(a => a.name == "0" + a.id).Count());
|
||||
|
||||
//--no primary
|
||||
iou = fsql.InsertOrUpdate<tbioudb022>().IfExistsDoNothing().SetSource(new tbioudb022 { name = "01" });
|
||||
sql = iou.ToSql();
|
||||
Assert.Equal(@"INSERT INTO ""tbioudb022""(""name"") VALUES('01')", sql);
|
||||
Assert.Equal(1, iou.ExecuteAffrows());
|
||||
|
||||
iou = fsql.InsertOrUpdate<tbioudb022>().IfExistsDoNothing().SetSource(new tbioudb022 { name = "011" });
|
||||
sql = iou.ToSql();
|
||||
Assert.Equal(@"INSERT INTO ""tbioudb022""(""name"") VALUES('011')", sql);
|
||||
Assert.Equal(1, iou.ExecuteAffrows());
|
||||
|
||||
iou = fsql.InsertOrUpdate<tbioudb022>().IfExistsDoNothing().SetSource(new tbioudb022 { name = "02" });
|
||||
sql = iou.ToSql();
|
||||
Assert.Equal(@"INSERT INTO ""tbioudb022""(""name"") VALUES('02')", sql);
|
||||
Assert.Equal(1, iou.ExecuteAffrows());
|
||||
|
||||
iou = fsql.InsertOrUpdate<tbioudb022>().IfExistsDoNothing().SetSource(new[] { new tbioudb022 { name = "01" }, new tbioudb022 { name = "02" }, new tbioudb022 { name = "03" }, new tbioudb022 { name = "04" } });
|
||||
sql = iou.ToSql();
|
||||
Assert.Equal(@"INSERT INTO ""tbioudb022""(""name"") VALUES('01'), ('02'), ('03'), ('04')", sql);
|
||||
Assert.Equal(4, iou.ExecuteAffrows());
|
||||
|
||||
iou = fsql.InsertOrUpdate<tbioudb022>().IfExistsDoNothing().SetSource(new[] { new tbioudb022 { name = "001" }, new tbioudb022 { name = "002" }, new tbioudb022 { name = "003" }, new tbioudb022 { name = "004" } });
|
||||
sql = iou.ToSql();
|
||||
Assert.Equal(@"INSERT INTO ""tbioudb022""(""name"") VALUES('001'), ('002'), ('003'), ('004')", sql);
|
||||
Assert.Equal(4, iou.ExecuteAffrows());
|
||||
|
||||
//--no primary and yes
|
||||
iou = fsql.InsertOrUpdate<tbioudb022>().IfExistsDoNothing().SetSource(new[] { new tbioudb022 { id = 1, name = "100001" }, new tbioudb022 { name = "00001" }, new tbioudb022 { id = 2, name = "100002" }, new tbioudb022 { name = "00002" }, new tbioudb022 { id = 3, name = "100003" }, new tbioudb022 { name = "00003" }, new tbioudb022 { id = 4, name = "100004" }, new tbioudb022 { name = "00004" } });
|
||||
sql = iou.ToSql();
|
||||
Assert.Equal(@"INSERT INTO ""tbioudb022""(""id"", ""name"") VALUES(1, '100001'), (2, '100002'), (3, '100003'), (4, '100004')
|
||||
ON CONFLICT(""id"") DO NOTHING
|
||||
|
||||
;
|
||||
|
||||
INSERT INTO ""tbioudb022""(""name"") VALUES('00001'), ('00002'), ('00003'), ('00004')", sql);
|
||||
Assert.Equal(4, iou.ExecuteAffrows());
|
||||
lst = fsql.Select<tbioudb022>().Where(a => new[] { 1, 2, 3, 4 }.Contains(a.id)).ToList();
|
||||
Assert.Equal(4, lst.Where(a => a.name == "0" + a.id).Count());
|
||||
}
|
||||
class tbioudb022
|
||||
{
|
||||
[Column(IsIdentity = true)]
|
||||
public int id { get; set; }
|
||||
public string name { get; set; }
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void InsertOrUpdate_TwoPrimary()
|
||||
{
|
||||
fsql.Delete<tbioudb03>().Where("1=1").ExecuteAffrows();
|
||||
var iou = fsql.InsertOrUpdate<tbioudb03>().IfExistsDoNothing().SetSource(new tbioudb03 { id1 = 1, id2 = "01", name = "01" });
|
||||
var sql = iou.ToSql();
|
||||
Assert.Equal(@"INSERT INTO ""tbioudb03""(""id1"", ""id2"", ""name"") VALUES(1, '01', '01')
|
||||
ON CONFLICT(""id1"", ""id2"") DO NOTHING", sql);
|
||||
Assert.Equal(1, iou.ExecuteAffrows());
|
||||
|
||||
iou = fsql.InsertOrUpdate<tbioudb03>().IfExistsDoNothing().SetSource(new tbioudb03 { id1 = 1, id2 = "01", name = "011" });
|
||||
sql = iou.ToSql();
|
||||
Assert.Equal(@"INSERT INTO ""tbioudb03""(""id1"", ""id2"", ""name"") VALUES(1, '01', '011')
|
||||
ON CONFLICT(""id1"", ""id2"") DO NOTHING", sql);
|
||||
Assert.Equal(0, iou.ExecuteAffrows());
|
||||
|
||||
iou = fsql.InsertOrUpdate<tbioudb03>().IfExistsDoNothing().SetSource(new tbioudb03 { id1 = 2, id2 = "02", name = "02" });
|
||||
sql = iou.ToSql();
|
||||
Assert.Equal(@"INSERT INTO ""tbioudb03""(""id1"", ""id2"", ""name"") VALUES(2, '02', '02')
|
||||
ON CONFLICT(""id1"", ""id2"") DO NOTHING", sql);
|
||||
Assert.Equal(1, iou.ExecuteAffrows());
|
||||
|
||||
iou = fsql.InsertOrUpdate<tbioudb03>().IfExistsDoNothing().SetSource(new[] { new tbioudb03 { id1 = 1, id2 = "01", name = "01" }, new tbioudb03 { id1 = 2, id2 = "02", name = "02" }, new tbioudb03 { id1 = 3, id2 = "03", name = "03" }, new tbioudb03 { id1 = 4, id2 = "04", name = "04" } });
|
||||
sql = iou.ToSql();
|
||||
Assert.Equal(@"INSERT INTO ""tbioudb03""(""id1"", ""id2"", ""name"") VALUES(1, '01', '01'), (2, '02', '02'), (3, '03', '03'), (4, '04', '04')
|
||||
ON CONFLICT(""id1"", ""id2"") DO NOTHING", sql);
|
||||
Assert.Equal(2, iou.ExecuteAffrows());
|
||||
|
||||
iou = fsql.InsertOrUpdate<tbioudb03>().IfExistsDoNothing().SetSource(new[] { new tbioudb03 { id1 = 1, id2 = "01", name = "001" }, new tbioudb03 { id1 = 2, id2 = "02", name = "002" }, new tbioudb03 { id1 = 3, id2 = "03", name = "003" }, new tbioudb03 { id1 = 4, id2 = "04", name = "004" } });
|
||||
sql = iou.ToSql();
|
||||
Assert.Equal(@"INSERT INTO ""tbioudb03""(""id1"", ""id2"", ""name"") VALUES(1, '01', '001'), (2, '02', '002'), (3, '03', '003'), (4, '04', '004')
|
||||
ON CONFLICT(""id1"", ""id2"") DO NOTHING", sql);
|
||||
Assert.Equal(0, iou.ExecuteAffrows());
|
||||
var lst = fsql.Select<tbioudb03>().Where(a => a.id1 == 1 && a.id2 == "01" || a.id1 == 2 && a.id2 == "02" || a.id1 == 3 && a.id2 == "03" || a.id1 == 4 && a.id2 == "04").ToList();
|
||||
Assert.Equal(4, lst.Where(a => a.name == "0" + a.id1).Count());
|
||||
}
|
||||
class tbioudb03
|
||||
{
|
||||
[Column(IsPrimary = true)]
|
||||
public int id1 { get; set; }
|
||||
[Column(IsPrimary = true)]
|
||||
public string id2 { get; set; }
|
||||
public string name { get; set; }
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void InsertOrUpdate_OnePrimaryAndVersionAndCanUpdate()
|
||||
{
|
||||
fsql.Delete<tbioudb04>().Where("1=1").ExecuteAffrows();
|
||||
var iou = fsql.InsertOrUpdate<tbioudb04>().IfExistsDoNothing().SetSource(new tbioudb04 { id = 1, name = "01" });
|
||||
var sql = iou.ToSql();
|
||||
Assert.Equal(@"INSERT INTO ""tbioudb04""(""id"", ""name"", ""version"", ""createtime"") VALUES(1, '01', 0, current_timestamp)
|
||||
ON CONFLICT(""id"") DO NOTHING", sql);
|
||||
Assert.Equal(1, iou.ExecuteAffrows());
|
||||
|
||||
iou = fsql.InsertOrUpdate<tbioudb04>().IfExistsDoNothing().SetSource(new tbioudb04 { id = 1, name = "011" });
|
||||
sql = iou.ToSql();
|
||||
Assert.Equal(@"INSERT INTO ""tbioudb04""(""id"", ""name"", ""version"", ""createtime"") VALUES(1, '011', 0, current_timestamp)
|
||||
ON CONFLICT(""id"") DO NOTHING", sql);
|
||||
Assert.Equal(0, iou.ExecuteAffrows());
|
||||
|
||||
iou = fsql.InsertOrUpdate<tbioudb04>().IfExistsDoNothing().SetSource(new tbioudb04 { id = 2, name = "02" });
|
||||
sql = iou.ToSql();
|
||||
Assert.Equal(@"INSERT INTO ""tbioudb04""(""id"", ""name"", ""version"", ""createtime"") VALUES(2, '02', 0, current_timestamp)
|
||||
ON CONFLICT(""id"") DO NOTHING", sql);
|
||||
Assert.Equal(1, iou.ExecuteAffrows());
|
||||
|
||||
iou = fsql.InsertOrUpdate<tbioudb04>().IfExistsDoNothing().SetSource(new[] { new tbioudb04 { id = 1, name = "01" }, new tbioudb04 { id = 2, name = "02" }, new tbioudb04 { id = 3, name = "03" }, new tbioudb04 { id = 4, name = "04" } });
|
||||
sql = iou.ToSql();
|
||||
Assert.Equal(@"INSERT INTO ""tbioudb04""(""id"", ""name"", ""version"", ""createtime"") VALUES(1, '01', 0, current_timestamp), (2, '02', 0, current_timestamp), (3, '03', 0, current_timestamp), (4, '04', 0, current_timestamp)
|
||||
ON CONFLICT(""id"") DO NOTHING", sql);
|
||||
Assert.Equal(2, iou.ExecuteAffrows());
|
||||
|
||||
iou = fsql.InsertOrUpdate<tbioudb04>().IfExistsDoNothing().SetSource(new[] { new tbioudb04 { id = 1, name = "001" }, new tbioudb04 { id = 2, name = "002" }, new tbioudb04 { id = 3, name = "003" }, new tbioudb04 { id = 4, name = "004" } });
|
||||
sql = iou.ToSql();
|
||||
Assert.Equal(@"INSERT INTO ""tbioudb04""(""id"", ""name"", ""version"", ""createtime"") VALUES(1, '001', 0, current_timestamp), (2, '002', 0, current_timestamp), (3, '003', 0, current_timestamp), (4, '004', 0, current_timestamp)
|
||||
ON CONFLICT(""id"") DO NOTHING", sql);
|
||||
Assert.Equal(0, iou.ExecuteAffrows());
|
||||
var lst = fsql.Select<tbioudb04>().Where(a => new[] { 1, 2, 3, 4 }.Contains(a.id)).ToList();
|
||||
Assert.Equal(4, lst.Where(a => a.name == "0" + a.id).Count());
|
||||
}
|
||||
class tbioudb04
|
||||
{
|
||||
public int id { get; set; }
|
||||
public string name { get; set; }
|
||||
[Column(IsVersion = true)]
|
||||
public int version { get; set; }
|
||||
[Column(CanUpdate = false, ServerTime = DateTimeKind.Local)]
|
||||
public DateTime CreateTime { get; set; }
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,292 @@
|
||||
using FreeSql.DataAnnotations;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Xunit;
|
||||
|
||||
namespace FreeSql.Tests.Custom.PostgreSQL
|
||||
{
|
||||
public class PostgreSQLInsertOrUpdateTest
|
||||
{
|
||||
IFreeSql fsql => g.pgsql;
|
||||
|
||||
[Fact]
|
||||
public void InsertOrUpdate_OnlyPrimary()
|
||||
{
|
||||
fsql.Delete<tbiou01>().Where("1=1").ExecuteAffrows();
|
||||
var iou = fsql.InsertOrUpdate<tbiou01>().SetSource(new tbiou01 { id = 1 });
|
||||
var sql = iou.ToSql();
|
||||
Assert.Equal(@"INSERT INTO ""tbiou01""(""id"") VALUES(1)
|
||||
ON CONFLICT(""id"") DO NOTHING", sql);
|
||||
Assert.Equal(1, iou.ExecuteAffrows());
|
||||
|
||||
iou = fsql.InsertOrUpdate<tbiou01>().SetSource(new tbiou01 { id = 1 });
|
||||
sql = iou.ToSql();
|
||||
Assert.Equal(@"INSERT INTO ""tbiou01""(""id"") VALUES(1)
|
||||
ON CONFLICT(""id"") DO NOTHING", sql);
|
||||
Assert.Equal(0, iou.ExecuteAffrows());
|
||||
|
||||
iou = fsql.InsertOrUpdate<tbiou01>().SetSource(new tbiou01 { id = 2 });
|
||||
sql = iou.ToSql();
|
||||
Assert.Equal(@"INSERT INTO ""tbiou01""(""id"") VALUES(2)
|
||||
ON CONFLICT(""id"") DO NOTHING", sql);
|
||||
Assert.Equal(1, iou.ExecuteAffrows());
|
||||
|
||||
iou = fsql.InsertOrUpdate<tbiou01>().SetSource(new[] { new tbiou01 { id = 1 }, new tbiou01 { id = 2 }, new tbiou01 { id = 3 }, new tbiou01 { id = 4 } });
|
||||
sql = iou.ToSql();
|
||||
Assert.Equal(@"INSERT INTO ""tbiou01""(""id"") VALUES(1), (2), (3), (4)
|
||||
ON CONFLICT(""id"") DO NOTHING", sql);
|
||||
Assert.Equal(2, iou.ExecuteAffrows());
|
||||
|
||||
iou = fsql.InsertOrUpdate<tbiou01>().SetSource(new[] { new tbiou01 { id = 1 }, new tbiou01 { id = 2 }, new tbiou01 { id = 3 }, new tbiou01 { id = 4 } });
|
||||
sql = iou.ToSql();
|
||||
Assert.Equal(@"INSERT INTO ""tbiou01""(""id"") VALUES(1), (2), (3), (4)
|
||||
ON CONFLICT(""id"") DO NOTHING", sql);
|
||||
Assert.Equal(0, iou.ExecuteAffrows());
|
||||
}
|
||||
class tbiou01
|
||||
{
|
||||
public int id { get; set; }
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void InsertOrUpdate_OnePrimary()
|
||||
{
|
||||
fsql.Delete<tbiou02>().Where("1=1").ExecuteAffrows();
|
||||
var iou = fsql.InsertOrUpdate<tbiou02>().SetSource(new tbiou02 { id = 1, name = "01" });
|
||||
var sql = iou.ToSql();
|
||||
Assert.Equal(@"INSERT INTO ""tbiou02""(""id"", ""name"") VALUES(1, '01')
|
||||
ON CONFLICT(""id"") DO UPDATE SET
|
||||
""name"" = EXCLUDED.""name""", sql);
|
||||
Assert.Equal(1, iou.ExecuteAffrows());
|
||||
|
||||
iou = fsql.InsertOrUpdate<tbiou02>().SetSource(new tbiou02 { id = 1, name = "011" });
|
||||
sql = iou.ToSql();
|
||||
Assert.Equal(@"INSERT INTO ""tbiou02""(""id"", ""name"") VALUES(1, '011')
|
||||
ON CONFLICT(""id"") DO UPDATE SET
|
||||
""name"" = EXCLUDED.""name""", sql);
|
||||
Assert.Equal(1, iou.ExecuteAffrows());
|
||||
|
||||
iou = fsql.InsertOrUpdate<tbiou02>().SetSource(new tbiou02 { id = 2, name = "02" });
|
||||
sql = iou.ToSql();
|
||||
Assert.Equal(@"INSERT INTO ""tbiou02""(""id"", ""name"") VALUES(2, '02')
|
||||
ON CONFLICT(""id"") DO UPDATE SET
|
||||
""name"" = EXCLUDED.""name""", sql);
|
||||
Assert.Equal(1, iou.ExecuteAffrows());
|
||||
|
||||
iou = fsql.InsertOrUpdate<tbiou02>().SetSource(new[] { new tbiou02 { id = 1, name = "01" }, new tbiou02 { id = 2, name = "02" }, new tbiou02 { id = 3, name = "03" }, new tbiou02 { id = 4, name = "04" } });
|
||||
sql = iou.ToSql();
|
||||
Assert.Equal(@"INSERT INTO ""tbiou02""(""id"", ""name"") VALUES(1, '01'), (2, '02'), (3, '03'), (4, '04')
|
||||
ON CONFLICT(""id"") DO UPDATE SET
|
||||
""name"" = EXCLUDED.""name""", sql);
|
||||
Assert.Equal(4, iou.ExecuteAffrows());
|
||||
|
||||
iou = fsql.InsertOrUpdate<tbiou02>().SetSource(new[] { new tbiou02 { id = 1, name = "001" }, new tbiou02 { id = 2, name = "002" }, new tbiou02 { id = 3, name = "003" }, new tbiou02 { id = 4, name = "004" } });
|
||||
sql = iou.ToSql();
|
||||
Assert.Equal(@"INSERT INTO ""tbiou02""(""id"", ""name"") VALUES(1, '001'), (2, '002'), (3, '003'), (4, '004')
|
||||
ON CONFLICT(""id"") DO UPDATE SET
|
||||
""name"" = EXCLUDED.""name""", sql);
|
||||
Assert.Equal(4, iou.ExecuteAffrows());
|
||||
var lst = fsql.Select<tbiou02>().Where(a => new[] { 1, 2, 3, 4 }.Contains(a.id)).ToList();
|
||||
Assert.Equal(4, lst.Where(a => a.name == "00" + a.id).Count());
|
||||
}
|
||||
class tbiou02
|
||||
{
|
||||
public int id { get; set; }
|
||||
public string name { get; set; }
|
||||
}
|
||||
[Fact]
|
||||
public void InsertOrUpdate_OnePrimaryAndIdentity()
|
||||
{
|
||||
fsql.Delete<tbiou022>().Where("1=1").ExecuteAffrows();
|
||||
var iou = fsql.InsertOrUpdate<tbiou022>().SetSource(new tbiou022 { id = 1, name = "01" });
|
||||
var sql = iou.ToSql();
|
||||
Assert.Equal(@"INSERT INTO ""tbiou022""(""id"", ""name"") VALUES(1, '01')
|
||||
ON CONFLICT(""id"") DO UPDATE SET
|
||||
""name"" = EXCLUDED.""name""", sql);
|
||||
Assert.Equal(1, iou.ExecuteAffrows());
|
||||
|
||||
iou = fsql.InsertOrUpdate<tbiou022>().SetSource(new tbiou022 { id = 1, name = "011" });
|
||||
sql = iou.ToSql();
|
||||
Assert.Equal(@"INSERT INTO ""tbiou022""(""id"", ""name"") VALUES(1, '011')
|
||||
ON CONFLICT(""id"") DO UPDATE SET
|
||||
""name"" = EXCLUDED.""name""", sql);
|
||||
Assert.Equal(1, iou.ExecuteAffrows());
|
||||
|
||||
iou = fsql.InsertOrUpdate<tbiou022>().SetSource(new tbiou022 { id = 2, name = "02" });
|
||||
sql = iou.ToSql();
|
||||
Assert.Equal(@"INSERT INTO ""tbiou022""(""id"", ""name"") VALUES(2, '02')
|
||||
ON CONFLICT(""id"") DO UPDATE SET
|
||||
""name"" = EXCLUDED.""name""", sql);
|
||||
Assert.Equal(1, iou.ExecuteAffrows());
|
||||
|
||||
iou = fsql.InsertOrUpdate<tbiou022>().SetSource(new[] { new tbiou022 { id = 1, name = "01" }, new tbiou022 { id = 2, name = "02" }, new tbiou022 { id = 3, name = "03" }, new tbiou022 { id = 4, name = "04" } });
|
||||
sql = iou.ToSql();
|
||||
Assert.Equal(@"INSERT INTO ""tbiou022""(""id"", ""name"") VALUES(1, '01'), (2, '02'), (3, '03'), (4, '04')
|
||||
ON CONFLICT(""id"") DO UPDATE SET
|
||||
""name"" = EXCLUDED.""name""", sql);
|
||||
Assert.Equal(4, iou.ExecuteAffrows());
|
||||
|
||||
iou = fsql.InsertOrUpdate<tbiou022>().SetSource(new[] { new tbiou022 { id = 1, name = "001" }, new tbiou022 { id = 2, name = "002" }, new tbiou022 { id = 3, name = "003" }, new tbiou022 { id = 4, name = "004" } });
|
||||
sql = iou.ToSql();
|
||||
Assert.Equal(@"INSERT INTO ""tbiou022""(""id"", ""name"") VALUES(1, '001'), (2, '002'), (3, '003'), (4, '004')
|
||||
ON CONFLICT(""id"") DO UPDATE SET
|
||||
""name"" = EXCLUDED.""name""", sql);
|
||||
Assert.Equal(4, iou.ExecuteAffrows());
|
||||
var lst = fsql.Select<tbiou022>().Where(a => new[] { 1, 2, 3, 4 }.Contains(a.id)).ToList();
|
||||
Assert.Equal(4, lst.Where(a => a.name == "00" + a.id).Count());
|
||||
|
||||
//--no primary
|
||||
iou = fsql.InsertOrUpdate<tbiou022>().SetSource(new tbiou022 { name = "01" });
|
||||
sql = iou.ToSql();
|
||||
Assert.Equal(@"INSERT INTO ""tbiou022""(""name"") VALUES('01')", sql);
|
||||
Assert.Equal(1, iou.ExecuteAffrows());
|
||||
|
||||
iou = fsql.InsertOrUpdate<tbiou022>().SetSource(new tbiou022 { name = "011" });
|
||||
sql = iou.ToSql();
|
||||
Assert.Equal(@"INSERT INTO ""tbiou022""(""name"") VALUES('011')", sql);
|
||||
Assert.Equal(1, iou.ExecuteAffrows());
|
||||
|
||||
iou = fsql.InsertOrUpdate<tbiou022>().SetSource(new tbiou022 { name = "02" });
|
||||
sql = iou.ToSql();
|
||||
Assert.Equal(@"INSERT INTO ""tbiou022""(""name"") VALUES('02')", sql);
|
||||
Assert.Equal(1, iou.ExecuteAffrows());
|
||||
|
||||
iou = fsql.InsertOrUpdate<tbiou022>().SetSource(new[] { new tbiou022 { name = "01" }, new tbiou022 { name = "02" }, new tbiou022 { name = "03" }, new tbiou022 { name = "04" } });
|
||||
sql = iou.ToSql();
|
||||
Assert.Equal(@"INSERT INTO ""tbiou022""(""name"") VALUES('01'), ('02'), ('03'), ('04')", sql);
|
||||
Assert.Equal(4, iou.ExecuteAffrows());
|
||||
|
||||
iou = fsql.InsertOrUpdate<tbiou022>().SetSource(new[] { new tbiou022 { name = "001" }, new tbiou022 { name = "002" }, new tbiou022 { name = "003" }, new tbiou022 { name = "004" } });
|
||||
sql = iou.ToSql();
|
||||
Assert.Equal(@"INSERT INTO ""tbiou022""(""name"") VALUES('001'), ('002'), ('003'), ('004')", sql);
|
||||
Assert.Equal(4, iou.ExecuteAffrows());
|
||||
|
||||
//--no primary and yes
|
||||
iou = fsql.InsertOrUpdate<tbiou022>().SetSource(new[] { new tbiou022 { id = 1, name = "100001" }, new tbiou022 { name = "00001" }, new tbiou022 { id = 2, name = "100002" }, new tbiou022 { name = "00002" }, new tbiou022 { id = 3, name = "100003" }, new tbiou022 { name = "00003" }, new tbiou022 { id = 4, name = "100004" }, new tbiou022 { name = "00004" } });
|
||||
sql = iou.ToSql();
|
||||
Assert.Equal(@"INSERT INTO ""tbiou022""(""id"", ""name"") VALUES(1, '100001'), (2, '100002'), (3, '100003'), (4, '100004')
|
||||
ON CONFLICT(""id"") DO UPDATE SET
|
||||
""name"" = EXCLUDED.""name""
|
||||
|
||||
;
|
||||
|
||||
INSERT INTO ""tbiou022""(""name"") VALUES('00001'), ('00002'), ('00003'), ('00004')", sql);
|
||||
Assert.Equal(8, iou.ExecuteAffrows());
|
||||
lst = fsql.Select<tbiou022>().Where(a => new[] { 1, 2, 3, 4 }.Contains(a.id)).ToList();
|
||||
Assert.Equal(4, lst.Where(a => a.name == "10000" + a.id).Count());
|
||||
}
|
||||
class tbiou022
|
||||
{
|
||||
[Column(IsIdentity = true)]
|
||||
public int id { get; set; }
|
||||
public string name { get; set; }
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void InsertOrUpdate_TwoPrimary()
|
||||
{
|
||||
fsql.Delete<tbiou03>().Where("1=1").ExecuteAffrows();
|
||||
var iou = fsql.InsertOrUpdate<tbiou03>().SetSource(new tbiou03 { id1 = 1, id2 = "01", name = "01" });
|
||||
var sql = iou.ToSql();
|
||||
Assert.Equal(@"INSERT INTO ""tbiou03""(""id1"", ""id2"", ""name"") VALUES(1, '01', '01')
|
||||
ON CONFLICT(""id1"", ""id2"") DO UPDATE SET
|
||||
""name"" = EXCLUDED.""name""", sql);
|
||||
Assert.Equal(1, iou.ExecuteAffrows());
|
||||
|
||||
iou = fsql.InsertOrUpdate<tbiou03>().SetSource(new tbiou03 { id1 = 1, id2 = "01", name = "011" });
|
||||
sql = iou.ToSql();
|
||||
Assert.Equal(@"INSERT INTO ""tbiou03""(""id1"", ""id2"", ""name"") VALUES(1, '01', '011')
|
||||
ON CONFLICT(""id1"", ""id2"") DO UPDATE SET
|
||||
""name"" = EXCLUDED.""name""", sql);
|
||||
Assert.Equal(1, iou.ExecuteAffrows());
|
||||
|
||||
iou = fsql.InsertOrUpdate<tbiou03>().SetSource(new tbiou03 { id1 = 2, id2 = "02", name = "02" });
|
||||
sql = iou.ToSql();
|
||||
Assert.Equal(@"INSERT INTO ""tbiou03""(""id1"", ""id2"", ""name"") VALUES(2, '02', '02')
|
||||
ON CONFLICT(""id1"", ""id2"") DO UPDATE SET
|
||||
""name"" = EXCLUDED.""name""", sql);
|
||||
Assert.Equal(1, iou.ExecuteAffrows());
|
||||
|
||||
iou = fsql.InsertOrUpdate<tbiou03>().SetSource(new[] { new tbiou03 { id1 = 1, id2 = "01", name = "01" }, new tbiou03 { id1 = 2, id2 = "02", name = "02" }, new tbiou03 { id1 = 3, id2 = "03", name = "03" }, new tbiou03 { id1 = 4, id2 = "04", name = "04" } });
|
||||
sql = iou.ToSql();
|
||||
Assert.Equal(@"INSERT INTO ""tbiou03""(""id1"", ""id2"", ""name"") VALUES(1, '01', '01'), (2, '02', '02'), (3, '03', '03'), (4, '04', '04')
|
||||
ON CONFLICT(""id1"", ""id2"") DO UPDATE SET
|
||||
""name"" = EXCLUDED.""name""", sql);
|
||||
Assert.Equal(4, iou.ExecuteAffrows());
|
||||
|
||||
iou = fsql.InsertOrUpdate<tbiou03>().SetSource(new[] { new tbiou03 { id1 = 1, id2 = "01", name = "001" }, new tbiou03 { id1 = 2, id2 = "02", name = "002" }, new tbiou03 { id1 = 3, id2 = "03", name = "003" }, new tbiou03 { id1 = 4, id2 = "04", name = "004" } });
|
||||
sql = iou.ToSql();
|
||||
Assert.Equal(@"INSERT INTO ""tbiou03""(""id1"", ""id2"", ""name"") VALUES(1, '01', '001'), (2, '02', '002'), (3, '03', '003'), (4, '04', '004')
|
||||
ON CONFLICT(""id1"", ""id2"") DO UPDATE SET
|
||||
""name"" = EXCLUDED.""name""", sql);
|
||||
Assert.Equal(4, iou.ExecuteAffrows());
|
||||
var lst = fsql.Select<tbiou03>().Where(a => a.id1 == 1 && a.id2 == "01" || a.id1 == 2 && a.id2 == "02" || a.id1 == 3 && a.id2 == "03" || a.id1 == 4 && a.id2 == "04").ToList();
|
||||
Assert.Equal(4, lst.Where(a => a.name == "00" + a.id1).Count());
|
||||
}
|
||||
class tbiou03
|
||||
{
|
||||
[Column(IsPrimary = true)]
|
||||
public int id1 { get; set; }
|
||||
[Column(IsPrimary = true)]
|
||||
public string id2 { get; set; }
|
||||
public string name { get; set; }
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void InsertOrUpdate_OnePrimaryAndVersionAndCanUpdate()
|
||||
{
|
||||
fsql.Delete<tbiou04>().Where("1=1").ExecuteAffrows();
|
||||
var iou = fsql.InsertOrUpdate<tbiou04>().SetSource(new tbiou04 { id = 1, name = "01" });
|
||||
var sql = iou.ToSql();
|
||||
Assert.Equal(@"INSERT INTO ""tbiou04""(""id"", ""name"", ""version"", ""createtime"") VALUES(1, '01', 0, current_timestamp)
|
||||
ON CONFLICT(""id"") DO UPDATE SET
|
||||
""name"" = EXCLUDED.""name"",
|
||||
""version"" = ""tbiou04"".""version"" + 1", sql);
|
||||
Assert.Equal(1, iou.ExecuteAffrows());
|
||||
|
||||
iou = fsql.InsertOrUpdate<tbiou04>().SetSource(new tbiou04 { id = 1, name = "011" });
|
||||
sql = iou.ToSql();
|
||||
Assert.Equal(@"INSERT INTO ""tbiou04""(""id"", ""name"", ""version"", ""createtime"") VALUES(1, '011', 0, current_timestamp)
|
||||
ON CONFLICT(""id"") DO UPDATE SET
|
||||
""name"" = EXCLUDED.""name"",
|
||||
""version"" = ""tbiou04"".""version"" + 1", sql);
|
||||
Assert.Equal(1, iou.ExecuteAffrows());
|
||||
|
||||
iou = fsql.InsertOrUpdate<tbiou04>().SetSource(new tbiou04 { id = 2, name = "02" });
|
||||
sql = iou.ToSql();
|
||||
Assert.Equal(@"INSERT INTO ""tbiou04""(""id"", ""name"", ""version"", ""createtime"") VALUES(2, '02', 0, current_timestamp)
|
||||
ON CONFLICT(""id"") DO UPDATE SET
|
||||
""name"" = EXCLUDED.""name"",
|
||||
""version"" = ""tbiou04"".""version"" + 1", sql);
|
||||
Assert.Equal(1, iou.ExecuteAffrows());
|
||||
|
||||
iou = fsql.InsertOrUpdate<tbiou04>().SetSource(new[] { new tbiou04 { id = 1, name = "01" }, new tbiou04 { id = 2, name = "02" }, new tbiou04 { id = 3, name = "03" }, new tbiou04 { id = 4, name = "04" } });
|
||||
sql = iou.ToSql();
|
||||
Assert.Equal(@"INSERT INTO ""tbiou04""(""id"", ""name"", ""version"", ""createtime"") VALUES(1, '01', 0, current_timestamp), (2, '02', 0, current_timestamp), (3, '03', 0, current_timestamp), (4, '04', 0, current_timestamp)
|
||||
ON CONFLICT(""id"") DO UPDATE SET
|
||||
""name"" = EXCLUDED.""name"",
|
||||
""version"" = ""tbiou04"".""version"" + 1", sql);
|
||||
Assert.Equal(4, iou.ExecuteAffrows());
|
||||
|
||||
iou = fsql.InsertOrUpdate<tbiou04>().SetSource(new[] { new tbiou04 { id = 1, name = "001" }, new tbiou04 { id = 2, name = "002" }, new tbiou04 { id = 3, name = "003" }, new tbiou04 { id = 4, name = "004" } });
|
||||
sql = iou.ToSql();
|
||||
Assert.Equal(@"INSERT INTO ""tbiou04""(""id"", ""name"", ""version"", ""createtime"") VALUES(1, '001', 0, current_timestamp), (2, '002', 0, current_timestamp), (3, '003', 0, current_timestamp), (4, '004', 0, current_timestamp)
|
||||
ON CONFLICT(""id"") DO UPDATE SET
|
||||
""name"" = EXCLUDED.""name"",
|
||||
""version"" = ""tbiou04"".""version"" + 1", sql);
|
||||
Assert.Equal(4, iou.ExecuteAffrows());
|
||||
var lst = fsql.Select<tbiou04>().Where(a => new[] { 1, 2, 3, 4 }.Contains(a.id)).ToList();
|
||||
Assert.Equal(4, lst.Where(a => a.name == "00" + a.id).Count());
|
||||
}
|
||||
class tbiou04
|
||||
{
|
||||
public int id { get; set; }
|
||||
public string name { get; set; }
|
||||
[Column(IsVersion = true)]
|
||||
public int version { get; set; }
|
||||
[Column(CanUpdate = false, ServerTime = DateTimeKind.Local)]
|
||||
public DateTime CreateTime { get; set; }
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,141 @@
|
||||
using FreeSql.DataAnnotations;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Xunit;
|
||||
|
||||
namespace FreeSql.Tests.Custom.PostgreSQL
|
||||
{
|
||||
public class PostgreSQLInsertTest
|
||||
{
|
||||
|
||||
IInsert<Topic> insert => g.pgsql.Insert<Topic>();
|
||||
|
||||
[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 });
|
||||
|
||||
var sql = insert.AppendData(items.First()).ToSql();
|
||||
Assert.Equal("INSERT INTO \"tb_topic_insert\"(\"clicks\", \"title\", \"createtime\") VALUES(0, 'newtitle0', '0001-01-01 00:00:00.000000')", sql);
|
||||
|
||||
sql = insert.AppendData(items).ToSql();
|
||||
Assert.Equal("INSERT INTO \"tb_topic_insert\"(\"clicks\", \"title\", \"createtime\") VALUES(0, 'newtitle0', '0001-01-01 00:00:00.000000'), (100, 'newtitle1', '0001-01-01 00:00:00.000000'), (200, 'newtitle2', '0001-01-01 00:00:00.000000'), (300, 'newtitle3', '0001-01-01 00:00:00.000000'), (400, 'newtitle4', '0001-01-01 00:00:00.000000'), (500, 'newtitle5', '0001-01-01 00:00:00.000000'), (600, 'newtitle6', '0001-01-01 00:00:00.000000'), (700, 'newtitle7', '0001-01-01 00:00:00.000000'), (800, 'newtitle8', '0001-01-01 00:00:00.000000'), (900, 'newtitle9', '0001-01-01 00:00:00.000000')", sql);
|
||||
|
||||
sql = insert.AppendData(items).InsertColumns(a => a.Title).ToSql();
|
||||
Assert.Equal("INSERT INTO \"tb_topic_insert\"(\"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_insert\"(\"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 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_insert\"(\"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_insert\"(\"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_insert\"(\"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_insert\"(\"clicks\") VALUES(0), (100), (200), (300), (400), (500), (600), (700), (800), (900)", sql);
|
||||
|
||||
g.pgsql.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.pgsql.Insert<TopicIgnore>().AppendData(itemsIgnore).IgnoreColumns(a => new { a.Title }).ExecuteAffrows();
|
||||
Assert.Equal(2072, itemsIgnore.Count);
|
||||
Assert.Equal(2072, g.pgsql.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 });
|
||||
|
||||
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 });
|
||||
|
||||
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 });
|
||||
|
||||
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.000000')", 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.000000'), (100, 'newTitle1', '0001-01-01 00:00:00.000000'), (200, 'newTitle2', '0001-01-01 00:00:00.000000'), (300, 'newTitle3', '0001-01-01 00:00:00.000000'), (400, 'newTitle4', '0001-01-01 00:00:00.000000'), (500, 'newTitle5', '0001-01-01 00:00:00.000000'), (600, 'newTitle6', '0001-01-01 00:00:00.000000'), (700, 'newTitle7', '0001-01-01 00:00:00.000000'), (800, 'newTitle8', '0001-01-01 00:00:00.000000'), (900, 'newTitle9', '0001-01-01 00:00:00.000000')", 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,185 @@
|
||||
using FreeSql.DataAnnotations;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Xunit;
|
||||
|
||||
namespace FreeSql.Tests.Custom.PostgreSQL
|
||||
{
|
||||
public class PostgreSQLUpdateTest
|
||||
{
|
||||
IUpdate<Topic> update => g.pgsql.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.pgsql.Update<Topic>().ToSql());
|
||||
Assert.Equal("UPDATE \"tb_topic\" SET title='test' \r\nWHERE (\"id\" IN (1,2))", g.pgsql.Update<Topic>(new[] { 1, 2 }).SetRaw("title='test'").ToSql());
|
||||
Assert.Equal("UPDATE \"tb_topic\" SET title='test1' \r\nWHERE (\"id\" = 1)", g.pgsql.Update<Topic>(new Topic { Id = 1, Title = "test" }).SetRaw("title='test1'").ToSql());
|
||||
Assert.Equal("UPDATE \"tb_topic\" SET title='test1' \r\nWHERE (\"id\" IN (1,2))", g.pgsql.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.pgsql.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.000000' 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::int4, \"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::text, \"createtime\" = CASE \"id\" WHEN 1 THEN '0001-01-01 00:00:00.000000' WHEN 2 THEN '0001-01-01 00:00:00.000000' WHEN 3 THEN '0001-01-01 00:00:00.000000' WHEN 4 THEN '0001-01-01 00:00:00.000000' WHEN 5 THEN '0001-01-01 00:00:00.000000' WHEN 6 THEN '0001-01-01 00:00:00.000000' WHEN 7 THEN '0001-01-01 00:00:00.000000' WHEN 8 THEN '0001-01-01 00:00:00.000000' WHEN 9 THEN '0001-01-01 00:00:00.000000' WHEN 10 THEN '0001-01-01 00:00:00.000000' END::timestamp 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::text 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.000000' WHERE (\"id\" IN (1,2,3,4,5,6,7,8,9,10))", sql);
|
||||
|
||||
sql = g.pgsql.Update<ts_source_mpk>().SetSource(new[] {
|
||||
new ts_source_mpk { id1 = 1, id2 = 7, xx = "a1" },
|
||||
new ts_source_mpk { id1 = 1, id2 = 8, xx = "b122" }
|
||||
}).NoneParameter().ToSql().Replace("\r\n", "");
|
||||
}
|
||||
public class ts_source_mpk
|
||||
{
|
||||
[Column(IsPrimary = true)]
|
||||
public int id1 { get; set; }
|
||||
[Column(IsPrimary = true)]
|
||||
public int id2 { get; set; }
|
||||
public string xx { get; set; }
|
||||
}
|
||||
[Fact]
|
||||
public void SetSourceIgnore()
|
||||
{
|
||||
Assert.Equal("UPDATE \"tssi01\" SET \"tint\" = 10 WHERE (\"id\" = '00000000-0000-0000-0000-000000000000')",
|
||||
g.pgsql.Update<tssi01>().NoneParameter()
|
||||
.SetSourceIgnore(new tssi01 { id = Guid.Empty, tint = 10 }, col => col == null).ToSql().Replace("\r\n", ""));
|
||||
}
|
||||
public class tssi01
|
||||
{
|
||||
[Column(CanUpdate = false)]
|
||||
public Guid id { get; set; }
|
||||
public int tint { get; set; }
|
||||
public string title { get; set; }
|
||||
}
|
||||
[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\" = '2020-01-01 00:00:00.000000' 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\" = coalesce(\"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\" = coalesce(\"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);
|
||||
|
||||
var dt2000 = DateTime.Parse("2000-01-01");
|
||||
sql = update.Set(a => a.Clicks == (a.CreateTime > dt2000 ? 1 : 2)).Where(a => a.Id == 1).ToSql().Replace("\r\n", "");
|
||||
Assert.Equal("UPDATE \"tb_topic\" SET \"clicks\" = case when \"createtime\" > '2000-01-01 00:00:00.000000' then 1 else 2 end 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);
|
||||
|
||||
sql = update.Set(a => a.Clicks == null).Where(a => a.Id == 1).ToSql().Replace("\r\n", "");
|
||||
Assert.Equal("UPDATE \"tb_topic\" SET \"clicks\" = NULL 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 SetDto()
|
||||
{
|
||||
var sql = update.SetDto(new { clicks = 1, title = "xxx" }).Where(a => a.Id == 1).ToSql().Replace("\r\n", "");
|
||||
Assert.Equal("UPDATE \"tb_topic\" SET \"clicks\" = 1, \"title\" = 'xxx' WHERE (\"id\" = 1)", sql);
|
||||
|
||||
sql = update.SetDto(new Dictionary<string, object> { ["clicks"] = 1, ["title"] = "xxx" }).Where(a => a.Id == 1).ToSql().Replace("\r\n", "");
|
||||
Assert.Equal("UPDATE \"tb_topic\" SET \"clicks\" = 1, \"title\" = 'xxx' 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 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 });
|
||||
|
||||
update.SetSource(items.First()).NoneParameter().ExecuteAffrows();
|
||||
update.SetSource(items).NoneParameter().ExecuteAffrows();
|
||||
}
|
||||
[Fact]
|
||||
public void ExecuteUpdated()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void AsTable()
|
||||
{
|
||||
Assert.Null(g.pgsql.Update<Topic>().ToSql());
|
||||
Assert.Equal("UPDATE \"tb_topicastable\" SET title='test' \r\nWHERE (\"id\" IN (1,2))", g.pgsql.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.pgsql.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\" IN (1,2))", g.pgsql.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.pgsql.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.Custom.PostgreSQLMapType
|
||||
{
|
||||
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.pgsql;
|
||||
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,261 @@
|
||||
using FreeSql.DataAnnotations;
|
||||
using System;
|
||||
using System.Numerics;
|
||||
using Xunit;
|
||||
|
||||
namespace FreeSql.Tests.Custom.PostgreSQLMapType
|
||||
{
|
||||
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.pgsql;
|
||||
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.pgsql;
|
||||
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.pgsql;
|
||||
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.pgsql;
|
||||
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.Custom.PostgreSQLMapType
|
||||
{
|
||||
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.pgsql;
|
||||
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.pgsql;
|
||||
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.pgsql;
|
||||
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.pgsql;
|
||||
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.pgsql;
|
||||
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.pgsql;
|
||||
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.pgsql;
|
||||
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.pgsql;
|
||||
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.pgsql;
|
||||
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.pgsql;
|
||||
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,75 @@
|
||||
using FreeSql.DataAnnotations;
|
||||
using System;
|
||||
using Xunit;
|
||||
|
||||
namespace FreeSql.Tests.Custom.PostgreSQL
|
||||
{
|
||||
public class PostgreSQLAdoTest
|
||||
{
|
||||
[Fact]
|
||||
public void Pool()
|
||||
{
|
||||
var t1 = g.pgsql.Ado.MasterPool.StatisticsFullily;
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void SlavePools()
|
||||
{
|
||||
var t2 = g.pgsql.Ado.SlavePools.Count;
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ExecuteTest()
|
||||
{
|
||||
Assert.True(g.pgsql.Ado.ExecuteConnectTest());
|
||||
}
|
||||
[Fact]
|
||||
public void ExecuteReader()
|
||||
{
|
||||
|
||||
}
|
||||
[Fact]
|
||||
public void ExecuteArray()
|
||||
{
|
||||
|
||||
}
|
||||
[Fact]
|
||||
public void ExecuteNonQuery()
|
||||
{
|
||||
|
||||
}
|
||||
[Fact]
|
||||
public void ExecuteScalar()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Query()
|
||||
{
|
||||
|
||||
g.pgsql.CodeFirst.SyncStructure<xxx>();
|
||||
var t3 = g.pgsql.Ado.Query<xxx>("select * from xxx");
|
||||
|
||||
var t4 = g.pgsql.Ado.Query<(int, string, string)>("select * from xxx");
|
||||
|
||||
var t5 = g.pgsql.Ado.Query<dynamic>("select * from xxx");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void QueryMultipline()
|
||||
{
|
||||
g.pgsql.CodeFirst.SyncStructure<xxx>();
|
||||
var t3 = g.pgsql.Ado.Query<xxx, (int, string, string), dynamic>("select * from xxx; select * from xxx; select * from xxx");
|
||||
}
|
||||
|
||||
class xxx
|
||||
{
|
||||
public string Id { get; set; }
|
||||
public string Path { get; set; }
|
||||
public string Title2 { get; set; }
|
||||
|
||||
public string testf { get; set; }
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,40 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Reflection;
|
||||
using System.Text;
|
||||
using Xunit;
|
||||
|
||||
namespace FreeSql.Tests.Custom.PostgreSQL
|
||||
{
|
||||
public class PostgreSQLAopTest
|
||||
{
|
||||
|
||||
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.pgsql.Aop.AuditValue += audit;
|
||||
|
||||
g.pgsql.Insert(item).ExecuteAffrows();
|
||||
|
||||
g.pgsql.Aop.AuditValue -= audit;
|
||||
|
||||
Assert.Equal(item.createtime, date);
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,287 @@
|
||||
using FreeSql.DataAnnotations;
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
using System.Net.NetworkInformation;
|
||||
using System.Text;
|
||||
using Xunit;
|
||||
|
||||
namespace FreeSql.Tests.Custom.PostgreSQL
|
||||
{
|
||||
public class PostgreSQLCodeFirstTest
|
||||
{
|
||||
[Fact]
|
||||
public void Test_0String()
|
||||
{
|
||||
var fsql = g.pgsql;
|
||||
fsql.Delete<test_0string01>().Where("1=1").ExecuteAffrows();
|
||||
|
||||
Assert.Equal(1, fsql.Insert(new test_0string01 { name = @"1.0000\0.0000\0.0000\0.0000\1.0000\0.0000" }).ExecuteAffrows());
|
||||
Assert.Equal(1, fsql.Insert(new test_0string01 { name = @"1.0000\0.0000\0.0000\0.0000\1.0000\0.0000" }).NoneParameter().ExecuteAffrows());
|
||||
|
||||
var list = fsql.Select<test_0string01>().ToList();
|
||||
Assert.Equal(2, list.Count);
|
||||
Assert.Equal(@"1.0000\0.0000\0.0000\0.0000\1.0000\0.0000", list[0].name);
|
||||
Assert.Equal(@"1.0000\0.0000\0.0000\0.0000\1.0000\0.0000", list[1].name);
|
||||
}
|
||||
class test_0string01
|
||||
{
|
||||
public Guid id { get; set; }
|
||||
public string name { get; set; }
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void StringLength()
|
||||
{
|
||||
var dll = g.pgsql.CodeFirst.GetComparisonDDLStatements<TS_SLTB>();
|
||||
g.pgsql.CodeFirst.SyncStructure<TS_SLTB>();
|
||||
}
|
||||
class TS_SLTB
|
||||
{
|
||||
public Guid Id { get; set; }
|
||||
[Column(StringLength = 50)]
|
||||
public string Title { get; set; }
|
||||
|
||||
[Column(IsNullable = false, StringLength = 50)]
|
||||
public string TitleSub { get; set; }
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void 中文表_字段()
|
||||
{
|
||||
var sql = g.pgsql.CodeFirst.GetComparisonDDLStatements<测试中文表>();
|
||||
g.pgsql.CodeFirst.SyncStructure<测试中文表>();
|
||||
|
||||
var item = new 测试中文表
|
||||
{
|
||||
标题 = "测试标题",
|
||||
创建时间 = DateTime.Now
|
||||
};
|
||||
Assert.Equal(1, g.pgsql.Insert<测试中文表>().AppendData(item).ExecuteAffrows());
|
||||
Assert.NotEqual(Guid.Empty, item.编号);
|
||||
var item2 = g.pgsql.Select<测试中文表>().Where(a => a.编号 == item.编号).First();
|
||||
Assert.NotNull(item2);
|
||||
Assert.Equal(item.编号, item2.编号);
|
||||
Assert.Equal(item.标题, item2.标题);
|
||||
|
||||
item.标题 = "测试标题更新";
|
||||
Assert.Equal(1, g.pgsql.Update<测试中文表>().SetSource(item).ExecuteAffrows());
|
||||
item2 = g.pgsql.Select<测试中文表>().Where(a => a.编号 == item.编号).First();
|
||||
Assert.NotNull(item2);
|
||||
Assert.Equal(item.编号, item2.编号);
|
||||
Assert.Equal(item.标题, item2.标题);
|
||||
|
||||
item.标题 = "测试标题更新_repo";
|
||||
var repo = g.pgsql.GetRepository<测试中文表>();
|
||||
Assert.Equal(1, repo.Update(item));
|
||||
item2 = g.pgsql.Select<测试中文表>().Where(a => a.编号 == item.编号).First();
|
||||
Assert.NotNull(item2);
|
||||
Assert.Equal(item.编号, item2.编号);
|
||||
Assert.Equal(item.标题, item2.标题);
|
||||
|
||||
item.标题 = "测试标题更新_repo22";
|
||||
Assert.Equal(1, repo.Update(item));
|
||||
item2 = g.pgsql.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.pgsql.CodeFirst.GetComparisonDDLStatements<AddUniquesInfo>();
|
||||
g.pgsql.CodeFirst.SyncStructure<AddUniquesInfo>();
|
||||
g.pgsql.CodeFirst.SyncStructure(typeof(AddUniquesInfo), "AddUniquesInfo1");
|
||||
}
|
||||
[Table(Name = "AddUniquesInfo", OldName = "AddUniquesInfo2")]
|
||||
[Index("{tablename}_uk_phone", "phone", true)]
|
||||
[Index("{tablename}_uk_group_index", "group,index", true)]
|
||||
[Index("{tablename}_uk_group_index22", "group, index22", true)]
|
||||
class AddUniquesInfo
|
||||
{
|
||||
public Guid id { get; set; }
|
||||
public string phone { get; set; }
|
||||
|
||||
public string group { get; set; }
|
||||
public int index { get; set; }
|
||||
public string index22 { get; set; }
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void AddField()
|
||||
{
|
||||
var sql = g.pgsql.CodeFirst.GetComparisonDDLStatements<TopicAddField>();
|
||||
Assert.True(string.IsNullOrEmpty(sql)); //测试运行两次后
|
||||
g.pgsql.Select<TopicAddField>();
|
||||
var id = g.pgsql.Insert<TopicAddField>().AppendData(new TopicAddField { }).ExecuteIdentity();
|
||||
}
|
||||
|
||||
[Table(Name = "ccc.TopicAddField", OldName = "TopicAddField")]
|
||||
public class TopicAddField
|
||||
{
|
||||
[Column(IsIdentity = true)]
|
||||
public int Id { get; set; }
|
||||
|
||||
public string name { get; set; } = "xxx";
|
||||
|
||||
public int clicks { get; set; } = 10;
|
||||
//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.pgsql.CodeFirst.GetComparisonDDLStatements<TableAllType>();
|
||||
g.pgsql.Select<TableAllType>();
|
||||
}
|
||||
|
||||
IInsert<TableAllType> insert => g.pgsql.Insert<TableAllType>();
|
||||
ISelect<TableAllType> select => g.pgsql.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.AddDays(-1),
|
||||
testFieldDecimal = 999.99M,
|
||||
testFieldDecimalNullable = 111.11M,
|
||||
testFieldDouble = 888.88,
|
||||
testFieldDoubleNullable = 222.22,
|
||||
testFieldEnum1 = TableAllTypeEnumType1.e3,
|
||||
testFieldEnum1Nullable = TableAllTypeEnumType1.e2,
|
||||
testFieldEnum2 = TableAllTypeEnumType2.f2,
|
||||
testFieldEnum2Nullable = TableAllTypeEnumType2.f3,
|
||||
testFieldFloat = 777.77F,
|
||||
testFieldFloatNullable = 333.33F,
|
||||
testFieldGuid = Guid.NewGuid(),
|
||||
testFieldGuidNullable = Guid.NewGuid(),
|
||||
testFieldInt = int.MaxValue,
|
||||
testFieldIntNullable = 123,
|
||||
testFieldLong = long.MaxValue,
|
||||
|
||||
testFieldSByte = sbyte.MaxValue,
|
||||
testFieldSByteNullable = sbyte.MinValue,
|
||||
testFieldShort = short.MaxValue,
|
||||
testFieldShortNullable = short.MinValue,
|
||||
testFieldString = "我是中国人string'\\?!@#$%^&*()_+{}}{~?><<>",
|
||||
testFieldChar = 'X',
|
||||
testFieldTimeSpan = TimeSpan.FromDays(1),
|
||||
testFieldTimeSpanNullable = TimeSpan.FromSeconds(90),
|
||||
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 item3 = insert.AppendData(item2).ExecuteInserted().First();
|
||||
var newitem2 = select.Where(a => a.Id == item3.Id).ToOne();
|
||||
Assert.Equal(item2.testFieldString, newitem2.testFieldString);
|
||||
Assert.Equal(item2.testFieldChar, newitem2.testFieldChar);
|
||||
|
||||
item3 = insert.NoneParameter().AppendData(item2).ExecuteInserted().First();
|
||||
newitem2 = select.Where(a => a.Id == item3.Id).ToOne();
|
||||
Assert.Equal(item2.testFieldString, newitem2.testFieldString);
|
||||
Assert.Equal(item2.testFieldChar, newitem2.testFieldChar);
|
||||
|
||||
var items = select.ToList();
|
||||
var itemstb = select.ToDataTable();
|
||||
}
|
||||
|
||||
[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 char testFieldChar { 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,65 @@
|
||||
using FreeSql.DataAnnotations;
|
||||
using System;
|
||||
using System.Linq;
|
||||
using Xunit;
|
||||
|
||||
namespace FreeSql.Tests.Custom.PostgreSQL
|
||||
{
|
||||
public class PostgreSQLDbFirstTest
|
||||
{
|
||||
[Fact]
|
||||
public void GetDatabases()
|
||||
{
|
||||
var t1 = g.pgsql.DbFirst.GetDatabases();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void GetTablesByDatabase()
|
||||
{
|
||||
var t2 = g.pgsql.DbFirst.GetTablesByDatabase();
|
||||
Assert.True(t2.Count > 0);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void GetTableByName()
|
||||
{
|
||||
var fsql = g.pgsql;
|
||||
var t1 = fsql.DbFirst.GetTableByName("tb_alltype");
|
||||
var t2 = fsql.DbFirst.GetTableByName("public.tb_alltype");
|
||||
Assert.NotNull(t1);
|
||||
Assert.NotNull(t2);
|
||||
Assert.True(t1.Columns.Count > 0);
|
||||
Assert.True(t2.Columns.Count > 0);
|
||||
Assert.Equal(t1.Columns.Count, t2.Columns.Count);
|
||||
var t3 = fsql.DbFirst.GetTableByName("notexists_tb");
|
||||
Assert.Null(t3);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ExistsTable()
|
||||
{
|
||||
var fsql = g.pgsql;
|
||||
Assert.False(fsql.DbFirst.ExistsTable("test_existstb01"));
|
||||
Assert.False(fsql.DbFirst.ExistsTable("public.test_existstb01"));
|
||||
Assert.False(fsql.DbFirst.ExistsTable("test_existstb01", false));
|
||||
Assert.False(fsql.DbFirst.ExistsTable("public.test_existstb01", false));
|
||||
fsql.CodeFirst.SyncStructure(typeof(test_existstb01));
|
||||
Assert.True(fsql.DbFirst.ExistsTable("test_existstb01"));
|
||||
Assert.True(fsql.DbFirst.ExistsTable("public.test_existstb01"));
|
||||
Assert.False(fsql.DbFirst.ExistsTable("Test_existstb01", false));
|
||||
Assert.False(fsql.DbFirst.ExistsTable("public.Test_existstb01", false));
|
||||
fsql.Ado.ExecuteNonQuery("drop table test_existstb01");
|
||||
|
||||
Assert.False(fsql.DbFirst.ExistsTable("tbexts.test_existstb01"));
|
||||
Assert.False(fsql.DbFirst.ExistsTable("tbexts.test_existstb01", false));
|
||||
fsql.CodeFirst.SyncStructure(typeof(test_existstb01), "tbexts.test_existstb01");
|
||||
Assert.True(fsql.DbFirst.ExistsTable("tbexts.test_existstb01"));
|
||||
Assert.False(fsql.DbFirst.ExistsTable("tbexts.Test_existstb01", false));
|
||||
fsql.Ado.ExecuteNonQuery("drop table \"tbexts\".test_existstb01");
|
||||
}
|
||||
class test_existstb01
|
||||
{
|
||||
public Guid id { get; set; }
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,169 @@
|
||||
using FreeSql.DataAnnotations;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Xunit;
|
||||
|
||||
namespace FreeSql.Tests.Custom.PostgreSQLExpression
|
||||
{
|
||||
public class ConvertTest
|
||||
{
|
||||
|
||||
ISelect<Topic> select => g.pgsql.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,732 @@
|
||||
using FreeSql.DataAnnotations;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Xunit;
|
||||
|
||||
namespace FreeSql.Tests.Custom.PostgreSQLExpression
|
||||
{
|
||||
public class DateTimeTest
|
||||
{
|
||||
|
||||
ISelect<Topic> select => g.pgsql.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 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()))
|
||||
|
||||
g.pgsql.Insert(new Topic()).ExecuteAffrows();
|
||||
var dtn = DateTime.Parse("2020-1-1 0:0:0");
|
||||
var dts = Enumerable.Range(1, 12).Select(a => dtn.AddMonths(a))
|
||||
.Concat(Enumerable.Range(1, 31).Select(a => dtn.AddDays(a)))
|
||||
.Concat(Enumerable.Range(1, 24).Select(a => dtn.AddHours(a)))
|
||||
.Concat(Enumerable.Range(1, 60).Select(a => dtn.AddMinutes(a)))
|
||||
.Concat(Enumerable.Range(1, 60).Select(a => dtn.AddSeconds(a)));
|
||||
foreach (var dt in dts)
|
||||
{
|
||||
Assert.Equal(dt.ToString("yyyy-MM-dd HH:mm:ss.ffffff"), select.First(a => dt.ToString()));
|
||||
Assert.Equal(dt.ToString("yyyy-MM-dd HH:mm:ss"), select.First(a => dt.ToString("yyyy-MM-dd HH:mm:ss")));
|
||||
Assert.Equal(dt.ToString("yyyy-MM-dd HH:mm"), select.First(a => dt.ToString("yyyy-MM-dd HH:mm")));
|
||||
Assert.Equal(dt.ToString("yyyy-MM-dd HH"), select.First(a => dt.ToString("yyyy-MM-dd HH")));
|
||||
Assert.Equal(dt.ToString("yyyy-MM-dd"), select.First(a => dt.ToString("yyyy-MM-dd")));
|
||||
Assert.Equal(dt.ToString("yyyy-MM"), select.First(a => dt.ToString("yyyy-MM")));
|
||||
Assert.Equal(dt.ToString("yyyyMMddHHmmss"), select.First(a => dt.ToString("yyyyMMddHHmmss")));
|
||||
Assert.Equal(dt.ToString("yyyyMMddHHmm"), select.First(a => dt.ToString("yyyyMMddHHmm")));
|
||||
Assert.Equal(dt.ToString("yyyyMMddHH"), select.First(a => dt.ToString("yyyyMMddHH")));
|
||||
Assert.Equal(dt.ToString("yyyyMMdd"), select.First(a => dt.ToString("yyyyMMdd")));
|
||||
Assert.Equal(dt.ToString("yyyyMM"), select.First(a => dt.ToString("yyyyMM")));
|
||||
Assert.Equal(dt.ToString("yyyy"), select.First(a => dt.ToString("yyyy")));
|
||||
Assert.Equal(dt.ToString("HH:mm:ss"), select.First(a => dt.ToString("HH:mm:ss")));
|
||||
Assert.Equal(dt.ToString("yyyy MM dd HH mm ss yy M d H hh h"), select.First(a => dt.ToString("yyyy MM dd HH mm ss yy M d H hh h")));
|
||||
Assert.Equal(dt.ToString("yyyy MM dd HH mm ss yy M d H hh h m s tt t").Replace("上午", "AM").Replace("下午", "PM").Replace("上", "A").Replace("下", "P"), select.First(a => dt.ToString("yyyy MM dd HH mm ss yy M d H hh h m s tt t")));
|
||||
}
|
||||
}
|
||||
[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(epoch from (a."createtime")::timestamp-(current_timestamp)::timestamp)*1000000))/1000000) > 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(epoch from (a__Type."time")::timestamp-(current_timestamp)::timestamp)*1000000))/1000000) > 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 "testtypeparentinfo23123" a__Type__Parent ON a__Type__Parent."id" = a__Type."parentid"
|
||||
//WHERE ((((extract(epoch from (a__Type__Parent."time2")::timestamp-(current_timestamp)::timestamp)*1000000))/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", a."clicks", a."typeguid", a."title", a."createtime"
|
||||
//FROM "tb_topic111333" a
|
||||
//WHERE (((a."createtime")::timestamp-((((1)*86400000000))||' microseconds')::interval) > 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")::timestamp-((((1)*86400000000))||' microseconds')::interval) > 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 "testtypeparentinfo23123" a__Type__Parent ON a__Type__Parent."id" = a__Type."parentid"
|
||||
//WHERE (((a__Type__Parent."time2")::timestamp-((((1)*86400000000))||' microseconds')::interval) > 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(epoch from (a."createtime")::timestamp-(current_timestamp)::timestamp)*1000000))/1000000) > 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(epoch from (a__Type."time")::timestamp-(current_timestamp)::timestamp)*1000000))/1000000) > 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 "testtypeparentinfo23123" a__Type__Parent ON a__Type__Parent."id" = a__Type."parentid"
|
||||
//WHERE ((((extract(epoch from (a__Type__Parent."time2")::timestamp-(current_timestamp)::timestamp)*1000000))/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", a."clicks", a."typeguid", a."title", a."createtime"
|
||||
//FROM "tb_topic111333" a
|
||||
//WHERE (((a."createtime")::timestamp-((((1)*86400000000))||' microseconds')::interval) > 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")::timestamp-((((1)*86400000000))||' microseconds')::interval) > 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 "testtypeparentinfo23123" a__Type__Parent ON a__Type__Parent."id" = a__Type."parentid"
|
||||
//WHERE (((a__Type__Parent."time2")::timestamp-((((1)*86400000000))||' microseconds')::interval) > 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 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.Custom.PostgreSQLExpression
|
||||
{
|
||||
public class MathTest
|
||||
{
|
||||
|
||||
ISelect<Topic> select => g.pgsql.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,169 @@
|
||||
using FreeSql.DataAnnotations;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
using System.Net.NetworkInformation;
|
||||
using Xunit;
|
||||
|
||||
namespace FreeSql.Tests.Custom.PostgreSQLExpression
|
||||
{
|
||||
public class OtherTest
|
||||
{
|
||||
|
||||
ISelect<TableAllType> select => g.pgsql.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 t51 = select.WhereCascade(a => a.testFieldBool).Limit(10).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();
|
||||
|
||||
var t111 = select.Where(a => a.testFieldBool == true && a.Id > 0).ToList();
|
||||
var t222 = select.Where(a => a.testFieldBool != true && a.Id > 0).ToList();
|
||||
var t333 = select.Where(a => a.testFieldBool == false && a.Id > 0).ToList();
|
||||
var t444 = select.Where(a => !a.testFieldBool && a.Id > 0).ToList();
|
||||
var t555 = select.Where(a => a.testFieldBool && a.Id > 0).ToList();
|
||||
|
||||
var t1111 = select.Where(a => a.testFieldBoolNullable == true && a.Id > 0).ToList();
|
||||
var t2222 = select.Where(a => a.testFieldBoolNullable != true && a.Id > 0).ToList();
|
||||
var t3333 = select.Where(a => a.testFieldBoolNullable == false && a.Id > 0).ToList();
|
||||
var t4444 = select.Where(a => !a.testFieldBoolNullable.Value && a.Id > 0).ToList();
|
||||
var t5555 = select.Where(a => a.testFieldBoolNullable.Value && a.Id > 0).ToList();
|
||||
|
||||
var t11111 = select.Where(a => a.testFieldBool == true && a.Id > 0 && a.testFieldBool == true).ToList();
|
||||
var t22222 = select.Where(a => a.testFieldBool != true && a.Id > 0 && a.testFieldBool != true).ToList();
|
||||
var t33333 = select.Where(a => a.testFieldBool == false && a.Id > 0 && a.testFieldBool == false).ToList();
|
||||
var t44444 = select.Where(a => !a.testFieldBool && a.Id > 0 && !a.testFieldBool).ToList();
|
||||
var t55555 = select.Where(a => a.testFieldBool && a.Id > 0 && a.testFieldBool).ToList();
|
||||
|
||||
var t111111 = select.Where(a => a.testFieldBoolNullable == true && a.Id > 0 && a.testFieldBoolNullable == true).ToList();
|
||||
var t222222 = select.Where(a => a.testFieldBoolNullable != true && a.Id > 0 && a.testFieldBoolNullable != true).ToList();
|
||||
var t333333 = select.Where(a => a.testFieldBoolNullable == false && a.Id > 0 && a.testFieldBoolNullable == false).ToList();
|
||||
var t444444 = select.Where(a => !a.testFieldBoolNullable.Value && a.Id > 0 && !a.testFieldBoolNullable.Value).ToList();
|
||||
var t555555 = select.Where(a => a.testFieldBoolNullable.Value && a.Id > 0 && a.testFieldBoolNullable.Value).ToList();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Array()
|
||||
{
|
||||
//g.pgsql.Aop.CurdAfter = (s, e) => {
|
||||
// Trace.WriteLine(e.CurdType + ": " + e.ElapsedMilliseconds + "ms " + e.Sql.Replace("\n", ""));
|
||||
//};
|
||||
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)).ToSql();
|
||||
var sql1122 = select.Where(a => inarray.Contains(a.testFieldInt) == false).ToSql();
|
||||
var sql1133 = select.Where(a => !inarray.Contains(a.testFieldInt)).ToSql();
|
||||
|
||||
//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();
|
||||
|
||||
var inarray2n = Enumerable.Range(1, 3333).ToArray();
|
||||
var sql1111111 = select.Where(a => inarray2n.Contains(a.testFieldInt)).ToList();
|
||||
var sql1122222 = select.Where(a => inarray2n.Contains(a.testFieldInt) == false).ToList();
|
||||
var sql1133333 = select.Where(a => !inarray2n.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,829 @@
|
||||
using FreeSql.DataAnnotations;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Xunit;
|
||||
|
||||
namespace FreeSql.Tests.Custom.PostgreSQLExpression
|
||||
{
|
||||
public class StringTest
|
||||
{
|
||||
|
||||
ISelect<Topic> select => g.pgsql.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.pgsql.Select<TestEqualsGuid>().Where(a => a.id.Equals(Guid.Empty)).ToList());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void StringJoin()
|
||||
{
|
||||
var fsql = g.pgsql;
|
||||
fsql.Delete<StringJoin01>().Where("1=1").ExecuteAffrows();
|
||||
fsql.Insert(new[] { new StringJoin01 { name = "北京" }, new StringJoin01 { name = "上海" }, new StringJoin01 { name = "深圳" }, }).ExecuteAffrows();
|
||||
|
||||
var val1 = string.Join(",", fsql.Select<StringJoin01>().ToList(a => a.name));
|
||||
var val2 = fsql.Select<StringJoin01>().ToList(a => string.Join(",", fsql.Select<StringJoin01>().As("b").ToList(b => b.name)));
|
||||
Assert.Equal(val1, val2[0]);
|
||||
|
||||
val1 = string.Join("**", fsql.Select<StringJoin01>().ToList(a => a.name));
|
||||
val2 = fsql.Select<StringJoin01>().ToList(a => string.Join("**", fsql.Select<StringJoin01>().As("b").ToList(b => b.name)));
|
||||
Assert.Equal(val1, val2[0]);
|
||||
|
||||
val1 = string.Join(",", fsql.Select<StringJoin01>().ToList(a => a.id));
|
||||
val2 = fsql.Select<StringJoin01>().ToList(a => string.Join(",", fsql.Select<StringJoin01>().As("b").ToList(b => b.id)));
|
||||
Assert.Equal(val1, val2[0]);
|
||||
|
||||
val1 = string.Join("**", fsql.Select<StringJoin01>().ToList(a => a.id));
|
||||
val2 = fsql.Select<StringJoin01>().ToList(a => string.Join("**", fsql.Select<StringJoin01>().As("b").ToList(b => b.id)));
|
||||
Assert.Equal(val1, val2[0]);
|
||||
}
|
||||
class StringJoin01
|
||||
{
|
||||
[Column(IsIdentity = true)]
|
||||
public int id { get; set; }
|
||||
public string name { get; set; }
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void First()
|
||||
{
|
||||
Assert.Equal('x', select.First(a => "x1".First()));
|
||||
Assert.Equal('z', select.First(a => "z1".First()));
|
||||
}
|
||||
[Fact]
|
||||
public void FirstOrDefault()
|
||||
{
|
||||
Assert.Equal('x', select.First(a => "x1".FirstOrDefault()));
|
||||
Assert.Equal('z', select.First(a => "z1".FirstOrDefault()));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Format()
|
||||
{
|
||||
var item = g.pgsql.GetRepository<Topic>().Insert(new Topic { Clicks = 101, Title = "我是中国人101", CreateTime = DateTime.Parse("2020-7-5") });
|
||||
var sql = select.WhereDynamic(item).ToSql(a => new
|
||||
{
|
||||
str = $"x{a.Id + 1}z-{a.CreateTime.ToString("yyyyMM")}{a.Title}",
|
||||
str2 = string.Format("{0}x{0}z-{1}{2}", a.Id + 1, a.CreateTime.ToString("yyyyMM"), a.Title)
|
||||
});
|
||||
Assert.Equal($@"SELECT 'x'||coalesce(((a.""id"" + 1))::text, '')||'z-'||coalesce(to_char((a.""createtime"")::timestamp,'YYYYMM'), '')||''||coalesce(a.""title"", '')||'' as1, ''||coalesce(((a.""id"" + 1))::text, '')||'x'||coalesce(((a.""id"" + 1))::text, '')||'z-'||coalesce(to_char((a.""createtime"")::timestamp,'YYYYMM'), '')||''||coalesce(a.""title"", '')||'' as2
|
||||
FROM ""tb_topic"" a
|
||||
WHERE (a.""id"" = {item.Id})", sql);
|
||||
|
||||
var item2 = select.WhereDynamic(item).First(a => new
|
||||
{
|
||||
str = $"x{a.Id + 1}z-{a.CreateTime.ToString("yyyyMM")}{a.Title}",
|
||||
str2 = string.Format("{0}x{0}z-{1}{2}", a.Id + 1, a.CreateTime.ToString("yyyyMM"), a.Title)
|
||||
});
|
||||
Assert.NotNull(item2);
|
||||
Assert.Equal($"x{item.Id + 1}z-{item.CreateTime.ToString("yyyyMM")}{item.Title}", item2.str);
|
||||
Assert.Equal(string.Format("{0}x{0}z-{1}{2}", item.Id + 1, item.CreateTime.ToString("yyyyMM"), item.Title), item2.str2);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Format4()
|
||||
{
|
||||
//3个 {} 时,Arguments 解析出来是分开的
|
||||
//4个 {} 时,Arguments[1] 只能解析这个出来,然后里面是 NewArray []
|
||||
var item = g.pgsql.GetRepository<Topic>().Insert(new Topic { Clicks = 101, Title = "我是中国人101", CreateTime = DateTime.Parse("2020-7-5") });
|
||||
var sql = select.WhereDynamic(item).ToSql(a => new
|
||||
{
|
||||
str = $"x{a.Id + 1}z-{a.CreateTime.ToString("yyyyMM")}{a.Title}{a.Title}",
|
||||
str2 = string.Format("{0}x{0}z-{1}{2}{3}", a.Id + 1, a.CreateTime.ToString("yyyyMM"), a.Title, a.Title)
|
||||
});
|
||||
Assert.Equal($@"SELECT 'x'||coalesce(((a.""id"" + 1))::text, '')||'z-'||coalesce(to_char((a.""createtime"")::timestamp,'YYYYMM'), '')||''||coalesce(a.""title"", '')||''||coalesce(a.""title"", '')||'' as1, ''||coalesce(((a.""id"" + 1))::text, '')||'x'||coalesce(((a.""id"" + 1))::text, '')||'z-'||coalesce(to_char((a.""createtime"")::timestamp,'YYYYMM'), '')||''||coalesce(a.""title"", '')||''||coalesce(a.""title"", '')||'' as2
|
||||
FROM ""tb_topic"" a
|
||||
WHERE (a.""id"" = {item.Id})", sql);
|
||||
|
||||
var item2 = select.WhereDynamic(item).First(a => new
|
||||
{
|
||||
str = $"x{a.Id + 1}z-{a.CreateTime.ToString("yyyyMM")}{a.Title}{a.Title}",
|
||||
str2 = string.Format("{0}x{0}z-{1}{2}{3}", a.Id + 1, a.CreateTime.ToString("yyyyMM"), a.Title, a.Title)
|
||||
});
|
||||
Assert.NotNull(item2);
|
||||
Assert.Equal($"x{item.Id + 1}z-{item.CreateTime.ToString("yyyyMM")}{item.Title}{item.Title}", item2.str);
|
||||
Assert.Equal(string.Format("{0}x{0}z-{1}{2}{3}", item.Id + 1, item.CreateTime.ToString("yyyyMM"), item.Title, item.Title), item2.str2);
|
||||
}
|
||||
|
||||
[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`, '%'))
|
||||
|
||||
|
||||
list.Add(select.Where(a => a.Title.Contains("%")).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());
|
||||
//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.Custom.PostgreSQLExpression
|
||||
{
|
||||
public class TimeSpanTest
|
||||
{
|
||||
|
||||
ISelect<Topic> select => g.pgsql.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,112 @@
|
||||
using FreeSql.DataAnnotations;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Xunit;
|
||||
|
||||
namespace FreeSql.Tests.Custom.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] IN (1,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] IN (1,2))", sql);
|
||||
|
||||
sql = g.sqlserver.Delete<Topic>(new { id = 1 }).ToSql();
|
||||
Assert.Equal("DELETE FROM [tb_topic22211] WHERE ([Id] = 1)", sql);
|
||||
|
||||
sql = g.sqlserver.Delete<MultiPkTopic>(new[] { new { Id1 = 1, Id2 = 10 }, new { Id1 = 2, Id2 = 20 } }).ToSql();
|
||||
Assert.Equal("DELETE FROM [MultiPkTopic] WHERE ([Id1] = 1 AND [Id2] = 10 OR [Id1] = 2 AND [Id2] = 20)", sql);
|
||||
}
|
||||
class MultiPkTopic
|
||||
{
|
||||
[Column(IsPrimary = true)]
|
||||
public int Id1 { get; set; }
|
||||
[Column(IsPrimary = true)]
|
||||
public int Id2 { get; set; }
|
||||
public int Clicks { get; set; }
|
||||
public string Title { get; set; }
|
||||
public DateTime CreateTime { get; set; }
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Where()
|
||||
{
|
||||
var sql = delete.Where(a => a.Id == 1).ToSql().Replace("\r\n", "");
|
||||
Assert.Equal("DELETE FROM [tb_topic22211] WHERE ([Id] = 1)", sql);
|
||||
|
||||
sql = delete.Where("id = @id", new { id = 1 }).ToSql().Replace("\r\n", "");
|
||||
Assert.Equal("DELETE FROM [tb_topic22211] WHERE (id = @id)", sql);
|
||||
|
||||
var item = new Topic { Id = 1, Title = "newtitle" };
|
||||
sql = delete.Where(item).ToSql().Replace("\r\n", "");
|
||||
Assert.Equal("DELETE FROM [tb_topic22211] WHERE ([Id] = 1)", sql);
|
||||
|
||||
var items = new List<Topic>();
|
||||
for (var a = 0; a < 10; a++) items.Add(new Topic { Id = a + 1, Title = $"newtitle{a}", Clicks = a * 100 });
|
||||
|
||||
sql = delete.Where(items).ToSql().Replace("\r\n", "");
|
||||
Assert.Equal("DELETE FROM [tb_topic22211] WHERE ([Id] IN (1,2,3,4,5,6,7,8,9,10))", sql);
|
||||
}
|
||||
[Fact]
|
||||
public void ExecuteAffrows()
|
||||
{
|
||||
|
||||
var id = g.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 }).ToArray();
|
||||
var itemsInserted = g.sqlserver.Insert(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] IN (1,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] IN (1,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,422 @@
|
||||
using FreeSql.DataAnnotations;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Xunit;
|
||||
|
||||
namespace FreeSql.Tests.Custom.SqlServer
|
||||
{
|
||||
public class SqlServerInsertOrUpdateIfExistsDoNothingTest
|
||||
{
|
||||
IFreeSql fsql => g.sqlserver;
|
||||
|
||||
[Fact]
|
||||
public void InsertOrUpdate_OnlyPrimary()
|
||||
{
|
||||
fsql.Delete<tbioudb01>().Where("1=1").ExecuteAffrows();
|
||||
var iou = fsql.InsertOrUpdate<tbioudb01>().IfExistsDoNothing().SetSource(new tbioudb01 { id = 1 });
|
||||
var sql = iou.ToSql();
|
||||
Assert.Equal(@"MERGE INTO [tbioudb01] t1
|
||||
USING (SELECT 1 as [id] ) t2 ON (t1.[id] = t2.[id])
|
||||
WHEN NOT MATCHED THEN
|
||||
insert ([id])
|
||||
values (t2.[id]);", sql);
|
||||
Assert.Equal(1, iou.ExecuteAffrows());
|
||||
|
||||
iou = fsql.InsertOrUpdate<tbioudb01>().IfExistsDoNothing().SetSource(new tbioudb01 { id = 1 });
|
||||
sql = iou.ToSql();
|
||||
Assert.Equal(@"MERGE INTO [tbioudb01] t1
|
||||
USING (SELECT 1 as [id] ) t2 ON (t1.[id] = t2.[id])
|
||||
WHEN NOT MATCHED THEN
|
||||
insert ([id])
|
||||
values (t2.[id]);", sql);
|
||||
Assert.Equal(0, iou.ExecuteAffrows());
|
||||
|
||||
iou = fsql.InsertOrUpdate<tbioudb01>().IfExistsDoNothing().SetSource(new tbioudb01 { id = 2 });
|
||||
sql = iou.ToSql();
|
||||
Assert.Equal(@"MERGE INTO [tbioudb01] t1
|
||||
USING (SELECT 2 as [id] ) t2 ON (t1.[id] = t2.[id])
|
||||
WHEN NOT MATCHED THEN
|
||||
insert ([id])
|
||||
values (t2.[id]);", sql);
|
||||
Assert.Equal(1, iou.ExecuteAffrows());
|
||||
|
||||
iou = fsql.InsertOrUpdate<tbioudb01>().IfExistsDoNothing().SetSource(new[] { new tbioudb01 { id = 1 }, new tbioudb01 { id = 2 }, new tbioudb01 { id = 3 }, new tbioudb01 { id = 4 } });
|
||||
sql = iou.ToSql();
|
||||
Assert.Equal(@"MERGE INTO [tbioudb01] t1
|
||||
USING (SELECT 1 as [id]
|
||||
UNION ALL
|
||||
SELECT 2
|
||||
UNION ALL
|
||||
SELECT 3
|
||||
UNION ALL
|
||||
SELECT 4 ) t2 ON (t1.[id] = t2.[id])
|
||||
WHEN NOT MATCHED THEN
|
||||
insert ([id])
|
||||
values (t2.[id]);", sql);
|
||||
Assert.Equal(2, iou.ExecuteAffrows());
|
||||
|
||||
iou = fsql.InsertOrUpdate<tbioudb01>().IfExistsDoNothing().SetSource(new[] { new tbioudb01 { id = 1 }, new tbioudb01 { id = 2 }, new tbioudb01 { id = 3 }, new tbioudb01 { id = 4 } });
|
||||
sql = iou.ToSql();
|
||||
Assert.Equal(@"MERGE INTO [tbioudb01] t1
|
||||
USING (SELECT 1 as [id]
|
||||
UNION ALL
|
||||
SELECT 2
|
||||
UNION ALL
|
||||
SELECT 3
|
||||
UNION ALL
|
||||
SELECT 4 ) t2 ON (t1.[id] = t2.[id])
|
||||
WHEN NOT MATCHED THEN
|
||||
insert ([id])
|
||||
values (t2.[id]);", sql);
|
||||
Assert.Equal(0, iou.ExecuteAffrows());
|
||||
}
|
||||
class tbioudb01
|
||||
{
|
||||
public int id { get; set; }
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void InsertOrUpdate_OnePrimary()
|
||||
{
|
||||
fsql.Delete<tbioudb02>().Where("1=1").ExecuteAffrows();
|
||||
var iou = fsql.InsertOrUpdate<tbioudb02>().IfExistsDoNothing().SetSource(new tbioudb02 { id = 1, name = "01" });
|
||||
var sql = iou.ToSql();
|
||||
Assert.Equal(@"MERGE INTO [tbioudb02] t1
|
||||
USING (SELECT 1 as [id], N'01' as [name] ) t2 ON (t1.[id] = t2.[id])
|
||||
WHEN NOT MATCHED THEN
|
||||
insert ([id], [name])
|
||||
values (t2.[id], t2.[name]);", sql);
|
||||
Assert.Equal(1, iou.ExecuteAffrows());
|
||||
|
||||
iou = fsql.InsertOrUpdate<tbioudb02>().IfExistsDoNothing().SetSource(new tbioudb02 { id = 1, name = "011" });
|
||||
sql = iou.ToSql();
|
||||
Assert.Equal(@"MERGE INTO [tbioudb02] t1
|
||||
USING (SELECT 1 as [id], N'011' as [name] ) t2 ON (t1.[id] = t2.[id])
|
||||
WHEN NOT MATCHED THEN
|
||||
insert ([id], [name])
|
||||
values (t2.[id], t2.[name]);", sql);
|
||||
Assert.Equal(0, iou.ExecuteAffrows());
|
||||
|
||||
iou = fsql.InsertOrUpdate<tbioudb02>().IfExistsDoNothing().SetSource(new tbioudb02 { id = 2, name = "02" });
|
||||
sql = iou.ToSql();
|
||||
Assert.Equal(@"MERGE INTO [tbioudb02] t1
|
||||
USING (SELECT 2 as [id], N'02' as [name] ) t2 ON (t1.[id] = t2.[id])
|
||||
WHEN NOT MATCHED THEN
|
||||
insert ([id], [name])
|
||||
values (t2.[id], t2.[name]);", sql);
|
||||
Assert.Equal(1, iou.ExecuteAffrows());
|
||||
|
||||
iou = fsql.InsertOrUpdate<tbioudb02>().IfExistsDoNothing().SetSource(new[] { new tbioudb02 { id = 1, name = "01" }, new tbioudb02 { id = 2, name = "02" }, new tbioudb02 { id = 3, name = "03" }, new tbioudb02 { id = 4, name = "04" } });
|
||||
sql = iou.ToSql();
|
||||
Assert.Equal(@"MERGE INTO [tbioudb02] t1
|
||||
USING (SELECT 1 as [id], N'01' as [name]
|
||||
UNION ALL
|
||||
SELECT 2, N'02'
|
||||
UNION ALL
|
||||
SELECT 3, N'03'
|
||||
UNION ALL
|
||||
SELECT 4, N'04' ) t2 ON (t1.[id] = t2.[id])
|
||||
WHEN NOT MATCHED THEN
|
||||
insert ([id], [name])
|
||||
values (t2.[id], t2.[name]);", sql);
|
||||
Assert.Equal(2, iou.ExecuteAffrows());
|
||||
|
||||
iou = fsql.InsertOrUpdate<tbioudb02>().IfExistsDoNothing().SetSource(new[] { new tbioudb02 { id = 1, name = "001" }, new tbioudb02 { id = 2, name = "002" }, new tbioudb02 { id = 3, name = "003" }, new tbioudb02 { id = 4, name = "004" } });
|
||||
sql = iou.ToSql();
|
||||
Assert.Equal(@"MERGE INTO [tbioudb02] t1
|
||||
USING (SELECT 1 as [id], N'001' as [name]
|
||||
UNION ALL
|
||||
SELECT 2, N'002'
|
||||
UNION ALL
|
||||
SELECT 3, N'003'
|
||||
UNION ALL
|
||||
SELECT 4, N'004' ) t2 ON (t1.[id] = t2.[id])
|
||||
WHEN NOT MATCHED THEN
|
||||
insert ([id], [name])
|
||||
values (t2.[id], t2.[name]);", sql);
|
||||
Assert.Equal(0, iou.ExecuteAffrows());
|
||||
var lst = fsql.Select<tbioudb02>().Where(a => new[] { 1, 2, 3, 4 }.Contains(a.id)).ToList();
|
||||
Assert.Equal(4, lst.Where(a => a.name == "0" + a.id).Count());
|
||||
}
|
||||
class tbioudb02
|
||||
{
|
||||
public int id { get; set; }
|
||||
public string name { get; set; }
|
||||
}
|
||||
[Fact]
|
||||
public void InsertOrUpdate_OnePrimaryAndIdentity()
|
||||
{
|
||||
fsql.Delete<tbioudb022>().Where("1=1").ExecuteAffrows();
|
||||
var iou = fsql.InsertOrUpdate<tbioudb022>().IfExistsDoNothing().SetSource(new tbioudb022 { id = 1, name = "01" });
|
||||
var sql = iou.ToSql();
|
||||
Assert.Equal(@"SET IDENTITY_INSERT [tbioudb022] ON;
|
||||
MERGE INTO [tbioudb022] t1
|
||||
USING (SELECT 1 as [id], N'01' as [name] ) t2 ON (t1.[id] = t2.[id])
|
||||
WHEN NOT MATCHED THEN
|
||||
insert ([id], [name])
|
||||
values (t2.[id], t2.[name]);;
|
||||
SET IDENTITY_INSERT [tbioudb022] OFF;", sql);
|
||||
Assert.Equal(1, iou.ExecuteAffrows());
|
||||
|
||||
iou = fsql.InsertOrUpdate<tbioudb022>().IfExistsDoNothing().SetSource(new tbioudb022 { id = 1, name = "011" });
|
||||
sql = iou.ToSql();
|
||||
Assert.Equal(@"SET IDENTITY_INSERT [tbioudb022] ON;
|
||||
MERGE INTO [tbioudb022] t1
|
||||
USING (SELECT 1 as [id], N'011' as [name] ) t2 ON (t1.[id] = t2.[id])
|
||||
WHEN NOT MATCHED THEN
|
||||
insert ([id], [name])
|
||||
values (t2.[id], t2.[name]);;
|
||||
SET IDENTITY_INSERT [tbioudb022] OFF;", sql);
|
||||
Assert.Equal(0, iou.ExecuteAffrows());
|
||||
|
||||
iou = fsql.InsertOrUpdate<tbioudb022>().IfExistsDoNothing().SetSource(new tbioudb022 { id = 2, name = "02" });
|
||||
sql = iou.ToSql();
|
||||
Assert.Equal(@"SET IDENTITY_INSERT [tbioudb022] ON;
|
||||
MERGE INTO [tbioudb022] t1
|
||||
USING (SELECT 2 as [id], N'02' as [name] ) t2 ON (t1.[id] = t2.[id])
|
||||
WHEN NOT MATCHED THEN
|
||||
insert ([id], [name])
|
||||
values (t2.[id], t2.[name]);;
|
||||
SET IDENTITY_INSERT [tbioudb022] OFF;", sql);
|
||||
Assert.Equal(1, iou.ExecuteAffrows());
|
||||
|
||||
iou = fsql.InsertOrUpdate<tbioudb022>().IfExistsDoNothing().SetSource(new[] { new tbioudb022 { id = 1, name = "01" }, new tbioudb022 { id = 2, name = "02" }, new tbioudb022 { id = 3, name = "03" }, new tbioudb022 { id = 4, name = "04" } });
|
||||
sql = iou.ToSql();
|
||||
Assert.Equal(@"SET IDENTITY_INSERT [tbioudb022] ON;
|
||||
MERGE INTO [tbioudb022] t1
|
||||
USING (SELECT 1 as [id], N'01' as [name]
|
||||
UNION ALL
|
||||
SELECT 2, N'02'
|
||||
UNION ALL
|
||||
SELECT 3, N'03'
|
||||
UNION ALL
|
||||
SELECT 4, N'04' ) t2 ON (t1.[id] = t2.[id])
|
||||
WHEN NOT MATCHED THEN
|
||||
insert ([id], [name])
|
||||
values (t2.[id], t2.[name]);;
|
||||
SET IDENTITY_INSERT [tbioudb022] OFF;", sql);
|
||||
Assert.Equal(2, iou.ExecuteAffrows());
|
||||
|
||||
iou = fsql.InsertOrUpdate<tbioudb022>().IfExistsDoNothing().SetSource(new[] { new tbioudb022 { id = 1, name = "001" }, new tbioudb022 { id = 2, name = "002" }, new tbioudb022 { id = 3, name = "003" }, new tbioudb022 { id = 4, name = "004" } });
|
||||
sql = iou.ToSql();
|
||||
Assert.Equal(@"SET IDENTITY_INSERT [tbioudb022] ON;
|
||||
MERGE INTO [tbioudb022] t1
|
||||
USING (SELECT 1 as [id], N'001' as [name]
|
||||
UNION ALL
|
||||
SELECT 2, N'002'
|
||||
UNION ALL
|
||||
SELECT 3, N'003'
|
||||
UNION ALL
|
||||
SELECT 4, N'004' ) t2 ON (t1.[id] = t2.[id])
|
||||
WHEN NOT MATCHED THEN
|
||||
insert ([id], [name])
|
||||
values (t2.[id], t2.[name]);;
|
||||
SET IDENTITY_INSERT [tbioudb022] OFF;", sql);
|
||||
Assert.Equal(0, iou.ExecuteAffrows());
|
||||
var lst = fsql.Select<tbioudb022>().Where(a => new[] { 1, 2, 3, 4 }.Contains(a.id)).ToList();
|
||||
Assert.Equal(4, lst.Where(a => a.name == "0" + a.id).Count());
|
||||
|
||||
//--no primary
|
||||
iou = fsql.InsertOrUpdate<tbioudb022>().IfExistsDoNothing().SetSource(new tbioudb022 { name = "01" });
|
||||
sql = iou.ToSql();
|
||||
Assert.Equal(@"INSERT INTO [tbioudb022]([name]) VALUES(N'01')", sql);
|
||||
Assert.Equal(1, iou.ExecuteAffrows());
|
||||
|
||||
iou = fsql.InsertOrUpdate<tbioudb022>().IfExistsDoNothing().SetSource(new tbioudb022 { name = "011" });
|
||||
sql = iou.ToSql();
|
||||
Assert.Equal(@"INSERT INTO [tbioudb022]([name]) VALUES(N'011')", sql);
|
||||
Assert.Equal(1, iou.ExecuteAffrows());
|
||||
|
||||
iou = fsql.InsertOrUpdate<tbioudb022>().IfExistsDoNothing().SetSource(new tbioudb022 { name = "02" });
|
||||
sql = iou.ToSql();
|
||||
Assert.Equal(@"INSERT INTO [tbioudb022]([name]) VALUES(N'02')", sql);
|
||||
Assert.Equal(1, iou.ExecuteAffrows());
|
||||
|
||||
iou = fsql.InsertOrUpdate<tbioudb022>().IfExistsDoNothing().SetSource(new[] { new tbioudb022 { name = "01" }, new tbioudb022 { name = "02" }, new tbioudb022 { name = "03" }, new tbioudb022 { name = "04" } });
|
||||
sql = iou.ToSql();
|
||||
Assert.Equal(@"INSERT INTO [tbioudb022]([name]) VALUES(N'01'), (N'02'), (N'03'), (N'04')", sql);
|
||||
Assert.Equal(4, iou.ExecuteAffrows());
|
||||
|
||||
iou = fsql.InsertOrUpdate<tbioudb022>().IfExistsDoNothing().SetSource(new[] { new tbioudb022 { name = "001" }, new tbioudb022 { name = "002" }, new tbioudb022 { name = "003" }, new tbioudb022 { name = "004" } });
|
||||
sql = iou.ToSql();
|
||||
Assert.Equal(@"INSERT INTO [tbioudb022]([name]) VALUES(N'001'), (N'002'), (N'003'), (N'004')", sql);
|
||||
Assert.Equal(4, iou.ExecuteAffrows());
|
||||
|
||||
//--no primary and yes
|
||||
iou = fsql.InsertOrUpdate<tbioudb022>().IfExistsDoNothing().SetSource(new[] { new tbioudb022 { id = 1, name = "100001" }, new tbioudb022 { name = "00001" }, new tbioudb022 { id = 2, name = "100002" }, new tbioudb022 { name = "00002" }, new tbioudb022 { id = 3, name = "100003" }, new tbioudb022 { name = "00003" }, new tbioudb022 { id = 4, name = "100004" }, new tbioudb022 { name = "00004" } });
|
||||
sql = iou.ToSql();
|
||||
Assert.Equal(@"SET IDENTITY_INSERT [tbioudb022] ON;
|
||||
MERGE INTO [tbioudb022] t1
|
||||
USING (SELECT 1 as [id], N'100001' as [name]
|
||||
UNION ALL
|
||||
SELECT 2, N'100002'
|
||||
UNION ALL
|
||||
SELECT 3, N'100003'
|
||||
UNION ALL
|
||||
SELECT 4, N'100004' ) t2 ON (t1.[id] = t2.[id])
|
||||
WHEN NOT MATCHED THEN
|
||||
insert ([id], [name])
|
||||
values (t2.[id], t2.[name]);;
|
||||
SET IDENTITY_INSERT [tbioudb022] OFF;
|
||||
|
||||
;
|
||||
|
||||
INSERT INTO [tbioudb022]([name]) VALUES(N'00001'), (N'00002'), (N'00003'), (N'00004')", sql);
|
||||
Assert.Equal(4, iou.ExecuteAffrows());
|
||||
lst = fsql.Select<tbioudb022>().Where(a => new[] { 1, 2, 3, 4 }.Contains(a.id)).ToList();
|
||||
Assert.Equal(4, lst.Where(a => a.name == "0" + a.id).Count());
|
||||
}
|
||||
class tbioudb022
|
||||
{
|
||||
[Column(IsIdentity = true)]
|
||||
public int id { get; set; }
|
||||
public string name { get; set; }
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void InsertOrUpdate_TwoPrimary()
|
||||
{
|
||||
fsql.Delete<tbioudb03>().Where("1=1").ExecuteAffrows();
|
||||
var iou = fsql.InsertOrUpdate<tbioudb03>().IfExistsDoNothing().SetSource(new tbioudb03 { id1 = 1, id2 = "01", name = "01" });
|
||||
var sql = iou.ToSql();
|
||||
Assert.Equal(@"MERGE INTO [tbioudb03] t1
|
||||
USING (SELECT 1 as [id1], N'01' as [id2], N'01' as [name] ) t2 ON (t1.[id1] = t2.[id1] AND t1.[id2] = t2.[id2])
|
||||
WHEN NOT MATCHED THEN
|
||||
insert ([id1], [id2], [name])
|
||||
values (t2.[id1], t2.[id2], t2.[name]);", sql);
|
||||
Assert.Equal(1, iou.ExecuteAffrows());
|
||||
|
||||
iou = fsql.InsertOrUpdate<tbioudb03>().IfExistsDoNothing().SetSource(new tbioudb03 { id1 = 1, id2 = "01", name = "011" });
|
||||
sql = iou.ToSql();
|
||||
Assert.Equal(@"MERGE INTO [tbioudb03] t1
|
||||
USING (SELECT 1 as [id1], N'01' as [id2], N'011' as [name] ) t2 ON (t1.[id1] = t2.[id1] AND t1.[id2] = t2.[id2])
|
||||
WHEN NOT MATCHED THEN
|
||||
insert ([id1], [id2], [name])
|
||||
values (t2.[id1], t2.[id2], t2.[name]);", sql);
|
||||
Assert.Equal(0, iou.ExecuteAffrows());
|
||||
|
||||
iou = fsql.InsertOrUpdate<tbioudb03>().IfExistsDoNothing().SetSource(new tbioudb03 { id1 = 2, id2 = "02", name = "02" });
|
||||
sql = iou.ToSql();
|
||||
Assert.Equal(@"MERGE INTO [tbioudb03] t1
|
||||
USING (SELECT 2 as [id1], N'02' as [id2], N'02' as [name] ) t2 ON (t1.[id1] = t2.[id1] AND t1.[id2] = t2.[id2])
|
||||
WHEN NOT MATCHED THEN
|
||||
insert ([id1], [id2], [name])
|
||||
values (t2.[id1], t2.[id2], t2.[name]);", sql);
|
||||
Assert.Equal(1, iou.ExecuteAffrows());
|
||||
|
||||
iou = fsql.InsertOrUpdate<tbioudb03>().IfExistsDoNothing().SetSource(new[] { new tbioudb03 { id1 = 1, id2 = "01", name = "01" }, new tbioudb03 { id1 = 2, id2 = "02", name = "02" }, new tbioudb03 { id1 = 3, id2 = "03", name = "03" }, new tbioudb03 { id1 = 4, id2 = "04", name = "04" } });
|
||||
sql = iou.ToSql();
|
||||
Assert.Equal(@"MERGE INTO [tbioudb03] t1
|
||||
USING (SELECT 1 as [id1], N'01' as [id2], N'01' as [name]
|
||||
UNION ALL
|
||||
SELECT 2, N'02', N'02'
|
||||
UNION ALL
|
||||
SELECT 3, N'03', N'03'
|
||||
UNION ALL
|
||||
SELECT 4, N'04', N'04' ) t2 ON (t1.[id1] = t2.[id1] AND t1.[id2] = t2.[id2])
|
||||
WHEN NOT MATCHED THEN
|
||||
insert ([id1], [id2], [name])
|
||||
values (t2.[id1], t2.[id2], t2.[name]);", sql);
|
||||
Assert.Equal(2, iou.ExecuteAffrows());
|
||||
|
||||
iou = fsql.InsertOrUpdate<tbioudb03>().IfExistsDoNothing().SetSource(new[] { new tbioudb03 { id1 = 1, id2 = "01", name = "001" }, new tbioudb03 { id1 = 2, id2 = "02", name = "002" }, new tbioudb03 { id1 = 3, id2 = "03", name = "003" }, new tbioudb03 { id1 = 4, id2 = "04", name = "004" } });
|
||||
sql = iou.ToSql();
|
||||
Assert.Equal(@"MERGE INTO [tbioudb03] t1
|
||||
USING (SELECT 1 as [id1], N'01' as [id2], N'001' as [name]
|
||||
UNION ALL
|
||||
SELECT 2, N'02', N'002'
|
||||
UNION ALL
|
||||
SELECT 3, N'03', N'003'
|
||||
UNION ALL
|
||||
SELECT 4, N'04', N'004' ) t2 ON (t1.[id1] = t2.[id1] AND t1.[id2] = t2.[id2])
|
||||
WHEN NOT MATCHED THEN
|
||||
insert ([id1], [id2], [name])
|
||||
values (t2.[id1], t2.[id2], t2.[name]);", sql);
|
||||
Assert.Equal(0, iou.ExecuteAffrows());
|
||||
var lst = fsql.Select<tbioudb03>().Where(a => a.id1 == 1 && a.id2 == "01" || a.id1 == 2 && a.id2 == "02" || a.id1 == 3 && a.id2 == "03" || a.id1 == 4 && a.id2 == "04").ToList();
|
||||
Assert.Equal(4, lst.Where(a => a.name == "0" + a.id1).Count());
|
||||
}
|
||||
class tbioudb03
|
||||
{
|
||||
[Column(IsPrimary = true)]
|
||||
public int id1 { get; set; }
|
||||
[Column(IsPrimary = true)]
|
||||
public string id2 { get; set; }
|
||||
public string name { get; set; }
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void InsertOrUpdate_OnePrimaryAndVersionAndCanUpdate()
|
||||
{
|
||||
fsql.Delete<tbioudb04>().Where("1=1").ExecuteAffrows();
|
||||
var iou = fsql.InsertOrUpdate<tbioudb04>().IfExistsDoNothing().SetSource(new tbioudb04 { id = 1, name = "01" });
|
||||
var sql = iou.ToSql();
|
||||
Assert.Equal(@"MERGE INTO [tbioudb04] t1
|
||||
USING (SELECT 1 as [id], N'01' as [name], 0 as [version], getdate() as [CreateTime] ) t2 ON (t1.[id] = t2.[id])
|
||||
WHEN NOT MATCHED THEN
|
||||
insert ([id], [name], [version], [CreateTime])
|
||||
values (t2.[id], t2.[name], t2.[version], t2.[CreateTime]);", sql);
|
||||
Assert.Equal(1, iou.ExecuteAffrows());
|
||||
|
||||
iou = fsql.InsertOrUpdate<tbioudb04>().IfExistsDoNothing().SetSource(new tbioudb04 { id = 1, name = "011" });
|
||||
sql = iou.ToSql();
|
||||
Assert.Equal(@"MERGE INTO [tbioudb04] t1
|
||||
USING (SELECT 1 as [id], N'011' as [name], 0 as [version], getdate() as [CreateTime] ) t2 ON (t1.[id] = t2.[id])
|
||||
WHEN NOT MATCHED THEN
|
||||
insert ([id], [name], [version], [CreateTime])
|
||||
values (t2.[id], t2.[name], t2.[version], t2.[CreateTime]);", sql);
|
||||
Assert.Equal(0, iou.ExecuteAffrows());
|
||||
|
||||
iou = fsql.InsertOrUpdate<tbioudb04>().IfExistsDoNothing().SetSource(new tbioudb04 { id = 2, name = "02" });
|
||||
sql = iou.ToSql();
|
||||
Assert.Equal(@"MERGE INTO [tbioudb04] t1
|
||||
USING (SELECT 2 as [id], N'02' as [name], 0 as [version], getdate() as [CreateTime] ) t2 ON (t1.[id] = t2.[id])
|
||||
WHEN NOT MATCHED THEN
|
||||
insert ([id], [name], [version], [CreateTime])
|
||||
values (t2.[id], t2.[name], t2.[version], t2.[CreateTime]);", sql);
|
||||
Assert.Equal(1, iou.ExecuteAffrows());
|
||||
|
||||
iou = fsql.InsertOrUpdate<tbioudb04>().IfExistsDoNothing().SetSource(new[] { new tbioudb04 { id = 1, name = "01" }, new tbioudb04 { id = 2, name = "02" }, new tbioudb04 { id = 3, name = "03" }, new tbioudb04 { id = 4, name = "04" } });
|
||||
sql = iou.ToSql();
|
||||
Assert.Equal(@"MERGE INTO [tbioudb04] t1
|
||||
USING (SELECT 1 as [id], N'01' as [name], 0 as [version], getdate() as [CreateTime]
|
||||
UNION ALL
|
||||
SELECT 2, N'02', 0, getdate()
|
||||
UNION ALL
|
||||
SELECT 3, N'03', 0, getdate()
|
||||
UNION ALL
|
||||
SELECT 4, N'04', 0, getdate() ) t2 ON (t1.[id] = t2.[id])
|
||||
WHEN NOT MATCHED THEN
|
||||
insert ([id], [name], [version], [CreateTime])
|
||||
values (t2.[id], t2.[name], t2.[version], t2.[CreateTime]);", sql);
|
||||
Assert.Equal(2, iou.ExecuteAffrows());
|
||||
|
||||
iou = fsql.InsertOrUpdate<tbioudb04>().IfExistsDoNothing().SetSource(new[] { new tbioudb04 { id = 1, name = "001" }, new tbioudb04 { id = 2, name = "002" }, new tbioudb04 { id = 3, name = "003" }, new tbioudb04 { id = 4, name = "004" } });
|
||||
sql = iou.ToSql();
|
||||
Assert.Equal(@"MERGE INTO [tbioudb04] t1
|
||||
USING (SELECT 1 as [id], N'001' as [name], 0 as [version], getdate() as [CreateTime]
|
||||
UNION ALL
|
||||
SELECT 2, N'002', 0, getdate()
|
||||
UNION ALL
|
||||
SELECT 3, N'003', 0, getdate()
|
||||
UNION ALL
|
||||
SELECT 4, N'004', 0, getdate() ) t2 ON (t1.[id] = t2.[id])
|
||||
WHEN NOT MATCHED THEN
|
||||
insert ([id], [name], [version], [CreateTime])
|
||||
values (t2.[id], t2.[name], t2.[version], t2.[CreateTime]);", sql);
|
||||
Assert.Equal(0, iou.ExecuteAffrows());
|
||||
var lst = fsql.Select<tbioudb04>().Where(a => new[] { 1, 2, 3, 4 }.Contains(a.id)).ToList();
|
||||
Assert.Equal(4, lst.Where(a => a.name == "0" + a.id).Count());
|
||||
}
|
||||
class tbioudb04
|
||||
{
|
||||
public int id { get; set; }
|
||||
public string name { get; set; }
|
||||
[Column(IsVersion = true)]
|
||||
public int version { get; set; }
|
||||
[Column(CanUpdate = false, ServerTime = DateTimeKind.Local)]
|
||||
public DateTime CreateTime { get; set; }
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,464 @@
|
||||
using FreeSql.DataAnnotations;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Xunit;
|
||||
|
||||
namespace FreeSql.Tests.Custom.SqlServer
|
||||
{
|
||||
public class SqlServerInsertOrUpdateTest
|
||||
{
|
||||
IFreeSql fsql => g.sqlserver;
|
||||
|
||||
[Fact]
|
||||
public void InsertOrUpdate_OnlyPrimary()
|
||||
{
|
||||
fsql.Delete<tbiou01>().Where("1=1").ExecuteAffrows();
|
||||
var iou = fsql.InsertOrUpdate<tbiou01>().SetSource(new tbiou01 { id = 1 });
|
||||
var sql = iou.ToSql();
|
||||
Assert.Equal(@"MERGE INTO [tbiou01] t1
|
||||
USING (SELECT 1 as [id] ) t2 ON (t1.[id] = t2.[id])
|
||||
WHEN NOT MATCHED THEN
|
||||
insert ([id])
|
||||
values (t2.[id]);", sql);
|
||||
Assert.Equal(1, iou.ExecuteAffrows());
|
||||
|
||||
iou = fsql.InsertOrUpdate<tbiou01>().SetSource(new tbiou01 { id = 1 });
|
||||
sql = iou.ToSql();
|
||||
Assert.Equal(@"MERGE INTO [tbiou01] t1
|
||||
USING (SELECT 1 as [id] ) t2 ON (t1.[id] = t2.[id])
|
||||
WHEN NOT MATCHED THEN
|
||||
insert ([id])
|
||||
values (t2.[id]);", sql);
|
||||
Assert.Equal(0, iou.ExecuteAffrows());
|
||||
|
||||
iou = fsql.InsertOrUpdate<tbiou01>().SetSource(new tbiou01 { id = 2 });
|
||||
sql = iou.ToSql();
|
||||
Assert.Equal(@"MERGE INTO [tbiou01] t1
|
||||
USING (SELECT 2 as [id] ) t2 ON (t1.[id] = t2.[id])
|
||||
WHEN NOT MATCHED THEN
|
||||
insert ([id])
|
||||
values (t2.[id]);", sql);
|
||||
Assert.Equal(1, iou.ExecuteAffrows());
|
||||
|
||||
iou = fsql.InsertOrUpdate<tbiou01>().SetSource(new[] { new tbiou01 { id = 1 }, new tbiou01 { id = 2 }, new tbiou01 { id = 3 }, new tbiou01 { id = 4 } });
|
||||
sql = iou.ToSql();
|
||||
Assert.Equal(@"MERGE INTO [tbiou01] t1
|
||||
USING (SELECT 1 as [id]
|
||||
UNION ALL
|
||||
SELECT 2
|
||||
UNION ALL
|
||||
SELECT 3
|
||||
UNION ALL
|
||||
SELECT 4 ) t2 ON (t1.[id] = t2.[id])
|
||||
WHEN NOT MATCHED THEN
|
||||
insert ([id])
|
||||
values (t2.[id]);", sql);
|
||||
Assert.Equal(2, iou.ExecuteAffrows());
|
||||
|
||||
iou = fsql.InsertOrUpdate<tbiou01>().SetSource(new[] { new tbiou01 { id = 1 }, new tbiou01 { id = 2 }, new tbiou01 { id = 3 }, new tbiou01 { id = 4 } });
|
||||
sql = iou.ToSql();
|
||||
Assert.Equal(@"MERGE INTO [tbiou01] t1
|
||||
USING (SELECT 1 as [id]
|
||||
UNION ALL
|
||||
SELECT 2
|
||||
UNION ALL
|
||||
SELECT 3
|
||||
UNION ALL
|
||||
SELECT 4 ) t2 ON (t1.[id] = t2.[id])
|
||||
WHEN NOT MATCHED THEN
|
||||
insert ([id])
|
||||
values (t2.[id]);", sql);
|
||||
Assert.Equal(0, iou.ExecuteAffrows());
|
||||
}
|
||||
class tbiou01
|
||||
{
|
||||
public int id { get; set; }
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void InsertOrUpdate_OnePrimary()
|
||||
{
|
||||
fsql.Delete<tbiou02>().Where("1=1").ExecuteAffrows();
|
||||
var iou = fsql.InsertOrUpdate<tbiou02>().SetSource(new tbiou02 { id = 1, name = "01" });
|
||||
var sql = iou.ToSql();
|
||||
Assert.Equal(@"MERGE INTO [tbiou02] t1
|
||||
USING (SELECT 1 as [id], N'01' as [name] ) t2 ON (t1.[id] = t2.[id])
|
||||
WHEN MATCHED THEN
|
||||
update set [name] = t2.[name]
|
||||
WHEN NOT MATCHED THEN
|
||||
insert ([id], [name])
|
||||
values (t2.[id], t2.[name]);", sql);
|
||||
Assert.Equal(1, iou.ExecuteAffrows());
|
||||
|
||||
iou = fsql.InsertOrUpdate<tbiou02>().SetSource(new tbiou02 { id = 1, name = "011" });
|
||||
sql = iou.ToSql();
|
||||
Assert.Equal(@"MERGE INTO [tbiou02] t1
|
||||
USING (SELECT 1 as [id], N'011' as [name] ) t2 ON (t1.[id] = t2.[id])
|
||||
WHEN MATCHED THEN
|
||||
update set [name] = t2.[name]
|
||||
WHEN NOT MATCHED THEN
|
||||
insert ([id], [name])
|
||||
values (t2.[id], t2.[name]);", sql);
|
||||
Assert.Equal(1, iou.ExecuteAffrows());
|
||||
|
||||
iou = fsql.InsertOrUpdate<tbiou02>().SetSource(new tbiou02 { id = 2, name = "02" });
|
||||
sql = iou.ToSql();
|
||||
Assert.Equal(@"MERGE INTO [tbiou02] t1
|
||||
USING (SELECT 2 as [id], N'02' as [name] ) t2 ON (t1.[id] = t2.[id])
|
||||
WHEN MATCHED THEN
|
||||
update set [name] = t2.[name]
|
||||
WHEN NOT MATCHED THEN
|
||||
insert ([id], [name])
|
||||
values (t2.[id], t2.[name]);", sql);
|
||||
Assert.Equal(1, iou.ExecuteAffrows());
|
||||
|
||||
iou = fsql.InsertOrUpdate<tbiou02>().SetSource(new[] { new tbiou02 { id = 1, name = "01" }, new tbiou02 { id = 2, name = "02" }, new tbiou02 { id = 3, name = "03" }, new tbiou02 { id = 4, name = "04" } });
|
||||
sql = iou.ToSql();
|
||||
Assert.Equal(@"MERGE INTO [tbiou02] t1
|
||||
USING (SELECT 1 as [id], N'01' as [name]
|
||||
UNION ALL
|
||||
SELECT 2, N'02'
|
||||
UNION ALL
|
||||
SELECT 3, N'03'
|
||||
UNION ALL
|
||||
SELECT 4, N'04' ) t2 ON (t1.[id] = t2.[id])
|
||||
WHEN MATCHED THEN
|
||||
update set [name] = t2.[name]
|
||||
WHEN NOT MATCHED THEN
|
||||
insert ([id], [name])
|
||||
values (t2.[id], t2.[name]);", sql);
|
||||
Assert.Equal(4, iou.ExecuteAffrows());
|
||||
|
||||
iou = fsql.InsertOrUpdate<tbiou02>().SetSource(new[] { new tbiou02 { id = 1, name = "001" }, new tbiou02 { id = 2, name = "002" }, new tbiou02 { id = 3, name = "003" }, new tbiou02 { id = 4, name = "004" } });
|
||||
sql = iou.ToSql();
|
||||
Assert.Equal(@"MERGE INTO [tbiou02] t1
|
||||
USING (SELECT 1 as [id], N'001' as [name]
|
||||
UNION ALL
|
||||
SELECT 2, N'002'
|
||||
UNION ALL
|
||||
SELECT 3, N'003'
|
||||
UNION ALL
|
||||
SELECT 4, N'004' ) t2 ON (t1.[id] = t2.[id])
|
||||
WHEN MATCHED THEN
|
||||
update set [name] = t2.[name]
|
||||
WHEN NOT MATCHED THEN
|
||||
insert ([id], [name])
|
||||
values (t2.[id], t2.[name]);", sql);
|
||||
Assert.Equal(4, iou.ExecuteAffrows());
|
||||
var lst = fsql.Select<tbiou02>().Where(a => new[] { 1, 2, 3, 4 }.Contains(a.id)).ToList();
|
||||
Assert.Equal(4, lst.Where(a => a.name == "00" + a.id).Count());
|
||||
}
|
||||
class tbiou02
|
||||
{
|
||||
public int id { get; set; }
|
||||
public string name { get; set; }
|
||||
}
|
||||
[Fact]
|
||||
public void InsertOrUpdate_OnePrimaryAndIdentity()
|
||||
{
|
||||
fsql.Delete<tbiou022>().Where("1=1").ExecuteAffrows();
|
||||
var iou = fsql.InsertOrUpdate<tbiou022>().SetSource(new tbiou022 { id = 1, name = "01" });
|
||||
var sql = iou.ToSql();
|
||||
Assert.Equal(@"SET IDENTITY_INSERT [tbiou022] ON;
|
||||
MERGE INTO [tbiou022] t1
|
||||
USING (SELECT 1 as [id], N'01' as [name] ) t2 ON (t1.[id] = t2.[id])
|
||||
WHEN MATCHED THEN
|
||||
update set [name] = t2.[name]
|
||||
WHEN NOT MATCHED THEN
|
||||
insert ([id], [name])
|
||||
values (t2.[id], t2.[name]);;
|
||||
SET IDENTITY_INSERT [tbiou022] OFF;", sql);
|
||||
Assert.Equal(1, iou.ExecuteAffrows());
|
||||
|
||||
iou = fsql.InsertOrUpdate<tbiou022>().SetSource(new tbiou022 { id = 1, name = "011" });
|
||||
sql = iou.ToSql();
|
||||
Assert.Equal(@"SET IDENTITY_INSERT [tbiou022] ON;
|
||||
MERGE INTO [tbiou022] t1
|
||||
USING (SELECT 1 as [id], N'011' as [name] ) t2 ON (t1.[id] = t2.[id])
|
||||
WHEN MATCHED THEN
|
||||
update set [name] = t2.[name]
|
||||
WHEN NOT MATCHED THEN
|
||||
insert ([id], [name])
|
||||
values (t2.[id], t2.[name]);;
|
||||
SET IDENTITY_INSERT [tbiou022] OFF;", sql);
|
||||
Assert.Equal(1, iou.ExecuteAffrows());
|
||||
|
||||
iou = fsql.InsertOrUpdate<tbiou022>().SetSource(new tbiou022 { id = 2, name = "02" });
|
||||
sql = iou.ToSql();
|
||||
Assert.Equal(@"SET IDENTITY_INSERT [tbiou022] ON;
|
||||
MERGE INTO [tbiou022] t1
|
||||
USING (SELECT 2 as [id], N'02' as [name] ) t2 ON (t1.[id] = t2.[id])
|
||||
WHEN MATCHED THEN
|
||||
update set [name] = t2.[name]
|
||||
WHEN NOT MATCHED THEN
|
||||
insert ([id], [name])
|
||||
values (t2.[id], t2.[name]);;
|
||||
SET IDENTITY_INSERT [tbiou022] OFF;", sql);
|
||||
Assert.Equal(1, iou.ExecuteAffrows());
|
||||
|
||||
iou = fsql.InsertOrUpdate<tbiou022>().SetSource(new[] { new tbiou022 { id = 1, name = "01" }, new tbiou022 { id = 2, name = "02" }, new tbiou022 { id = 3, name = "03" }, new tbiou022 { id = 4, name = "04" } });
|
||||
sql = iou.ToSql();
|
||||
Assert.Equal(@"SET IDENTITY_INSERT [tbiou022] ON;
|
||||
MERGE INTO [tbiou022] t1
|
||||
USING (SELECT 1 as [id], N'01' as [name]
|
||||
UNION ALL
|
||||
SELECT 2, N'02'
|
||||
UNION ALL
|
||||
SELECT 3, N'03'
|
||||
UNION ALL
|
||||
SELECT 4, N'04' ) t2 ON (t1.[id] = t2.[id])
|
||||
WHEN MATCHED THEN
|
||||
update set [name] = t2.[name]
|
||||
WHEN NOT MATCHED THEN
|
||||
insert ([id], [name])
|
||||
values (t2.[id], t2.[name]);;
|
||||
SET IDENTITY_INSERT [tbiou022] OFF;", sql);
|
||||
Assert.Equal(4, iou.ExecuteAffrows());
|
||||
|
||||
iou = fsql.InsertOrUpdate<tbiou022>().SetSource(new[] { new tbiou022 { id = 1, name = "001" }, new tbiou022 { id = 2, name = "002" }, new tbiou022 { id = 3, name = "003" }, new tbiou022 { id = 4, name = "004" } });
|
||||
sql = iou.ToSql();
|
||||
Assert.Equal(@"SET IDENTITY_INSERT [tbiou022] ON;
|
||||
MERGE INTO [tbiou022] t1
|
||||
USING (SELECT 1 as [id], N'001' as [name]
|
||||
UNION ALL
|
||||
SELECT 2, N'002'
|
||||
UNION ALL
|
||||
SELECT 3, N'003'
|
||||
UNION ALL
|
||||
SELECT 4, N'004' ) t2 ON (t1.[id] = t2.[id])
|
||||
WHEN MATCHED THEN
|
||||
update set [name] = t2.[name]
|
||||
WHEN NOT MATCHED THEN
|
||||
insert ([id], [name])
|
||||
values (t2.[id], t2.[name]);;
|
||||
SET IDENTITY_INSERT [tbiou022] OFF;", sql);
|
||||
Assert.Equal(4, iou.ExecuteAffrows());
|
||||
var lst = fsql.Select<tbiou022>().Where(a => new[] { 1, 2, 3, 4 }.Contains(a.id)).ToList();
|
||||
Assert.Equal(4, lst.Where(a => a.name == "00" + a.id).Count());
|
||||
|
||||
//--no primary
|
||||
iou = fsql.InsertOrUpdate<tbiou022>().SetSource(new tbiou022 { name = "01" });
|
||||
sql = iou.ToSql();
|
||||
Assert.Equal(@"INSERT INTO [tbiou022]([name]) VALUES(N'01')", sql);
|
||||
Assert.Equal(1, iou.ExecuteAffrows());
|
||||
|
||||
iou = fsql.InsertOrUpdate<tbiou022>().SetSource(new tbiou022 { name = "011" });
|
||||
sql = iou.ToSql();
|
||||
Assert.Equal(@"INSERT INTO [tbiou022]([name]) VALUES(N'011')", sql);
|
||||
Assert.Equal(1, iou.ExecuteAffrows());
|
||||
|
||||
iou = fsql.InsertOrUpdate<tbiou022>().SetSource(new tbiou022 { name = "02" });
|
||||
sql = iou.ToSql();
|
||||
Assert.Equal(@"INSERT INTO [tbiou022]([name]) VALUES(N'02')", sql);
|
||||
Assert.Equal(1, iou.ExecuteAffrows());
|
||||
|
||||
iou = fsql.InsertOrUpdate<tbiou022>().SetSource(new[] { new tbiou022 { name = "01" }, new tbiou022 { name = "02" }, new tbiou022 { name = "03" }, new tbiou022 { name = "04" } });
|
||||
sql = iou.ToSql();
|
||||
Assert.Equal(@"INSERT INTO [tbiou022]([name]) VALUES(N'01'), (N'02'), (N'03'), (N'04')", sql);
|
||||
Assert.Equal(4, iou.ExecuteAffrows());
|
||||
|
||||
iou = fsql.InsertOrUpdate<tbiou022>().SetSource(new[] { new tbiou022 { name = "001" }, new tbiou022 { name = "002" }, new tbiou022 { name = "003" }, new tbiou022 { name = "004" } });
|
||||
sql = iou.ToSql();
|
||||
Assert.Equal(@"INSERT INTO [tbiou022]([name]) VALUES(N'001'), (N'002'), (N'003'), (N'004')", sql);
|
||||
Assert.Equal(4, iou.ExecuteAffrows());
|
||||
|
||||
//--no primary and yes
|
||||
iou = fsql.InsertOrUpdate<tbiou022>().SetSource(new[] { new tbiou022 { id = 1, name = "100001" }, new tbiou022 { name = "00001" }, new tbiou022 { id = 2, name = "100002" }, new tbiou022 { name = "00002" }, new tbiou022 { id = 3, name = "100003" }, new tbiou022 { name = "00003" }, new tbiou022 { id = 4, name = "100004" }, new tbiou022 { name = "00004" } });
|
||||
sql = iou.ToSql();
|
||||
Assert.Equal(@"SET IDENTITY_INSERT [tbiou022] ON;
|
||||
MERGE INTO [tbiou022] t1
|
||||
USING (SELECT 1 as [id], N'100001' as [name]
|
||||
UNION ALL
|
||||
SELECT 2, N'100002'
|
||||
UNION ALL
|
||||
SELECT 3, N'100003'
|
||||
UNION ALL
|
||||
SELECT 4, N'100004' ) t2 ON (t1.[id] = t2.[id])
|
||||
WHEN MATCHED THEN
|
||||
update set [name] = t2.[name]
|
||||
WHEN NOT MATCHED THEN
|
||||
insert ([id], [name])
|
||||
values (t2.[id], t2.[name]);;
|
||||
SET IDENTITY_INSERT [tbiou022] OFF;
|
||||
|
||||
;
|
||||
|
||||
INSERT INTO [tbiou022]([name]) VALUES(N'00001'), (N'00002'), (N'00003'), (N'00004')", sql);
|
||||
Assert.Equal(8, iou.ExecuteAffrows());
|
||||
lst = fsql.Select<tbiou022>().Where(a => new[] { 1, 2, 3, 4 }.Contains(a.id)).ToList();
|
||||
Assert.Equal(4, lst.Where(a => a.name == "10000" + a.id).Count());
|
||||
}
|
||||
class tbiou022
|
||||
{
|
||||
[Column(IsIdentity = true)]
|
||||
public int id { get; set; }
|
||||
public string name { get; set; }
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void InsertOrUpdate_TwoPrimary()
|
||||
{
|
||||
fsql.Delete<tbiou03>().Where("1=1").ExecuteAffrows();
|
||||
var iou = fsql.InsertOrUpdate<tbiou03>().SetSource(new tbiou03 { id1 = 1, id2 = "01", name = "01" });
|
||||
var sql = iou.ToSql();
|
||||
Assert.Equal(@"MERGE INTO [tbiou03] t1
|
||||
USING (SELECT 1 as [id1], N'01' as [id2], N'01' as [name] ) t2 ON (t1.[id1] = t2.[id1] AND t1.[id2] = t2.[id2])
|
||||
WHEN MATCHED THEN
|
||||
update set [name] = t2.[name]
|
||||
WHEN NOT MATCHED THEN
|
||||
insert ([id1], [id2], [name])
|
||||
values (t2.[id1], t2.[id2], t2.[name]);", sql);
|
||||
Assert.Equal(1, iou.ExecuteAffrows());
|
||||
|
||||
iou = fsql.InsertOrUpdate<tbiou03>().SetSource(new tbiou03 { id1 = 1, id2 = "01", name = "011" });
|
||||
sql = iou.ToSql();
|
||||
Assert.Equal(@"MERGE INTO [tbiou03] t1
|
||||
USING (SELECT 1 as [id1], N'01' as [id2], N'011' as [name] ) t2 ON (t1.[id1] = t2.[id1] AND t1.[id2] = t2.[id2])
|
||||
WHEN MATCHED THEN
|
||||
update set [name] = t2.[name]
|
||||
WHEN NOT MATCHED THEN
|
||||
insert ([id1], [id2], [name])
|
||||
values (t2.[id1], t2.[id2], t2.[name]);", sql);
|
||||
Assert.Equal(1, iou.ExecuteAffrows());
|
||||
|
||||
iou = fsql.InsertOrUpdate<tbiou03>().SetSource(new tbiou03 { id1 = 2, id2 = "02", name = "02" });
|
||||
sql = iou.ToSql();
|
||||
Assert.Equal(@"MERGE INTO [tbiou03] t1
|
||||
USING (SELECT 2 as [id1], N'02' as [id2], N'02' as [name] ) t2 ON (t1.[id1] = t2.[id1] AND t1.[id2] = t2.[id2])
|
||||
WHEN MATCHED THEN
|
||||
update set [name] = t2.[name]
|
||||
WHEN NOT MATCHED THEN
|
||||
insert ([id1], [id2], [name])
|
||||
values (t2.[id1], t2.[id2], t2.[name]);", sql);
|
||||
Assert.Equal(1, iou.ExecuteAffrows());
|
||||
|
||||
iou = fsql.InsertOrUpdate<tbiou03>().SetSource(new[] { new tbiou03 { id1 = 1, id2 = "01", name = "01" }, new tbiou03 { id1 = 2, id2 = "02", name = "02" }, new tbiou03 { id1 = 3, id2 = "03", name = "03" }, new tbiou03 { id1 = 4, id2 = "04", name = "04" } });
|
||||
sql = iou.ToSql();
|
||||
Assert.Equal(@"MERGE INTO [tbiou03] t1
|
||||
USING (SELECT 1 as [id1], N'01' as [id2], N'01' as [name]
|
||||
UNION ALL
|
||||
SELECT 2, N'02', N'02'
|
||||
UNION ALL
|
||||
SELECT 3, N'03', N'03'
|
||||
UNION ALL
|
||||
SELECT 4, N'04', N'04' ) t2 ON (t1.[id1] = t2.[id1] AND t1.[id2] = t2.[id2])
|
||||
WHEN MATCHED THEN
|
||||
update set [name] = t2.[name]
|
||||
WHEN NOT MATCHED THEN
|
||||
insert ([id1], [id2], [name])
|
||||
values (t2.[id1], t2.[id2], t2.[name]);", sql);
|
||||
Assert.Equal(4, iou.ExecuteAffrows());
|
||||
|
||||
iou = fsql.InsertOrUpdate<tbiou03>().SetSource(new[] { new tbiou03 { id1 = 1, id2 = "01", name = "001" }, new tbiou03 { id1 = 2, id2 = "02", name = "002" }, new tbiou03 { id1 = 3, id2 = "03", name = "003" }, new tbiou03 { id1 = 4, id2 = "04", name = "004" } });
|
||||
sql = iou.ToSql();
|
||||
Assert.Equal(@"MERGE INTO [tbiou03] t1
|
||||
USING (SELECT 1 as [id1], N'01' as [id2], N'001' as [name]
|
||||
UNION ALL
|
||||
SELECT 2, N'02', N'002'
|
||||
UNION ALL
|
||||
SELECT 3, N'03', N'003'
|
||||
UNION ALL
|
||||
SELECT 4, N'04', N'004' ) t2 ON (t1.[id1] = t2.[id1] AND t1.[id2] = t2.[id2])
|
||||
WHEN MATCHED THEN
|
||||
update set [name] = t2.[name]
|
||||
WHEN NOT MATCHED THEN
|
||||
insert ([id1], [id2], [name])
|
||||
values (t2.[id1], t2.[id2], t2.[name]);", sql);
|
||||
Assert.Equal(4, iou.ExecuteAffrows());
|
||||
var lst = fsql.Select<tbiou03>().Where(a => a.id1 == 1 && a.id2 == "01" || a.id1 == 2 && a.id2 == "02" || a.id1 == 3 && a.id2 == "03" || a.id1 == 4 && a.id2 == "04").ToList();
|
||||
Assert.Equal(4, lst.Where(a => a.name == "00" + a.id1).Count());
|
||||
}
|
||||
class tbiou03
|
||||
{
|
||||
[Column(IsPrimary = true)]
|
||||
public int id1 { get; set; }
|
||||
[Column(IsPrimary = true)]
|
||||
public string id2 { get; set; }
|
||||
public string name { get; set; }
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void InsertOrUpdate_OnePrimaryAndVersionAndCanUpdate()
|
||||
{
|
||||
fsql.Delete<tbiou04>().Where("1=1").ExecuteAffrows();
|
||||
var iou = fsql.InsertOrUpdate<tbiou04>().SetSource(new tbiou04 { id = 1, name = "01" });
|
||||
var sql = iou.ToSql();
|
||||
Assert.Equal(@"MERGE INTO [tbiou04] t1
|
||||
USING (SELECT 1 as [id], N'01' as [name], 0 as [version], getdate() as [CreateTime] ) t2 ON (t1.[id] = t2.[id])
|
||||
WHEN MATCHED THEN
|
||||
update set [name] = t2.[name], [version] = t1.[version] + 1
|
||||
WHEN NOT MATCHED THEN
|
||||
insert ([id], [name], [version], [CreateTime])
|
||||
values (t2.[id], t2.[name], t2.[version], t2.[CreateTime]);", sql);
|
||||
Assert.Equal(1, iou.ExecuteAffrows());
|
||||
|
||||
iou = fsql.InsertOrUpdate<tbiou04>().SetSource(new tbiou04 { id = 1, name = "011" });
|
||||
sql = iou.ToSql();
|
||||
Assert.Equal(@"MERGE INTO [tbiou04] t1
|
||||
USING (SELECT 1 as [id], N'011' as [name], 0 as [version], getdate() as [CreateTime] ) t2 ON (t1.[id] = t2.[id])
|
||||
WHEN MATCHED THEN
|
||||
update set [name] = t2.[name], [version] = t1.[version] + 1
|
||||
WHEN NOT MATCHED THEN
|
||||
insert ([id], [name], [version], [CreateTime])
|
||||
values (t2.[id], t2.[name], t2.[version], t2.[CreateTime]);", sql);
|
||||
Assert.Equal(1, iou.ExecuteAffrows());
|
||||
|
||||
iou = fsql.InsertOrUpdate<tbiou04>().SetSource(new tbiou04 { id = 2, name = "02" });
|
||||
sql = iou.ToSql();
|
||||
Assert.Equal(@"MERGE INTO [tbiou04] t1
|
||||
USING (SELECT 2 as [id], N'02' as [name], 0 as [version], getdate() as [CreateTime] ) t2 ON (t1.[id] = t2.[id])
|
||||
WHEN MATCHED THEN
|
||||
update set [name] = t2.[name], [version] = t1.[version] + 1
|
||||
WHEN NOT MATCHED THEN
|
||||
insert ([id], [name], [version], [CreateTime])
|
||||
values (t2.[id], t2.[name], t2.[version], t2.[CreateTime]);", sql);
|
||||
Assert.Equal(1, iou.ExecuteAffrows());
|
||||
|
||||
iou = fsql.InsertOrUpdate<tbiou04>().SetSource(new[] { new tbiou04 { id = 1, name = "01" }, new tbiou04 { id = 2, name = "02" }, new tbiou04 { id = 3, name = "03" }, new tbiou04 { id = 4, name = "04" } });
|
||||
sql = iou.ToSql();
|
||||
Assert.Equal(@"MERGE INTO [tbiou04] t1
|
||||
USING (SELECT 1 as [id], N'01' as [name], 0 as [version], getdate() as [CreateTime]
|
||||
UNION ALL
|
||||
SELECT 2, N'02', 0, getdate()
|
||||
UNION ALL
|
||||
SELECT 3, N'03', 0, getdate()
|
||||
UNION ALL
|
||||
SELECT 4, N'04', 0, getdate() ) t2 ON (t1.[id] = t2.[id])
|
||||
WHEN MATCHED THEN
|
||||
update set [name] = t2.[name], [version] = t1.[version] + 1
|
||||
WHEN NOT MATCHED THEN
|
||||
insert ([id], [name], [version], [CreateTime])
|
||||
values (t2.[id], t2.[name], t2.[version], t2.[CreateTime]);", sql);
|
||||
Assert.Equal(4, iou.ExecuteAffrows());
|
||||
|
||||
iou = fsql.InsertOrUpdate<tbiou04>().SetSource(new[] { new tbiou04 { id = 1, name = "001" }, new tbiou04 { id = 2, name = "002" }, new tbiou04 { id = 3, name = "003" }, new tbiou04 { id = 4, name = "004" } });
|
||||
sql = iou.ToSql();
|
||||
Assert.Equal(@"MERGE INTO [tbiou04] t1
|
||||
USING (SELECT 1 as [id], N'001' as [name], 0 as [version], getdate() as [CreateTime]
|
||||
UNION ALL
|
||||
SELECT 2, N'002', 0, getdate()
|
||||
UNION ALL
|
||||
SELECT 3, N'003', 0, getdate()
|
||||
UNION ALL
|
||||
SELECT 4, N'004', 0, getdate() ) t2 ON (t1.[id] = t2.[id])
|
||||
WHEN MATCHED THEN
|
||||
update set [name] = t2.[name], [version] = t1.[version] + 1
|
||||
WHEN NOT MATCHED THEN
|
||||
insert ([id], [name], [version], [CreateTime])
|
||||
values (t2.[id], t2.[name], t2.[version], t2.[CreateTime]);", sql);
|
||||
Assert.Equal(4, iou.ExecuteAffrows());
|
||||
var lst = fsql.Select<tbiou04>().Where(a => new[] { 1, 2, 3, 4 }.Contains(a.id)).ToList();
|
||||
Assert.Equal(4, lst.Where(a => a.name == "00" + a.id).Count());
|
||||
}
|
||||
class tbiou04
|
||||
{
|
||||
public int id { get; set; }
|
||||
public string name { get; set; }
|
||||
[Column(IsVersion = true)]
|
||||
public int version { get; set; }
|
||||
[Column(CanUpdate = false, ServerTime = DateTimeKind.Local)]
|
||||
public DateTime CreateTime { get; set; }
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,155 @@
|
||||
using FreeSql.DataAnnotations;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Xunit;
|
||||
|
||||
namespace FreeSql.Tests.Custom.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,199 @@
|
||||
using FreeSql.DataAnnotations;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Xunit;
|
||||
|
||||
namespace FreeSql.Tests.Custom.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] IN (1,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] IN (1,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);
|
||||
|
||||
sql = g.sqlserver.Update<ts_source_mpk>().SetSource(new[] {
|
||||
new ts_source_mpk { id1 = 1, id2 = 7, xx = "a1" },
|
||||
new ts_source_mpk { id1 = 1, id2 = 8, xx = "b122" }
|
||||
}).NoneParameter().ToSql().Replace("\r\n", "");
|
||||
}
|
||||
public class ts_source_mpk
|
||||
{
|
||||
[Column(IsPrimary = true)]
|
||||
public int id1 { get; set; }
|
||||
[Column(IsPrimary = true)]
|
||||
public int id2 { get; set; }
|
||||
public string xx { get; set; }
|
||||
}
|
||||
[Fact]
|
||||
public void SetSourceIgnore()
|
||||
{
|
||||
Assert.Equal("UPDATE [tssi01] SET [tint] = 10 WHERE ([id] = '00000000-0000-0000-0000-000000000000')",
|
||||
g.sqlserver.Update<tssi01>().NoneParameter()
|
||||
.SetSourceIgnore(new tssi01 { id = Guid.Empty, tint = 10 }, col => col == null).ToSql().Replace("\r\n", ""));
|
||||
}
|
||||
public class tssi01
|
||||
{
|
||||
[Column(CanUpdate = false)]
|
||||
public Guid id { get; set; }
|
||||
public int tint { get; set; }
|
||||
public string title { get; set; }
|
||||
}
|
||||
[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);
|
||||
|
||||
var dt2000 = DateTime.Parse("2000-01-01");
|
||||
sql = update.Set(a => a.Clicks == (a.CreateTime > dt2000 ? 1 : 2)).Where(a => a.Id == 1).ToSql().Replace("\r\n", "");
|
||||
Assert.Equal("UPDATE [tb_topic] SET [Clicks] = case when [CreateTime] > '2000-01-01 00:00:00.000' then 1 else 2 end 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);
|
||||
|
||||
sql = update.Set(a => a.Clicks == null).Where(a => a.Id == 1).ToSql().Replace("\r\n", "");
|
||||
Assert.Equal("UPDATE [tb_topic] SET [Clicks] = NULL 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 SetDto()
|
||||
{
|
||||
var sql = update.SetDto(new { clicks = 1, title = "xxx" }).Where(a => a.Id == 1).ToSql().Replace("\r\n", "");
|
||||
Assert.Equal("UPDATE [tb_topic] SET [Clicks] = 1, [Title] = N'xxx' WHERE ([Id] = 1)", sql);
|
||||
|
||||
sql = update.SetDto(new Dictionary<string, object> { ["clicks"] = 1, ["title"] = "xxx" }).Where(a => a.Id == 1).ToSql().Replace("\r\n", "");
|
||||
Assert.Equal("UPDATE [tb_topic] SET [Clicks] = 1, [Title] = N'xxx' 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 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] IN (1,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] IN (1,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.Custom.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.Custom.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.Custom.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,98 @@
|
||||
using FreeSql.DataAnnotations;
|
||||
using System;
|
||||
using System.Data.Odbc;
|
||||
using Xunit;
|
||||
|
||||
namespace FreeSql.Tests.Custom.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 ExecuteTest()
|
||||
{
|
||||
Assert.True(g.sqlserver.Ado.ExecuteConnectTest());
|
||||
}
|
||||
[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");
|
||||
}
|
||||
|
||||
[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.Custom.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,485 @@
|
||||
using FreeSql.DataAnnotations;
|
||||
using Newtonsoft.Json;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using Xunit;
|
||||
|
||||
namespace FreeSql.Tests.Custom.SqlServer
|
||||
{
|
||||
|
||||
[Collection("SqlServerCollection")]
|
||||
public class SqlServerCodeFirstTest
|
||||
{
|
||||
[Fact]
|
||||
public void Test_0String()
|
||||
{
|
||||
var fsql = g.sqlserver;
|
||||
fsql.Delete<test_0string01>().Where("1=1").ExecuteAffrows();
|
||||
|
||||
Assert.Equal(1, fsql.Insert(new test_0string01 { name = @"1.0000\0.0000\0.0000\0.0000\1.0000\0.0000" }).ExecuteAffrows());
|
||||
Assert.Equal(1, fsql.Insert(new test_0string01 { name = @"1.0000\0.0000\0.0000\0.0000\1.0000\0.0000" }).NoneParameter().ExecuteAffrows());
|
||||
|
||||
var list = fsql.Select<test_0string01>().ToList();
|
||||
Assert.Equal(2, list.Count);
|
||||
Assert.Equal(@"1.0000\0.0000\0.0000\0.0000\1.0000\0.0000", list[0].name);
|
||||
Assert.Equal(@"1.0000\0.0000\0.0000\0.0000\1.0000\0.0000", list[1].name);
|
||||
}
|
||||
class test_0string01
|
||||
{
|
||||
public Guid id { get; set; }
|
||||
public string name { get; set; }
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void StringLength()
|
||||
{
|
||||
var dll = g.sqlserver.CodeFirst.GetComparisonDDLStatements<TS_SLTB>();
|
||||
g.sqlserver.CodeFirst.SyncStructure<TS_SLTB>();
|
||||
}
|
||||
class TS_SLTB
|
||||
{
|
||||
public Guid Id { get; set; }
|
||||
[Column(StringLength = 50)]
|
||||
public string Title { get; set; }
|
||||
|
||||
[Column(IsNullable = false, StringLength = 50)]
|
||||
public string TitleSub { get; set; }
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void 表名中有点()
|
||||
{
|
||||
var item = new tbdot01 { name = "insert" };
|
||||
g.sqlserver.Insert(item).ExecuteAffrows();
|
||||
|
||||
var find = g.sqlserver.Select<tbdot01>().Where(a => a.id == item.id).First();
|
||||
Assert.NotNull(find);
|
||||
Assert.Equal(item.id, find.id);
|
||||
Assert.Equal("insert", find.name);
|
||||
|
||||
Assert.Equal(1, g.sqlserver.Update<tbdot01>().Set(a => a.name == "update").Where(a => a.id == item.id).ExecuteAffrows());
|
||||
find = g.sqlserver.Select<tbdot01>().Where(a => a.id == item.id).First();
|
||||
Assert.NotNull(find);
|
||||
Assert.Equal(item.id, find.id);
|
||||
Assert.Equal("update", find.name);
|
||||
|
||||
Assert.Equal(1, g.sqlserver.Delete<tbdot01>().Where(a => a.id == item.id).ExecuteAffrows());
|
||||
find = g.sqlserver.Select<tbdot01>().Where(a => a.id == item.id).First();
|
||||
Assert.Null(find);
|
||||
}
|
||||
/// <summary>
|
||||
/// 表中带点
|
||||
/// </summary>
|
||||
[Table(Name = "[freesql.T].[dbo].[sys.tbdot01]")]
|
||||
class tbdot01
|
||||
{
|
||||
/// <summary>
|
||||
/// 主键
|
||||
/// </summary>
|
||||
public Guid id { get; set; }
|
||||
public string name { get; set; }
|
||||
}
|
||||
|
||||
[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.标题);
|
||||
|
||||
item.标题 = "测试标题更新";
|
||||
Assert.Equal(1, g.sqlserver.Update<测试中文表>().SetSource(item).ExecuteAffrows());
|
||||
item2 = g.sqlserver.Select<测试中文表>().Where(a => a.编号 == item.编号).First();
|
||||
Assert.NotNull(item2);
|
||||
Assert.Equal(item.编号, item2.编号);
|
||||
Assert.Equal(item.标题, item2.标题);
|
||||
|
||||
item.标题 = "测试标题更新_repo";
|
||||
var repo = g.sqlserver.GetRepository<测试中文表>();
|
||||
Assert.Equal(1, repo.Update(item));
|
||||
item2 = g.sqlserver.Select<测试中文表>().Where(a => a.编号 == item.编号).First();
|
||||
Assert.NotNull(item2);
|
||||
Assert.Equal(item.编号, item2.编号);
|
||||
Assert.Equal(item.标题, item2.标题);
|
||||
|
||||
item.标题 = "测试标题更新_repo22";
|
||||
Assert.Equal(1, repo.Update(item));
|
||||
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>();
|
||||
g.sqlserver.CodeFirst.SyncStructure(typeof(AddUniquesInfo), "AddUniquesInfo1");
|
||||
}
|
||||
[Table(Name = "AddUniquesInfo", OldName = "AddUniquesInfo2")]
|
||||
[Index("uk_phone", "phone", true)]
|
||||
[Index("uk_group_index", "group,index", true)]
|
||||
[Index("uk_group_index22", "group, index22", true)]
|
||||
class AddUniquesInfo
|
||||
{
|
||||
public Guid id { get; set; }
|
||||
public string phone { get; set; }
|
||||
|
||||
public string group { get; set; }
|
||||
public int index { get; set; }
|
||||
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>();
|
||||
Assert.True(string.IsNullOrEmpty(sql)); //测试运行两次后
|
||||
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'\\?!@#$%^&*()_+{}}{~?><<>",
|
||||
testFieldChar = 'X',
|
||||
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 == item3[0].Id).ToOne();
|
||||
Assert.Equal(item2.testFieldString, newitem2.testFieldString);
|
||||
Assert.Equal(item2.testFieldChar, newitem2.testFieldChar);
|
||||
|
||||
item3 = insert.NoneParameter().AppendData(item2).ExecuteInserted();
|
||||
newitem2 = select.Where(a => a.Id == item3[0].Id).ToOne();
|
||||
Assert.Equal(item2.testFieldString, newitem2.testFieldString);
|
||||
Assert.Equal(item2.testFieldChar, newitem2.testFieldChar);
|
||||
|
||||
var items = select.ToList();
|
||||
var itemstb = select.ToDataTable();
|
||||
}
|
||||
|
||||
[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 = "testFieldChar", DbType = "char(1)", IsNullable = true)]
|
||||
public char testFieldChar { 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 char testFieldChar { 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,65 @@
|
||||
using FreeSql.DataAnnotations;
|
||||
using System;
|
||||
using Xunit;
|
||||
|
||||
namespace FreeSql.Tests.Custom.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();
|
||||
Assert.True(t2.Count > 0);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void GetTableByName()
|
||||
{
|
||||
var fsql = g.sqlserver;
|
||||
var t1 = fsql.DbFirst.GetTableByName("tb_alltype");
|
||||
var t2 = fsql.DbFirst.GetTableByName("dbo.tb_alltype");
|
||||
Assert.NotNull(t1);
|
||||
Assert.NotNull(t2);
|
||||
Assert.True(t1.Columns.Count > 0);
|
||||
Assert.True(t2.Columns.Count > 0);
|
||||
Assert.Equal(t1.Columns.Count, t2.Columns.Count);
|
||||
var t3 = fsql.DbFirst.GetTableByName("notexists_tb");
|
||||
Assert.Null(t3);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ExistsTable()
|
||||
{
|
||||
var fsql = g.sqlserver;
|
||||
Assert.False(fsql.DbFirst.ExistsTable("test_existstb01"));
|
||||
Assert.False(fsql.DbFirst.ExistsTable("dbo.test_existstb01"));
|
||||
Assert.False(fsql.DbFirst.ExistsTable("test_existstb01", false));
|
||||
Assert.False(fsql.DbFirst.ExistsTable("dbo.test_existstb01", false));
|
||||
fsql.CodeFirst.SyncStructure(typeof(test_existstb01));
|
||||
Assert.True(fsql.DbFirst.ExistsTable("test_existstb01"));
|
||||
Assert.True(fsql.DbFirst.ExistsTable("dbo.test_existstb01"));
|
||||
Assert.True(fsql.DbFirst.ExistsTable("Test_existstb01", false));
|
||||
Assert.True(fsql.DbFirst.ExistsTable("dbo.Test_existstb01", false));
|
||||
fsql.Ado.ExecuteNonQuery("drop table test_existstb01");
|
||||
|
||||
Assert.False(fsql.DbFirst.ExistsTable("xxxtb.test_existstb01"));
|
||||
Assert.False(fsql.DbFirst.ExistsTable("xxxtb.test_existstb01", false));
|
||||
fsql.CodeFirst.SyncStructure(typeof(test_existstb01), "xxxtb.test_existstb01");
|
||||
Assert.True(fsql.DbFirst.ExistsTable("xxxtb.test_existstb01"));
|
||||
Assert.True(fsql.DbFirst.ExistsTable("xxxtb.Test_existstb01", false));
|
||||
fsql.Ado.ExecuteNonQuery("drop table xxxtb.test_existstb01");
|
||||
}
|
||||
class test_existstb01
|
||||
{
|
||||
public Guid id { get; set; }
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,169 @@
|
||||
using FreeSql.DataAnnotations;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Xunit;
|
||||
|
||||
namespace FreeSql.Tests.Custom.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,349 @@
|
||||
using FreeSql.DataAnnotations;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Xunit;
|
||||
|
||||
namespace FreeSql.Tests.Custom.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 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());
|
||||
|
||||
g.sqlserver.Insert(new Topic()).ExecuteAffrows();
|
||||
var dtn = DateTime.Parse("2020-1-1 0:0:0");
|
||||
var dts = Enumerable.Range(1, 12).Select(a => dtn.AddMonths(a))
|
||||
.Concat(Enumerable.Range(1, 31).Select(a => dtn.AddDays(a)))
|
||||
.Concat(Enumerable.Range(1, 24).Select(a => dtn.AddHours(a)))
|
||||
.Concat(Enumerable.Range(1, 60).Select(a => dtn.AddMinutes(a)))
|
||||
.Concat(Enumerable.Range(1, 60).Select(a => dtn.AddSeconds(a)));
|
||||
foreach (var dt in dts)
|
||||
{
|
||||
Assert.Equal(dt.ToString("yyyy-MM-dd HH:mm:ss.fff"), select.First(a => dt.ToString()));
|
||||
Assert.Equal(dt.ToString("yyyy-MM-dd HH:mm:ss"), select.First(a => dt.ToString("yyyy-MM-dd HH:mm:ss")));
|
||||
Assert.Equal(dt.ToString("yyyy-MM-dd HH:mm"), select.First(a => dt.ToString("yyyy-MM-dd HH:mm")));
|
||||
Assert.Equal(dt.ToString("yyyy-MM-dd HH"), select.First(a => dt.ToString("yyyy-MM-dd HH")));
|
||||
Assert.Equal(dt.ToString("yyyy-MM-dd"), select.First(a => dt.ToString("yyyy-MM-dd")));
|
||||
Assert.Equal(dt.ToString("yyyy-MM"), select.First(a => dt.ToString("yyyy-MM")));
|
||||
Assert.Equal(dt.ToString("yyyyMMddHHmmss"), select.First(a => dt.ToString("yyyyMMddHHmmss")));
|
||||
Assert.Equal(dt.ToString("yyyyMMddHHmm"), select.First(a => dt.ToString("yyyyMMddHHmm")));
|
||||
Assert.Equal(dt.ToString("yyyyMMddHH"), select.First(a => dt.ToString("yyyyMMddHH")));
|
||||
Assert.Equal(dt.ToString("yyyyMMdd"), select.First(a => dt.ToString("yyyyMMdd")));
|
||||
Assert.Equal(dt.ToString("yyyyMM"), select.First(a => dt.ToString("yyyyMM")));
|
||||
Assert.Equal(dt.ToString("yyyy"), select.First(a => dt.ToString("yyyy")));
|
||||
Assert.Equal(dt.ToString("HH:mm:ss"), select.First(a => dt.ToString("HH:mm:ss")));
|
||||
Assert.Equal(dt.ToString("yyyy MM dd HH mm ss yy M d H hh h"), select.First(a => dt.ToString("yyyy MM dd HH mm ss yy M d H hh h")));
|
||||
Assert.Equal(dt.ToString("yyyy MM dd HH mm ss yy M d H hh h m s tt t").Replace("上午", "AM").Replace("下午", "PM").Replace("上", "A").Replace("下", "P"), select.First(a => dt.ToString("yyyy MM dd HH mm ss yy M d H hh h m s tt t")));
|
||||
}
|
||||
}
|
||||
[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 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.Custom.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,229 @@
|
||||
using FreeSql.DataAnnotations;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Xunit;
|
||||
|
||||
namespace FreeSql.Tests.Custom.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 t51 = select.WhereCascade(a => a.testFieldBool).Limit(10).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();
|
||||
|
||||
var t111 = select.Where(a => a.testFieldBool == true && a.Id > 0).ToList();
|
||||
var t222 = select.Where(a => a.testFieldBool != true && a.Id > 0).ToList();
|
||||
var t333 = select.Where(a => a.testFieldBool == false && a.Id > 0).ToList();
|
||||
var t444 = select.Where(a => !a.testFieldBool && a.Id > 0).ToList();
|
||||
var t555 = select.Where(a => a.testFieldBool && a.Id > 0).ToList();
|
||||
|
||||
var t1111 = select.Where(a => a.testFieldBoolNullable == true && a.Id > 0).ToList();
|
||||
var t2222 = select.Where(a => a.testFieldBoolNullable != true && a.Id > 0).ToList();
|
||||
var t3333 = select.Where(a => a.testFieldBoolNullable == false && a.Id > 0).ToList();
|
||||
var t4444 = select.Where(a => !a.testFieldBoolNullable.Value && a.Id > 0).ToList();
|
||||
var t5555 = select.Where(a => a.testFieldBoolNullable.Value && a.Id > 0).ToList();
|
||||
|
||||
var t11111 = select.Where(a => a.testFieldBool == true && a.Id > 0 && a.testFieldBool == true).ToList();
|
||||
var t22222 = select.Where(a => a.testFieldBool != true && a.Id > 0 && a.testFieldBool != true).ToList();
|
||||
var t33333 = select.Where(a => a.testFieldBool == false && a.Id > 0 && a.testFieldBool == false).ToList();
|
||||
var t44444 = select.Where(a => !a.testFieldBool && a.Id > 0 && !a.testFieldBool).ToList();
|
||||
var t55555 = select.Where(a => a.testFieldBool && a.Id > 0 && a.testFieldBool).ToList();
|
||||
|
||||
var t111111 = select.Where(a => a.testFieldBoolNullable == true && a.Id > 0 && a.testFieldBoolNullable == true).ToList();
|
||||
var t222222 = select.Where(a => a.testFieldBoolNullable != true && a.Id > 0 && a.testFieldBoolNullable != true).ToList();
|
||||
var t333333 = select.Where(a => a.testFieldBoolNullable == false && a.Id > 0 && a.testFieldBoolNullable == false).ToList();
|
||||
var t444444 = select.Where(a => !a.testFieldBoolNullable.Value && a.Id > 0 && !a.testFieldBoolNullable.Value).ToList();
|
||||
var t555555 = select.Where(a => a.testFieldBoolNullable.Value && a.Id > 0 && 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();
|
||||
|
||||
var inarray2n = Enumerable.Range(1, 3333).ToArray();
|
||||
var sql1111111 = select.Where(a => inarray2n.Contains(a.testFieldInt)).ToList();
|
||||
var sql1122222 = select.Where(a => inarray2n.Contains(a.testFieldInt) == false).ToList();
|
||||
var sql1133333 = select.Where(a => !inarray2n.Contains(a.testFieldInt)).ToList();
|
||||
|
||||
//nvarchar
|
||||
IEnumerable<string> stringlinqlist = new List<string>(new[] { "a1", "a2", "a3" });
|
||||
var ntestlinq = select.Where(a => stringlinqlist.Contains(a.testFieldString)).ToList();
|
||||
|
||||
//in not in
|
||||
var nsql111 = select.Where(a => new[] { "a1", "a2", "a3" }.Contains(a.testFieldString)).ToList();
|
||||
var nsql112 = select.Where(a => new[] { "a1", "a2", "a3" }.Contains(a.testFieldString) == false).ToList();
|
||||
var nsql113 = select.Where(a => !new[] { "a1", "a2", "a3" }.Contains(a.testFieldString)).ToList();
|
||||
|
||||
var ninarray = new[] { "a1", "a2", "a3" };
|
||||
var nsql1111 = select.Where(a => ninarray.Contains(a.testFieldString)).ToList();
|
||||
var nsql1122 = select.Where(a => ninarray.Contains(a.testFieldString) == false).ToList();
|
||||
var nsql1133 = select.Where(a => !ninarray.Contains(a.testFieldString)).ToList();
|
||||
|
||||
//in not in
|
||||
var nsql11111 = select.Where(a => new List<string>() { "a1", "a2", "a3" }.Contains(a.testFieldString)).ToList();
|
||||
var nsql11222 = select.Where(a => new List<string>() { "a1", "a2", "a3" }.Contains(a.testFieldString) == false).ToList();
|
||||
var nsql11333 = select.Where(a => !new List<string>() { "a1", "a2", "a3" }.Contains(a.testFieldString)).ToList();
|
||||
|
||||
var nsql11111a = select.Where(a => new List<string>(new[] { "a1", "a2", "a3" }).Contains(a.testFieldString)).ToList();
|
||||
var nsql11222b = select.Where(a => new List<string>(new[] { "a1", "a2", "a3" }).Contains(a.testFieldString) == false).ToList();
|
||||
var nsql11333c = select.Where(a => !new List<string>(new[] { "a1", "a2", "a3" }).Contains(a.testFieldString)).ToList();
|
||||
|
||||
var ninarray2 = new List<string>() { "a1", "a2", "a3" };
|
||||
var nsql111111 = select.Where(a => ninarray2.Contains(a.testFieldString)).ToList();
|
||||
var nsql112222 = select.Where(a => ninarray2.Contains(a.testFieldString) == false).ToList();
|
||||
var nsql113333 = select.Where(a => !ninarray2.Contains(a.testFieldString)).ToList();
|
||||
|
||||
var ninarray2n = Enumerable.Range(1, 3333).Select(a => "testnvarchar" + a).ToArray();
|
||||
var nsql1111111 = select.Where(a => ninarray2n.Contains(a.testFieldString)).ToList();
|
||||
var nsql1122222 = select.Where(a => ninarray2n.Contains(a.testFieldString) == false).ToList();
|
||||
var nsql1133333 = select.Where(a => !ninarray2n.Contains(a.testFieldString)).ToList();
|
||||
|
||||
//varchar
|
||||
IEnumerable<string> vstringlinqlist = new List<string>(new[] { "a1", "a2", "a3" });
|
||||
var vtestlinq = select.Where(a => vstringlinqlist.Contains(a.testFieldStringVarchar)).ToList();
|
||||
|
||||
//in not in
|
||||
var vsql111 = select.Where(a => new[] { "a1", "a2", "a3" }.Contains(a.testFieldStringVarchar)).ToList();
|
||||
var vsql112 = select.Where(a => new[] { "a1", "a2", "a3" }.Contains(a.testFieldStringVarchar) == false).ToList();
|
||||
var vsql113 = select.Where(a => !new[] { "a1", "a2", "a3" }.Contains(a.testFieldStringVarchar)).ToList();
|
||||
|
||||
var vinarray = new[] { "a1", "a2", "a3" };
|
||||
var vsql1111 = select.Where(a => ninarray.Contains(a.testFieldStringVarchar)).ToList();
|
||||
var vsql1122 = select.Where(a => ninarray.Contains(a.testFieldStringVarchar) == false).ToList();
|
||||
var vsql1133 = select.Where(a => !ninarray.Contains(a.testFieldStringVarchar)).ToList();
|
||||
|
||||
//in not in
|
||||
var vsql11111 = select.Where(a => new List<string>() { "a1", "a2", "a3" }.Contains(a.testFieldStringVarchar)).ToList();
|
||||
var vsql11222 = select.Where(a => new List<string>() { "a1", "a2", "a3" }.Contains(a.testFieldStringVarchar) == false).ToList();
|
||||
var vsql11333 = select.Where(a => !new List<string>() { "a1", "a2", "a3" }.Contains(a.testFieldStringVarchar)).ToList();
|
||||
|
||||
var vsql11111a = select.Where(a => new List<string>(new[] { "a1", "a2", "a3" }).Contains(a.testFieldStringVarchar)).ToList();
|
||||
var vsql11222b = select.Where(a => new List<string>(new[] { "a1", "a2", "a3" }).Contains(a.testFieldStringVarchar) == false).ToList();
|
||||
var vsql11333c = select.Where(a => !new List<string>(new[] { "a1", "a2", "a3" }).Contains(a.testFieldStringVarchar)).ToList();
|
||||
|
||||
var vinarray2 = new List<string>() { "a1", "a2", "a3" };
|
||||
var vsql111111 = select.Where(a => ninarray2.Contains(a.testFieldStringVarchar)).ToList();
|
||||
var vsql112222 = select.Where(a => ninarray2.Contains(a.testFieldStringVarchar) == false).ToList();
|
||||
var vsql113333 = select.Where(a => !ninarray2.Contains(a.testFieldStringVarchar)).ToList();
|
||||
|
||||
var vinarray2n = Enumerable.Range(1, 3333).Select(a => "testvarchar" + a).ToArray();
|
||||
var vsql1111111 = select.Where(a => vinarray2n.Contains(a.testFieldStringVarchar)).ToList();
|
||||
var vsql1122222 = select.Where(a => vinarray2n.Contains(a.testFieldStringVarchar) == false).ToList();
|
||||
var vsql1133333 = select.Where(a => !vinarray2n.Contains(a.testFieldStringVarchar)).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; }
|
||||
|
||||
[Column(DbType = "varchar(255)")]
|
||||
public string testFieldStringVarchar { 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,392 @@
|
||||
using FreeSql.DataAnnotations;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Xunit;
|
||||
|
||||
namespace FreeSql.Tests.Custom.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 StringJoin()
|
||||
{
|
||||
var fsql = g.sqlserver;
|
||||
fsql.Delete<StringJoin01>().Where("1=1").ExecuteAffrows();
|
||||
fsql.Insert(new[] { new StringJoin01 { name = "北京" }, new StringJoin01 { name = "上海" }, new StringJoin01 { name = "深圳" }, }).ExecuteAffrows();
|
||||
|
||||
var val1 = string.Join(",", fsql.Select<StringJoin01>().ToList(a => a.name));
|
||||
var val2 = fsql.Select<StringJoin01>().ToList(a => string.Join(",", fsql.Select<StringJoin01>().As("b").ToList(b => b.name)));
|
||||
Assert.Equal(val1, val2[0]);
|
||||
|
||||
val1 = string.Join("**", fsql.Select<StringJoin01>().ToList(a => a.name));
|
||||
val2 = fsql.Select<StringJoin01>().ToList(a => string.Join("**", fsql.Select<StringJoin01>().As("b").ToList(b => b.name)));
|
||||
Assert.Equal(val1, val2[0]);
|
||||
|
||||
val1 = string.Join(",", fsql.Select<StringJoin01>().ToList(a => a.id));
|
||||
val2 = fsql.Select<StringJoin01>().ToList(a => string.Join(",", fsql.Select<StringJoin01>().As("b").ToList(b => b.id)));
|
||||
Assert.Equal(val1, val2[0]);
|
||||
|
||||
val1 = string.Join("**", fsql.Select<StringJoin01>().ToList(a => a.id));
|
||||
val2 = fsql.Select<StringJoin01>().ToList(a => string.Join("**", fsql.Select<StringJoin01>().As("b").ToList(b => b.id)));
|
||||
Assert.Equal(val1, val2[0]);
|
||||
}
|
||||
class StringJoin01
|
||||
{
|
||||
[Column(IsIdentity = true)]
|
||||
public int id { get; set; }
|
||||
public string name { get; set; }
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void First()
|
||||
{
|
||||
Assert.Equal('x', select.First(a => "x1".First()));
|
||||
Assert.Equal('z', select.First(a => "z1".First()));
|
||||
}
|
||||
[Fact]
|
||||
public void FirstOrDefault()
|
||||
{
|
||||
Assert.Equal('x', select.First(a => "x1".FirstOrDefault()));
|
||||
Assert.Equal('z', select.First(a => "z1".FirstOrDefault()));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Format()
|
||||
{
|
||||
var item = g.sqlserver.GetRepository<Topic>().Insert(new Topic { Clicks = 101, Title = "我是中国人101", CreateTime = DateTime.Parse("2020-7-5") });
|
||||
var sql = select.WhereDynamic(item).ToSql(a => new
|
||||
{
|
||||
str = $"x{a.Id + 1}z-{a.CreateTime.ToString("yyyyMM")}{a.Title}",
|
||||
str2 = string.Format("{0}x{0}z-{1}{2}", a.Id + 1, a.CreateTime.ToString("yyyyMM"), a.Title)
|
||||
});
|
||||
Assert.Equal($@"SELECT N'x'+isnull(cast((a.[Id] + 1) as varchar), '')+N'z-'+isnull(substring(convert(char(8), cast(a.[CreateTime] as datetime), 112), 1, 6), '')+N''+isnull(a.[Title], '')+N'' as1, N''+isnull(cast((a.[Id] + 1) as varchar), '')+N'x'+isnull(cast((a.[Id] + 1) as varchar), '')+N'z-'+isnull(substring(convert(char(8), cast(a.[CreateTime] as datetime), 112), 1, 6), '')+N''+isnull(a.[Title], '')+N'' as2
|
||||
FROM [tb_topic] a
|
||||
WHERE (a.[Id] = {item.Id})", sql);
|
||||
|
||||
var item2 = select.WhereDynamic(item).First(a => new
|
||||
{
|
||||
str = $"x{a.Id + 1}z-{a.CreateTime.ToString("yyyyMM")}{a.Title}",
|
||||
str2 = string.Format("{0}x{0}z-{1}{2}", a.Id + 1, a.CreateTime.ToString("yyyyMM"), a.Title)
|
||||
});
|
||||
Assert.NotNull(item2);
|
||||
Assert.Equal($"x{item.Id + 1}z-{item.CreateTime.ToString("yyyyMM")}{item.Title}", item2.str);
|
||||
Assert.Equal(string.Format("{0}x{0}z-{1}{2}", item.Id + 1, item.CreateTime.ToString("yyyyMM"), item.Title), item2.str2);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Format4()
|
||||
{
|
||||
//3个 {} 时,Arguments 解析出来是分开的
|
||||
//4个 {} 时,Arguments[1] 只能解析这个出来,然后里面是 NewArray []
|
||||
var item = g.sqlserver.GetRepository<Topic>().Insert(new Topic { Clicks = 101, Title = "我是中国人101", CreateTime = DateTime.Parse("2020-7-5") });
|
||||
var sql = select.WhereDynamic(item).ToSql(a => new
|
||||
{
|
||||
str = $"x{a.Id + 1}z-{a.CreateTime.ToString("yyyyMM")}{a.Title}{a.Title}",
|
||||
str2 = string.Format("{0}x{0}z-{1}{2}{3}", a.Id + 1, a.CreateTime.ToString("yyyyMM"), a.Title, a.Title)
|
||||
});
|
||||
Assert.Equal($@"SELECT N'x'+isnull(cast((a.[Id] + 1) as varchar), '')+N'z-'+isnull(substring(convert(char(8), cast(a.[CreateTime] as datetime), 112), 1, 6), '')+N''+isnull(a.[Title], '')+N''+isnull(a.[Title], '')+N'' as1, N''+isnull(cast((a.[Id] + 1) as varchar), '')+N'x'+isnull(cast((a.[Id] + 1) as varchar), '')+N'z-'+isnull(substring(convert(char(8), cast(a.[CreateTime] as datetime), 112), 1, 6), '')+N''+isnull(a.[Title], '')+N''+isnull(a.[Title], '')+N'' as2
|
||||
FROM [tb_topic] a
|
||||
WHERE (a.[Id] = {item.Id})", sql);
|
||||
|
||||
var item2 = select.WhereDynamic(item).First(a => new
|
||||
{
|
||||
str = $"x{a.Id + 1}z-{a.CreateTime.ToString("yyyyMM")}{a.Title}{a.Title}",
|
||||
str2 = string.Format("{0}x{0}z-{1}{2}{3}", a.Id + 1, a.CreateTime.ToString("yyyyMM"), a.Title, a.Title)
|
||||
});
|
||||
Assert.NotNull(item2);
|
||||
Assert.Equal($"x{item.Id + 1}z-{item.CreateTime.ToString("yyyyMM")}{item.Title}{item.Title}", item2.str);
|
||||
Assert.Equal(string.Format("{0}x{0}z-{1}{2}{3}", item.Id + 1, item.CreateTime.ToString("yyyyMM"), item.Title, item.Title), item2.str2);
|
||||
}
|
||||
|
||||
[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());
|
||||
|
||||
|
||||
list.Add(select.Where(a => a.Title.Contains("%")).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.Custom.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());
|
||||
}
|
||||
}
|
||||
}
|
1075
FreeSql.Tests/FreeSql.Tests.Provider.Custom/UnitTest1.cs
Normal file
1075
FreeSql.Tests/FreeSql.Tests.Provider.Custom/UnitTest1.cs
Normal file
File diff suppressed because it is too large
Load Diff
77
FreeSql.Tests/FreeSql.Tests.Provider.Custom/g.cs
Normal file
77
FreeSql.Tests/FreeSql.Tests.Provider.Custom/g.cs
Normal file
@ -0,0 +1,77 @@
|
||||
using MySqlConnector;
|
||||
using Npgsql;
|
||||
using Oracle.ManagedDataAccess.Client;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data.SqlClient;
|
||||
using System.Diagnostics;
|
||||
using System.Text;
|
||||
|
||||
|
||||
public class g
|
||||
{
|
||||
static Lazy<IFreeSql> mysqlLazy = new Lazy<IFreeSql>(() =>
|
||||
{
|
||||
var fsql = new FreeSql.FreeSqlBuilder()
|
||||
.UseConnectionFactory(FreeSql.DataType.CustomMySql, () => new MySqlConnection("Server=127.0.0.1;Persist Security Info=False;UID=root;PWD=root;DATABASE=cccddd_custom;Charset=utf8;SslMode=none;"))
|
||||
.UseAutoSyncStructure(true)
|
||||
.UseMonitorCommand(
|
||||
cmd => Trace.WriteLine(cmd.CommandText), //监听SQL命令对象,在执行前
|
||||
(cmd, traceLog) => Console.WriteLine(traceLog))
|
||||
.UseLazyLoading(true)
|
||||
.Build();
|
||||
fsql.SetDbProviderFactory(MySqlConnectorFactory.Instance);
|
||||
return fsql;
|
||||
});
|
||||
public static IFreeSql mysql => mysqlLazy.Value;
|
||||
|
||||
static Lazy<IFreeSql> sqlserverLazy = new Lazy<IFreeSql>(() =>
|
||||
{
|
||||
var fsql = new FreeSql.FreeSqlBuilder()
|
||||
.UseConnectionFactory(FreeSql.DataType.CustomSqlServer, () => new SqlConnection("Server=.;Persist Security Info=False;Trusted_Connection=Yes;Integrated Security=True;DATABASE=freesqlTest_custom;Pooling=true;"))
|
||||
.UseAutoSyncStructure(true)
|
||||
.UseMonitorCommand(
|
||||
cmd => Trace.WriteLine(cmd.CommandText), //监听SQL命令对象,在执行前
|
||||
(cmd, traceLog) => Console.WriteLine(traceLog))
|
||||
.UseLazyLoading(true)
|
||||
.Build();
|
||||
fsql.SetDbProviderFactory(SqlClientFactory.Instance);
|
||||
return fsql;
|
||||
});
|
||||
public static IFreeSql sqlserver => sqlserverLazy.Value;
|
||||
|
||||
static Lazy<IFreeSql> oracleLazy = new Lazy<IFreeSql>(() =>
|
||||
{
|
||||
var fsql = new FreeSql.FreeSqlBuilder()
|
||||
.UseConnectionFactory(FreeSql.DataType.CustomOracle, () => new OracleConnection("user id=1custom;password=123456;data source=//127.0.0.1:1521/XE;Pooling=true;Max Pool Size=2"))
|
||||
.UseAutoSyncStructure(true)
|
||||
.UseLazyLoading(true)
|
||||
.UseNameConvert(FreeSql.Internal.NameConvertType.ToUpper)
|
||||
//.UseNoneCommandParameter(true)
|
||||
|
||||
.UseMonitorCommand(
|
||||
cmd => Trace.WriteLine(cmd.CommandText), //监听SQL命令对象,在执行前
|
||||
(cmd, traceLog) => Console.WriteLine(traceLog))
|
||||
.Build();
|
||||
fsql.SetDbProviderFactory(OracleClientFactory.Instance);
|
||||
return fsql;
|
||||
});
|
||||
public static IFreeSql oracle => oracleLazy.Value;
|
||||
|
||||
static Lazy<IFreeSql> pgsqlLazy = new Lazy<IFreeSql>(() =>
|
||||
{
|
||||
var fsql = new FreeSql.FreeSqlBuilder()
|
||||
.UseConnectionFactory(FreeSql.DataType.CustomPostgreSQL, () => new NpgsqlConnection("Server=192.168.164.10;Port=5432;UID=postgres;PWD=123456;Database=tedb_custom;Pooling=true;"))
|
||||
.UseAutoSyncStructure(true)
|
||||
.UseNameConvert(FreeSql.Internal.NameConvertType.ToLower)
|
||||
.UseLazyLoading(true)
|
||||
.UseMonitorCommand(
|
||||
cmd => Trace.WriteLine(cmd.CommandText), //监听SQL命令对象,在执行前
|
||||
(cmd, traceLog) => Console.WriteLine(traceLog))
|
||||
.Build();
|
||||
fsql.SetDbProviderFactory(NpgsqlFactory.Instance);
|
||||
return fsql;
|
||||
});
|
||||
public static IFreeSql pgsql => pgsqlLazy.Value;
|
||||
|
||||
}
|
18
FreeSql.sln
18
FreeSql.sln
@ -115,6 +115,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "FreeSql.Provider.OracleOled
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "FreeSql.Tests.Provider.OracleOledb", "FreeSql.Tests\FreeSql.Tests.Provider.OracleOledb\FreeSql.Tests.Provider.OracleOledb.csproj", "{1DA3FF04-AA2C-4374-9368-68931D8D5B09}"
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "FreeSql.Tests.Provider.Custom", "FreeSql.Tests\FreeSql.Tests.Provider.Custom\FreeSql.Tests.Provider.Custom.csproj", "{530E3032-F7CE-4EB2-9F21-B7D46331B9E6}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
@ -677,6 +679,18 @@ Global
|
||||
{1DA3FF04-AA2C-4374-9368-68931D8D5B09}.Release|x64.Build.0 = Release|Any CPU
|
||||
{1DA3FF04-AA2C-4374-9368-68931D8D5B09}.Release|x86.ActiveCfg = Release|Any CPU
|
||||
{1DA3FF04-AA2C-4374-9368-68931D8D5B09}.Release|x86.Build.0 = Release|Any CPU
|
||||
{530E3032-F7CE-4EB2-9F21-B7D46331B9E6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{530E3032-F7CE-4EB2-9F21-B7D46331B9E6}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{530E3032-F7CE-4EB2-9F21-B7D46331B9E6}.Debug|x64.ActiveCfg = Debug|Any CPU
|
||||
{530E3032-F7CE-4EB2-9F21-B7D46331B9E6}.Debug|x64.Build.0 = Debug|Any CPU
|
||||
{530E3032-F7CE-4EB2-9F21-B7D46331B9E6}.Debug|x86.ActiveCfg = Debug|Any CPU
|
||||
{530E3032-F7CE-4EB2-9F21-B7D46331B9E6}.Debug|x86.Build.0 = Debug|Any CPU
|
||||
{530E3032-F7CE-4EB2-9F21-B7D46331B9E6}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{530E3032-F7CE-4EB2-9F21-B7D46331B9E6}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{530E3032-F7CE-4EB2-9F21-B7D46331B9E6}.Release|x64.ActiveCfg = Release|Any CPU
|
||||
{530E3032-F7CE-4EB2-9F21-B7D46331B9E6}.Release|x64.Build.0 = Release|Any CPU
|
||||
{530E3032-F7CE-4EB2-9F21-B7D46331B9E6}.Release|x86.ActiveCfg = Release|Any CPU
|
||||
{530E3032-F7CE-4EB2-9F21-B7D46331B9E6}.Release|x86.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
@ -716,8 +730,8 @@ Global
|
||||
{ECF7FC70-A7FC-4FC3-9BF7-462EA0A65F9C} = {2A381C57-2697-427B-9F10-55DA11FD02E4}
|
||||
EndGlobalSection
|
||||
GlobalSection(ExtensibilityGlobals) = postSolution
|
||||
SolutionGuid = {089687FD-5D25-40AB-BA8A-A10D1E137F98}
|
||||
RESX_PrefixTranslations = True
|
||||
RESX_NeutralResourcesLanguage = en-US
|
||||
RESX_PrefixTranslations = True
|
||||
SolutionGuid = {089687FD-5D25-40AB-BA8A-A10D1E137F98}
|
||||
EndGlobalSection
|
||||
EndGlobal
|
||||
|
@ -67,6 +67,8 @@ namespace FreeSql
|
||||
/// <summary>
|
||||
/// 天津南大通用数据技术股份有限公司成立于2004年,是国产数据库、大数据领域的知名企业,基于 Odbc 的实现
|
||||
/// </summary>
|
||||
GBase
|
||||
GBase,
|
||||
|
||||
CustomOracle, CustomSqlServer, CustomMySql, CustomPostgreSQL
|
||||
}
|
||||
}
|
||||
|
@ -309,6 +309,26 @@ namespace FreeSql
|
||||
if (type == null) throwNotFind("FreeSql.Provider.GBase.dll", "FreeSql.GBase.GBaseProvider<>");
|
||||
break;
|
||||
|
||||
case DataType.CustomOracle:
|
||||
type = Type.GetType("FreeSql.Custom.Oracle.CustomOracleProvider`1,FreeSql.Provider.Custom")?.MakeGenericType(typeof(TMark));
|
||||
if (type == null) throwNotFind("FreeSql.Provider.Custom.dll", "FreeSql.Custom.Oracle.CustomOracleProvider<>");
|
||||
break;
|
||||
|
||||
case DataType.CustomSqlServer:
|
||||
type = Type.GetType("FreeSql.Custom.SqlServer.CustomSqlServerProvider`1,FreeSql.Provider.Custom")?.MakeGenericType(typeof(TMark));
|
||||
if (type == null) throwNotFind("FreeSql.Provider.Custom.dll", "FreeSql.Custom.SqlServer.CustomSqlServerProvider<>");
|
||||
break;
|
||||
|
||||
case DataType.CustomMySql:
|
||||
type = Type.GetType("FreeSql.Custom.MySql.CustomMySqlProvider`1,FreeSql.Provider.Custom")?.MakeGenericType(typeof(TMark));
|
||||
if (type == null) throwNotFind("FreeSql.Provider.Custom.dll", "FreeSql.Custom.MySql.CustomMySqlProvider<>");
|
||||
break;
|
||||
|
||||
case DataType.CustomPostgreSQL:
|
||||
type = Type.GetType("FreeSql.Custom.PostgreSQL.CustomPostgreSQLProvider`1,FreeSql.Provider.Custom")?.MakeGenericType(typeof(TMark));
|
||||
if (type == null) throwNotFind("FreeSql.Provider.Custom.dll", "FreeSql.Custom.PostgreSQL.CustomPostgreSQLProvider<>");
|
||||
break;
|
||||
|
||||
default: throw new Exception(CoreStrings.NotSpecified_UseConnectionString_UseConnectionFactory);
|
||||
}
|
||||
}
|
||||
|
@ -77,6 +77,7 @@ namespace FreeSql.Custom
|
||||
finally
|
||||
{
|
||||
FreeSqlCustomAdapterGlobalExtensions._dicCustomAdater.TryRemove(Ado.Identifier, out var tryada);
|
||||
FreeSqlCustomAdapterGlobalExtensions._dicDbProviderFactory.TryRemove(Ado.Identifier, out var trydbpf);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -88,4 +89,8 @@ public static class FreeSqlCustomAdapterGlobalExtensions
|
||||
internal static ConcurrentDictionary<Guid, CustomAdapter> _dicCustomAdater = new ConcurrentDictionary<Guid, CustomAdapter>();
|
||||
public static void SetCustomAdapter(this IFreeSql that, CustomAdapter adapter) => _dicCustomAdater.AddOrUpdate(that.Ado.Identifier, adapter, (fsql, old) => adapter);
|
||||
internal static CustomAdapter GetCustomAdapter(this IFreeSql that) => _dicCustomAdater.TryGetValue(that.Ado.Identifier, out var tryada) ? tryada : DefaultAdapter;
|
||||
|
||||
internal static ConcurrentDictionary<Guid, DbProviderFactory> _dicDbProviderFactory = new ConcurrentDictionary<Guid, DbProviderFactory>();
|
||||
public static void SetDbProviderFactory(this IFreeSql that, DbProviderFactory factory) => _dicDbProviderFactory.AddOrUpdate(that.Ado.Identifier, factory, (fsql, old) => factory);
|
||||
internal static DbProviderFactory GetDbProviderFactory(this IFreeSql that) => _dicDbProviderFactory.TryGetValue(that.Ado.Identifier, out var trydbpf) ? trydbpf : throw new Exception("需要先设置 fsql.SetDbProviderFactory(..) 方法");
|
||||
}
|
||||
|
@ -0,0 +1,39 @@
|
||||
public static partial class FreeSqlCustomGlobalExtensions
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
/// 特殊处理类似 string.Format 的使用方法,防止注入,以及 IS NULL 转换
|
||||
/// </summary>
|
||||
/// <param name="that"></param>
|
||||
/// <param name="args"></param>
|
||||
/// <returns></returns>
|
||||
internal static string FormatCustomOracle(this string that, params object[] args) => _customOracleAdo.Addslashes(that, args);
|
||||
static FreeSql.Custom.Oracle.CustomOracleAdo _customOracleAdo = new FreeSql.Custom.Oracle.CustomOracleAdo();
|
||||
|
||||
/// <summary>
|
||||
/// 特殊处理类似 string.Format 的使用方法,防止注入,以及 IS NULL 转换
|
||||
/// </summary>
|
||||
/// <param name="that"></param>
|
||||
/// <param name="args"></param>
|
||||
/// <returns></returns>
|
||||
internal static string FormatCustomSqlServer(this string that, params object[] args) => _customSqlServerAdo.Addslashes(that, args);
|
||||
static FreeSql.Custom.SqlServer.CustomSqlServerAdo _customSqlServerAdo = new FreeSql.Custom.SqlServer.CustomSqlServerAdo();
|
||||
|
||||
/// <summary>
|
||||
/// 特殊处理类似 string.Format 的使用方法,防止注入,以及 IS NULL 转换
|
||||
/// </summary>
|
||||
/// <param name="that"></param>
|
||||
/// <param name="args"></param>
|
||||
/// <returns></returns>
|
||||
internal static string FormatCustomMySql(this string that, params object[] args) => _customMySqlAdo.Addslashes(that, args);
|
||||
static FreeSql.Custom.MySql.CustomMySqlAdo _customMySqlAdo = new FreeSql.Custom.MySql.CustomMySqlAdo();
|
||||
|
||||
/// <summary>
|
||||
/// 特殊处理类似 string.Format 的使用方法,防止注入,以及 IS NULL 转换
|
||||
/// </summary>
|
||||
/// <param name="that"></param>
|
||||
/// <param name="args"></param>
|
||||
/// <returns></returns>
|
||||
internal static string FormatCustomPostgreSQL(this string that, params object[] args) => _customPostgreSQLAdo.Addslashes(that, args);
|
||||
static FreeSql.Custom.PostgreSQL.CustomPostgreSQLAdo _customPostgreSQLAdo = new FreeSql.Custom.PostgreSQL.CustomPostgreSQLAdo();
|
||||
}
|
@ -0,0 +1,121 @@
|
||||
using FreeSql.Internal;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
using System.Data.Common;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace FreeSql.Custom.MySql
|
||||
{
|
||||
|
||||
class CustomMySqlDelete<T1> : Internal.CommonProvider.DeleteProvider<T1>
|
||||
{
|
||||
public CustomMySqlDelete(IFreeSql orm, CommonUtils commonUtils, CommonExpression commonExpression, object dywhere)
|
||||
: base(orm, commonUtils, commonExpression, dywhere)
|
||||
{
|
||||
}
|
||||
|
||||
public override List<T1> ExecuteDeleted()
|
||||
{
|
||||
var ret = new List<T1>();
|
||||
DbParameter[] dbParms = null;
|
||||
StringBuilder sbret = null;
|
||||
ToSqlFetch(sb =>
|
||||
{
|
||||
if (dbParms == null)
|
||||
{
|
||||
dbParms = _params.ToArray();
|
||||
sbret = new StringBuilder();
|
||||
sbret.Append(" RETURNING ");
|
||||
|
||||
var colidx = 0;
|
||||
foreach (var col in _table.Columns.Values)
|
||||
{
|
||||
if (colidx > 0) sbret.Append(", ");
|
||||
sbret.Append(_commonUtils.RereadColumn(col, _commonUtils.QuoteSqlName(col.Attribute.Name))).Append(" as ").Append(_commonUtils.QuoteSqlName(col.CsName));
|
||||
++colidx;
|
||||
}
|
||||
}
|
||||
var sql = sb.Append(sbret).ToString();
|
||||
var before = new Aop.CurdBeforeEventArgs(_table.Type, _table, Aop.CurdType.Delete, sql, dbParms);
|
||||
_orm.Aop.CurdBeforeHandler?.Invoke(this, before);
|
||||
|
||||
Exception exception = null;
|
||||
try
|
||||
{
|
||||
ret.AddRange(_orm.Ado.Query<T1>(_table.TypeLazy ?? _table.Type, _connection, _transaction, CommandType.Text, sql, _commandTimeout, dbParms));
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
exception = ex;
|
||||
throw ex;
|
||||
}
|
||||
finally
|
||||
{
|
||||
var after = new Aop.CurdAfterEventArgs(before, exception, ret);
|
||||
_orm.Aop.CurdAfterHandler?.Invoke(this, after);
|
||||
}
|
||||
});
|
||||
if (dbParms != null)
|
||||
{
|
||||
this.ClearData();
|
||||
sbret.Clear();
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
#if net40
|
||||
#else
|
||||
async public override Task<List<T1>> ExecuteDeletedAsync(CancellationToken cancellationToken = default)
|
||||
{
|
||||
var ret = new List<T1>();
|
||||
DbParameter[] dbParms = null;
|
||||
StringBuilder sbret = null;
|
||||
await ToSqlFetchAsync(async sb =>
|
||||
{
|
||||
if (dbParms == null)
|
||||
{
|
||||
dbParms = _params.ToArray();
|
||||
sbret = new StringBuilder();
|
||||
sbret.Append(" RETURNING ");
|
||||
|
||||
var colidx = 0;
|
||||
foreach (var col in _table.Columns.Values)
|
||||
{
|
||||
if (colidx > 0) sbret.Append(", ");
|
||||
sbret.Append(_commonUtils.RereadColumn(col, _commonUtils.QuoteSqlName(col.Attribute.Name))).Append(" as ").Append(_commonUtils.QuoteSqlName(col.CsName));
|
||||
++colidx;
|
||||
}
|
||||
}
|
||||
var sql = sb.Append(sbret).ToString();
|
||||
var before = new Aop.CurdBeforeEventArgs(_table.Type, _table, Aop.CurdType.Delete, sql, dbParms);
|
||||
_orm.Aop.CurdBeforeHandler?.Invoke(this, before);
|
||||
|
||||
Exception exception = null;
|
||||
try
|
||||
{
|
||||
ret.AddRange(await _orm.Ado.QueryAsync<T1>(_table.TypeLazy ?? _table.Type, _connection, _transaction, CommandType.Text, sql, _commandTimeout, dbParms, cancellationToken));
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
exception = ex;
|
||||
throw ex;
|
||||
}
|
||||
finally
|
||||
{
|
||||
var after = new Aop.CurdAfterEventArgs(before, exception, ret);
|
||||
_orm.Aop.CurdAfterHandler?.Invoke(this, after);
|
||||
}
|
||||
});
|
||||
if (dbParms != null)
|
||||
{
|
||||
this.ClearData();
|
||||
sbret.Clear();
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
@ -0,0 +1,201 @@
|
||||
using FreeSql.Internal;
|
||||
using FreeSql.Internal.Model;
|
||||
using FreeSql.Internal.ObjectPool;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
using System.Data.Common;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace FreeSql.Custom.MySql
|
||||
{
|
||||
|
||||
class CustomMySqlInsert<T1> : Internal.CommonProvider.InsertProvider<T1> where T1 : class
|
||||
{
|
||||
public CustomMySqlInsert(IFreeSql orm, CommonUtils commonUtils, CommonExpression commonExpression)
|
||||
: base(orm, commonUtils, commonExpression)
|
||||
{
|
||||
}
|
||||
|
||||
internal bool InternalIsIgnoreInto = false;
|
||||
internal IFreeSql InternalOrm => _orm;
|
||||
internal TableInfo InternalTable => _table;
|
||||
internal DbParameter[] InternalParams => _params;
|
||||
internal DbConnection InternalConnection => _connection;
|
||||
internal DbTransaction InternalTransaction => _transaction;
|
||||
internal CommonUtils InternalCommonUtils => _commonUtils;
|
||||
internal CommonExpression InternalCommonExpression => _commonExpression;
|
||||
internal List<T1> InternalSource => _source;
|
||||
internal Dictionary<string, bool> InternalIgnore => _ignore;
|
||||
internal void InternalClearData() => ClearData();
|
||||
|
||||
public override int ExecuteAffrows() => base.SplitExecuteAffrows(_batchValuesLimit > 0 ? _batchValuesLimit : 5000, _batchParameterLimit > 0 ? _batchParameterLimit : 3000);
|
||||
public override long ExecuteIdentity() => base.SplitExecuteIdentity(_batchValuesLimit > 0 ? _batchValuesLimit : 5000, _batchParameterLimit > 0 ? _batchParameterLimit : 3000);
|
||||
public override List<T1> ExecuteInserted() => base.SplitExecuteInserted(_batchValuesLimit > 0 ? _batchValuesLimit : 5000, _batchParameterLimit > 0 ? _batchParameterLimit : 3000);
|
||||
|
||||
|
||||
public override string ToSql()
|
||||
{
|
||||
if (InternalIsIgnoreInto == false) return base.ToSqlValuesOrSelectUnionAll();
|
||||
var sql = base.ToSqlValuesOrSelectUnionAll();
|
||||
return $"INSERT IGNORE INTO {sql.Substring(12)}";
|
||||
}
|
||||
|
||||
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, _table, Aop.CurdType.Insert, string.Concat(sql, "; SELECT LAST_INSERT_ID();", _commandTimeout), _params);
|
||||
_orm.Aop.CurdBeforeHandler?.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, _commandTimeout, _params);
|
||||
ret = long.TryParse(string.Concat(_orm.Ado.ExecuteScalar(conn, _transaction, CommandType.Text, " SELECT LAST_INSERT_ID()", _commandTimeout)), 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.CurdAfterHandler?.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.RereadColumn(col, _commonUtils.QuoteSqlName(col.Attribute.Name))).Append(" as ").Append(_commonUtils.QuoteSqlName(col.CsName));
|
||||
++colidx;
|
||||
}
|
||||
sql = sb.ToString();
|
||||
var before = new Aop.CurdBeforeEventArgs(_table.Type, _table, Aop.CurdType.Insert, sql, _params);
|
||||
_orm.Aop.CurdBeforeHandler?.Invoke(this, before);
|
||||
var ret = new List<T1>();
|
||||
Exception exception = null;
|
||||
try
|
||||
{
|
||||
ret = _orm.Ado.Query<T1>(_table.TypeLazy ?? _table.Type, _connection, _transaction, CommandType.Text, sql, _commandTimeout, _params);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
exception = ex;
|
||||
throw ex;
|
||||
}
|
||||
finally
|
||||
{
|
||||
var after = new Aop.CurdAfterEventArgs(before, exception, ret);
|
||||
_orm.Aop.CurdAfterHandler?.Invoke(this, after);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
#if net40
|
||||
#else
|
||||
public override Task<int> ExecuteAffrowsAsync(CancellationToken cancellationToken = default) => base.SplitExecuteAffrowsAsync(_batchValuesLimit > 0 ? _batchValuesLimit : 5000, _batchParameterLimit > 0 ? _batchParameterLimit : 3000, cancellationToken);
|
||||
public override Task<long> ExecuteIdentityAsync(CancellationToken cancellationToken = default) => base.SplitExecuteIdentityAsync(_batchValuesLimit > 0 ? _batchValuesLimit : 5000, _batchParameterLimit > 0 ? _batchParameterLimit : 3000, cancellationToken);
|
||||
public override Task<List<T1>> ExecuteInsertedAsync(CancellationToken cancellationToken = default) => base.SplitExecuteInsertedAsync(_batchValuesLimit > 0 ? _batchValuesLimit : 5000, _batchParameterLimit > 0 ? _batchParameterLimit : 3000, cancellationToken);
|
||||
|
||||
async protected override Task<long> RawExecuteIdentityAsync(CancellationToken cancellationToken = default)
|
||||
{
|
||||
var sql = this.ToSql();
|
||||
if (string.IsNullOrEmpty(sql)) return 0;
|
||||
|
||||
Object<DbConnection> poolConn = null;
|
||||
var before = new Aop.CurdBeforeEventArgs(_table.Type, _table, Aop.CurdType.Insert, string.Concat(sql, "; SELECT LAST_INSERT_ID();"), _params);
|
||||
_orm.Aop.CurdBeforeHandler?.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, _commandTimeout, _params, cancellationToken);
|
||||
ret = long.TryParse(string.Concat(await _orm.Ado.ExecuteScalarAsync(conn, _transaction, CommandType.Text, " SELECT LAST_INSERT_ID()", _commandTimeout, null, cancellationToken)), 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.CurdAfterHandler?.Invoke(this, after);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
async protected override Task<List<T1>> RawExecuteInsertedAsync(CancellationToken cancellationToken = default)
|
||||
{
|
||||
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.RereadColumn(col, _commonUtils.QuoteSqlName(col.Attribute.Name))).Append(" as ").Append(_commonUtils.QuoteSqlName(col.CsName));
|
||||
++colidx;
|
||||
}
|
||||
sql = sb.ToString();
|
||||
var before = new Aop.CurdBeforeEventArgs(_table.Type, _table, Aop.CurdType.Insert, sql, _params);
|
||||
_orm.Aop.CurdBeforeHandler?.Invoke(this, before);
|
||||
var ret = new List<T1>();
|
||||
Exception exception = null;
|
||||
try
|
||||
{
|
||||
ret = await _orm.Ado.QueryAsync<T1>(_table.TypeLazy ?? _table.Type, _connection, _transaction, CommandType.Text, sql, _commandTimeout, _params, cancellationToken);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
exception = ex;
|
||||
throw ex;
|
||||
}
|
||||
finally
|
||||
{
|
||||
var after = new Aop.CurdAfterEventArgs(before, exception, ret);
|
||||
_orm.Aop.CurdAfterHandler?.Invoke(this, after);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
@ -0,0 +1,88 @@
|
||||
using FreeSql.Internal;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data.Common;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace FreeSql.Custom.MySql
|
||||
{
|
||||
|
||||
class CustomMySqlInsertOrUpdate<T1> : Internal.CommonProvider.InsertOrUpdateProvider<T1> where T1 : class
|
||||
{
|
||||
public CustomMySqlInsertOrUpdate(IFreeSql orm, CommonUtils commonUtils, CommonExpression commonExpression)
|
||||
: base(orm, commonUtils, commonExpression)
|
||||
{
|
||||
}
|
||||
|
||||
public override string ToSql()
|
||||
{
|
||||
var dbParams = new List<DbParameter>();
|
||||
if (_sourceSql != null)
|
||||
{
|
||||
var data = new List<T1>();
|
||||
data.Add((T1)_table.Type.CreateInstanceGetDefaultValue());
|
||||
var sql = getInsertSql(data, false, false);
|
||||
var sb = new StringBuilder();
|
||||
sb.Append(sql.Substring(0, sql.IndexOf(") VALUES")));
|
||||
sb.Append(") \r\n");
|
||||
WriteSourceSelectUnionAll(null, sb, null);
|
||||
if (_doNothing == false)
|
||||
sb.Append(sql.Substring(sql.IndexOf("\r\nON DUPLICATE KEY UPDATE\r\n") + 2));
|
||||
else
|
||||
throw new Exception("Not implemented! fsql.InsertOrUpdate + SetSource(sql) + IfExistsDoNothing + MySql");
|
||||
return sb.ToString();
|
||||
}
|
||||
if (_source?.Any() != true) return null;
|
||||
|
||||
var sqls = new string[2];
|
||||
var ds = SplitSourceByIdentityValueIsNull(_source);
|
||||
if (ds.Item1.Any()) sqls[0] = string.Join("\r\n\r\n;\r\n\r\n", ds.Item1.Select(a => getInsertSql(a, false, true)));
|
||||
if (ds.Item2.Any()) sqls[1] = string.Join("\r\n\r\n;\r\n\r\n", ds.Item2.Select(a => getInsertSql(a, true, true)));
|
||||
_params = dbParams.ToArray();
|
||||
if (ds.Item2.Any() == false) return sqls[0];
|
||||
if (ds.Item1.Any() == false) return sqls[1];
|
||||
return string.Join("\r\n\r\n;\r\n\r\n", sqls);
|
||||
|
||||
string getInsertSql(List<T1> data, bool flagInsert, bool noneParameter)
|
||||
{
|
||||
var insert = _orm.Insert<T1>()
|
||||
.AsTable(_tableRule).AsType(_table.Type)
|
||||
.WithConnection(_connection)
|
||||
.WithTransaction(_transaction)
|
||||
.NoneParameter(noneParameter) as Internal.CommonProvider.InsertProvider<T1>;
|
||||
insert._source = data;
|
||||
insert._table = _table;
|
||||
insert._noneParameterFlag = flagInsert ? "cuc" : "cu";
|
||||
|
||||
string sql = "";
|
||||
if (IdentityColumn != null && flagInsert) sql = insert.ToSql();
|
||||
else
|
||||
{
|
||||
insert.InsertIdentity();
|
||||
if (_doNothing == false)
|
||||
{
|
||||
var cols = _table.Columns.Values.Where(a => _tempPrimarys.Contains(a) == false && a.Attribute.CanUpdate == true && _updateIgnore.ContainsKey(a.Attribute.Name) == false);
|
||||
sql = new CustomMySqlOnDuplicateKeyUpdate<T1>(insert)
|
||||
.UpdateColumns(cols.Select(a => a.Attribute.Name).ToArray())
|
||||
.ToSql();
|
||||
}
|
||||
else
|
||||
{
|
||||
if (_tempPrimarys.Any() == false) throw new Exception(CoreStrings.Entity_Must_Primary_Key("fsql.InsertOrUpdate + IfExistsDoNothing + MySql ", _table.CsName));
|
||||
sql = insert.ToSqlValuesOrSelectUnionAllExtension101(false, (rowd, idx, sb) =>
|
||||
sb.Append(" \r\n FROM dual WHERE NOT EXISTS(").Append(
|
||||
_orm.Select<T1>()
|
||||
.AsTable((_, __) => _tableRule?.Invoke(__)).AsType(_table.Type)
|
||||
.DisableGlobalFilter()
|
||||
.WhereDynamic(rowd)
|
||||
.Limit(1).ToSql("1").Replace(" \r\n", " \r\n ")).Append(")"));
|
||||
}
|
||||
}
|
||||
if (string.IsNullOrEmpty(sql)) return null;
|
||||
if (insert._params?.Any() == true) dbParams.AddRange(insert._params);
|
||||
return sql;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
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