mirror of
https://github.com/nsnail/FreeSql.git
synced 2025-04-22 02:32:50 +08:00
Merge branch 'master' into fix_tree
This commit is contained in:
commit
d5dc037d09
@ -106,9 +106,12 @@ namespace base_entity
|
|||||||
.UseAutoSyncStructure(true)
|
.UseAutoSyncStructure(true)
|
||||||
.UseNoneCommandParameter(true)
|
.UseNoneCommandParameter(true)
|
||||||
|
|
||||||
.UseConnectionString(FreeSql.DataType.Sqlite, "data source=test.db;max pool size=5")
|
.UseConnectionString(FreeSql.DataType.Sqlite, "data source=test1.db;max pool size=5")
|
||||||
|
.UseSlave("data source=test1.db", "data source=test2.db", "data source=test3.db", "data source=test4.db")
|
||||||
|
.UseSlaveWeight(10, 1, 1, 5)
|
||||||
|
|
||||||
.UseConnectionString(FreeSql.DataType.MySql, "Data Source=127.0.0.1;Port=3306;User ID=root;Password=root;Initial Catalog=cccddd;Charset=utf8;SslMode=none;Max pool size=2")
|
|
||||||
|
//.UseConnectionString(FreeSql.DataType.MySql, "Data Source=127.0.0.1;Port=3306;User ID=root;Password=root;Initial Catalog=cccddd;Charset=utf8;SslMode=none;Max pool size=2")
|
||||||
|
|
||||||
//.UseConnectionString(FreeSql.DataType.SqlServer, "Data Source=.;Integrated Security=True;Initial Catalog=freesqlTest;Pooling=true;Max Pool Size=3")
|
//.UseConnectionString(FreeSql.DataType.SqlServer, "Data Source=.;Integrated Security=True;Initial Catalog=freesqlTest;Pooling=true;Max Pool Size=3")
|
||||||
|
|
||||||
@ -131,13 +134,58 @@ namespace base_entity
|
|||||||
|
|
||||||
//.UseConnectionString(FreeSql.DataType.OdbcDameng, "Driver={DM8 ODBC DRIVER};Server=127.0.0.1:5236;Persist Security Info=False;Trusted_Connection=Yes;UID=USER1;PWD=123456789")
|
//.UseConnectionString(FreeSql.DataType.OdbcDameng, "Driver={DM8 ODBC DRIVER};Server=127.0.0.1:5236;Persist Security Info=False;Trusted_Connection=Yes;UID=USER1;PWD=123456789")
|
||||||
|
|
||||||
.UseMonitorCommand(umcmd => Console.WriteLine(umcmd.CommandText))
|
.UseMonitorCommand(null, (umcmd, log) => Console.WriteLine(umcmd.Connection.ConnectionString + ":" + umcmd.CommandText))
|
||||||
.UseLazyLoading(true)
|
.UseLazyLoading(true)
|
||||||
.UseGenerateCommandParameterWithLambda(true)
|
.UseGenerateCommandParameterWithLambda(true)
|
||||||
.Build();
|
.Build();
|
||||||
BaseEntity.Initialization(fsql, () => _asyncUow.Value);
|
BaseEntity.Initialization(fsql, () => _asyncUow.Value);
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
fsql.Aop.AuditValue += new EventHandler<FreeSql.Aop.AuditValueEventArgs>((_, e) =>
|
||||||
|
{
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
Dictionary<string, object> dic = new Dictionary<string, object>();
|
||||||
|
dic.Add("id", 1);
|
||||||
|
dic.Add("name", "xxxx");
|
||||||
|
var diclist = new List<Dictionary<string, object>>();
|
||||||
|
diclist.Add(dic);
|
||||||
|
diclist.Add(new Dictionary<string, object>
|
||||||
|
{
|
||||||
|
["id"] = 2,
|
||||||
|
["name"] = "yyyy"
|
||||||
|
});
|
||||||
|
|
||||||
|
var sqss = fsql.InsertDict(dic).AsTable("table1").ToSql();
|
||||||
|
var sqss2 = fsql.InsertDict(diclist).AsTable("table1").ToSql();
|
||||||
|
sqss = fsql.InsertDict(dic).AsTable("table1").NoneParameter(false).ToSql();
|
||||||
|
sqss2 = fsql.InsertDict(diclist).AsTable("table1").NoneParameter(false).ToSql();
|
||||||
|
|
||||||
|
var sqlupd1 = fsql.UpdateDict(dic).AsTable("table1").WherePrimary("id").ToSql();
|
||||||
|
var sqlupd2 = fsql.UpdateDict(diclist).AsTable("table1").WherePrimary("id").ToSql();
|
||||||
|
var sqlupd11 = fsql.UpdateDict(dic).AsTable("table1").WherePrimary("id").NoneParameter(false).ToSql();
|
||||||
|
var sqlupd22 = fsql.UpdateDict(diclist).AsTable("table1").WherePrimary("id").NoneParameter(false).ToSql();
|
||||||
|
|
||||||
|
var sqldel1 = fsql.DeleteDict(dic).AsTable("table1").ToSql();
|
||||||
|
var sqldel2 = fsql.DeleteDict(diclist).AsTable("table1").ToSql();
|
||||||
|
diclist[1]["title"] = "newtitle";
|
||||||
|
var sqldel3 = fsql.DeleteDict(diclist).AsTable("table1").ToSql();
|
||||||
|
diclist.Clear();
|
||||||
|
diclist.Add(new Dictionary<string, object>
|
||||||
|
{
|
||||||
|
["id"] = 1
|
||||||
|
});
|
||||||
|
diclist.Add(new Dictionary<string, object>
|
||||||
|
{
|
||||||
|
["id"] = 2
|
||||||
|
});
|
||||||
|
var sqldel4 = fsql.DeleteDict(diclist).AsTable("table1").ToSql();
|
||||||
|
|
||||||
|
|
||||||
|
for (var a = 0; a < 10000; a++)
|
||||||
|
fsql.Select<User1>().First();
|
||||||
|
|
||||||
for (var a = 0; a < 1000; a++)
|
for (var a = 0; a < 1000; a++)
|
||||||
{
|
{
|
||||||
fsql.Transaction(() =>
|
fsql.Transaction(() =>
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<TargetFrameworks>netstandard2.0;net45;net40</TargetFrameworks>
|
<TargetFrameworks>netstandard2.0;net45;net40</TargetFrameworks>
|
||||||
<Version>2.6.100</Version>
|
<Version>3.2.300</Version>
|
||||||
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
|
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
|
||||||
<Authors>FreeSql;ncc;YeXiangQin</Authors>
|
<Authors>FreeSql;ncc;YeXiangQin</Authors>
|
||||||
<Description>BaseEntity 是一种极简单的 CodeFirst 开发方式,特别对单表或多表CRUD,利用继承节省了每个实体类的重复属性(创建时间、ID等字段),软件删除等功能,进行 crud 操作时不必时常考虑仓储的使用.</Description>
|
<Description>BaseEntity 是一种极简单的 CodeFirst 开发方式,特别对单表或多表CRUD,利用继承节省了每个实体类的重复属性(创建时间、ID等字段),软件删除等功能,进行 crud 操作时不必时常考虑仓储的使用.</Description>
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<TargetFrameworks>netstandard2.0;net45;net40</TargetFrameworks>
|
<TargetFrameworks>netstandard2.0;net45;net40</TargetFrameworks>
|
||||||
<Version>2.6.100</Version>
|
<Version>3.2.300</Version>
|
||||||
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
|
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
|
||||||
<Authors>FreeSql;ncc;YeXiangQin</Authors>
|
<Authors>FreeSql;ncc;YeXiangQin</Authors>
|
||||||
<Description>FreeSql 扩展包,可实现实体类属性为对象时,以JSON形式映射存储.</Description>
|
<Description>FreeSql 扩展包,可实现实体类属性为对象时,以JSON形式映射存储.</Description>
|
||||||
|
@ -14,6 +14,7 @@ public static class FreeSqlJsonMapCoreExtensions
|
|||||||
static MethodInfo MethodJsonConvertDeserializeObject = typeof(JsonConvert).GetMethod("DeserializeObject", new[] { typeof(string), typeof(Type) });
|
static MethodInfo MethodJsonConvertDeserializeObject = typeof(JsonConvert).GetMethod("DeserializeObject", new[] { typeof(string), typeof(Type) });
|
||||||
static MethodInfo MethodJsonConvertSerializeObject = typeof(JsonConvert).GetMethod("SerializeObject", new[] { typeof(object), typeof(JsonSerializerSettings) });
|
static MethodInfo MethodJsonConvertSerializeObject = typeof(JsonConvert).GetMethod("SerializeObject", new[] { typeof(object), typeof(JsonSerializerSettings) });
|
||||||
static ConcurrentDictionary<Type, ConcurrentDictionary<string, bool>> _dicJsonMapFluentApi = new ConcurrentDictionary<Type, ConcurrentDictionary<string, bool>>();
|
static ConcurrentDictionary<Type, ConcurrentDictionary<string, bool>> _dicJsonMapFluentApi = new ConcurrentDictionary<Type, ConcurrentDictionary<string, bool>>();
|
||||||
|
static object _concurrentObj = new object();
|
||||||
|
|
||||||
public static ColumnFluent JsonMap(this ColumnFluent col)
|
public static ColumnFluent JsonMap(this ColumnFluent col)
|
||||||
{
|
{
|
||||||
@ -52,13 +53,17 @@ public static class FreeSqlJsonMapCoreExtensions
|
|||||||
e.ModifyResult.StringLength = -2;
|
e.ModifyResult.StringLength = -2;
|
||||||
if (_dicTypes.TryAdd(e.Property.PropertyType, true))
|
if (_dicTypes.TryAdd(e.Property.PropertyType, true))
|
||||||
{
|
{
|
||||||
FreeSql.Internal.Utils.GetDataReaderValueBlockExpressionObjectToStringIfThenElse.Add((LabelTarget returnTarget, Expression valueExp, Expression elseExp, Type type) =>
|
lock (_concurrentObj)
|
||||||
{
|
{
|
||||||
return Expression.IfThenElse(
|
FreeSql.Internal.Utils.dicExecuteArrayRowReadClassOrTuple[e.Property.PropertyType] = true;
|
||||||
Expression.TypeIs(valueExp, e.Property.PropertyType),
|
FreeSql.Internal.Utils.GetDataReaderValueBlockExpressionObjectToStringIfThenElse.Add((LabelTarget returnTarget, Expression valueExp, Expression elseExp, Type type) =>
|
||||||
Expression.Return(returnTarget, Expression.Call(MethodJsonConvertSerializeObject, Expression.Convert(valueExp, typeof(object)), Expression.Constant(settings)), typeof(object)),
|
{
|
||||||
elseExp);
|
return Expression.IfThenElse(
|
||||||
});
|
Expression.TypeIs(valueExp, e.Property.PropertyType),
|
||||||
|
Expression.Return(returnTarget, Expression.Call(MethodJsonConvertSerializeObject, Expression.Convert(valueExp, typeof(object)), Expression.Constant(settings)), typeof(object)),
|
||||||
|
elseExp);
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<TargetFrameworks>netstandard2.0;netstandard2.1;net45;net40</TargetFrameworks>
|
<TargetFrameworks>netstandard2.0;netstandard2.1;net45;net40</TargetFrameworks>
|
||||||
<Version>2.6.100</Version>
|
<Version>3.2.300</Version>
|
||||||
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
|
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
|
||||||
<Authors>FreeSql;ncc;YeXiangQin</Authors>
|
<Authors>FreeSql;ncc;YeXiangQin</Authors>
|
||||||
<Description>FreeSql 扩展包,可实现【延时加载】属性.</Description>
|
<Description>FreeSql 扩展包,可实现【延时加载】属性.</Description>
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<TargetFrameworks>netstandard2.0;net45;net40</TargetFrameworks>
|
<TargetFrameworks>netstandard2.0;net45;net40</TargetFrameworks>
|
||||||
<Version>2.6.100</Version>
|
<Version>3.2.300</Version>
|
||||||
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
|
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
|
||||||
<Authors>FreeSql;ncc;YeXiangQin</Authors>
|
<Authors>FreeSql;ncc;YeXiangQin</Authors>
|
||||||
<Description>FreeSql 扩展包,实现 linq queryable 和 linq to sql 语法进行开发.</Description>
|
<Description>FreeSql 扩展包,实现 linq queryable 和 linq to sql 语法进行开发.</Description>
|
||||||
|
@ -180,6 +180,7 @@ new Colorful.Formatter("推荐在实体类目录创建 gen.bat,双击它重新
|
|||||||
case "dameng": ArgsDbType = DataType.Dameng; break;
|
case "dameng": ArgsDbType = DataType.Dameng; break;
|
||||||
case "kingbasees": ArgsDbType = DataType.KingbaseES; break;
|
case "kingbasees": ArgsDbType = DataType.KingbaseES; break;
|
||||||
case "shentong": ArgsDbType = DataType.ShenTong; break;
|
case "shentong": ArgsDbType = DataType.ShenTong; break;
|
||||||
|
case "clickhouse": ArgsDbType = DataType.ClickHouse; break;
|
||||||
default: throw new ArgumentException($"-DB 参数错误,不支持的类型:\"{dbargs[0]}\"");
|
default: throw new ArgumentException($"-DB 参数错误,不支持的类型:\"{dbargs[0]}\"");
|
||||||
}
|
}
|
||||||
ArgsConnectionString = dbargs[1].Trim();
|
ArgsConnectionString = dbargs[1].Trim();
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<OutputType>Exe</OutputType>
|
<OutputType>Exe</OutputType>
|
||||||
<TargetFrameworks>netcoreapp3.1;net50</TargetFrameworks>
|
<TargetFrameworks>netcoreapp3.1;net60</TargetFrameworks>
|
||||||
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
|
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
|
||||||
<IsPackable>true</IsPackable>
|
<IsPackable>true</IsPackable>
|
||||||
<PackAsTool>true</PackAsTool>
|
<PackAsTool>true</PackAsTool>
|
||||||
@ -12,15 +12,15 @@
|
|||||||
<Description>使用 FreeSql 快速生成数据库的实体类,安装:dotnet tool install -g FreeSql.Generator</Description>
|
<Description>使用 FreeSql 快速生成数据库的实体类,安装:dotnet tool install -g FreeSql.Generator</Description>
|
||||||
<PackageProjectUrl>https://github.com/2881099/FreeSql</PackageProjectUrl>
|
<PackageProjectUrl>https://github.com/2881099/FreeSql</PackageProjectUrl>
|
||||||
<RepositoryUrl>https://github.com/2881099/FreeSql</RepositoryUrl>
|
<RepositoryUrl>https://github.com/2881099/FreeSql</RepositoryUrl>
|
||||||
<Version>2.6.100</Version>
|
<Version>3.2.300</Version>
|
||||||
<PackageTags>FreeSql DbFirst 实体生成器</PackageTags>
|
<PackageTags>FreeSql DbFirst 实体生成器</PackageTags>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="Colorful.Console" Version="1.2.9" />
|
<PackageReference Include="Colorful.Console" Version="1.2.9" />
|
||||||
<PackageReference Include="RazorEngine.NetCore" Version="2.2.6" />
|
<PackageReference Include="RazorEngine.NetCore" Version="2.2.6" />
|
||||||
<PackageReference Include="System.CodeDom" Version="5.0.0" />
|
<PackageReference Include="System.CodeDom" Version="6.0.0" />
|
||||||
<PackageReference Include="System.Text.Encoding.CodePages" Version="5.0.0" />
|
<PackageReference Include="System.Text.Encoding.CodePages" Version="6.0.0" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
@ -63,9 +63,9 @@ namespace @gen.NameSpace {
|
|||||||
|
|
||||||
@foreach (var col in gen.columns) {
|
@foreach (var col in gen.columns) {
|
||||||
|
|
||||||
if (string.IsNullOrEmpty(col.Coment) == false) {
|
if (string.IsNullOrEmpty(col.Comment) == false) {
|
||||||
@:/// <summary>
|
@:/// <summary>
|
||||||
@:/// @col.Coment.Replace(""\r\n"", ""\n"").Replace(""\n"", ""\r\n /// "")
|
@:/// @col.Comment.Replace(""\r\n"", ""\n"").Replace(""\n"", ""\r\n /// "")
|
||||||
@:/// </summary>
|
@:/// </summary>
|
||||||
}
|
}
|
||||||
@:@(""[JsonProperty"" + GetAttributeString(gen.GetColumnAttribute(col, true)) + ""]"")
|
@:@(""[JsonProperty"" + GetAttributeString(gen.GetColumnAttribute(col, true)) + ""]"")
|
||||||
@ -154,9 +154,9 @@ namespace @gen.NameSpace {
|
|||||||
var findfks = fks.Where(fkaa => fkaa.Columns.Where(fkaac1 => fkaac1.Name == col.Name).Any());
|
var findfks = fks.Where(fkaa => fkaa.Columns.Where(fkaac1 => fkaac1.Name == col.Name).Any());
|
||||||
var csname = gen.GetCsName(col.Name);
|
var csname = gen.GetCsName(col.Name);
|
||||||
|
|
||||||
if (string.IsNullOrEmpty(col.Coment) == false) {
|
if (string.IsNullOrEmpty(col.Comment) == false) {
|
||||||
@:/// <summary>
|
@:/// <summary>
|
||||||
@:/// @col.Coment.Replace(""\r\n"", ""\n"").Replace(""\n"", ""\r\n /// "")
|
@:/// @col.Comment.Replace(""\r\n"", ""\n"").Replace(""\n"", ""\r\n /// "")
|
||||||
@:/// </summary>
|
@:/// </summary>
|
||||||
}
|
}
|
||||||
@:@(""[JsonProperty"" + GetAttributeString(gen.GetColumnAttribute(col, true)) + ""]"")
|
@:@(""[JsonProperty"" + GetAttributeString(gen.GetColumnAttribute(col, true)) + ""]"")
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<TargetFrameworks>netstandard2.0;net45;net40</TargetFrameworks>
|
<TargetFrameworks>netstandard2.0;net45;net40</TargetFrameworks>
|
||||||
<Version>2.6.100</Version>
|
<Version>3.2.300</Version>
|
||||||
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
|
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
|
||||||
<Authors>FreeSql;ncc;YeXiangQin</Authors>
|
<Authors>FreeSql;ncc;YeXiangQin</Authors>
|
||||||
<Description>FreeSql 全家桶,懒人专用</Description>
|
<Description>FreeSql 全家桶,懒人专用</Description>
|
||||||
|
@ -217,7 +217,7 @@ namespace FreeSql
|
|||||||
/// 比较实体,计算出值发生变化的属性,以及属性变化的前后值
|
/// 比较实体,计算出值发生变化的属性,以及属性变化的前后值
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="newdata">最新的实体对象,它将与附加实体的状态对比</param>
|
/// <param name="newdata">最新的实体对象,它将与附加实体的状态对比</param>
|
||||||
/// <returns></returns>
|
/// <returns>key: 属性名, value: [旧值, 新值]</returns>
|
||||||
public Dictionary<string, object[]> CompareState<TEntity>(TEntity newdata) where TEntity : class
|
public Dictionary<string, object[]> CompareState<TEntity>(TEntity newdata) where TEntity : class
|
||||||
{
|
{
|
||||||
CheckEntityTypeOrThrow(typeof(TEntity));
|
CheckEntityTypeOrThrow(typeof(TEntity));
|
||||||
|
@ -223,7 +223,7 @@ namespace FreeSql
|
|||||||
/// 比较实体,计算出值发生变化的属性,以及属性变化的前后值
|
/// 比较实体,计算出值发生变化的属性,以及属性变化的前后值
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="newdata">最新的实体对象,它将与附加实体的状态对比</param>
|
/// <param name="newdata">最新的实体对象,它将与附加实体的状态对比</param>
|
||||||
/// <returns></returns>
|
/// <returns>key: 属性名, value: [旧值, 新值]</returns>
|
||||||
public Dictionary<string, object[]> CompareState(TEntity newdata)
|
public Dictionary<string, object[]> CompareState(TEntity newdata)
|
||||||
{
|
{
|
||||||
if (newdata == null) return null;
|
if (newdata == null) return null;
|
||||||
@ -305,6 +305,7 @@ namespace FreeSql
|
|||||||
case DataType.KingbaseES:
|
case DataType.KingbaseES:
|
||||||
case DataType.OdbcKingbaseES:
|
case DataType.OdbcKingbaseES:
|
||||||
case DataType.ShenTong:
|
case DataType.ShenTong:
|
||||||
|
case DataType.ClickHouse:
|
||||||
return true;
|
return true;
|
||||||
default:
|
default:
|
||||||
if (_tableIdentitys.Length == 1 && _table.Primarys.Length == 1)
|
if (_tableIdentitys.Length == 1 && _table.Primarys.Length == 1)
|
||||||
@ -320,6 +321,7 @@ namespace FreeSql
|
|||||||
if (isThrow) throw new Exception($"不可添加,已存在于状态管理:{_db.OrmOriginal.GetEntityString(_entityType, data)}");
|
if (isThrow) throw new Exception($"不可添加,已存在于状态管理:{_db.OrmOriginal.GetEntityString(_entityType, data)}");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
if (_db.OrmOriginal.Ado.DataType == DataType.ClickHouse) return true;
|
||||||
var idval = _db.OrmOriginal.GetEntityIdentityValueWithPrimary(_entityType, data);
|
var idval = _db.OrmOriginal.GetEntityIdentityValueWithPrimary(_entityType, data);
|
||||||
if (idval > 0)
|
if (idval > 0)
|
||||||
{
|
{
|
||||||
|
@ -274,9 +274,9 @@ namespace FreeSql
|
|||||||
var isEquals = true;
|
var isEquals = true;
|
||||||
for (var midcolidx = tref.Columns.Count; midcolidx < tref.MiddleColumns.Count; midcolidx++)
|
for (var midcolidx = tref.Columns.Count; midcolidx < tref.MiddleColumns.Count; midcolidx++)
|
||||||
{
|
{
|
||||||
var refcol = tref.Columns[midcolidx - tref.Columns.Count];
|
var refcol = tref.RefColumns[midcolidx - tref.Columns.Count];
|
||||||
var midval = FreeSql.Internal.Utils.GetDataReaderValue(refcol.CsType, _db.OrmOriginal.GetEntityValueWithPropertyName(tref.RefMiddleEntityType, midItem, tref.MiddleColumns[midcolidx].CsName));
|
var midval = FreeSql.Internal.Utils.GetDataReaderValue(refcol.CsType, _db.OrmOriginal.GetEntityValueWithPropertyName(tref.RefMiddleEntityType, midItem, tref.MiddleColumns[midcolidx].CsName));
|
||||||
var refval = FreeSql.Internal.Utils.GetDataReaderValue(refcol.CsType, _db.OrmOriginal.GetEntityValueWithPropertyName(tref.RefEntityType, curList[curIdx], tref.Columns[midcolidx - tref.Columns.Count].CsName));
|
var refval = FreeSql.Internal.Utils.GetDataReaderValue(refcol.CsType, _db.OrmOriginal.GetEntityValueWithPropertyName(tref.RefEntityType, curList[curIdx], refcol.CsName));
|
||||||
if (object.Equals(midval, refval) == false)
|
if (object.Equals(midval, refval) == false)
|
||||||
{
|
{
|
||||||
isEquals = false;
|
isEquals = false;
|
||||||
|
@ -2,10 +2,10 @@
|
|||||||
|
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<TargetFrameworks>netstandard2.0;net60;net50;netcoreapp31;netcoreapp21;net45;net40</TargetFrameworks>
|
<TargetFrameworks>netstandard2.0;net60;net50;netcoreapp31;netcoreapp21;net45;net40</TargetFrameworks>
|
||||||
<Version>2.6.100</Version>
|
<Version>3.2.300</Version>
|
||||||
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
|
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
|
||||||
<Authors>FreeSql;ncc;YeXiangQin</Authors>
|
<Authors>FreeSql;ncc;YeXiangQin</Authors>
|
||||||
<Description>FreeSql is the ORM in .NetCore, .NetFramework, And Xamarin. It supports Mysql, Postgresql, SqlServer, Oracle, Sqlite, Firebird, Odbc, 达梦, 人大金仓, 神舟通用, 翰高, And Access</Description>
|
<Description>FreeSql is the ORM in .NetCore, .NetFramework, And Xamarin. It supports Mysql, Postgresql, SqlServer, Oracle, Sqlite, Firebird, Odbc, 达梦, 人大金仓, 神舟通用, 南大通用, 翰高, And Access</Description>
|
||||||
<PackageProjectUrl>https://github.com/2881099/FreeSql/wiki/DbContext</PackageProjectUrl>
|
<PackageProjectUrl>https://github.com/2881099/FreeSql/wiki/DbContext</PackageProjectUrl>
|
||||||
<PackageTags>FreeSql ORM DbContext</PackageTags>
|
<PackageTags>FreeSql ORM DbContext</PackageTags>
|
||||||
<RepositoryType>git</RepositoryType>
|
<RepositoryType>git</RepositoryType>
|
||||||
|
@ -67,7 +67,7 @@
|
|||||||
比较实体,计算出值发生变化的属性,以及属性变化的前后值
|
比较实体,计算出值发生变化的属性,以及属性变化的前后值
|
||||||
</summary>
|
</summary>
|
||||||
<param name="newdata">最新的实体对象,它将与附加实体的状态对比</param>
|
<param name="newdata">最新的实体对象,它将与附加实体的状态对比</param>
|
||||||
<returns></returns>
|
<returns>key: 属性名, value: [旧值, 新值]</returns>
|
||||||
</member>
|
</member>
|
||||||
<member name="P:FreeSql.DbContext.EntityChangeReport.ChangeInfo.BeforeObject">
|
<member name="P:FreeSql.DbContext.EntityChangeReport.ChangeInfo.BeforeObject">
|
||||||
<summary>
|
<summary>
|
||||||
@ -142,7 +142,7 @@
|
|||||||
比较实体,计算出值发生变化的属性,以及属性变化的前后值
|
比较实体,计算出值发生变化的属性,以及属性变化的前后值
|
||||||
</summary>
|
</summary>
|
||||||
<param name="newdata">最新的实体对象,它将与附加实体的状态对比</param>
|
<param name="newdata">最新的实体对象,它将与附加实体的状态对比</param>
|
||||||
<returns></returns>
|
<returns>key: 属性名, value: [旧值, 新值]</returns>
|
||||||
</member>
|
</member>
|
||||||
<member name="M:FreeSql.DbSet`1.FlushState">
|
<member name="M:FreeSql.DbSet`1.FlushState">
|
||||||
<summary>
|
<summary>
|
||||||
@ -333,7 +333,7 @@
|
|||||||
比较实体,计算出值发生变化的属性,以及属性变化的前后值
|
比较实体,计算出值发生变化的属性,以及属性变化的前后值
|
||||||
</summary>
|
</summary>
|
||||||
<param name="newdata">最新的实体对象,它将与附加实体的状态对比</param>
|
<param name="newdata">最新的实体对象,它将与附加实体的状态对比</param>
|
||||||
<returns></returns>
|
<returns>key: 属性名, value: [旧值, 新值]</returns>
|
||||||
</member>
|
</member>
|
||||||
<member name="M:FreeSql.IBaseRepository`1.SaveMany(`0,System.String)">
|
<member name="M:FreeSql.IBaseRepository`1.SaveMany(`0,System.String)">
|
||||||
<summary>
|
<summary>
|
||||||
|
@ -40,7 +40,7 @@ namespace FreeSql
|
|||||||
{
|
{
|
||||||
_dbsetPriv?.Dispose();
|
_dbsetPriv?.Dispose();
|
||||||
_dbPriv?.Dispose();
|
_dbPriv?.Dispose();
|
||||||
this.DataFilter.Dispose();
|
this.DataFilter?.Dispose();
|
||||||
}
|
}
|
||||||
finally
|
finally
|
||||||
{
|
{
|
||||||
|
@ -62,7 +62,7 @@ namespace FreeSql
|
|||||||
/// 比较实体,计算出值发生变化的属性,以及属性变化的前后值
|
/// 比较实体,计算出值发生变化的属性,以及属性变化的前后值
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="newdata">最新的实体对象,它将与附加实体的状态对比</param>
|
/// <param name="newdata">最新的实体对象,它将与附加实体的状态对比</param>
|
||||||
/// <returns></returns>
|
/// <returns>key: 属性名, value: [旧值, 新值]</returns>
|
||||||
Dictionary<string, object[]> CompareState(TEntity newdata);
|
Dictionary<string, object[]> CompareState(TEntity newdata);
|
||||||
|
|
||||||
int Update(TEntity entity);
|
int Update(TEntity entity);
|
||||||
|
@ -2,9 +2,9 @@
|
|||||||
|
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<TargetFrameworks>netstandard2.0;net60;net50;netcoreapp31;netcoreapp21;net45;net40</TargetFrameworks>
|
<TargetFrameworks>netstandard2.0;net60;net50;netcoreapp31;netcoreapp21;net45;net40</TargetFrameworks>
|
||||||
<Version>2.6.100</Version>
|
<Version>3.2.300</Version>
|
||||||
<Authors>FreeSql;ncc;YeXiangQin</Authors>
|
<Authors>FreeSql;ncc;YeXiangQin</Authors>
|
||||||
<Description>FreeSql Implementation of General Repository, Support MySql/SqlServer/PostgreSQL/Oracle/Sqlite/Firebird/达梦/人大金仓/神舟通用/翰高/Access, and read/write separation、and split table.</Description>
|
<Description>FreeSql Implementation of General Repository, Support MySql/SqlServer/PostgreSQL/Oracle/Sqlite/Firebird/达梦/人大金仓/神舟通用/南大通用/翰高/Access, and read/write separation、and split table.</Description>
|
||||||
<PackageProjectUrl>https://github.com/2881099/FreeSql/wiki/Repository</PackageProjectUrl>
|
<PackageProjectUrl>https://github.com/2881099/FreeSql/wiki/Repository</PackageProjectUrl>
|
||||||
<PackageTags>FreeSql ORM Repository</PackageTags>
|
<PackageTags>FreeSql ORM Repository</PackageTags>
|
||||||
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
|
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
Public Class g
|
Public Class g
|
||||||
|
|
||||||
Shared sqlserverLazy As Lazy(Of IFreeSql) = New Lazy(Of IFreeSql)(New Func(Of IFreeSql)(Function() New FreeSqlBuilder() _
|
Shared sqlserverLazy As Lazy(Of IFreeSql) = New Lazy(Of IFreeSql)(New Func(Of IFreeSql)(Function() New FreeSqlBuilder() _
|
||||||
.UseConnectionString(DataType.SqlServer, "Data Source=.;Integrated Security=True;Initial Catalog=freesqlTest;Pooling=true;Max Pool Size=3") _
|
.UseConnectionString(DataType.SqlServer, "Data Source=.;Integrated Security=True;Initial Catalog=freesqlTest;Pooling=true;Max Pool Size=3;TrustServerCertificate=true") _
|
||||||
.UseAutoSyncStructure(True) _
|
.UseAutoSyncStructure(True) _
|
||||||
.UseMonitorCommand(Sub(cmd) Trace.WriteLine(vbCrLf & "线程" & Thread.CurrentThread.ManagedThreadId & ": " & cmd.CommandText)) _
|
.UseMonitorCommand(Sub(cmd) Trace.WriteLine(vbCrLf & "线程" & Thread.CurrentThread.ManagedThreadId & ": " & cmd.CommandText)) _
|
||||||
.UseLazyLoading(True) _
|
.UseLazyLoading(True) _
|
||||||
|
@ -8,7 +8,7 @@ public class g
|
|||||||
{
|
{
|
||||||
|
|
||||||
static Lazy<IFreeSql> sqlserverLazy = new Lazy<IFreeSql>(() => new FreeSql.FreeSqlBuilder()
|
static Lazy<IFreeSql> sqlserverLazy = new Lazy<IFreeSql>(() => new FreeSql.FreeSqlBuilder()
|
||||||
.UseConnectionString(FreeSql.DataType.SqlServer, "Data Source=.;Integrated Security=True;Initial Catalog=freesqlTest;Pooling=true;Max Pool Size=10")
|
.UseConnectionString(FreeSql.DataType.SqlServer, "Data Source=.;Integrated Security=True;Initial Catalog=freesqlTest;Pooling=true;Max Pool Size=10;TrustServerCertificate=true")
|
||||||
.UseAutoSyncStructure(true)
|
.UseAutoSyncStructure(true)
|
||||||
.UseMonitorCommand(
|
.UseMonitorCommand(
|
||||||
cmd =>
|
cmd =>
|
||||||
|
4
FreeSql.Tests/FreeSql.Tests.Provider.GBase/.editorconfig
Normal file
4
FreeSql.Tests/FreeSql.Tests.Provider.GBase/.editorconfig
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
[*.cs]
|
||||||
|
|
||||||
|
# xUnit2000: Constants and literals should be the expected argument
|
||||||
|
dotnet_diagnostic.xUnit2000.severity = none
|
@ -0,0 +1,32 @@
|
|||||||
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
|
<PropertyGroup>
|
||||||
|
<TargetFramework>net5.0</TargetFramework>
|
||||||
|
<IsPackable>false</IsPackable>
|
||||||
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
|
||||||
|
<DocumentationFile>FreeSql.Tests.Provider.GBase.xml</DocumentationFile>
|
||||||
|
<WarningLevel>3</WarningLevel>
|
||||||
|
<NoWarn>1701;1702;1591</NoWarn>
|
||||||
|
<!--<Prefer32Bit>false</Prefer32Bit>
|
||||||
|
<PlatformTarget>x86</PlatformTarget>-->
|
||||||
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.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="..\..\Extensions\FreeSql.Extensions.Linq\FreeSql.Extensions.Linq.csproj" />
|
||||||
|
<ProjectReference Include="..\..\FreeSql.DbContext\FreeSql.DbContext.csproj" />
|
||||||
|
<ProjectReference Include="..\..\FreeSql\FreeSql.csproj" />
|
||||||
|
<ProjectReference Include="..\..\Providers\FreeSql.Provider.GBase\FreeSql.Provider.GBase.csproj" />
|
||||||
|
</ItemGroup>
|
||||||
|
</Project>
|
@ -0,0 +1,13 @@
|
|||||||
|
<?xml version="1.0"?>
|
||||||
|
<doc>
|
||||||
|
<assembly>
|
||||||
|
<name>FreeSql.Tests.Provider.GBase</name>
|
||||||
|
</assembly>
|
||||||
|
<members>
|
||||||
|
<member name="P:FreeSql.Tests.GBase.GBaseCodeFirstTest.AddUniquesInfo.id">
|
||||||
|
<summary>
|
||||||
|
编号
|
||||||
|
</summary>
|
||||||
|
</member>
|
||||||
|
</members>
|
||||||
|
</doc>
|
@ -0,0 +1,127 @@
|
|||||||
|
using FreeSql.DataAnnotations;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using Xunit;
|
||||||
|
|
||||||
|
namespace FreeSql.Tests.GBase
|
||||||
|
{
|
||||||
|
public class GBaseDeleteTest
|
||||||
|
{
|
||||||
|
|
||||||
|
IDelete<Topic> delete => g.gbase.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 string Title { get; set; }
|
||||||
|
public DateTime CreateTime { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void Dywhere()
|
||||||
|
{
|
||||||
|
Assert.Null(g.gbase.Delete<Topic>().ToSql());
|
||||||
|
var sql = g.gbase.Delete<Topic>(new[] { 1, 2 }).ToSql();
|
||||||
|
Assert.Equal("DELETE FROM tb_topic_del WHERE (Id IN (1,2))", sql);
|
||||||
|
|
||||||
|
sql = g.gbase.Delete<Topic>(new Topic { Id = 1, Title = "test" }).ToSql();
|
||||||
|
Assert.Equal("DELETE FROM tb_topic_del WHERE (Id = 1)", sql);
|
||||||
|
|
||||||
|
sql = g.gbase.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.gbase.Delete<Topic>(new { id = 1 }).ToSql();
|
||||||
|
Assert.Equal("DELETE FROM tb_topic_del WHERE (Id = 1)", sql);
|
||||||
|
|
||||||
|
sql = g.gbase.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.gbase.Insert<Topic>(new Topic { Title = "xxxx" }).ExecuteIdentity();
|
||||||
|
Assert.Equal(1, delete.Where(a => a.Id == id).ExecuteAffrows());
|
||||||
|
}
|
||||||
|
[Fact]
|
||||||
|
public void ExecuteDeleted()
|
||||||
|
{
|
||||||
|
Assert.Throws<NotImplementedException>(() => delete.Where(a => a.Id > 0).ExecuteDeleted());
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void AsTable()
|
||||||
|
{
|
||||||
|
//var connectionBuilder = new IfxConnectionStringBuilder
|
||||||
|
//{
|
||||||
|
// Host = "192.168.164.134",
|
||||||
|
// Service = "9088",
|
||||||
|
// Server = "gbase01",
|
||||||
|
// Database = "testdb",
|
||||||
|
// UID = "gbasedbt",
|
||||||
|
// Pwd = "GBase123",
|
||||||
|
// DbLocale = "zh_CN.utf8",
|
||||||
|
// ClientLocale = "zh_CN.utf8",
|
||||||
|
// PersistSecurityInfo = true
|
||||||
|
//};
|
||||||
|
//using (IfxConnection conn = new IfxConnection(connectionBuilder.ConnectionString))
|
||||||
|
//{
|
||||||
|
// conn.Open();
|
||||||
|
|
||||||
|
// var cmd = conn.CreateCommand();
|
||||||
|
// cmd.CommandText = "select 1 from dual";
|
||||||
|
// var val = cmd.ExecuteScalar();
|
||||||
|
|
||||||
|
// conn.Close();
|
||||||
|
//}
|
||||||
|
|
||||||
|
|
||||||
|
Assert.Null(g.gbase.Delete<Topic>().ToSql());
|
||||||
|
var sql = g.gbase.Delete<Topic>(new[] { 1, 2 }).AsTable(a => "TopicAsTable").ToSql();
|
||||||
|
Assert.Equal("DELETE FROM TopicAsTable WHERE (Id IN (1,2))", sql);
|
||||||
|
|
||||||
|
sql = g.gbase.Delete<Topic>(new Topic { Id = 1, Title = "test" }).AsTable(a => "TopicAsTable").ToSql();
|
||||||
|
Assert.Equal("DELETE FROM TopicAsTable WHERE (Id = 1)", sql);
|
||||||
|
|
||||||
|
sql = g.gbase.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.gbase.Delete<Topic>(new { id = 1 }).AsTable(a => "TopicAsTable").ToSql();
|
||||||
|
Assert.Equal("DELETE FROM TopicAsTable WHERE (Id = 1)", sql);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,437 @@
|
|||||||
|
using FreeSql.DataAnnotations;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using Xunit;
|
||||||
|
|
||||||
|
namespace FreeSql.Tests.GBase
|
||||||
|
{
|
||||||
|
public class GBaseInsertOrUpdateIfExistsDoNothingTest
|
||||||
|
{
|
||||||
|
IFreeSql fsql => g.gbase;
|
||||||
|
|
||||||
|
[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);
|
||||||
|
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 FROM dual ) 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 FROM dual ) 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 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);
|
||||||
|
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 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);
|
||||||
|
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, '01' as name FROM dual ) 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, '011' as name FROM dual ) 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, '02' as name FROM dual ) 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, '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);
|
||||||
|
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, '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);
|
||||||
|
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(@"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);
|
||||||
|
Assert.Equal(1, 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);
|
||||||
|
Assert.Equal(0, 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);
|
||||||
|
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(@"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);
|
||||||
|
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(@"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);
|
||||||
|
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 == "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);
|
||||||
|
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)
|
||||||
|
SELECT * FROM (
|
||||||
|
SELECT '01' FROM dual
|
||||||
|
UNION ALL
|
||||||
|
SELECT '02' FROM dual
|
||||||
|
UNION ALL
|
||||||
|
SELECT '03' FROM dual
|
||||||
|
UNION ALL
|
||||||
|
SELECT '04' FROM dual
|
||||||
|
) ftbtmp", 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)
|
||||||
|
SELECT * FROM (
|
||||||
|
SELECT '001' FROM dual
|
||||||
|
UNION ALL
|
||||||
|
SELECT '002' FROM dual
|
||||||
|
UNION ALL
|
||||||
|
SELECT '003' FROM dual
|
||||||
|
UNION ALL
|
||||||
|
SELECT '004' FROM dual
|
||||||
|
) ftbtmp", 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(@"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 INTO tbioudb022(name)
|
||||||
|
SELECT * FROM (
|
||||||
|
SELECT '00001' FROM dual
|
||||||
|
UNION ALL
|
||||||
|
SELECT '00002' FROM dual
|
||||||
|
UNION ALL
|
||||||
|
SELECT '00003' FROM dual
|
||||||
|
UNION ALL
|
||||||
|
SELECT '00004' FROM dual
|
||||||
|
) ftbtmp", 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 == "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);
|
||||||
|
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, '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);
|
||||||
|
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, '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);
|
||||||
|
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, '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);
|
||||||
|
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, '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);
|
||||||
|
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, '01' as name, 0 as version, current 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);
|
||||||
|
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, '011' as name, 0 as version, current 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);
|
||||||
|
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, '02' as name, 0 as version, current 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);
|
||||||
|
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, '01' as name, 0 as version, current as CreateTime FROM dual
|
||||||
|
UNION ALL
|
||||||
|
SELECT 2, '02', 0, current FROM dual
|
||||||
|
UNION ALL
|
||||||
|
SELECT 3, '03', 0, current FROM dual
|
||||||
|
UNION ALL
|
||||||
|
SELECT 4, '04', 0, current 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);
|
||||||
|
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, '001' as name, 0 as version, current as CreateTime FROM dual
|
||||||
|
UNION ALL
|
||||||
|
SELECT 2, '002', 0, current FROM dual
|
||||||
|
UNION ALL
|
||||||
|
SELECT 3, '003', 0, current FROM dual
|
||||||
|
UNION ALL
|
||||||
|
SELECT 4, '004', 0, current 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);
|
||||||
|
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,479 @@
|
|||||||
|
using FreeSql.DataAnnotations;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using Xunit;
|
||||||
|
|
||||||
|
namespace FreeSql.Tests.GBase
|
||||||
|
{
|
||||||
|
public class GBaseInsertOrUpdateTest
|
||||||
|
{
|
||||||
|
IFreeSql fsql => g.gbase;
|
||||||
|
|
||||||
|
[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);
|
||||||
|
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 FROM dual ) 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 FROM dual ) 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 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);
|
||||||
|
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 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);
|
||||||
|
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, '01' as name FROM dual ) t2 ON (t1.id = t2.id)
|
||||||
|
WHEN MATCHED THEN
|
||||||
|
update set t1.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, '011' as name FROM dual ) t2 ON (t1.id = t2.id)
|
||||||
|
WHEN MATCHED THEN
|
||||||
|
update set t1.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, '02' as name FROM dual ) t2 ON (t1.id = t2.id)
|
||||||
|
WHEN MATCHED THEN
|
||||||
|
update set t1.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, '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 t1.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, '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 t1.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(@"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 t1.name = t2.name
|
||||||
|
WHEN NOT MATCHED THEN
|
||||||
|
insert (id, name)
|
||||||
|
values (t2.id, t2.name)", sql);
|
||||||
|
Assert.Equal(1, 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 t1.name = t2.name
|
||||||
|
WHEN NOT MATCHED THEN
|
||||||
|
insert (id, name)
|
||||||
|
values (t2.id, t2.name)", sql);
|
||||||
|
Assert.Equal(1, 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 t1.name = t2.name
|
||||||
|
WHEN NOT MATCHED THEN
|
||||||
|
insert (id, name)
|
||||||
|
values (t2.id, t2.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(@"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 t1.name = t2.name
|
||||||
|
WHEN NOT MATCHED THEN
|
||||||
|
insert (id, name)
|
||||||
|
values (t2.id, t2.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(@"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 t1.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<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)
|
||||||
|
SELECT * FROM (
|
||||||
|
SELECT '01' FROM dual
|
||||||
|
UNION ALL
|
||||||
|
SELECT '02' FROM dual
|
||||||
|
UNION ALL
|
||||||
|
SELECT '03' FROM dual
|
||||||
|
UNION ALL
|
||||||
|
SELECT '04' FROM dual
|
||||||
|
) ftbtmp", 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)
|
||||||
|
SELECT * FROM (
|
||||||
|
SELECT '001' FROM dual
|
||||||
|
UNION ALL
|
||||||
|
SELECT '002' FROM dual
|
||||||
|
UNION ALL
|
||||||
|
SELECT '003' FROM dual
|
||||||
|
UNION ALL
|
||||||
|
SELECT '004' FROM dual
|
||||||
|
) ftbtmp", 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(@"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 t1.name = t2.name
|
||||||
|
WHEN NOT MATCHED THEN
|
||||||
|
insert (id, name)
|
||||||
|
values (t2.id, t2.name)
|
||||||
|
|
||||||
|
;
|
||||||
|
|
||||||
|
INSERT INTO tbiou022(name)
|
||||||
|
SELECT * FROM (
|
||||||
|
SELECT '00001' FROM dual
|
||||||
|
UNION ALL
|
||||||
|
SELECT '00002' FROM dual
|
||||||
|
UNION ALL
|
||||||
|
SELECT '00003' FROM dual
|
||||||
|
UNION ALL
|
||||||
|
SELECT '00004' FROM dual
|
||||||
|
) ftbtmp", 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, '01' as id2, '01' as name FROM dual ) t2 ON (t1.id1 = t2.id1 AND t1.id2 = t2.id2)
|
||||||
|
WHEN MATCHED THEN
|
||||||
|
update set t1.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, '01' as id2, '011' as name FROM dual ) t2 ON (t1.id1 = t2.id1 AND t1.id2 = t2.id2)
|
||||||
|
WHEN MATCHED THEN
|
||||||
|
update set t1.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, '02' as id2, '02' as name FROM dual ) t2 ON (t1.id1 = t2.id1 AND t1.id2 = t2.id2)
|
||||||
|
WHEN MATCHED THEN
|
||||||
|
update set t1.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, '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 t1.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, '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 t1.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, '01' as name, 0 as version, current as CreateTime FROM dual ) t2 ON (t1.id = t2.id)
|
||||||
|
WHEN MATCHED THEN
|
||||||
|
update set t1.name = t2.name, t1.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, '011' as name, 0 as version, current as CreateTime FROM dual ) t2 ON (t1.id = t2.id)
|
||||||
|
WHEN MATCHED THEN
|
||||||
|
update set t1.name = t2.name, t1.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, '02' as name, 0 as version, current as CreateTime FROM dual ) t2 ON (t1.id = t2.id)
|
||||||
|
WHEN MATCHED THEN
|
||||||
|
update set t1.name = t2.name, t1.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, '01' as name, 0 as version, current as CreateTime FROM dual
|
||||||
|
UNION ALL
|
||||||
|
SELECT 2, '02', 0, current FROM dual
|
||||||
|
UNION ALL
|
||||||
|
SELECT 3, '03', 0, current FROM dual
|
||||||
|
UNION ALL
|
||||||
|
SELECT 4, '04', 0, current FROM dual ) t2 ON (t1.id = t2.id)
|
||||||
|
WHEN MATCHED THEN
|
||||||
|
update set t1.name = t2.name, t1.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, '001' as name, 0 as version, current as CreateTime FROM dual
|
||||||
|
UNION ALL
|
||||||
|
SELECT 2, '002', 0, current FROM dual
|
||||||
|
UNION ALL
|
||||||
|
SELECT 3, '003', 0, current FROM dual
|
||||||
|
UNION ALL
|
||||||
|
SELECT 4, '004', 0, current FROM dual ) t2 ON (t1.id = t2.id)
|
||||||
|
WHEN MATCHED THEN
|
||||||
|
update set t1.name = t2.name, t1.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,439 @@
|
|||||||
|
using FreeSql.DataAnnotations;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using Xunit;
|
||||||
|
|
||||||
|
namespace FreeSql.Tests.GBase
|
||||||
|
{
|
||||||
|
public class GBaseInsertTest
|
||||||
|
{
|
||||||
|
|
||||||
|
IInsert<Topic> insert => g.gbase.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 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.000')", sql);
|
||||||
|
|
||||||
|
sql = insert.AppendData(items).ToSql();
|
||||||
|
Assert.Equal(@"INSERT INTO TB_TOPIC_INSERT(Clicks, Title, CreateTime)
|
||||||
|
SELECT * FROM (
|
||||||
|
SELECT 0, 'newtitle0', '0001-01-01 00:00:00.000' FROM dual
|
||||||
|
UNION ALL
|
||||||
|
SELECT 100, 'newtitle1', '0001-01-01 00:00:00.000' FROM dual
|
||||||
|
UNION ALL
|
||||||
|
SELECT 200, 'newtitle2', '0001-01-01 00:00:00.000' FROM dual
|
||||||
|
UNION ALL
|
||||||
|
SELECT 300, 'newtitle3', '0001-01-01 00:00:00.000' FROM dual
|
||||||
|
UNION ALL
|
||||||
|
SELECT 400, 'newtitle4', '0001-01-01 00:00:00.000' FROM dual
|
||||||
|
UNION ALL
|
||||||
|
SELECT 500, 'newtitle5', '0001-01-01 00:00:00.000' FROM dual
|
||||||
|
UNION ALL
|
||||||
|
SELECT 600, 'newtitle6', '0001-01-01 00:00:00.000' FROM dual
|
||||||
|
UNION ALL
|
||||||
|
SELECT 700, 'newtitle7', '0001-01-01 00:00:00.000' FROM dual
|
||||||
|
UNION ALL
|
||||||
|
SELECT 800, 'newtitle8', '0001-01-01 00:00:00.000' FROM dual
|
||||||
|
UNION ALL
|
||||||
|
SELECT 900, 'newtitle9', '0001-01-01 00:00:00.000' FROM dual
|
||||||
|
) ftbtmp", sql);
|
||||||
|
|
||||||
|
sql = insert.AppendData(items).InsertColumns(a => a.Title).ToSql();
|
||||||
|
Assert.Equal(@"INSERT INTO TB_TOPIC_INSERT(Title)
|
||||||
|
SELECT * FROM (
|
||||||
|
SELECT 'newtitle0' FROM dual
|
||||||
|
UNION ALL
|
||||||
|
SELECT 'newtitle1' FROM dual
|
||||||
|
UNION ALL
|
||||||
|
SELECT 'newtitle2' FROM dual
|
||||||
|
UNION ALL
|
||||||
|
SELECT 'newtitle3' FROM dual
|
||||||
|
UNION ALL
|
||||||
|
SELECT 'newtitle4' FROM dual
|
||||||
|
UNION ALL
|
||||||
|
SELECT 'newtitle5' FROM dual
|
||||||
|
UNION ALL
|
||||||
|
SELECT 'newtitle6' FROM dual
|
||||||
|
UNION ALL
|
||||||
|
SELECT 'newtitle7' FROM dual
|
||||||
|
UNION ALL
|
||||||
|
SELECT 'newtitle8' FROM dual
|
||||||
|
UNION ALL
|
||||||
|
SELECT 'newtitle9' FROM dual
|
||||||
|
) ftbtmp", sql);
|
||||||
|
|
||||||
|
sql = insert.AppendData(items).IgnoreColumns(a => a.CreateTime).ToSql();
|
||||||
|
Assert.Equal(@"INSERT INTO TB_TOPIC_INSERT(Clicks, Title)
|
||||||
|
SELECT * FROM (
|
||||||
|
SELECT 0, 'newtitle0' FROM dual
|
||||||
|
UNION ALL
|
||||||
|
SELECT 100, 'newtitle1' FROM dual
|
||||||
|
UNION ALL
|
||||||
|
SELECT 200, 'newtitle2' FROM dual
|
||||||
|
UNION ALL
|
||||||
|
SELECT 300, 'newtitle3' FROM dual
|
||||||
|
UNION ALL
|
||||||
|
SELECT 400, 'newtitle4' FROM dual
|
||||||
|
UNION ALL
|
||||||
|
SELECT 500, 'newtitle5' FROM dual
|
||||||
|
UNION ALL
|
||||||
|
SELECT 600, 'newtitle6' FROM dual
|
||||||
|
UNION ALL
|
||||||
|
SELECT 700, 'newtitle7' FROM dual
|
||||||
|
UNION ALL
|
||||||
|
SELECT 800, 'newtitle8' FROM dual
|
||||||
|
UNION ALL
|
||||||
|
SELECT 900, 'newtitle9' FROM dual
|
||||||
|
) ftbtmp", 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)
|
||||||
|
SELECT * FROM (
|
||||||
|
SELECT 'newtitle0' FROM dual
|
||||||
|
UNION ALL
|
||||||
|
SELECT 'newtitle1' FROM dual
|
||||||
|
UNION ALL
|
||||||
|
SELECT 'newtitle2' FROM dual
|
||||||
|
UNION ALL
|
||||||
|
SELECT 'newtitle3' FROM dual
|
||||||
|
UNION ALL
|
||||||
|
SELECT 'newtitle4' FROM dual
|
||||||
|
UNION ALL
|
||||||
|
SELECT 'newtitle5' FROM dual
|
||||||
|
UNION ALL
|
||||||
|
SELECT 'newtitle6' FROM dual
|
||||||
|
UNION ALL
|
||||||
|
SELECT 'newtitle7' FROM dual
|
||||||
|
UNION ALL
|
||||||
|
SELECT 'newtitle8' FROM dual
|
||||||
|
UNION ALL
|
||||||
|
SELECT 'newtitle9' FROM dual
|
||||||
|
) ftbtmp", sql);
|
||||||
|
|
||||||
|
sql = insert.AppendData(items).InsertColumns(a => new { a.Title, a.Clicks }).ToSql();
|
||||||
|
Assert.Equal(@"INSERT INTO TB_TOPIC_INSERT(Clicks, Title)
|
||||||
|
SELECT * FROM (
|
||||||
|
SELECT 0, 'newtitle0' FROM dual
|
||||||
|
UNION ALL
|
||||||
|
SELECT 100, 'newtitle1' FROM dual
|
||||||
|
UNION ALL
|
||||||
|
SELECT 200, 'newtitle2' FROM dual
|
||||||
|
UNION ALL
|
||||||
|
SELECT 300, 'newtitle3' FROM dual
|
||||||
|
UNION ALL
|
||||||
|
SELECT 400, 'newtitle4' FROM dual
|
||||||
|
UNION ALL
|
||||||
|
SELECT 500, 'newtitle5' FROM dual
|
||||||
|
UNION ALL
|
||||||
|
SELECT 600, 'newtitle6' FROM dual
|
||||||
|
UNION ALL
|
||||||
|
SELECT 700, 'newtitle7' FROM dual
|
||||||
|
UNION ALL
|
||||||
|
SELECT 800, 'newtitle8' FROM dual
|
||||||
|
UNION ALL
|
||||||
|
SELECT 900, 'newtitle9' FROM dual
|
||||||
|
) ftbtmp", 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)
|
||||||
|
SELECT * FROM (
|
||||||
|
SELECT 0, 'newtitle0' FROM dual
|
||||||
|
UNION ALL
|
||||||
|
SELECT 100, 'newtitle1' FROM dual
|
||||||
|
UNION ALL
|
||||||
|
SELECT 200, 'newtitle2' FROM dual
|
||||||
|
UNION ALL
|
||||||
|
SELECT 300, 'newtitle3' FROM dual
|
||||||
|
UNION ALL
|
||||||
|
SELECT 400, 'newtitle4' FROM dual
|
||||||
|
UNION ALL
|
||||||
|
SELECT 500, 'newtitle5' FROM dual
|
||||||
|
UNION ALL
|
||||||
|
SELECT 600, 'newtitle6' FROM dual
|
||||||
|
UNION ALL
|
||||||
|
SELECT 700, 'newtitle7' FROM dual
|
||||||
|
UNION ALL
|
||||||
|
SELECT 800, 'newtitle8' FROM dual
|
||||||
|
UNION ALL
|
||||||
|
SELECT 900, 'newtitle9' FROM dual
|
||||||
|
) ftbtmp", sql);
|
||||||
|
|
||||||
|
sql = insert.AppendData(items).IgnoreColumns(a => new { a.Title, a.CreateTime }).ToSql();
|
||||||
|
Assert.Equal(@"INSERT INTO TB_TOPIC_INSERT(Clicks)
|
||||||
|
SELECT * FROM (
|
||||||
|
SELECT 0 FROM dual
|
||||||
|
UNION ALL
|
||||||
|
SELECT 100 FROM dual
|
||||||
|
UNION ALL
|
||||||
|
SELECT 200 FROM dual
|
||||||
|
UNION ALL
|
||||||
|
SELECT 300 FROM dual
|
||||||
|
UNION ALL
|
||||||
|
SELECT 400 FROM dual
|
||||||
|
UNION ALL
|
||||||
|
SELECT 500 FROM dual
|
||||||
|
UNION ALL
|
||||||
|
SELECT 600 FROM dual
|
||||||
|
UNION ALL
|
||||||
|
SELECT 700 FROM dual
|
||||||
|
UNION ALL
|
||||||
|
SELECT 800 FROM dual
|
||||||
|
UNION ALL
|
||||||
|
SELECT 900 FROM dual
|
||||||
|
) ftbtmp", sql);
|
||||||
|
|
||||||
|
g.gbase.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.gbase.Insert<TopicIgnore>().AppendData(itemsIgnore).IgnoreColumns(a => new { a.Title }).ExecuteAffrows();
|
||||||
|
Assert.Equal(2072, itemsIgnore.Count);
|
||||||
|
Assert.Equal(2072, g.gbase.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.NoneParameter().AppendData(items).ExecuteAffrows());
|
||||||
|
|
||||||
|
Assert.Equal(10, g.gbase.Select<Topic>().Limit(10).InsertInto(null, a => new Topic
|
||||||
|
{
|
||||||
|
Title = a.Title
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
[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 });
|
||||||
|
|
||||||
|
Assert.Throws<NotImplementedException>(() => 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)
|
||||||
|
SELECT * FROM (
|
||||||
|
SELECT 0, 'newTitle0', '0001-01-01 00:00:00.000' FROM dual
|
||||||
|
UNION ALL
|
||||||
|
SELECT 100, 'newTitle1', '0001-01-01 00:00:00.000' FROM dual
|
||||||
|
UNION ALL
|
||||||
|
SELECT 200, 'newTitle2', '0001-01-01 00:00:00.000' FROM dual
|
||||||
|
UNION ALL
|
||||||
|
SELECT 300, 'newTitle3', '0001-01-01 00:00:00.000' FROM dual
|
||||||
|
UNION ALL
|
||||||
|
SELECT 400, 'newTitle4', '0001-01-01 00:00:00.000' FROM dual
|
||||||
|
UNION ALL
|
||||||
|
SELECT 500, 'newTitle5', '0001-01-01 00:00:00.000' FROM dual
|
||||||
|
UNION ALL
|
||||||
|
SELECT 600, 'newTitle6', '0001-01-01 00:00:00.000' FROM dual
|
||||||
|
UNION ALL
|
||||||
|
SELECT 700, 'newTitle7', '0001-01-01 00:00:00.000' FROM dual
|
||||||
|
UNION ALL
|
||||||
|
SELECT 800, 'newTitle8', '0001-01-01 00:00:00.000' FROM dual
|
||||||
|
UNION ALL
|
||||||
|
SELECT 900, 'newTitle9', '0001-01-01 00:00:00.000' FROM dual
|
||||||
|
) ftbtmp", sql);
|
||||||
|
|
||||||
|
sql = insert.AppendData(items).InsertColumns(a => a.Title).AsTable(a => "Topic_InsertAsTable").ToSql();
|
||||||
|
Assert.Equal(@"INSERT INTO Topic_InsertAsTable(Title)
|
||||||
|
SELECT * FROM (
|
||||||
|
SELECT 'newTitle0' FROM dual
|
||||||
|
UNION ALL
|
||||||
|
SELECT 'newTitle1' FROM dual
|
||||||
|
UNION ALL
|
||||||
|
SELECT 'newTitle2' FROM dual
|
||||||
|
UNION ALL
|
||||||
|
SELECT 'newTitle3' FROM dual
|
||||||
|
UNION ALL
|
||||||
|
SELECT 'newTitle4' FROM dual
|
||||||
|
UNION ALL
|
||||||
|
SELECT 'newTitle5' FROM dual
|
||||||
|
UNION ALL
|
||||||
|
SELECT 'newTitle6' FROM dual
|
||||||
|
UNION ALL
|
||||||
|
SELECT 'newTitle7' FROM dual
|
||||||
|
UNION ALL
|
||||||
|
SELECT 'newTitle8' FROM dual
|
||||||
|
UNION ALL
|
||||||
|
SELECT 'newTitle9' FROM dual
|
||||||
|
) ftbtmp", sql);
|
||||||
|
|
||||||
|
sql = insert.AppendData(items).IgnoreColumns(a => a.CreateTime).AsTable(a => "Topic_InsertAsTable").ToSql();
|
||||||
|
Assert.Equal(@"INSERT INTO Topic_InsertAsTable(Clicks, Title)
|
||||||
|
SELECT * FROM (
|
||||||
|
SELECT 0, 'newTitle0' FROM dual
|
||||||
|
UNION ALL
|
||||||
|
SELECT 100, 'newTitle1' FROM dual
|
||||||
|
UNION ALL
|
||||||
|
SELECT 200, 'newTitle2' FROM dual
|
||||||
|
UNION ALL
|
||||||
|
SELECT 300, 'newTitle3' FROM dual
|
||||||
|
UNION ALL
|
||||||
|
SELECT 400, 'newTitle4' FROM dual
|
||||||
|
UNION ALL
|
||||||
|
SELECT 500, 'newTitle5' FROM dual
|
||||||
|
UNION ALL
|
||||||
|
SELECT 600, 'newTitle6' FROM dual
|
||||||
|
UNION ALL
|
||||||
|
SELECT 700, 'newTitle7' FROM dual
|
||||||
|
UNION ALL
|
||||||
|
SELECT 800, 'newTitle8' FROM dual
|
||||||
|
UNION ALL
|
||||||
|
SELECT 900, 'newTitle9' FROM dual
|
||||||
|
) ftbtmp", sql);
|
||||||
|
|
||||||
|
sql = insert.AppendData(items).InsertColumns(a => a.Title).AsTable(a => "Topic_InsertAsTable").ToSql();
|
||||||
|
Assert.Equal(@"INSERT INTO Topic_InsertAsTable(Title)
|
||||||
|
SELECT * FROM (
|
||||||
|
SELECT 'newTitle0' FROM dual
|
||||||
|
UNION ALL
|
||||||
|
SELECT 'newTitle1' FROM dual
|
||||||
|
UNION ALL
|
||||||
|
SELECT 'newTitle2' FROM dual
|
||||||
|
UNION ALL
|
||||||
|
SELECT 'newTitle3' FROM dual
|
||||||
|
UNION ALL
|
||||||
|
SELECT 'newTitle4' FROM dual
|
||||||
|
UNION ALL
|
||||||
|
SELECT 'newTitle5' FROM dual
|
||||||
|
UNION ALL
|
||||||
|
SELECT 'newTitle6' FROM dual
|
||||||
|
UNION ALL
|
||||||
|
SELECT 'newTitle7' FROM dual
|
||||||
|
UNION ALL
|
||||||
|
SELECT 'newTitle8' FROM dual
|
||||||
|
UNION ALL
|
||||||
|
SELECT 'newTitle9' FROM dual
|
||||||
|
) ftbtmp", 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)
|
||||||
|
SELECT * FROM (
|
||||||
|
SELECT 0, 'newTitle0' FROM dual
|
||||||
|
UNION ALL
|
||||||
|
SELECT 100, 'newTitle1' FROM dual
|
||||||
|
UNION ALL
|
||||||
|
SELECT 200, 'newTitle2' FROM dual
|
||||||
|
UNION ALL
|
||||||
|
SELECT 300, 'newTitle3' FROM dual
|
||||||
|
UNION ALL
|
||||||
|
SELECT 400, 'newTitle4' FROM dual
|
||||||
|
UNION ALL
|
||||||
|
SELECT 500, 'newTitle5' FROM dual
|
||||||
|
UNION ALL
|
||||||
|
SELECT 600, 'newTitle6' FROM dual
|
||||||
|
UNION ALL
|
||||||
|
SELECT 700, 'newTitle7' FROM dual
|
||||||
|
UNION ALL
|
||||||
|
SELECT 800, 'newTitle8' FROM dual
|
||||||
|
UNION ALL
|
||||||
|
SELECT 900, 'newTitle9' FROM dual
|
||||||
|
) ftbtmp", sql);
|
||||||
|
|
||||||
|
sql = insert.AppendData(items).IgnoreColumns(a => a.CreateTime).AsTable(a => "Topic_InsertAsTable").ToSql();
|
||||||
|
Assert.Equal(@"INSERT INTO Topic_InsertAsTable(Clicks, Title)
|
||||||
|
SELECT * FROM (
|
||||||
|
SELECT 0, 'newTitle0' FROM dual
|
||||||
|
UNION ALL
|
||||||
|
SELECT 100, 'newTitle1' FROM dual
|
||||||
|
UNION ALL
|
||||||
|
SELECT 200, 'newTitle2' FROM dual
|
||||||
|
UNION ALL
|
||||||
|
SELECT 300, 'newTitle3' FROM dual
|
||||||
|
UNION ALL
|
||||||
|
SELECT 400, 'newTitle4' FROM dual
|
||||||
|
UNION ALL
|
||||||
|
SELECT 500, 'newTitle5' FROM dual
|
||||||
|
UNION ALL
|
||||||
|
SELECT 600, 'newTitle6' FROM dual
|
||||||
|
UNION ALL
|
||||||
|
SELECT 700, 'newTitle7' FROM dual
|
||||||
|
UNION ALL
|
||||||
|
SELECT 800, 'newTitle8' FROM dual
|
||||||
|
UNION ALL
|
||||||
|
SELECT 900, 'newTitle9' FROM dual
|
||||||
|
) ftbtmp", sql);
|
||||||
|
|
||||||
|
sql = insert.AppendData(items).IgnoreColumns(a => new { a.Title, a.CreateTime }).AsTable(a => "Topic_InsertAsTable").ToSql();
|
||||||
|
Assert.Equal(@"INSERT INTO Topic_InsertAsTable(Clicks)
|
||||||
|
SELECT * FROM (
|
||||||
|
SELECT 0 FROM dual
|
||||||
|
UNION ALL
|
||||||
|
SELECT 100 FROM dual
|
||||||
|
UNION ALL
|
||||||
|
SELECT 200 FROM dual
|
||||||
|
UNION ALL
|
||||||
|
SELECT 300 FROM dual
|
||||||
|
UNION ALL
|
||||||
|
SELECT 400 FROM dual
|
||||||
|
UNION ALL
|
||||||
|
SELECT 500 FROM dual
|
||||||
|
UNION ALL
|
||||||
|
SELECT 600 FROM dual
|
||||||
|
UNION ALL
|
||||||
|
SELECT 700 FROM dual
|
||||||
|
UNION ALL
|
||||||
|
SELECT 800 FROM dual
|
||||||
|
UNION ALL
|
||||||
|
SELECT 900 FROM dual
|
||||||
|
) ftbtmp", sql);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,234 @@
|
|||||||
|
using FreeSql.DataAnnotations;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using Xunit;
|
||||||
|
|
||||||
|
namespace FreeSql.Tests.GBase
|
||||||
|
{
|
||||||
|
public class GBaseUpdateTest
|
||||||
|
{
|
||||||
|
IUpdate<Topic> update => g.gbase.Update<Topic>();
|
||||||
|
|
||||||
|
[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; }
|
||||||
|
}
|
||||||
|
[Table(Name = "tb_topic_setsource")]
|
||||||
|
class Topic22
|
||||||
|
{
|
||||||
|
[Column(IsPrimary = true)]
|
||||||
|
public int Id { get; set; }
|
||||||
|
public int? Clicks { get; set; }
|
||||||
|
public int TypeGuid { get; set; }
|
||||||
|
public string Title { get; set; }
|
||||||
|
public DateTime CreateTime { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void Dywhere()
|
||||||
|
{
|
||||||
|
Assert.Null(g.gbase.Update<Topic>().ToSql());
|
||||||
|
Assert.Equal("UPDATE tb_topic_insert SET Title='test' \r\nWHERE (Id IN (1,2))", g.gbase.Update<Topic>(new[] { 1, 2 }).SetRaw("Title='test'").ToSql());
|
||||||
|
Assert.Equal("UPDATE tb_topic_insert SET Title='test1' \r\nWHERE (Id = 1)", g.gbase.Update<Topic>(new Topic { Id = 1, Title = "test" }).SetRaw("Title='test1'").ToSql());
|
||||||
|
Assert.Equal("UPDATE tb_topic_insert SET Title='test1' \r\nWHERE (Id IN (1,2))", g.gbase.Update<Topic>(new[] { new Topic { Id = 1, Title = "test" }, new Topic { Id = 2, Title = "test" } }).SetRaw("Title='test1'").ToSql());
|
||||||
|
Assert.Equal("UPDATE tb_topic_insert SET Title='test1' \r\nWHERE (Id = 1)", g.gbase.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_insert 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_insert 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_insert 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_insert 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.gbase.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", "");
|
||||||
|
Assert.Equal("UPDATE ts_source_mpk SET xx = CASE (id1 || '+' || id2) WHEN (1 || '+' || 7) THEN 'a1' WHEN (1 || '+' || 8) THEN 'b122' END WHERE ((id1 = 1 AND id2 = 7) OR (id1 = 1 AND id2 = 8))", sql);
|
||||||
|
}
|
||||||
|
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 SetSourceNoIdentity()
|
||||||
|
{
|
||||||
|
var fsql = g.gbase;
|
||||||
|
fsql.Delete<Topic22>().Where("1=1").ExecuteAffrows();
|
||||||
|
var sql = fsql.Update<Topic22>().SetSource(new Topic22 { Id = 1, Title = "newtitle" }).IgnoreColumns(a => a.TypeGuid).ToSql().Replace("\r\n", "");
|
||||||
|
Assert.Equal("UPDATE tb_topic_setsource SET Clicks = NULL, Title = 'newtitle', CreateTime = '0001-01-01 00:00:00.000' WHERE (Id = 1)", sql);
|
||||||
|
|
||||||
|
var items = new List<Topic22>();
|
||||||
|
for (var a = 0; a < 10; a++) items.Add(new Topic22 { Id = a + 1, Title = $"newtitle{a}", Clicks = a * 100 });
|
||||||
|
Assert.Equal(10, fsql.Insert(items).ExecuteAffrows());
|
||||||
|
items[0].Clicks = null;
|
||||||
|
|
||||||
|
sql = fsql.Update<Topic22>().SetSource(items).IgnoreColumns(a => a.TypeGuid).ToSql().Replace("\r\n", "");
|
||||||
|
Assert.Equal("UPDATE tb_topic_setsource 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 = fsql.Update<Topic22>().SetSource(items).IgnoreColumns(a => new { a.Clicks, a.CreateTime, a.TypeGuid }).ToSql().Replace("\r\n", "");
|
||||||
|
Assert.Equal("UPDATE tb_topic_setsource 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 = fsql.Update<Topic22>().SetSource(items).IgnoreColumns(a => a.TypeGuid).Set(a => a.CreateTime, new DateTime(2020, 1, 1)).ToSql().Replace("\r\n", "");
|
||||||
|
Assert.Equal("UPDATE tb_topic_setsource SET CreateTime = '2020-01-01 00:00:00.000' WHERE (Id IN (1,2,3,4,5,6,7,8,9,10))", sql);
|
||||||
|
}
|
||||||
|
[Fact]
|
||||||
|
public void SetSourceIgnore()
|
||||||
|
{
|
||||||
|
Assert.Equal("UPDATE tssi01 SET tint = 10 WHERE (id = '00000000-0000-0000-0000-000000000000')",
|
||||||
|
g.gbase.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_insert SET Title = 'newtitle' WHERE (Id = 1)", sql);
|
||||||
|
|
||||||
|
sql = update.SetSource(new Topic { Id = 1, Title = "newtitle" }).IgnoreColumns(a => new object[] { a.Clicks, a.CreateTime }).ToSql().Replace("\r\n", "");
|
||||||
|
Assert.Equal("UPDATE tb_topic_insert SET Title = 'newtitle' WHERE (Id = 1)", sql);
|
||||||
|
|
||||||
|
sql = update.SetSource(new Topic { Id = 1, Title = "newtitle" }).IgnoreColumns(a => new[] { "Clicks", "CreateTime" }).ToSql().Replace("\r\n", "");
|
||||||
|
Assert.Equal("UPDATE tb_topic_insert SET Title = 'newtitle' WHERE (Id = 1)", sql);
|
||||||
|
|
||||||
|
var cols = new[] { "Clicks", "CreateTime" };
|
||||||
|
sql = update.SetSource(new Topic { Id = 1, Title = "newtitle" }).IgnoreColumns(a => cols).ToSql().Replace("\r\n", "");
|
||||||
|
Assert.Equal("UPDATE tb_topic_insert SET Title = 'newtitle' WHERE (Id = 1)", sql);
|
||||||
|
|
||||||
|
cols = new[] { "Clicks", "CreateTime" };
|
||||||
|
sql = update.SetSource(new Topic { Id = 1, Title = "newtitle" }).IgnoreColumns(cols).ToSql().Replace("\r\n", "");
|
||||||
|
Assert.Equal("UPDATE tb_topic_insert 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_insert 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_insert 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_insert 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_insert 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_insert 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_insert 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_insert 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_insert 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_insert 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_insert 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_insert SET Clicks = NULL 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_insert SET Clicks = NULL WHERE (Id = 1)", sql);
|
||||||
|
}
|
||||||
|
[Fact]
|
||||||
|
public void SetRaw()
|
||||||
|
{
|
||||||
|
var sql = update.Where(a => a.Id == 1).SetRaw("clicks = clicks + @incrClick", new { incrClick = 1 }).ToSql().Replace("\r\n", "");
|
||||||
|
Assert.Equal("UPDATE tb_topic_insert SET clicks = clicks + @incrClick 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_insert SET Clicks = 1, Title = 'xxx' WHERE (Id = 1)", sql);
|
||||||
|
|
||||||
|
sql = update.NoneParameter().SetDto(new Dictionary<string, object> { ["clicks"] = 1, ["Title"] = "xxx" }).Where(a => a.Id == 1).ToSql().Replace("\r\n", "");
|
||||||
|
Assert.Equal("UPDATE tb_topic_insert 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_insert SET Title='newtitle' WHERE (Id = 1)", sql);
|
||||||
|
|
||||||
|
sql = update.Where("id = @id", new { id = 1 }).SetRaw("Title='newtitle'").ToSql().Replace("\r\n", "");
|
||||||
|
Assert.Equal("UPDATE tb_topic_insert SET Title='newtitle' WHERE (id = @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_insert 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_insert 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.gbase.Update<Topic>().ToSql());
|
||||||
|
Assert.Equal("UPDATE tb_topicAsTable SET Title='test' \r\nWHERE (Id IN (1,2))", g.gbase.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.gbase.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.gbase.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.gbase.Update<Topic>(new { id = 1 }).SetRaw("Title='test1'").AsTable(a => "tb_topicAsTable").ToSql());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,73 @@
|
|||||||
|
using FreeSql.DataAnnotations;
|
||||||
|
using System;
|
||||||
|
using Xunit;
|
||||||
|
|
||||||
|
namespace FreeSql.Tests.GBase
|
||||||
|
{
|
||||||
|
public class GBaseAdoTest
|
||||||
|
{
|
||||||
|
[Fact]
|
||||||
|
public void Pool()
|
||||||
|
{
|
||||||
|
var t1 = g.gbase.Ado.MasterPool.StatisticsFullily;
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void SlavePools()
|
||||||
|
{
|
||||||
|
var t2 = g.gbase.Ado.SlavePools.Count;
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void ExecuteTest()
|
||||||
|
{
|
||||||
|
Assert.True(g.gbase.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.gbase.Ado.Query<xxx>("select * from TB_TOPIC22");
|
||||||
|
|
||||||
|
var t4 = g.gbase.Ado.Query<(int, string, string)>("select * from TB_TOPIC22");
|
||||||
|
|
||||||
|
var t5 = g.gbase.Ado.Query<dynamic>("select * from TB_TOPIC22");
|
||||||
|
|
||||||
|
var t6 = g.gbase.Ado.Query<xxx>("select * from TB_TOPIC22 where ID in @ids", new { ids = new[] { 1, 2, 3 } });
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void QueryMultipline()
|
||||||
|
{
|
||||||
|
//var t3 = g.firebird.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,169 @@
|
|||||||
|
using FreeSql.DataAnnotations;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using Xunit;
|
||||||
|
|
||||||
|
namespace FreeSql.Tests.GBaseExpression
|
||||||
|
{
|
||||||
|
public class ConvertTest
|
||||||
|
{
|
||||||
|
|
||||||
|
ISelect<Topic> select => g.gbase.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,642 @@
|
|||||||
|
using FreeSql.DataAnnotations;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using Xunit;
|
||||||
|
|
||||||
|
namespace FreeSql.Tests.GBaseExpression
|
||||||
|
{
|
||||||
|
public class DateTimeTest
|
||||||
|
{
|
||||||
|
|
||||||
|
ISelect<Topic> select => g.gbase.Select<Topic>();
|
||||||
|
|
||||||
|
[Table(Name = "tb_topic111333")]
|
||||||
|
class Topic
|
||||||
|
{
|
||||||
|
[Column(IsIdentity = true, IsPrimary = true)]
|
||||||
|
public int Id { get; set; }
|
||||||
|
public int Clicks { get; set; }
|
||||||
|
public int TypeGuid { get; set; }
|
||||||
|
public TestTypeInfo Type { get; set; }
|
||||||
|
public string Title { get; set; }
|
||||||
|
public DateTime CreateTime { get; set; }
|
||||||
|
}
|
||||||
|
[Table(Name = "TestTypeInfo333")]
|
||||||
|
class TestTypeInfo
|
||||||
|
{
|
||||||
|
[Column(IsIdentity = true)]
|
||||||
|
public int Guid { get; set; }
|
||||||
|
public int ParentId { get; set; }
|
||||||
|
public TestTypeParentInfo Parent { get; set; }
|
||||||
|
public string Name { get; set; }
|
||||||
|
public DateTime Time { get; set; }
|
||||||
|
}
|
||||||
|
[Table(Name = "TestTypeParentInf1")]
|
||||||
|
class TestTypeParentInfo
|
||||||
|
{
|
||||||
|
public int Id { get; set; }
|
||||||
|
public string Name { get; set; }
|
||||||
|
|
||||||
|
public List<TestTypeInfo> Types { get; set; }
|
||||||
|
public DateTime Time2 { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void 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.gbase.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"), 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("上午 上", "上午 上午").Replace("下午 下", "下午 下午"), 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 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).TotalMinutes > 0).ToList());
|
||||||
|
//data.Add(select.Where(a => a.Type.Time.Subtract(DateTime.Now).TotalMinutes > 0).ToList());
|
||||||
|
//data.Add(select.Where(a => a.Type.Parent.Time2.Subtract(DateTime.Now).TotalMinutes > 0).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());
|
||||||
|
}
|
||||||
|
[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,150 @@
|
|||||||
|
using FreeSql.DataAnnotations;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using Xunit;
|
||||||
|
|
||||||
|
namespace FreeSql.Tests.GBaseExpression
|
||||||
|
{
|
||||||
|
public class MathTest
|
||||||
|
{
|
||||||
|
|
||||||
|
ISelect<Topic> select => g.gbase.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 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,169 @@
|
|||||||
|
using FreeSql.DataAnnotations;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using Xunit;
|
||||||
|
|
||||||
|
namespace FreeSql.Tests.GBaseExpression
|
||||||
|
{
|
||||||
|
public class OtherTest
|
||||||
|
{
|
||||||
|
|
||||||
|
ISelect<TableAllType> select => g.gbase.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).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.Int > 0).ToList();
|
||||||
|
var t222 = select.Where(a => a.Bool != true && a.Int > 0).ToList();
|
||||||
|
var t333 = select.Where(a => a.Bool == false && a.Int > 0).ToList();
|
||||||
|
var t444 = select.Where(a => !a.Bool && a.Int > 0).ToList();
|
||||||
|
var t555 = select.Where(a => a.Bool && a.Int > 0).ToList();
|
||||||
|
|
||||||
|
var t1111 = select.Where(a => a.BoolNullable == true && a.Int > 0).ToList();
|
||||||
|
var t2222 = select.Where(a => a.BoolNullable != true && a.Int > 0).ToList();
|
||||||
|
var t3333 = select.Where(a => a.BoolNullable == false && a.Int > 0).ToList();
|
||||||
|
var t4444 = select.Where(a => !a.BoolNullable.Value && a.Int > 0).ToList();
|
||||||
|
var t5555 = select.Where(a => a.BoolNullable.Value && a.Int > 0).ToList();
|
||||||
|
|
||||||
|
var t11111 = select.Where(a => a.Bool == true && a.Int > 0 && a.Bool == true).ToList();
|
||||||
|
var t22222 = select.Where(a => a.Bool != true && a.Int > 0 && a.Bool != true).ToList();
|
||||||
|
var t33333 = select.Where(a => a.Bool == false && a.Int > 0 && a.Bool == false).ToList();
|
||||||
|
var t44444 = select.Where(a => !a.Bool && a.Int > 0 && !a.Bool).ToList();
|
||||||
|
var t55555 = select.Where(a => a.Bool && a.Int > 0 && a.Bool).ToList();
|
||||||
|
|
||||||
|
var t111111 = select.Where(a => a.BoolNullable == true && a.Int > 0 && a.BoolNullable == true).ToList();
|
||||||
|
var t222222 = select.Where(a => a.BoolNullable != true && a.Int > 0 && a.BoolNullable != true).ToList();
|
||||||
|
var t333333 = select.Where(a => a.BoolNullable == false && a.Int > 0 && a.BoolNullable == false).ToList();
|
||||||
|
var t444444 = select.Where(a => !a.BoolNullable.Value && a.Int > 0 && !a.BoolNullable.Value).ToList();
|
||||||
|
var t555555 = select.Where(a => a.BoolNullable.Value && a.Int > 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(IsPrimary = true)]
|
||||||
|
public Guid 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; }
|
||||||
|
|
||||||
|
[Column(ServerTime = DateTimeKind.Local)]
|
||||||
|
public DateTime DateTime { 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; }
|
||||||
|
|
||||||
|
[Column(ServerTime = DateTimeKind.Local)]
|
||||||
|
public DateTime? DateTimeNullable { 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,816 @@
|
|||||||
|
using FreeSql.DataAnnotations;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using Xunit;
|
||||||
|
|
||||||
|
namespace FreeSql.Tests.GBaseExpression
|
||||||
|
{
|
||||||
|
public class StringTest
|
||||||
|
{
|
||||||
|
|
||||||
|
ISelect<Topic> select => g.gbase.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.gbase.Select<TestEqualsGuid>().Where(a => a.id.Equals(Guid.Empty)).ToList());
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void StringJoin()
|
||||||
|
{
|
||||||
|
var fsql = g.gbase;
|
||||||
|
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.gbase.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.gbase.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 (coalesce(a.`Title`, '') = '')
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void StartsWith()
|
||||||
|
{
|
||||||
|
var list = new List<object>();
|
||||||
|
list.Add(select.Where(a => a.Title.StartsWith("aaa")).ToList());
|
||||||
|
list.Add(select.Where(a => a.Title.StartsWith(a.Title)).ToList());
|
||||||
|
list.Add(select.Where(a => a.Title.StartsWith(a.Title + 1)).ToList());
|
||||||
|
list.Add(select.Where(a => a.Title.StartsWith(a.Type.Name)).ToList());
|
||||||
|
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5
|
||||||
|
//FROM `tb_topic` a
|
||||||
|
//WHERE((a.`Title`) LIKE '%aaa')
|
||||||
|
|
||||||
|
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5
|
||||||
|
//FROM `tb_topic` a
|
||||||
|
//WHERE((a.`Title`) LIKE concat('%', a.`Title`))
|
||||||
|
|
||||||
|
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5
|
||||||
|
//FROM `tb_topic` a
|
||||||
|
//WHERE((a.`Title`) LIKE concat('%', concat(a.`Title`, 1)))
|
||||||
|
|
||||||
|
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a.`Title` as7, a.`CreateTime` as8
|
||||||
|
//FROM `tb_topic` a, `TestTypeInfo` a__Type
|
||||||
|
//WHERE((a.`Title`) LIKE concat('%', a__Type.`Name`))
|
||||||
|
list.Add(select.Where(a => (a.Title + "aaa").StartsWith("aaa")).ToList());
|
||||||
|
list.Add(select.Where(a => (a.Title + "aaa").StartsWith(a.Title)).ToList());
|
||||||
|
list.Add(select.Where(a => (a.Title + "aaa").StartsWith(a.Title + 1)).ToList());
|
||||||
|
list.Add(select.Where(a => (a.Title + "aaa").StartsWith(a.Type.Name)).ToList());
|
||||||
|
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5
|
||||||
|
//FROM `tb_topic` a
|
||||||
|
//WHERE((concat(a.`Title`, 'aaa')) LIKE '%aaa')
|
||||||
|
|
||||||
|
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5
|
||||||
|
//FROM `tb_topic` a
|
||||||
|
//WHERE((concat(a.`Title`, 'aaa')) LIKE concat('%', a.`Title`))
|
||||||
|
|
||||||
|
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5
|
||||||
|
//FROM `tb_topic` a
|
||||||
|
//WHERE((concat(a.`Title`, 'aaa')) LIKE concat('%', concat(a.`Title`, 1)))
|
||||||
|
|
||||||
|
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a.`Title` as7, a.`CreateTime` as8
|
||||||
|
//FROM `tb_topic` a, `TestTypeInfo` a__Type
|
||||||
|
//WHERE((concat(a.`Title`, 'aaa')) LIKE concat('%', a__Type.`Name`))
|
||||||
|
}
|
||||||
|
[Fact]
|
||||||
|
public void EndsWith()
|
||||||
|
{
|
||||||
|
var list = new List<object>();
|
||||||
|
list.Add(select.Where(a => a.Title.EndsWith("aaa")).ToList());
|
||||||
|
list.Add(select.Where(a => a.Title.EndsWith(a.Title)).ToList());
|
||||||
|
list.Add(select.Where(a => a.Title.EndsWith(a.Title + 1)).ToList());
|
||||||
|
list.Add(select.Where(a => a.Title.EndsWith(a.Type.Name)).ToList());
|
||||||
|
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5
|
||||||
|
//FROM `tb_topic` a
|
||||||
|
//WHERE((a.`Title`) LIKE 'aaa%')
|
||||||
|
|
||||||
|
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5
|
||||||
|
//FROM `tb_topic` a
|
||||||
|
//WHERE((a.`Title`) LIKE concat(a.`Title`, '%'))
|
||||||
|
|
||||||
|
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5
|
||||||
|
//FROM `tb_topic` a
|
||||||
|
//WHERE((a.`Title`) LIKE concat(concat(a.`Title`, 1), '%'))
|
||||||
|
|
||||||
|
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a.`Title` as7, a.`CreateTime` as8
|
||||||
|
//FROM `tb_topic` a, `TestTypeInfo` a__Type
|
||||||
|
//WHERE((a.`Title`) LIKE concat(a__Type.`Name`, '%'))
|
||||||
|
list.Add(select.Where(a => (a.Title + "aaa").EndsWith("aaa")).ToList());
|
||||||
|
list.Add(select.Where(a => (a.Title + "aaa").EndsWith(a.Title)).ToList());
|
||||||
|
list.Add(select.Where(a => (a.Title + "aaa").EndsWith(a.Title + 1)).ToList());
|
||||||
|
list.Add(select.Where(a => (a.Title + "aaa").EndsWith(a.Type.Name)).ToList());
|
||||||
|
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5
|
||||||
|
//FROM `tb_topic` a
|
||||||
|
//WHERE((concat(a.`Title`, 'aaa')) LIKE 'aaa%')
|
||||||
|
|
||||||
|
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5
|
||||||
|
//FROM `tb_topic` a
|
||||||
|
//WHERE((concat(a.`Title`, 'aaa')) LIKE concat(a.`Title`, '%'))
|
||||||
|
|
||||||
|
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5
|
||||||
|
//FROM `tb_topic` a
|
||||||
|
//WHERE((concat(a.`Title`, 'aaa')) LIKE concat(concat(a.`Title`, 1), '%'))
|
||||||
|
|
||||||
|
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a.`Title` as7, a.`CreateTime` as8
|
||||||
|
//FROM `tb_topic` a, `TestTypeInfo` a__Type
|
||||||
|
//WHERE((concat(a.`Title`, 'aaa')) LIKE concat(a__Type.`Name`, '%'))
|
||||||
|
}
|
||||||
|
[Fact]
|
||||||
|
public void Contains()
|
||||||
|
{
|
||||||
|
var list = new List<object>();
|
||||||
|
list.Add(select.Where(a => a.Title.Contains("aaa")).ToList());
|
||||||
|
list.Add(select.Where(a => a.Title.Contains(a.Title)).ToList());
|
||||||
|
list.Add(select.Where(a => a.Title.Contains(a.Title + 1)).ToList());
|
||||||
|
list.Add(select.Where(a => a.Title.Contains(a.Type.Name)).ToList());
|
||||||
|
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5
|
||||||
|
//FROM `tb_topic` a
|
||||||
|
//WHERE((a.`Title`) LIKE '%aaa%')
|
||||||
|
|
||||||
|
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5
|
||||||
|
//FROM `tb_topic` a
|
||||||
|
//WHERE((a.`Title`) LIKE concat('%', a.`Title`, '%'))
|
||||||
|
|
||||||
|
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5
|
||||||
|
//FROM `tb_topic` a
|
||||||
|
//WHERE((a.`Title`) LIKE concat('%', a.`Title` +1, '%'))
|
||||||
|
|
||||||
|
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a.`Title` as7, a.`CreateTime` as8
|
||||||
|
//FROM `tb_topic` a, `TestTypeInfo` a__Type
|
||||||
|
//WHERE((a.`Title`) LIKE concat('%', a__Type.`Name`, '%'))
|
||||||
|
list.Add(select.Where(a => (a.Title + "aaa").Contains("aaa")).ToList());
|
||||||
|
list.Add(select.Where(a => (a.Title + "aaa").Contains(a.Title)).ToList());
|
||||||
|
list.Add(select.Where(a => (a.Title + "aaa").Contains(a.Title + 1)).ToList());
|
||||||
|
list.Add(select.Where(a => (a.Title + "aaa").Contains(a.Type.Name)).ToList());
|
||||||
|
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5
|
||||||
|
//FROM `tb_topic` a
|
||||||
|
//WHERE((concat(a.`Title`, 'aaa')) LIKE '%aaa%')
|
||||||
|
|
||||||
|
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5
|
||||||
|
//FROM `tb_topic` a
|
||||||
|
//WHERE((concat(a.`Title`, 'aaa')) LIKE concat('%', a.`Title`, '%'))
|
||||||
|
|
||||||
|
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5
|
||||||
|
//FROM `tb_topic` a
|
||||||
|
//WHERE((concat(a.`Title`, 'aaa')) LIKE concat('%', concat(a.`Title`, 1), '%'))
|
||||||
|
|
||||||
|
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a.`Title` as7, a.`CreateTime` as8
|
||||||
|
//FROM `tb_topic` a, `TestTypeInfo` a__Type
|
||||||
|
//WHERE((concat(a.`Title`, 'aaa')) LIKE concat('%', a__Type.`Name`, '%'))
|
||||||
|
}
|
||||||
|
[Fact]
|
||||||
|
public void ToLower()
|
||||||
|
{
|
||||||
|
var data = new List<object>();
|
||||||
|
data.Add(select.Where(a => a.Title.ToLower() == "aaa").ToList());
|
||||||
|
data.Add(select.Where(a => a.Title.ToLower() == a.Title).ToList());
|
||||||
|
data.Add(select.Where(a => a.Title.ToLower() == (a.Title + 1)).ToList());
|
||||||
|
data.Add(select.Where(a => a.Title.ToLower() == a.Type.Name).ToList());
|
||||||
|
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5
|
||||||
|
//FROM `tb_topic` a
|
||||||
|
//WHERE(lower(a.`Title`) = 'aaa');
|
||||||
|
|
||||||
|
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5
|
||||||
|
//FROM `tb_topic` a
|
||||||
|
//WHERE(lower(a.`Title`) = a.`Title`);
|
||||||
|
|
||||||
|
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5
|
||||||
|
//FROM `tb_topic` a
|
||||||
|
//WHERE(lower(a.`Title`) = concat(a.`Title`, 1));
|
||||||
|
|
||||||
|
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a.`Title` as7, a.`CreateTime` as8
|
||||||
|
//FROM `tb_topic` a, `TestTypeInfo` a__Type
|
||||||
|
//WHERE(lower(a.`Title`) = a__Type.`Name`);
|
||||||
|
data.Add(select.Where(a => (a.Title.ToLower() + "aaa").ToLower() == "aaa").ToList());
|
||||||
|
data.Add(select.Where(a => (a.Title.ToLower() + "aaa").ToLower() == a.Title).ToList());
|
||||||
|
data.Add(select.Where(a => (a.Title.ToLower() + "aaa").ToLower() == (a.Title + 1)).ToList());
|
||||||
|
data.Add(select.Where(a => (a.Title.ToLower() + "aaa").ToLower() == a.Type.Name).ToList());
|
||||||
|
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5
|
||||||
|
//FROM `tb_topic` a
|
||||||
|
//WHERE(lower(concat(lower(a.`Title`), 'aaa')) = 'aaa');
|
||||||
|
|
||||||
|
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5
|
||||||
|
//FROM `tb_topic` a
|
||||||
|
//WHERE(lower(concat(lower(a.`Title`), 'aaa')) = a.`Title`);
|
||||||
|
|
||||||
|
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5
|
||||||
|
//FROM `tb_topic` a
|
||||||
|
//WHERE(lower(concat(lower(a.`Title`), 'aaa')) = concat(a.`Title`, 1));
|
||||||
|
|
||||||
|
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a.`Title` as7, a.`CreateTime` as8
|
||||||
|
//FROM `tb_topic` a, `TestTypeInfo` a__Type
|
||||||
|
//WHERE(lower(concat(lower(a.`Title`), 'aaa')) = a__Type.`Name`)
|
||||||
|
}
|
||||||
|
[Fact]
|
||||||
|
public void ToUpper()
|
||||||
|
{
|
||||||
|
var data = new List<object>();
|
||||||
|
data.Add(select.Where(a => a.Title.ToUpper() == "aaa").ToList());
|
||||||
|
data.Add(select.Where(a => a.Title.ToUpper() == a.Title).ToList());
|
||||||
|
data.Add(select.Where(a => a.Title.ToUpper() == (a.Title + 1)).ToList());
|
||||||
|
data.Add(select.Where(a => a.Title.ToUpper() == a.Type.Name).ToList());
|
||||||
|
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5
|
||||||
|
//FROM `tb_topic` a
|
||||||
|
//WHERE (upper(a.`Title`) = 'aaa');
|
||||||
|
|
||||||
|
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5
|
||||||
|
//FROM `tb_topic` a
|
||||||
|
//WHERE (upper(a.`Title`) = a.`Title`);
|
||||||
|
|
||||||
|
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5
|
||||||
|
//FROM `tb_topic` a
|
||||||
|
//WHERE (upper(a.`Title`) = concat(a.`Title`, 1));
|
||||||
|
|
||||||
|
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a.`Title` as7, a.`CreateTime` as8
|
||||||
|
//FROM `tb_topic` a, `TestTypeInfo` a__Type
|
||||||
|
//WHERE (upper(a.`Title`) = a__Type.`Name`);
|
||||||
|
data.Add(select.Where(a => (a.Title.ToUpper() + "aaa").ToUpper() == "aaa").ToList());
|
||||||
|
data.Add(select.Where(a => (a.Title.ToUpper() + "aaa").ToUpper() == a.Title).ToList());
|
||||||
|
data.Add(select.Where(a => (a.Title.ToUpper() + "aaa").ToUpper() == (a.Title + 1)).ToList());
|
||||||
|
data.Add(select.Where(a => (a.Title.ToUpper() + "aaa").ToUpper() == a.Type.Name).ToList());
|
||||||
|
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5
|
||||||
|
//FROM `tb_topic` a
|
||||||
|
//WHERE (upper(concat(upper(a.`Title`), 'aaa')) = 'aaa');
|
||||||
|
|
||||||
|
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5
|
||||||
|
//FROM `tb_topic` a
|
||||||
|
//WHERE (upper(concat(upper(a.`Title`), 'aaa')) = a.`Title`);
|
||||||
|
|
||||||
|
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5
|
||||||
|
//FROM `tb_topic` a
|
||||||
|
//WHERE (upper(concat(upper(a.`Title`), 'aaa')) = concat(a.`Title`, 1));
|
||||||
|
|
||||||
|
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a.`Title` as7, a.`CreateTime` as8
|
||||||
|
//FROM `tb_topic` a, `TestTypeInfo` a__Type
|
||||||
|
//WHERE (upper(concat(upper(a.`Title`), 'aaa')) = a__Type.`Name`)
|
||||||
|
}
|
||||||
|
[Fact]
|
||||||
|
public void Substring()
|
||||||
|
{
|
||||||
|
var data = new List<object>();
|
||||||
|
data.Add(select.Where(a => a.Title.Substring(0) == "aaa").ToList());
|
||||||
|
data.Add(select.Where(a => a.Title.Substring(0) == a.Title).ToList());
|
||||||
|
data.Add(select.Where(a => a.Title.Substring(0) == (a.Title + 1)).ToList());
|
||||||
|
data.Add(select.Where(a => a.Title.Substring(0) == a.Type.Name).ToList());
|
||||||
|
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5
|
||||||
|
//FROM `tb_topic` a
|
||||||
|
//WHERE (substr(a.`Title`, 1) = 'aaa');
|
||||||
|
|
||||||
|
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5
|
||||||
|
//FROM `tb_topic` a
|
||||||
|
//WHERE (substr(a.`Title`, 1) = a.`Title`);
|
||||||
|
|
||||||
|
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5
|
||||||
|
//FROM `tb_topic` a
|
||||||
|
//WHERE (substr(a.`Title`, 1) = concat(a.`Title`, 1));
|
||||||
|
|
||||||
|
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a.`Title` as7, a.`CreateTime` as8
|
||||||
|
//FROM `tb_topic` a, `TestTypeInfo` a__Type
|
||||||
|
//WHERE (substr(a.`Title`, 1) = a__Type.`Name`);
|
||||||
|
data.Add(select.Where(a => (a.Title.Substring(0) + "aaa").Substring(a.Title.Length) == "aaa").ToList());
|
||||||
|
data.Add(select.Where(a => (a.Title.Substring(0) + "aaa").Substring(0, a.Title.Length) == a.Title).ToList());
|
||||||
|
data.Add(select.Where(a => (a.Title.Substring(0) + "aaa").Substring(0, 3) == (a.Title + 1)).ToList());
|
||||||
|
data.Add(select.Where(a => (a.Title.Substring(0) + "aaa").Substring(1, 2) == a.Type.Name).ToList());
|
||||||
|
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5
|
||||||
|
//FROM `tb_topic` a
|
||||||
|
//WHERE (substr(concat(substr(a.`Title`, 1), 'aaa'), char_length(a.`Title`) + 1) = 'aaa');
|
||||||
|
|
||||||
|
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5
|
||||||
|
//FROM `tb_topic` a
|
||||||
|
//WHERE (substr(concat(substr(a.`Title`, 1), 'aaa'), 1, char_length(a.`Title`)) = a.`Title`);
|
||||||
|
|
||||||
|
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5
|
||||||
|
//FROM `tb_topic` a
|
||||||
|
//WHERE (substr(concat(substr(a.`Title`, 1), 'aaa'), 1, 3) = concat(a.`Title`, 1));
|
||||||
|
|
||||||
|
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a.`Title` as7, a.`CreateTime` as8
|
||||||
|
//FROM `tb_topic` a, `TestTypeInfo` a__Type
|
||||||
|
//WHERE (substr(concat(substr(a.`Title`, 1), 'aaa'), 2, 2) = a__Type.`Name`)
|
||||||
|
}
|
||||||
|
[Fact]
|
||||||
|
public void Length()
|
||||||
|
{
|
||||||
|
var data = new List<object>();
|
||||||
|
data.Add(select.Where(a => a.Title.Length == 0).ToList());
|
||||||
|
data.Add(select.Where(a => a.Title.Length == 1).ToList());
|
||||||
|
data.Add(select.Where(a => a.Title.Length == a.Title.Length + 1).ToList());
|
||||||
|
data.Add(select.Where(a => a.Title.Length == a.Type.Name.Length).ToList());
|
||||||
|
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5
|
||||||
|
//FROM `tb_topic` a
|
||||||
|
//WHERE (char_length(a.`Title`) = 0);
|
||||||
|
|
||||||
|
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5
|
||||||
|
//FROM `tb_topic` a
|
||||||
|
//WHERE (char_length(a.`Title`) = 1);
|
||||||
|
|
||||||
|
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5
|
||||||
|
//FROM `tb_topic` a
|
||||||
|
//WHERE (char_length(a.`Title`) = char_length(a.`Title`) + 1);
|
||||||
|
|
||||||
|
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a.`Title` as7, a.`CreateTime` as8
|
||||||
|
//FROM `tb_topic` a, `TestTypeInfo` a__Type
|
||||||
|
//WHERE (char_length(a.`Title`) = char_length(a__Type.`Name`));
|
||||||
|
data.Add(select.Where(a => (a.Title + "aaa").Length == 0).ToList());
|
||||||
|
data.Add(select.Where(a => (a.Title + "aaa").Length == 1).ToList());
|
||||||
|
data.Add(select.Where(a => (a.Title + "aaa").Length == a.Title.Length + 1).ToList());
|
||||||
|
data.Add(select.Where(a => (a.Title + "aaa").Length == a.Type.Name.Length).ToList());
|
||||||
|
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5
|
||||||
|
//FROM `tb_topic` a
|
||||||
|
//WHERE (char_length(concat(a.`Title`, 'aaa')) = 0);
|
||||||
|
|
||||||
|
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5
|
||||||
|
//FROM `tb_topic` a
|
||||||
|
//WHERE (char_length(concat(a.`Title`, 'aaa')) = 1);
|
||||||
|
|
||||||
|
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5
|
||||||
|
//FROM `tb_topic` a
|
||||||
|
//WHERE (char_length(concat(a.`Title`, 'aaa')) = char_length(a.`Title`) + 1);
|
||||||
|
|
||||||
|
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a.`Title` as7, a.`CreateTime` as8
|
||||||
|
//FROM `tb_topic` a, `TestTypeInfo` a__Type
|
||||||
|
//WHERE (char_length(concat(a.`Title`, 'aaa')) = char_length(a__Type.`Name`))
|
||||||
|
}
|
||||||
|
[Fact]
|
||||||
|
public void IndexOf()
|
||||||
|
{
|
||||||
|
var data = new List<object>();
|
||||||
|
data.Add(select.Where(a => a.Title.IndexOf("aaa") == -1).ToList());
|
||||||
|
data.Add(select.Where(a => a.Title.IndexOf("aaa", 2) == -1).ToList());
|
||||||
|
data.Add(select.Where(a => a.Title.IndexOf("aaa", 2) == (a.Title.Length + 1)).ToList());
|
||||||
|
data.Add(select.Where(a => a.Title.IndexOf("aaa", 2) == a.Type.Name.Length + 1).ToList());
|
||||||
|
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5
|
||||||
|
//FROM `tb_topic` a
|
||||||
|
//WHERE ((locate(a.`Title`, 'aaa') - 1) = -1);
|
||||||
|
|
||||||
|
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5
|
||||||
|
//FROM `tb_topic` a
|
||||||
|
//WHERE ((locate(a.`Title`, 'aaa', 3) - 1) = -1);
|
||||||
|
|
||||||
|
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5
|
||||||
|
//FROM `tb_topic` a
|
||||||
|
//WHERE ((locate(a.`Title`, 'aaa', 3) - 1) = char_length(a.`Title`) + 1);
|
||||||
|
|
||||||
|
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a.`Title` as7, a.`CreateTime` as8
|
||||||
|
//FROM `tb_topic` a, `TestTypeInfo` a__Type
|
||||||
|
//WHERE ((locate(a.`Title`, 'aaa', 3) - 1) = char_length(a__Type.`Name`) + 1);
|
||||||
|
data.Add(select.Where(a => (a.Title + "aaa").IndexOf("aaa") == -1).ToList());
|
||||||
|
data.Add(select.Where(a => (a.Title + "aaa").IndexOf("aaa", 2) == -1).ToList());
|
||||||
|
data.Add(select.Where(a => (a.Title + "aaa").IndexOf("aaa", 2) == (a.Title.Length + 1)).ToList());
|
||||||
|
data.Add(select.Where(a => (a.Title + "aaa").IndexOf("aaa", 2) == a.Type.Name.Length + 1).ToList());
|
||||||
|
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5
|
||||||
|
//FROM `tb_topic` a
|
||||||
|
//WHERE ((locate(concat(a.`Title`, 'aaa'), 'aaa') - 1) = -1);
|
||||||
|
|
||||||
|
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5
|
||||||
|
//FROM `tb_topic` a
|
||||||
|
//WHERE ((locate(concat(a.`Title`, 'aaa'), 'aaa', 3) - 1) = -1);
|
||||||
|
|
||||||
|
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5
|
||||||
|
//FROM `tb_topic` a
|
||||||
|
//WHERE ((locate(concat(a.`Title`, 'aaa'), 'aaa', 3) - 1) = char_length(a.`Title`) + 1);
|
||||||
|
|
||||||
|
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a.`Title` as7, a.`CreateTime` as8
|
||||||
|
//FROM `tb_topic` a, `TestTypeInfo` a__Type
|
||||||
|
//WHERE ((locate(concat(a.`Title`, 'aaa'), 'aaa', 3) - 1) = char_length(a__Type.`Name`) + 1)
|
||||||
|
}
|
||||||
|
[Fact]
|
||||||
|
public void PadLeft()
|
||||||
|
{
|
||||||
|
var data = new List<object>();
|
||||||
|
data.Add(select.Where(a => a.Title.PadLeft(10, 'a') == "aaa").ToList());
|
||||||
|
data.Add(select.Where(a => a.Title.PadLeft(10, 'a') == a.Title).ToList());
|
||||||
|
data.Add(select.Where(a => a.Title.PadLeft(10, 'a') == (a.Title + 1)).ToList());
|
||||||
|
data.Add(select.Where(a => a.Title.PadLeft(10, 'a') == a.Type.Name).ToList());
|
||||||
|
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5
|
||||||
|
//FROM `tb_topic` a
|
||||||
|
//WHERE (lpad(a.`Title`, 10, 'a') = 'aaa');
|
||||||
|
|
||||||
|
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5
|
||||||
|
//FROM `tb_topic` a
|
||||||
|
//WHERE (lpad(a.`Title`, 10, 'a') = a.`Title`);
|
||||||
|
|
||||||
|
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5
|
||||||
|
//FROM `tb_topic` a
|
||||||
|
//WHERE (lpad(a.`Title`, 10, 'a') = concat(a.`Title`, 1));
|
||||||
|
|
||||||
|
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a.`Title` as7, a.`CreateTime` as8
|
||||||
|
//FROM `tb_topic` a, `TestTypeInfo` a__Type
|
||||||
|
//WHERE (lpad(a.`Title`, 10, 'a') = a__Type.`Name`);
|
||||||
|
data.Add(select.Where(a => (a.Title.PadLeft(10, 'a') + "aaa").PadLeft(20, 'b') == "aaa").ToList());
|
||||||
|
data.Add(select.Where(a => (a.Title.PadLeft(10, 'a') + "aaa").PadLeft(20, 'b') == a.Title).ToList());
|
||||||
|
data.Add(select.Where(a => (a.Title.PadLeft(10, 'a') + "aaa").PadLeft(20, 'b') == (a.Title + 1)).ToList());
|
||||||
|
data.Add(select.Where(a => (a.Title.PadLeft(10, 'a') + "aaa").PadLeft(20, 'b') == a.Type.Name).ToList());
|
||||||
|
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5
|
||||||
|
//FROM `tb_topic` a
|
||||||
|
//WHERE (lpad(concat(lpad(a.`Title`, 10, 'a'), 'aaa'), 20, 'b') = 'aaa');
|
||||||
|
|
||||||
|
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5
|
||||||
|
//FROM `tb_topic` a
|
||||||
|
//WHERE (lpad(concat(lpad(a.`Title`, 10, 'a'), 'aaa'), 20, 'b') = a.`Title`);
|
||||||
|
|
||||||
|
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5
|
||||||
|
//FROM `tb_topic` a
|
||||||
|
//WHERE (lpad(concat(lpad(a.`Title`, 10, 'a'), 'aaa'), 20, 'b') = concat(a.`Title`, 1));
|
||||||
|
|
||||||
|
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a.`Title` as7, a.`CreateTime` as8
|
||||||
|
//FROM `tb_topic` a, `TestTypeInfo` a__Type
|
||||||
|
//WHERE (lpad(concat(lpad(a.`Title`, 10, 'a'), 'aaa'), 20, 'b') = a__Type.`Name`)
|
||||||
|
}
|
||||||
|
[Fact]
|
||||||
|
public void PadRight()
|
||||||
|
{
|
||||||
|
var data = new List<object>();
|
||||||
|
data.Add(select.Where(a => a.Title.PadRight(10, 'a') == "aaa").ToList());
|
||||||
|
data.Add(select.Where(a => a.Title.PadRight(10, 'a') == a.Title).ToList());
|
||||||
|
data.Add(select.Where(a => a.Title.PadRight(10, 'a') == (a.Title + 1)).ToList());
|
||||||
|
data.Add(select.Where(a => a.Title.PadRight(10, 'a') == a.Type.Name).ToList());
|
||||||
|
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5
|
||||||
|
//FROM `tb_topic` a
|
||||||
|
//WHERE (rpad(a.`Title`, 10, 'a') = 'aaa');
|
||||||
|
|
||||||
|
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5
|
||||||
|
//FROM `tb_topic` a
|
||||||
|
//WHERE (rpad(a.`Title`, 10, 'a') = a.`Title`);
|
||||||
|
|
||||||
|
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5
|
||||||
|
//FROM `tb_topic` a
|
||||||
|
//WHERE (rpad(a.`Title`, 10, 'a') = concat(a.`Title`, 1));
|
||||||
|
|
||||||
|
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a.`Title` as7, a.`CreateTime` as8
|
||||||
|
//FROM `tb_topic` a, `TestTypeInfo` a__Type
|
||||||
|
//WHERE (rpad(a.`Title`, 10, 'a') = a__Type.`Name`);
|
||||||
|
data.Add(select.Where(a => (a.Title.PadRight(10, 'a') + "aaa").PadRight(20, 'b') == "aaa").ToList());
|
||||||
|
data.Add(select.Where(a => (a.Title.PadRight(10, 'a') + "aaa").PadRight(20, 'b') == a.Title).ToList());
|
||||||
|
data.Add(select.Where(a => (a.Title.PadRight(10, 'a') + "aaa").PadRight(20, 'b') == (a.Title + 1)).ToList());
|
||||||
|
data.Add(select.Where(a => (a.Title.PadRight(10, 'a') + "aaa").PadRight(20, 'b') == a.Type.Name).ToList());
|
||||||
|
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5
|
||||||
|
//FROM `tb_topic` a
|
||||||
|
//WHERE (rpad(concat(rpad(a.`Title`, 10, 'a'), 'aaa'), 20, 'b') = 'aaa');
|
||||||
|
|
||||||
|
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5
|
||||||
|
//FROM `tb_topic` a
|
||||||
|
//WHERE (rpad(concat(rpad(a.`Title`, 10, 'a'), 'aaa'), 20, 'b') = a.`Title`);
|
||||||
|
|
||||||
|
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5
|
||||||
|
//FROM `tb_topic` a
|
||||||
|
//WHERE (rpad(concat(rpad(a.`Title`, 10, 'a'), 'aaa'), 20, 'b') = concat(a.`Title`, 1));
|
||||||
|
|
||||||
|
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a.`Title` as7, a.`CreateTime` as8
|
||||||
|
//FROM `tb_topic` a, `TestTypeInfo` a__Type
|
||||||
|
//WHERE (rpad(concat(rpad(a.`Title`, 10, 'a'), 'aaa'), 20, 'b') = a__Type.`Name`)
|
||||||
|
}
|
||||||
|
[Fact]
|
||||||
|
public void Trim()
|
||||||
|
{
|
||||||
|
var data = new List<object>();
|
||||||
|
data.Add(select.Where(a => a.Title.Trim() == "aaa").ToList());
|
||||||
|
data.Add(select.Where(a => a.Title.Trim('a') == a.Title).ToList());
|
||||||
|
data.Add(select.Where(a => a.Title.Trim('a', 'b') == (a.Title + 1)).ToList());
|
||||||
|
data.Add(select.Where(a => a.Title.Trim('a', 'b', 'c') == a.Type.Name).ToList());
|
||||||
|
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5
|
||||||
|
//FROM `tb_topic` a
|
||||||
|
//WHERE (trim(a.`Title`) = 'aaa');
|
||||||
|
|
||||||
|
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5
|
||||||
|
//FROM `tb_topic` a
|
||||||
|
//WHERE (trim('a' from a.`Title`) = a.`Title`);
|
||||||
|
|
||||||
|
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5
|
||||||
|
//FROM `tb_topic` a
|
||||||
|
//WHERE (trim('b' from trim('a' from a.`Title`)) = concat(a.`Title`, 1));
|
||||||
|
|
||||||
|
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a.`Title` as7, a.`CreateTime` as8
|
||||||
|
//FROM `tb_topic` a, `TestTypeInfo` a__Type
|
||||||
|
//WHERE (trim('c' from trim('b' from trim('a' from a.`Title`))) = a__Type.`Name`);
|
||||||
|
data.Add(select.Where(a => (a.Title.Trim() + "aaa").Trim() == "aaa").ToList());
|
||||||
|
data.Add(select.Where(a => (a.Title.Trim('a') + "aaa").Trim('a') == a.Title).ToList());
|
||||||
|
data.Add(select.Where(a => (a.Title.Trim('a', 'b') + "aaa").Trim('a', 'b') == (a.Title + 1)).ToList());
|
||||||
|
data.Add(select.Where(a => (a.Title.Trim('a', 'b', 'c') + "aaa").Trim('a', 'b', 'c') == a.Type.Name).ToList());
|
||||||
|
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5
|
||||||
|
//FROM `tb_topic` a
|
||||||
|
//WHERE (trim(concat(trim(a.`Title`), 'aaa')) = 'aaa');
|
||||||
|
|
||||||
|
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5
|
||||||
|
//FROM `tb_topic` a
|
||||||
|
//WHERE (trim('a' from concat(trim('a' from a.`Title`), 'aaa')) = a.`Title`);
|
||||||
|
|
||||||
|
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5
|
||||||
|
//FROM `tb_topic` a
|
||||||
|
//WHERE (trim('b' from trim('a' from concat(trim('b' from trim('a' from a.`Title`)), 'aaa'))) = concat(a.`Title`, 1));
|
||||||
|
|
||||||
|
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a.`Title` as7, a.`CreateTime` as8
|
||||||
|
//FROM `tb_topic` a, `TestTypeInfo` a__Type
|
||||||
|
//WHERE (trim('c' from trim('b' from trim('a' from concat(trim('c' from trim('b' from trim('a' from a.`Title`))), 'aaa')))) = a__Type.`Name`)
|
||||||
|
}
|
||||||
|
[Fact]
|
||||||
|
public void TrimStart()
|
||||||
|
{
|
||||||
|
var data = new List<object>();
|
||||||
|
data.Add(select.Where(a => a.Title.TrimStart() == "aaa").ToList());
|
||||||
|
data.Add(select.Where(a => a.Title.TrimStart('a') == a.Title).ToList());
|
||||||
|
data.Add(select.Where(a => a.Title.TrimStart('a', 'b') == (a.Title + 1)).ToList());
|
||||||
|
data.Add(select.Where(a => a.Title.TrimStart('a', 'b', 'c') == a.Type.Name).ToList());
|
||||||
|
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5
|
||||||
|
//FROM `tb_topic` a
|
||||||
|
//WHERE (ltrim(a.`Title`) = 'aaa');
|
||||||
|
|
||||||
|
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5
|
||||||
|
//FROM `tb_topic` a
|
||||||
|
//WHERE (trim(trailing 'a' from trim(leading 'a' from a.`Title`)) = a.`Title`);
|
||||||
|
|
||||||
|
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5
|
||||||
|
//FROM `tb_topic` a
|
||||||
|
//WHERE (trim(trailing 'b' from trim(leading 'b' from trim(trailing 'a' from trim(leading 'a' from a.`Title`)))) = concat(a.`Title`, 1));
|
||||||
|
|
||||||
|
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a.`Title` as7, a.`CreateTime` as8
|
||||||
|
//FROM `tb_topic` a, `TestTypeInfo` a__Type
|
||||||
|
//WHERE (trim(trailing 'c' from trim(leading 'c' from trim(trailing 'b' from trim(leading 'b' from trim(trailing 'a' from trim(leading 'a' from a.`Title`)))))) = a__Type.`Name`);
|
||||||
|
data.Add(select.Where(a => (a.Title.TrimStart() + "aaa").TrimStart() == "aaa").ToList());
|
||||||
|
data.Add(select.Where(a => (a.Title.TrimStart('a') + "aaa").TrimStart('a') == a.Title).ToList());
|
||||||
|
data.Add(select.Where(a => (a.Title.TrimStart('a', 'b') + "aaa").TrimStart('a', 'b') == (a.Title + 1)).ToList());
|
||||||
|
data.Add(select.Where(a => (a.Title.TrimStart('a', 'b', 'c') + "aaa").TrimStart('a', 'b', 'c') == a.Type.Name).ToList());
|
||||||
|
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5
|
||||||
|
//FROM `tb_topic` a
|
||||||
|
//WHERE (ltrim(concat(ltrim(a.`Title`), 'aaa')) = 'aaa');
|
||||||
|
|
||||||
|
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5
|
||||||
|
//FROM `tb_topic` a
|
||||||
|
//WHERE (trim(trailing 'a' from trim(leading 'a' from concat(trim(trailing 'a' from trim(leading 'a' from a.`Title`)), 'aaa'))) = a.`Title`);
|
||||||
|
|
||||||
|
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5
|
||||||
|
//FROM `tb_topic` a
|
||||||
|
//WHERE (trim(trailing 'b' from trim(leading 'b' from trim(trailing 'a' from trim(leading 'a' from concat(trim(trailing 'b' from trim(leading 'b' from trim(trailing 'a' from trim(leading 'a' from a.`Title`)))), 'aaa'))))) = concat(a.`Title`, 1));
|
||||||
|
|
||||||
|
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a.`Title` as7, a.`CreateTime` as8
|
||||||
|
//FROM `tb_topic` a, `TestTypeInfo` a__Type
|
||||||
|
//WHERE (trim(trailing 'c' from trim(leading 'c' from trim(trailing 'b' from trim(leading 'b' from trim(trailing 'a' from trim(leading 'a' from concat(trim(trailing 'c' from trim(leading 'c' from trim(trailing 'b' from trim(leading 'b' from trim(trailing 'a' from trim(leading 'a' from a.`Title`)))))), 'aaa'))))))) = a__Type.`Name`)
|
||||||
|
}
|
||||||
|
[Fact]
|
||||||
|
public void TrimEnd()
|
||||||
|
{
|
||||||
|
var data = new List<object>();
|
||||||
|
data.Add(select.Where(a => a.Title.TrimEnd() == "aaa").ToList());
|
||||||
|
data.Add(select.Where(a => a.Title.TrimEnd('a') == a.Title).ToList());
|
||||||
|
data.Add(select.Where(a => a.Title.TrimEnd('a', 'b') == (a.Title + 1)).ToList());
|
||||||
|
data.Add(select.Where(a => a.Title.TrimEnd('a', 'b', 'c') == a.Type.Name).ToList());
|
||||||
|
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5
|
||||||
|
//FROM `tb_topic` a
|
||||||
|
//WHERE (rtrim(a.`Title`) = 'aaa');
|
||||||
|
|
||||||
|
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5
|
||||||
|
//FROM `tb_topic` a
|
||||||
|
//WHERE (trim(trailing 'a' from a.`Title`) = a.`Title`);
|
||||||
|
|
||||||
|
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5
|
||||||
|
//FROM `tb_topic` a
|
||||||
|
//WHERE (trim(trailing 'b' from trim(trailing 'a' from a.`Title`)) = concat(a.`Title`, 1));
|
||||||
|
|
||||||
|
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a.`Title` as7, a.`CreateTime` as8
|
||||||
|
//FROM `tb_topic` a, `TestTypeInfo` a__Type
|
||||||
|
//WHERE (trim(trailing 'c' from trim(trailing 'b' from trim(trailing 'a' from a.`Title`))) = a__Type.`Name`);
|
||||||
|
data.Add(select.Where(a => (a.Title.TrimEnd() + "aaa").TrimEnd() == "aaa").ToList());
|
||||||
|
data.Add(select.Where(a => (a.Title.TrimEnd('a') + "aaa").TrimEnd('a') == a.Title).ToList());
|
||||||
|
data.Add(select.Where(a => (a.Title.TrimEnd('a', 'b') + "aaa").TrimEnd('a', 'b') == (a.Title + 1)).ToList());
|
||||||
|
data.Add(select.Where(a => (a.Title.TrimEnd('a', 'b', 'c') + "aaa").TrimEnd('a', 'b', 'c') == a.Type.Name).ToList());
|
||||||
|
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5
|
||||||
|
//FROM `tb_topic` a
|
||||||
|
//WHERE (rtrim(concat(rtrim(a.`Title`), 'aaa')) = 'aaa');
|
||||||
|
|
||||||
|
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5
|
||||||
|
//FROM `tb_topic` a
|
||||||
|
//WHERE (trim(trailing 'a' from concat(trim(trailing 'a' from a.`Title`), 'aaa')) = a.`Title`);
|
||||||
|
|
||||||
|
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5
|
||||||
|
//FROM `tb_topic` a
|
||||||
|
//WHERE (trim(trailing 'b' from trim(trailing 'a' from concat(trim(trailing 'b' from trim(trailing 'a' from a.`Title`)), 'aaa'))) = concat(a.`Title`, 1));
|
||||||
|
|
||||||
|
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a.`Title` as7, a.`CreateTime` as8
|
||||||
|
//FROM `tb_topic` a, `TestTypeInfo` a__Type
|
||||||
|
//WHERE (trim(trailing 'c' from trim(trailing 'b' from trim(trailing 'a' from concat(trim(trailing 'c' from trim(trailing 'b' from trim(trailing 'a' from a.`Title`))), 'aaa')))) = a__Type.`Name`)
|
||||||
|
}
|
||||||
|
[Fact]
|
||||||
|
public void Replace()
|
||||||
|
{
|
||||||
|
var data = new List<object>();
|
||||||
|
data.Add(select.Where(a => a.Title.Replace("a", "b") == "aaa").ToList());
|
||||||
|
data.Add(select.Where(a => a.Title.Replace("a", "b").Replace("b", "c") == a.Title).ToList());
|
||||||
|
data.Add(select.Where(a => a.Title.Replace("a", "b").Replace("b", "c").Replace("c", "a") == (a.Title + 1)).ToList());
|
||||||
|
data.Add(select.Where(a => a.Title.Replace("a", "b").Replace("b", "c").Replace(a.Type.Name, "a") == a.Type.Name).ToList());
|
||||||
|
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5
|
||||||
|
//FROM `tb_topic` a
|
||||||
|
//WHERE (replace(a.`Title`, 'a', 'b') = 'aaa');
|
||||||
|
|
||||||
|
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5
|
||||||
|
//FROM `tb_topic` a
|
||||||
|
//WHERE (replace(replace(a.`Title`, 'a', 'b'), 'b', 'c') = a.`Title`);
|
||||||
|
|
||||||
|
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5
|
||||||
|
//FROM `tb_topic` a
|
||||||
|
//WHERE (replace(replace(replace(a.`Title`, 'a', 'b'), 'b', 'c'), 'c', 'a') = concat(a.`Title`, 1));
|
||||||
|
|
||||||
|
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a.`Title` as7, a.`CreateTime` as8
|
||||||
|
//FROM `tb_topic` a, `TestTypeInfo` a__Type
|
||||||
|
//WHERE (replace(replace(replace(a.`Title`, 'a', 'b'), 'b', 'c'), a__Type.`Name`, 'a') = a__Type.`Name`);
|
||||||
|
data.Add(select.Where(a => (a.Title.Replace("a", "b") + "aaa").TrimEnd() == "aaa").ToList());
|
||||||
|
data.Add(select.Where(a => (a.Title.Replace("a", "b").Replace("b", "c") + "aaa").TrimEnd('a') == a.Title).ToList());
|
||||||
|
data.Add(select.Where(a => (a.Title.Replace("a", "b").Replace("b", "c").Replace("c", "a") + "aaa").TrimEnd('a', 'b') == (a.Title + 1)).ToList());
|
||||||
|
data.Add(select.Where(a => (a.Title.Replace("a", "b").Replace("b", "c").Replace(a.Type.Name, "a") + "aaa").TrimEnd('a', 'b', 'c') == a.Type.Name).ToList());
|
||||||
|
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5
|
||||||
|
//FROM `tb_topic` a
|
||||||
|
//WHERE (concat(replace(a.`Title`, 'a', 'b'), 'aaa') = 'aaa');
|
||||||
|
|
||||||
|
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5
|
||||||
|
//FROM `tb_topic` a
|
||||||
|
//WHERE (concat(replace(replace(a.`Title`, 'a', 'b'), 'b', 'c'), 'aaa') = a.`Title`);
|
||||||
|
|
||||||
|
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5
|
||||||
|
//FROM `tb_topic` a
|
||||||
|
//WHERE (concat(replace(replace(replace(a.`Title`, 'a', 'b'), 'b', 'c'), 'c', 'a'), 'aaa') = concat(a.`Title`, 1));
|
||||||
|
|
||||||
|
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a.`Title` as7, a.`CreateTime` as8
|
||||||
|
//FROM `tb_topic` a, `TestTypeInfo` a__Type
|
||||||
|
//WHERE (concat(replace(replace(replace(a.`Title`, 'a', 'b'), 'b', 'c'), a__Type.`Name`, 'a'), 'aaa') = a__Type.`Name`)
|
||||||
|
}
|
||||||
|
[Fact]
|
||||||
|
public void CompareTo()
|
||||||
|
{
|
||||||
|
var data = new List<object>();
|
||||||
|
data.Add(select.Where(a => a.Title.CompareTo(a.Title) == 0).ToList());
|
||||||
|
data.Add(select.Where(a => a.Title.CompareTo(a.Title) > 0).ToList());
|
||||||
|
data.Add(select.Where(a => a.Title.CompareTo(a.Title + 1) == 0).ToList());
|
||||||
|
data.Add(select.Where(a => a.Title.CompareTo(a.Title + a.Type.Name) == 0).ToList());
|
||||||
|
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5
|
||||||
|
//FROM `tb_topic` a
|
||||||
|
//WHERE (strcmp(a.`Title`, a.`Title`) = 0);
|
||||||
|
|
||||||
|
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5
|
||||||
|
//FROM `tb_topic` a
|
||||||
|
//WHERE (strcmp(a.`Title`, a.`Title`) > 0);
|
||||||
|
|
||||||
|
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5
|
||||||
|
//FROM `tb_topic` a
|
||||||
|
//WHERE (strcmp(a.`Title`, concat(a.`Title`, 1)) = 0);
|
||||||
|
|
||||||
|
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a.`Title` as7, a.`CreateTime` as8
|
||||||
|
//FROM `tb_topic` a, `TestTypeInfo` a__Type
|
||||||
|
//WHERE (strcmp(a.`Title`, concat(a.`Title`, a__Type.`Name`)) = 0);
|
||||||
|
data.Add(select.Where(a => (a.Title + "aaa").CompareTo("aaa") == 0).ToList());
|
||||||
|
data.Add(select.Where(a => (a.Title + "aaa").CompareTo(a.Title) > 0).ToList());
|
||||||
|
data.Add(select.Where(a => (a.Title + "aaa").CompareTo(a.Title + 1) == 0).ToList());
|
||||||
|
data.Add(select.Where(a => (a.Title + "aaa").CompareTo(a.Type.Name) == 0).ToList());
|
||||||
|
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5
|
||||||
|
//FROM `tb_topic` a
|
||||||
|
//WHERE (strcmp(concat(a.`Title`, 'aaa'), 'aaa') = 0);
|
||||||
|
|
||||||
|
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5
|
||||||
|
//FROM `tb_topic` a
|
||||||
|
//WHERE (strcmp(concat(a.`Title`, 'aaa'), a.`Title`) > 0);
|
||||||
|
|
||||||
|
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5
|
||||||
|
//FROM `tb_topic` a
|
||||||
|
//WHERE (strcmp(concat(a.`Title`, 'aaa'), concat(a.`Title`, 1)) = 0);
|
||||||
|
|
||||||
|
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a.`Title` as7, a.`CreateTime` as8
|
||||||
|
//FROM `tb_topic` a, `TestTypeInfo` a__Type
|
||||||
|
//WHERE (strcmp(concat(a.`Title`, 'aaa'), a__Type.`Name`) = 0)
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void string_IsNullOrEmpty()
|
||||||
|
{
|
||||||
|
var data = new List<object>();
|
||||||
|
data.Add(select.Where(a => string.IsNullOrEmpty(a.Title)).ToList());
|
||||||
|
data.Add(select.Where(a => !string.IsNullOrEmpty(a.Title)).ToList());
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void string_IsNullOrWhiteSpace()
|
||||||
|
{
|
||||||
|
var data = new List<object>();
|
||||||
|
data.Add(select.Where(a => string.IsNullOrWhiteSpace(a.Title)).ToList());
|
||||||
|
data.Add(select.Where(a => !string.IsNullOrWhiteSpace(a.Title)).ToList());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,293 @@
|
|||||||
|
using FreeSql.DataAnnotations;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using Xunit;
|
||||||
|
|
||||||
|
namespace FreeSql.Tests.GBaseExpression
|
||||||
|
{
|
||||||
|
public class TimeSpanTest
|
||||||
|
{
|
||||||
|
|
||||||
|
ISelect<Topic> select => g.gbase.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,40 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Reflection;
|
||||||
|
using System.Text;
|
||||||
|
using Xunit;
|
||||||
|
|
||||||
|
namespace FreeSql.Tests.GBase
|
||||||
|
{
|
||||||
|
public class GBaseAopTest
|
||||||
|
{
|
||||||
|
|
||||||
|
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.gbase.Aop.AuditValue += audit;
|
||||||
|
|
||||||
|
g.gbase.Insert(item).ExecuteAffrows();
|
||||||
|
|
||||||
|
g.gbase.Aop.AuditValue -= audit;
|
||||||
|
|
||||||
|
Assert.Equal(item.createtime, date);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,346 @@
|
|||||||
|
using FreeSql.DataAnnotations;
|
||||||
|
using Newtonsoft.Json;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using Xunit;
|
||||||
|
|
||||||
|
namespace FreeSql.Tests.GBase
|
||||||
|
{
|
||||||
|
public class GBaseCodeFirstTest
|
||||||
|
{
|
||||||
|
[Fact]
|
||||||
|
public void InsertUpdateParameter()
|
||||||
|
{
|
||||||
|
var fsql = g.gbase;
|
||||||
|
fsql.CodeFirst.SyncStructure<ts_iupstr_bak>();
|
||||||
|
var item = new ts_iupstr { id = Guid.NewGuid(), title = string.Join(",", Enumerable.Range(0, 2000).Select(a => "我是中国人")) };
|
||||||
|
Assert.Equal(1, fsql.Insert(item).ExecuteAffrows());
|
||||||
|
var find = fsql.Select<ts_iupstr>().Where(a => a.id == item.id).First();
|
||||||
|
Assert.NotNull(find);
|
||||||
|
Assert.Equal(find.id, item.id);
|
||||||
|
Assert.Equal(find.title, item.title);
|
||||||
|
}
|
||||||
|
[Table(Name = "ts_iupstr_bak", DisableSyncStructure = true)]
|
||||||
|
class ts_iupstr
|
||||||
|
{
|
||||||
|
public Guid id { get; set; }
|
||||||
|
public string title { get; set; }
|
||||||
|
}
|
||||||
|
class ts_iupstr_bak
|
||||||
|
{
|
||||||
|
public Guid id { get; set; }
|
||||||
|
[Column(StringLength = -1)]
|
||||||
|
public string title { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void Text_StringLength_1()
|
||||||
|
{
|
||||||
|
var str1 = string.Join(",", Enumerable.Range(0, 10000).Select(a => "我是中国人"));
|
||||||
|
var str2 = string.Join(",", Enumerable.Range(0, 10000).Select(a => "我是中国人啊"));
|
||||||
|
|
||||||
|
var item1 = new TS_TEXT02 { Data = str1, Data2 = str2 };
|
||||||
|
Assert.Equal(1, g.gbase.Insert(item1).ExecuteAffrows());
|
||||||
|
|
||||||
|
var item2 = g.gbase.Select<TS_TEXT02>().Where(a => a.Id == item1.Id).First();
|
||||||
|
Assert.Equal(str1, item2.Data);
|
||||||
|
Assert.Equal(str2, item2.Data2);
|
||||||
|
|
||||||
|
//NoneParameter
|
||||||
|
item1 = new TS_TEXT02 { Data = str1, Data2 = str2 };
|
||||||
|
Assert.Equal(1, g.gbase.Insert(item1).NoneParameter().ExecuteAffrows());
|
||||||
|
item2 = g.gbase.Select<TS_TEXT02>().Where(a => a.Id == item1.Id).First();
|
||||||
|
Assert.Equal(str1, item2.Data);
|
||||||
|
Assert.Equal(str2, item2.Data2);
|
||||||
|
//Assert.Throws<Exception>(() => g.firebird.Insert(item1).NoneParameter().ExecuteAffrows());
|
||||||
|
//Dynamic SQL Error
|
||||||
|
//SQL error code = -104
|
||||||
|
//String literal with 159999 bytes exceeds the maximum length of 65535 bytes
|
||||||
|
}
|
||||||
|
class TS_TEXT02
|
||||||
|
{
|
||||||
|
public Guid Id { get; set; }
|
||||||
|
[Column(StringLength = - 1)]
|
||||||
|
public string Data { get; set; }
|
||||||
|
[Column(StringLength = -1)]
|
||||||
|
public string Data2 { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void Blob()
|
||||||
|
{
|
||||||
|
var str1 = string.Join(",", Enumerable.Range(0, 10000).Select(a => "我是中国人"));
|
||||||
|
var data1 = Encoding.UTF8.GetBytes(str1);
|
||||||
|
|
||||||
|
var item1 = new TS_BLB01 { Data = data1 };
|
||||||
|
Assert.Equal(1, g.gbase.Insert(item1).ExecuteAffrows());
|
||||||
|
|
||||||
|
var item2 = g.gbase.Select<TS_BLB01>().Where(a => a.Id == item1.Id).First();
|
||||||
|
Assert.Equal(item1.Data.Length, item2.Data.Length);
|
||||||
|
var str2 = Encoding.UTF8.GetString(item2.Data);
|
||||||
|
Assert.Equal(str1, str2);
|
||||||
|
|
||||||
|
//NoneParameter
|
||||||
|
item1 = new TS_BLB01 { Data = data1 };
|
||||||
|
Assert.Equal(1, g.gbase.Insert(item1).NoneParameter().ExecuteAffrows());
|
||||||
|
item2 = g.gbase.Select<TS_BLB01>().Where(a => a.Id == item1.Id).First();
|
||||||
|
Assert.Equal(item1.Data.Length, item2.Data.Length);
|
||||||
|
str2 = Encoding.UTF8.GetString(item2.Data);
|
||||||
|
Assert.Equal(str1, str2);
|
||||||
|
//Assert.Throws<Exception>(() => g.firebird.Insert(item1).NoneParameter().ExecuteAffrows());
|
||||||
|
//Dynamic SQL Error
|
||||||
|
//SQL error code = -104
|
||||||
|
//String literal with 159999 bytes exceeds the maximum length of 65535 bytes
|
||||||
|
}
|
||||||
|
class TS_BLB01
|
||||||
|
{
|
||||||
|
public Guid Id { get; set; }
|
||||||
|
public byte[] Data { get; set; }
|
||||||
|
}
|
||||||
|
[Fact]
|
||||||
|
public void StringLength()
|
||||||
|
{
|
||||||
|
var dll = g.gbase.CodeFirst.GetComparisonDDLStatements<TS_SLTB>();
|
||||||
|
g.gbase.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.gbase.CodeFirst.GetComparisonDDLStatements<测试中文表>();
|
||||||
|
g.gbase.CodeFirst.SyncStructure<测试中文表>();
|
||||||
|
|
||||||
|
var item = new 测试中文表
|
||||||
|
{
|
||||||
|
标题 = "测试标题",
|
||||||
|
创建时间 = DateTime.Now
|
||||||
|
};
|
||||||
|
Assert.Equal(1, g.gbase.Insert<测试中文表>().AppendData(item).ExecuteAffrows());
|
||||||
|
Assert.NotEqual(Guid.Empty, item.编号);
|
||||||
|
var item2 = g.gbase.Select<测试中文表>().Where(a => a.编号 == item.编号).First();
|
||||||
|
Assert.NotNull(item2);
|
||||||
|
Assert.Equal(item.编号, item2.编号);
|
||||||
|
Assert.Equal(item.标题, item2.标题);
|
||||||
|
|
||||||
|
item.标题 = "测试标题更新";
|
||||||
|
Assert.Equal(1, g.gbase.Update<测试中文表>().SetSource(item).ExecuteAffrows());
|
||||||
|
item2 = g.gbase.Select<测试中文表>().Where(a => a.编号 == item.编号).First();
|
||||||
|
Assert.NotNull(item2);
|
||||||
|
Assert.Equal(item.编号, item2.编号);
|
||||||
|
Assert.Equal(item.标题, item2.标题);
|
||||||
|
|
||||||
|
item.标题 = "测试标题更新_repo";
|
||||||
|
var repo = g.gbase.GetRepository<测试中文表>();
|
||||||
|
Assert.Equal(1, repo.Update(item));
|
||||||
|
item2 = g.gbase.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.gbase.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; }
|
||||||
|
|
||||||
|
[Column(ServerTime = DateTimeKind.Local, CanUpdate = false)]
|
||||||
|
public DateTime 创建时间 { get; set; }
|
||||||
|
|
||||||
|
[Column(ServerTime = DateTimeKind.Local)]
|
||||||
|
public DateTime 更新时间 { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void AddUniques()
|
||||||
|
{
|
||||||
|
var sql = g.gbase.CodeFirst.GetComparisonDDLStatements<AddUniquesInfo>();
|
||||||
|
g.gbase.CodeFirst.SyncStructure<AddUniquesInfo>();
|
||||||
|
}
|
||||||
|
[Table(Name = "AddUniquesInfo", OldName = "AddUniquesInfo2")]
|
||||||
|
[Index("uk_phone", "phone", true)]
|
||||||
|
[Index("uk_group_index", "group,index", true)]
|
||||||
|
[Index("uk_group_index2", "group,index", false)]
|
||||||
|
class AddUniquesInfo
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// 编号
|
||||||
|
/// </summary>
|
||||||
|
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.gbase.CodeFirst.GetComparisonDDLStatements<TopicAddField>();
|
||||||
|
|
||||||
|
var id = g.gbase.Insert<TopicAddField>().AppendData(new TopicAddField { }).ExecuteIdentity();
|
||||||
|
|
||||||
|
//var inserted = g.firebird.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 = "varchar(200) 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.gbase.CodeFirst.GetComparisonDDLStatements<TableAllType>();
|
||||||
|
}
|
||||||
|
|
||||||
|
IInsert<TableAllType> insert => g.gbase.Insert<TableAllType>();
|
||||||
|
ISelect<TableAllType> select => g.gbase.Select<TableAllType>();
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void CurdAllField()
|
||||||
|
{
|
||||||
|
var item = new TableAllType { };
|
||||||
|
insert.AppendData(item).ExecuteAffrows();
|
||||||
|
|
||||||
|
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 + 1,
|
||||||
|
SByte = 100,
|
||||||
|
SByteNullable = 99,
|
||||||
|
Short = short.MaxValue,
|
||||||
|
ShortNullable = short.MinValue + 1,
|
||||||
|
String = "我是中国人string'\\?!@#$%^&*()_+{}}{~?><<>",
|
||||||
|
TimeSpan = TimeSpan.FromSeconds(999),
|
||||||
|
TimeSpanNullable = TimeSpan.FromSeconds(60),
|
||||||
|
UInt = uint.MaxValue,
|
||||||
|
UIntNullable = uint.MinValue + 1,
|
||||||
|
ULong = long.MaxValue,
|
||||||
|
ULongNullable = ulong.MinValue + 1,
|
||||||
|
UShort = ushort.MaxValue,
|
||||||
|
UShortNullable = ushort.MinValue + 1,
|
||||||
|
testFielLongNullable = long.MinValue + 1
|
||||||
|
};
|
||||||
|
var sqlPar = insert.AppendData(item2).ToSql();
|
||||||
|
var sqlText = insert.AppendData(item2).NoneParameter().ToSql();
|
||||||
|
|
||||||
|
insert.AppendData(item2).ExecuteAffrows();
|
||||||
|
var newitem2 = select.Where(a => a.Id == item2.Id).ToOne();
|
||||||
|
Assert.Equal(item2.String, newitem2.String);
|
||||||
|
|
||||||
|
item2.Id = Guid.NewGuid();
|
||||||
|
insert.NoneParameter().AppendData(item2).ExecuteAffrows();
|
||||||
|
newitem2 = select.Where(a => a.Id == item2.Id).ToOne();
|
||||||
|
Assert.Equal(item2.String, newitem2.String);
|
||||||
|
|
||||||
|
var items = select.ToList();
|
||||||
|
}
|
||||||
|
|
||||||
|
[Table(Name = "tb_alltype")]
|
||||||
|
class TableAllType
|
||||||
|
{
|
||||||
|
[Column(IsPrimary = true)]
|
||||||
|
public Guid 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; }
|
||||||
|
|
||||||
|
[Column(ServerTime = DateTimeKind.Local)]
|
||||||
|
public DateTime DateTime { 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; }
|
||||||
|
|
||||||
|
[Column(ServerTime = DateTimeKind.Local)]
|
||||||
|
public DateTime? DateTimeNullable { 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,50 @@
|
|||||||
|
using FreeSql.DataAnnotations;
|
||||||
|
using System;
|
||||||
|
using Xunit;
|
||||||
|
|
||||||
|
namespace FreeSql.Tests.GBase
|
||||||
|
{
|
||||||
|
public class GBaseDbFirstTest
|
||||||
|
{
|
||||||
|
[Fact]
|
||||||
|
public void GetDatabases()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void GetTablesByDatabase()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void GetTableByName()
|
||||||
|
{
|
||||||
|
var fsql = g.gbase;
|
||||||
|
var t1 = fsql.DbFirst.GetTableByName("tb_alltype");
|
||||||
|
Assert.NotNull(t1);
|
||||||
|
var t3 = fsql.DbFirst.GetTableByName("notexists_tb");
|
||||||
|
Assert.Null(t3);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void ExistsTable()
|
||||||
|
{
|
||||||
|
var fsql = g.gbase;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
fsql.Ado.ExecuteNonQuery("drop table test_existstb011");
|
||||||
|
}
|
||||||
|
catch { }
|
||||||
|
Assert.False(fsql.DbFirst.ExistsTable("test_existstb011"));
|
||||||
|
Assert.False(fsql.DbFirst.ExistsTable("test_existstb011", false));
|
||||||
|
fsql.CodeFirst.SyncStructure(typeof(test_existstb011));
|
||||||
|
Assert.True(fsql.DbFirst.ExistsTable("test_existstb011"));
|
||||||
|
Assert.False(fsql.DbFirst.ExistsTable("Test_existstb011", false));
|
||||||
|
fsql.Ado.ExecuteNonQuery("drop table test_existstb011");
|
||||||
|
}
|
||||||
|
class test_existstb011
|
||||||
|
{
|
||||||
|
public Guid id { get; set; }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
File diff suppressed because it is too large
Load Diff
1105
FreeSql.Tests/FreeSql.Tests.Provider.GBase/GBase/MapType/BoolTest.cs
Normal file
1105
FreeSql.Tests/FreeSql.Tests.Provider.GBase/GBase/MapType/BoolTest.cs
Normal file
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,54 @@
|
|||||||
|
using FreeSql.DataAnnotations;
|
||||||
|
using System;
|
||||||
|
using System.Numerics;
|
||||||
|
using Xunit;
|
||||||
|
|
||||||
|
namespace FreeSql.Tests.GBaseMapType
|
||||||
|
{
|
||||||
|
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.gbase;
|
||||||
|
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.GBaseMapType
|
||||||
|
{
|
||||||
|
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.gbase;
|
||||||
|
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.gbase;
|
||||||
|
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.gbase;
|
||||||
|
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.gbase;
|
||||||
|
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.GBaseMapType
|
||||||
|
{
|
||||||
|
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.gbase;
|
||||||
|
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.gbase;
|
||||||
|
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.gbase;
|
||||||
|
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.gbase;
|
||||||
|
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.gbase;
|
||||||
|
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.gbase;
|
||||||
|
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.gbase;
|
||||||
|
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.gbase;
|
||||||
|
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.gbase;
|
||||||
|
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.gbase;
|
||||||
|
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());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
38
FreeSql.Tests/FreeSql.Tests.Provider.GBase/g.cs
Normal file
38
FreeSql.Tests/FreeSql.Tests.Provider.GBase/g.cs
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Data.Odbc;
|
||||||
|
using System.Diagnostics;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading;
|
||||||
|
|
||||||
|
public class g
|
||||||
|
{
|
||||||
|
|
||||||
|
|
||||||
|
static Lazy<IFreeSql> gbaseLazy = new Lazy<IFreeSql>(() =>
|
||||||
|
{
|
||||||
|
var build = new OdbcConnectionStringBuilder();
|
||||||
|
build.Driver = "GBase ODBC DRIVER (64-Bit)"; // 在系统中注册的驱动名称
|
||||||
|
build.Add("Host", "192.168.164.134"); // 主机地址或者IP地址
|
||||||
|
build.Add("Service", "9088"); // 数据库服务器的使用的端口号
|
||||||
|
build.Add("Server", "gbase01"); // 数据库服务名称
|
||||||
|
build.Add("Database", "testdb"); // 数据库名(DBNAME)
|
||||||
|
build.Add("Protocol", "onsoctcp"); // 网络协议名称
|
||||||
|
build.Add("Uid", "gbasedbt"); // 用户
|
||||||
|
build.Add("Pwd", "GBase123"); // 密码
|
||||||
|
build.Add("Db_locale", "zh_CN.utf8"); // 数据库字符集
|
||||||
|
build.Add("Client_locale", "zh_CN.utf8"); // 客户端字符集
|
||||||
|
|
||||||
|
return new FreeSql.FreeSqlBuilder()
|
||||||
|
.UseConnectionString(FreeSql.DataType.GBase, build.ConnectionString)
|
||||||
|
.UseAutoSyncStructure(true)
|
||||||
|
.UseLazyLoading(true)
|
||||||
|
|
||||||
|
.UseMonitorCommand(
|
||||||
|
cmd => Trace.WriteLine(cmd.CommandText), //监听SQL命令对象,在执行前
|
||||||
|
(cmd, traceLog) => Console.WriteLine(traceLog))
|
||||||
|
.Build();
|
||||||
|
});
|
||||||
|
public static IFreeSql gbase => gbaseLazy.Value;
|
||||||
|
|
||||||
|
}
|
@ -29,6 +29,31 @@ namespace FreeSql.Tests.MySqlConnector
|
|||||||
}
|
}
|
||||||
enum TestEnumInserTbType { str1, biggit, sum211 }
|
enum TestEnumInserTbType { str1, biggit, sum211 }
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void InsertDictionary()
|
||||||
|
{
|
||||||
|
var fsql = g.mysql;
|
||||||
|
Dictionary<string, object> dic = new Dictionary<string, object>();
|
||||||
|
dic.Add("id", 1);
|
||||||
|
dic.Add("name", "xxxx");
|
||||||
|
var diclist = new List<Dictionary<string, object>>();
|
||||||
|
diclist.Add(dic);
|
||||||
|
diclist.Add(new Dictionary<string, object>
|
||||||
|
{
|
||||||
|
["id"] = 2,
|
||||||
|
["name"] = "yyyy"
|
||||||
|
});
|
||||||
|
|
||||||
|
var sql1 = fsql.InsertDict(dic).AsTable("table1").ToSql();
|
||||||
|
Assert.Equal(@"INSERT INTO `table1`(`id`, `name`) VALUES(@id_0, @name_0)", sql1);
|
||||||
|
var sql2 = fsql.InsertDict(diclist).AsTable("table1").ToSql();
|
||||||
|
Assert.Equal(@"INSERT INTO `table1`(`id`, `name`) VALUES(@id_0, @name_0), (@id_1, @name_1)", sql2);
|
||||||
|
var sql3 = fsql.InsertDict(dic).AsTable("table1").NoneParameter().ToSql();
|
||||||
|
Assert.Equal(@"INSERT INTO `table1`(`id`, `name`) VALUES(1, 'xxxx')", sql3);
|
||||||
|
var sql4 = fsql.InsertDict(diclist).AsTable("table1").NoneParameter().ToSql();
|
||||||
|
Assert.Equal(@"INSERT INTO `table1`(`id`, `name`) VALUES(1, 'xxxx'), (2, 'yyyy')", sql4);
|
||||||
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void AppendData()
|
public void AppendData()
|
||||||
{
|
{
|
||||||
|
@ -0,0 +1,8 @@
|
|||||||
|
{
|
||||||
|
"profiles": {
|
||||||
|
"WSL": {
|
||||||
|
"commandName": "WSL2",
|
||||||
|
"distributionName": ""
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,31 @@
|
|||||||
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
|
<PropertyGroup>
|
||||||
|
<TargetFramework>net6.0</TargetFramework>
|
||||||
|
<Nullable>enable</Nullable>
|
||||||
|
|
||||||
|
<IsPackable>false</IsPackable>
|
||||||
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.11.0" />
|
||||||
|
<PackageReference Include="SQLitePCLRaw.bundle_e_sqlite3" Version="2.0.7" />
|
||||||
|
<PackageReference Include="xunit" Version="2.4.1" />
|
||||||
|
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.3">
|
||||||
|
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||||
|
<PrivateAssets>all</PrivateAssets>
|
||||||
|
</PackageReference>
|
||||||
|
<PackageReference Include="coverlet.collector" Version="3.1.0">
|
||||||
|
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||||
|
<PrivateAssets>all</PrivateAssets>
|
||||||
|
</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.SqliteCore\FreeSql.Provider.SqliteCore.csproj" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
</Project>
|
@ -0,0 +1,106 @@
|
|||||||
|
using FreeSql.DataAnnotations;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using Xunit;
|
||||||
|
|
||||||
|
namespace FreeSql.Tests.Sqlite
|
||||||
|
{
|
||||||
|
public class SqliteDeleteTest
|
||||||
|
{
|
||||||
|
|
||||||
|
IDelete<Topic> delete => g.sqlite.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.sqlite.Delete<Topic>().ToSql());
|
||||||
|
var sql = g.sqlite.Delete<Topic>(new[] { 1, 2 }).ToSql();
|
||||||
|
Assert.Equal("DELETE FROM \"tb_topic22211\" WHERE (\"Id\" IN (1,2))", sql);
|
||||||
|
|
||||||
|
sql = g.sqlite.Delete<Topic>(new Topic { Id = 1, Title = "test" }).ToSql();
|
||||||
|
Assert.Equal("DELETE FROM \"tb_topic22211\" WHERE (\"Id\" = 1)", sql);
|
||||||
|
|
||||||
|
sql = g.sqlite.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.sqlite.Delete<Topic>(new { id = 1 }).ToSql();
|
||||||
|
Assert.Equal("DELETE FROM \"tb_topic22211\" WHERE (\"Id\" = 1)", sql);
|
||||||
|
|
||||||
|
sql = g.sqlite.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.sqlite.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.Sqlite.Delete<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.sqlite.Delete<Topic>().AsTable(a => "TopicAsTable").ToSql());
|
||||||
|
var sql = g.sqlite.Delete<Topic>(new[] { 1, 2 }).AsTable(a => "TopicAsTable").ToSql();
|
||||||
|
Assert.Equal("DELETE FROM \"TopicAsTable\" WHERE (\"Id\" IN (1,2))", sql);
|
||||||
|
|
||||||
|
sql = g.sqlite.Delete<Topic>(new Topic { Id = 1, Title = "test" }).AsTable(a => "TopicAsTable").ToSql();
|
||||||
|
Assert.Equal("DELETE FROM \"TopicAsTable\" WHERE (\"Id\" = 1)", sql);
|
||||||
|
|
||||||
|
sql = g.sqlite.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.sqlite.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.Sqlite
|
||||||
|
{
|
||||||
|
public class SqliteInsertOrUpdateIfExistsDoNothingTest
|
||||||
|
{
|
||||||
|
|
||||||
|
IFreeSql fsql => g.sqlite;
|
||||||
|
|
||||||
|
[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'
|
||||||
|
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'
|
||||||
|
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'
|
||||||
|
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'
|
||||||
|
WHERE NOT EXISTS(SELECT 1
|
||||||
|
FROM ""tbioudb02"" a
|
||||||
|
WHERE (a.""id"" = 1)
|
||||||
|
limit 0,1)
|
||||||
|
UNION ALL
|
||||||
|
SELECT 2, '02'
|
||||||
|
WHERE NOT EXISTS(SELECT 1
|
||||||
|
FROM ""tbioudb02"" a
|
||||||
|
WHERE (a.""id"" = 2)
|
||||||
|
limit 0,1)
|
||||||
|
UNION ALL
|
||||||
|
SELECT 3, '03'
|
||||||
|
WHERE NOT EXISTS(SELECT 1
|
||||||
|
FROM ""tbioudb02"" a
|
||||||
|
WHERE (a.""id"" = 3)
|
||||||
|
limit 0,1)
|
||||||
|
UNION ALL
|
||||||
|
SELECT 4, '04'
|
||||||
|
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'
|
||||||
|
WHERE NOT EXISTS(SELECT 1
|
||||||
|
FROM ""tbioudb02"" a
|
||||||
|
WHERE (a.""id"" = 1)
|
||||||
|
limit 0,1)
|
||||||
|
UNION ALL
|
||||||
|
SELECT 2, '002'
|
||||||
|
WHERE NOT EXISTS(SELECT 1
|
||||||
|
FROM ""tbioudb02"" a
|
||||||
|
WHERE (a.""id"" = 2)
|
||||||
|
limit 0,1)
|
||||||
|
UNION ALL
|
||||||
|
SELECT 3, '003'
|
||||||
|
WHERE NOT EXISTS(SELECT 1
|
||||||
|
FROM ""tbioudb02"" a
|
||||||
|
WHERE (a.""id"" = 3)
|
||||||
|
limit 0,1)
|
||||||
|
UNION ALL
|
||||||
|
SELECT 4, '004'
|
||||||
|
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'
|
||||||
|
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'
|
||||||
|
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'
|
||||||
|
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'
|
||||||
|
WHERE NOT EXISTS(SELECT 1
|
||||||
|
FROM ""tbioudb022"" a
|
||||||
|
WHERE (a.""id"" = 1)
|
||||||
|
limit 0,1)
|
||||||
|
UNION ALL
|
||||||
|
SELECT 2, '02'
|
||||||
|
WHERE NOT EXISTS(SELECT 1
|
||||||
|
FROM ""tbioudb022"" a
|
||||||
|
WHERE (a.""id"" = 2)
|
||||||
|
limit 0,1)
|
||||||
|
UNION ALL
|
||||||
|
SELECT 3, '03'
|
||||||
|
WHERE NOT EXISTS(SELECT 1
|
||||||
|
FROM ""tbioudb022"" a
|
||||||
|
WHERE (a.""id"" = 3)
|
||||||
|
limit 0,1)
|
||||||
|
UNION ALL
|
||||||
|
SELECT 4, '04'
|
||||||
|
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'
|
||||||
|
WHERE NOT EXISTS(SELECT 1
|
||||||
|
FROM ""tbioudb022"" a
|
||||||
|
WHERE (a.""id"" = 1)
|
||||||
|
limit 0,1)
|
||||||
|
UNION ALL
|
||||||
|
SELECT 2, '002'
|
||||||
|
WHERE NOT EXISTS(SELECT 1
|
||||||
|
FROM ""tbioudb022"" a
|
||||||
|
WHERE (a.""id"" = 2)
|
||||||
|
limit 0,1)
|
||||||
|
UNION ALL
|
||||||
|
SELECT 3, '003'
|
||||||
|
WHERE NOT EXISTS(SELECT 1
|
||||||
|
FROM ""tbioudb022"" a
|
||||||
|
WHERE (a.""id"" = 3)
|
||||||
|
limit 0,1)
|
||||||
|
UNION ALL
|
||||||
|
SELECT 4, '004'
|
||||||
|
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'
|
||||||
|
WHERE NOT EXISTS(SELECT 1
|
||||||
|
FROM ""tbioudb022"" a
|
||||||
|
WHERE (a.""id"" = 1)
|
||||||
|
limit 0,1)
|
||||||
|
UNION ALL
|
||||||
|
SELECT 2, '100002'
|
||||||
|
WHERE NOT EXISTS(SELECT 1
|
||||||
|
FROM ""tbioudb022"" a
|
||||||
|
WHERE (a.""id"" = 2)
|
||||||
|
limit 0,1)
|
||||||
|
UNION ALL
|
||||||
|
SELECT 3, '100003'
|
||||||
|
WHERE NOT EXISTS(SELECT 1
|
||||||
|
FROM ""tbioudb022"" a
|
||||||
|
WHERE (a.""id"" = 3)
|
||||||
|
limit 0,1)
|
||||||
|
UNION ALL
|
||||||
|
SELECT 4, '100004'
|
||||||
|
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'
|
||||||
|
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'
|
||||||
|
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'
|
||||||
|
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'
|
||||||
|
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'
|
||||||
|
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'
|
||||||
|
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'
|
||||||
|
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'
|
||||||
|
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'
|
||||||
|
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'
|
||||||
|
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'
|
||||||
|
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, datetime(current_timestamp,'localtime')
|
||||||
|
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, datetime(current_timestamp,'localtime')
|
||||||
|
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, datetime(current_timestamp,'localtime')
|
||||||
|
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, datetime(current_timestamp,'localtime')
|
||||||
|
WHERE NOT EXISTS(SELECT 1
|
||||||
|
FROM ""tbioudb04"" a
|
||||||
|
WHERE (a.""id"" = 1)
|
||||||
|
limit 0,1)
|
||||||
|
UNION ALL
|
||||||
|
SELECT 2, '02', 0, datetime(current_timestamp,'localtime')
|
||||||
|
WHERE NOT EXISTS(SELECT 1
|
||||||
|
FROM ""tbioudb04"" a
|
||||||
|
WHERE (a.""id"" = 2)
|
||||||
|
limit 0,1)
|
||||||
|
UNION ALL
|
||||||
|
SELECT 3, '03', 0, datetime(current_timestamp,'localtime')
|
||||||
|
WHERE NOT EXISTS(SELECT 1
|
||||||
|
FROM ""tbioudb04"" a
|
||||||
|
WHERE (a.""id"" = 3)
|
||||||
|
limit 0,1)
|
||||||
|
UNION ALL
|
||||||
|
SELECT 4, '04', 0, datetime(current_timestamp,'localtime')
|
||||||
|
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, datetime(current_timestamp,'localtime')
|
||||||
|
WHERE NOT EXISTS(SELECT 1
|
||||||
|
FROM ""tbioudb04"" a
|
||||||
|
WHERE (a.""id"" = 1)
|
||||||
|
limit 0,1)
|
||||||
|
UNION ALL
|
||||||
|
SELECT 2, '002', 0, datetime(current_timestamp,'localtime')
|
||||||
|
WHERE NOT EXISTS(SELECT 1
|
||||||
|
FROM ""tbioudb04"" a
|
||||||
|
WHERE (a.""id"" = 2)
|
||||||
|
limit 0,1)
|
||||||
|
UNION ALL
|
||||||
|
SELECT 3, '003', 0, datetime(current_timestamp,'localtime')
|
||||||
|
WHERE NOT EXISTS(SELECT 1
|
||||||
|
FROM ""tbioudb04"" a
|
||||||
|
WHERE (a.""id"" = 3)
|
||||||
|
limit 0,1)
|
||||||
|
UNION ALL
|
||||||
|
SELECT 4, '004', 0, datetime(current_timestamp,'localtime')
|
||||||
|
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,241 @@
|
|||||||
|
using FreeSql.DataAnnotations;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using Xunit;
|
||||||
|
|
||||||
|
namespace FreeSql.Tests.Sqlite
|
||||||
|
{
|
||||||
|
public class SqliteInsertOrUpdateTest
|
||||||
|
{
|
||||||
|
IFreeSql fsql => g.sqlite;
|
||||||
|
|
||||||
|
[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(@"REPLACE INTO ""tbiou01""(""id"") VALUES(1)", sql);
|
||||||
|
Assert.Equal(1, iou.ExecuteAffrows());
|
||||||
|
|
||||||
|
iou = fsql.InsertOrUpdate<tbiou01>().SetSource(new tbiou01 { id = 1 });
|
||||||
|
sql = iou.ToSql();
|
||||||
|
Assert.Equal(@"REPLACE INTO ""tbiou01""(""id"") VALUES(1)", sql);
|
||||||
|
Assert.Equal(1, iou.ExecuteAffrows());
|
||||||
|
|
||||||
|
iou = fsql.InsertOrUpdate<tbiou01>().SetSource(new tbiou01 { id = 2 });
|
||||||
|
sql = iou.ToSql();
|
||||||
|
Assert.Equal(@"REPLACE INTO ""tbiou01""(""id"") VALUES(2)", 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(@"REPLACE INTO ""tbiou01""(""id"") VALUES(1), (2), (3), (4)", sql);
|
||||||
|
Assert.Equal(4, 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(@"REPLACE INTO ""tbiou01""(""id"") VALUES(1), (2), (3), (4)", sql);
|
||||||
|
Assert.Equal(4, 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(@"REPLACE INTO ""tbiou02""(""id"", ""name"") VALUES(1, '01')", sql);
|
||||||
|
Assert.Equal(1, iou.ExecuteAffrows());
|
||||||
|
|
||||||
|
iou = fsql.InsertOrUpdate<tbiou02>().SetSource(new tbiou02 { id = 1, name = "011" });
|
||||||
|
sql = iou.ToSql();
|
||||||
|
Assert.Equal(@"REPLACE INTO ""tbiou02""(""id"", ""name"") VALUES(1, '011')", sql);
|
||||||
|
Assert.Equal(1, iou.ExecuteAffrows());
|
||||||
|
|
||||||
|
iou = fsql.InsertOrUpdate<tbiou02>().SetSource(new tbiou02 { id = 2, name = "02" });
|
||||||
|
sql = iou.ToSql();
|
||||||
|
Assert.Equal(@"REPLACE INTO ""tbiou02""(""id"", ""name"") VALUES(2, '02')", 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(@"REPLACE INTO ""tbiou02""(""id"", ""name"") VALUES(1, '01'), (2, '02'), (3, '03'), (4, '04')", 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(@"REPLACE INTO ""tbiou02""(""id"", ""name"") VALUES(1, '001'), (2, '002'), (3, '003'), (4, '004')", 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(@"REPLACE INTO ""tbiou022""(""id"", ""name"") VALUES(1, '01')", sql);
|
||||||
|
Assert.Equal(1, iou.ExecuteAffrows());
|
||||||
|
|
||||||
|
iou = fsql.InsertOrUpdate<tbiou022>().SetSource(new tbiou022 { id = 1, name = "011" });
|
||||||
|
sql = iou.ToSql();
|
||||||
|
Assert.Equal(@"REPLACE INTO ""tbiou022""(""id"", ""name"") VALUES(1, '011')", sql);
|
||||||
|
Assert.Equal(1, iou.ExecuteAffrows());
|
||||||
|
|
||||||
|
iou = fsql.InsertOrUpdate<tbiou022>().SetSource(new tbiou022 { id = 2, name = "02" });
|
||||||
|
sql = iou.ToSql();
|
||||||
|
Assert.Equal(@"REPLACE INTO ""tbiou022""(""id"", ""name"") VALUES(2, '02')", 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(@"REPLACE INTO ""tbiou022""(""id"", ""name"") VALUES(1, '01'), (2, '02'), (3, '03'), (4, '04')", 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(@"REPLACE INTO ""tbiou022""(""id"", ""name"") VALUES(1, '001'), (2, '002'), (3, '003'), (4, '004')", 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(@"REPLACE INTO ""tbiou022""(""id"", ""name"") VALUES(1, '100001'), (2, '100002'), (3, '100003'), (4, '100004')
|
||||||
|
|
||||||
|
;
|
||||||
|
|
||||||
|
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(@"REPLACE INTO ""tbiou03""(""id1"", ""id2"", ""name"") VALUES(1, '01', '01')", sql);
|
||||||
|
Assert.Equal(1, iou.ExecuteAffrows());
|
||||||
|
|
||||||
|
iou = fsql.InsertOrUpdate<tbiou03>().SetSource(new tbiou03 { id1 = 1, id2 = "01", name = "011" });
|
||||||
|
sql = iou.ToSql();
|
||||||
|
Assert.Equal(@"REPLACE INTO ""tbiou03""(""id1"", ""id2"", ""name"") VALUES(1, '01', '011')", sql);
|
||||||
|
Assert.Equal(1, iou.ExecuteAffrows());
|
||||||
|
|
||||||
|
iou = fsql.InsertOrUpdate<tbiou03>().SetSource(new tbiou03 { id1 = 2, id2 = "02", name = "02" });
|
||||||
|
sql = iou.ToSql();
|
||||||
|
Assert.Equal(@"REPLACE INTO ""tbiou03""(""id1"", ""id2"", ""name"") VALUES(2, '02', '02')", 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(@"REPLACE INTO ""tbiou03""(""id1"", ""id2"", ""name"") VALUES(1, '01', '01'), (2, '02', '02'), (3, '03', '03'), (4, '04', '04')", 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(@"REPLACE INTO ""tbiou03""(""id1"", ""id2"", ""name"") VALUES(1, '01', '001'), (2, '02', '002'), (3, '03', '003'), (4, '04', '004')", 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(@"REPLACE INTO ""tbiou04""(""id"", ""name"", ""version"", ""CreateTime"") VALUES(1, '01', 0, datetime(current_timestamp,'localtime'))", sql);
|
||||||
|
Assert.Equal(1, iou.ExecuteAffrows());
|
||||||
|
|
||||||
|
iou = fsql.InsertOrUpdate<tbiou04>().SetSource(new tbiou04 { id = 1, name = "011" });
|
||||||
|
sql = iou.ToSql();
|
||||||
|
Assert.Equal(@"REPLACE INTO ""tbiou04""(""id"", ""name"", ""version"", ""CreateTime"") VALUES(1, '011', 0, datetime(current_timestamp,'localtime'))", sql);
|
||||||
|
Assert.Equal(1, iou.ExecuteAffrows());
|
||||||
|
|
||||||
|
iou = fsql.InsertOrUpdate<tbiou04>().SetSource(new tbiou04 { id = 2, name = "02" });
|
||||||
|
sql = iou.ToSql();
|
||||||
|
Assert.Equal(@"REPLACE INTO ""tbiou04""(""id"", ""name"", ""version"", ""CreateTime"") VALUES(2, '02', 0, datetime(current_timestamp,'localtime'))", 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(@"REPLACE INTO ""tbiou04""(""id"", ""name"", ""version"", ""CreateTime"") VALUES(1, '01', 0, datetime(current_timestamp,'localtime')), (2, '02', 0, datetime(current_timestamp,'localtime')), (3, '03', 0, datetime(current_timestamp,'localtime')), (4, '04', 0, datetime(current_timestamp,'localtime'))", 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(@"REPLACE INTO ""tbiou04""(""id"", ""name"", ""version"", ""CreateTime"") VALUES(1, '001', 0, datetime(current_timestamp,'localtime')), (2, '002', 0, datetime(current_timestamp,'localtime')), (3, '003', 0, datetime(current_timestamp,'localtime')), (4, '004', 0, datetime(current_timestamp,'localtime'))", 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,142 @@
|
|||||||
|
using FreeSql.DataAnnotations;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using Xunit;
|
||||||
|
|
||||||
|
namespace FreeSql.Tests.Sqlite
|
||||||
|
{
|
||||||
|
public class SqliteInsertTest
|
||||||
|
{
|
||||||
|
|
||||||
|
IInsert<Topic> insert => g.sqlite.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(@Clicks_0, @Title_0, @CreateTime_0)", sql);
|
||||||
|
|
||||||
|
sql = insert.AppendData(items).ToSql();
|
||||||
|
Assert.Equal("INSERT INTO \"tb_topic_insert\"(\"Clicks\", \"Title\", \"CreateTime\") VALUES(@Clicks_0, @Title_0, @CreateTime_0), (@Clicks_1, @Title_1, @CreateTime_1), (@Clicks_2, @Title_2, @CreateTime_2), (@Clicks_3, @Title_3, @CreateTime_3), (@Clicks_4, @Title_4, @CreateTime_4), (@Clicks_5, @Title_5, @CreateTime_5), (@Clicks_6, @Title_6, @CreateTime_6), (@Clicks_7, @Title_7, @CreateTime_7), (@Clicks_8, @Title_8, @CreateTime_8), (@Clicks_9, @Title_9, @CreateTime_9)", sql);
|
||||||
|
|
||||||
|
sql = insert.AppendData(items).InsertColumns(a => a.Title).ToSql();
|
||||||
|
Assert.Equal("INSERT INTO \"tb_topic_insert\"(\"Title\") VALUES(@Title_0), (@Title_1), (@Title_2), (@Title_3), (@Title_4), (@Title_5), (@Title_6), (@Title_7), (@Title_8), (@Title_9)", sql);
|
||||||
|
|
||||||
|
sql = insert.AppendData(items).IgnoreColumns(a => a.CreateTime).ToSql();
|
||||||
|
Assert.Equal("INSERT INTO \"tb_topic_insert\"(\"Clicks\", \"Title\") VALUES(@Clicks_0, @Title_0), (@Clicks_1, @Title_1), (@Clicks_2, @Title_2), (@Clicks_3, @Title_3), (@Clicks_4, @Title_4), (@Clicks_5, @Title_5), (@Clicks_6, @Title_6), (@Clicks_7, @Title_7), (@Clicks_8, @Title_8), (@Clicks_9, @Title_9)", 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(@Title_0), (@Title_1), (@Title_2), (@Title_3), (@Title_4), (@Title_5), (@Title_6), (@Title_7), (@Title_8), (@Title_9)", sql);
|
||||||
|
|
||||||
|
sql = insert.AppendData(items).InsertColumns(a => new { a.Title, a.Clicks }).ToSql();
|
||||||
|
Assert.Equal("INSERT INTO \"tb_topic_insert\"(\"Clicks\", \"Title\") VALUES(@Clicks_0, @Title_0), (@Clicks_1, @Title_1), (@Clicks_2, @Title_2), (@Clicks_3, @Title_3), (@Clicks_4, @Title_4), (@Clicks_5, @Title_5), (@Clicks_6, @Title_6), (@Clicks_7, @Title_7), (@Clicks_8, @Title_8), (@Clicks_9, @Title_9)", 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(@Clicks_0, @Title_0), (@Clicks_1, @Title_1), (@Clicks_2, @Title_2), (@Clicks_3, @Title_3), (@Clicks_4, @Title_4), (@Clicks_5, @Title_5), (@Clicks_6, @Title_6), (@Clicks_7, @Title_7), (@Clicks_8, @Title_8), (@Clicks_9, @Title_9)", sql);
|
||||||
|
|
||||||
|
sql = insert.AppendData(items).IgnoreColumns(a => new { a.Title, a.CreateTime }).ToSql();
|
||||||
|
Assert.Equal("INSERT INTO \"tb_topic_insert\"(\"Clicks\") VALUES(@Clicks_0), (@Clicks_1), (@Clicks_2), (@Clicks_3), (@Clicks_4), (@Clicks_5), (@Clicks_6), (@Clicks_7), (@Clicks_8), (@Clicks_9)", sql);
|
||||||
|
|
||||||
|
g.sqlite.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.sqlite.Insert<TopicIgnore>().AppendData(itemsIgnore).IgnoreColumns(a => new { a.Title }).ExecuteAffrows();
|
||||||
|
Assert.Equal(2072, itemsIgnore.Count);
|
||||||
|
Assert.Equal(2072, g.sqlite.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());
|
||||||
|
|
||||||
|
Assert.Equal(10, g.sqlite.Select<Topic>().Limit(10).InsertInto(null, a => new Topic
|
||||||
|
{
|
||||||
|
Title = a.Title
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
[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()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
[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(@Clicks_0, @Title_0, @CreateTime_0)", sql);
|
||||||
|
|
||||||
|
sql = insert.AppendData(items).AsTable(a => "Topic_InsertAsTable").ToSql();
|
||||||
|
Assert.Equal("INSERT INTO \"Topic_InsertAsTable\"(\"Clicks\", \"Title\", \"CreateTime\") VALUES(@Clicks_0, @Title_0, @CreateTime_0), (@Clicks_1, @Title_1, @CreateTime_1), (@Clicks_2, @Title_2, @CreateTime_2), (@Clicks_3, @Title_3, @CreateTime_3), (@Clicks_4, @Title_4, @CreateTime_4), (@Clicks_5, @Title_5, @CreateTime_5), (@Clicks_6, @Title_6, @CreateTime_6), (@Clicks_7, @Title_7, @CreateTime_7), (@Clicks_8, @Title_8, @CreateTime_8), (@Clicks_9, @Title_9, @CreateTime_9)", sql);
|
||||||
|
|
||||||
|
sql = insert.AppendData(items).InsertColumns(a => a.Title).AsTable(a => "Topic_InsertAsTable").ToSql();
|
||||||
|
Assert.Equal("INSERT INTO \"Topic_InsertAsTable\"(\"Title\") VALUES(@Title_0), (@Title_1), (@Title_2), (@Title_3), (@Title_4), (@Title_5), (@Title_6), (@Title_7), (@Title_8), (@Title_9)", sql);
|
||||||
|
|
||||||
|
sql = insert.AppendData(items).IgnoreColumns(a => a.CreateTime).AsTable(a => "Topic_InsertAsTable").ToSql();
|
||||||
|
Assert.Equal("INSERT INTO \"Topic_InsertAsTable\"(\"Clicks\", \"Title\") VALUES(@Clicks_0, @Title_0), (@Clicks_1, @Title_1), (@Clicks_2, @Title_2), (@Clicks_3, @Title_3), (@Clicks_4, @Title_4), (@Clicks_5, @Title_5), (@Clicks_6, @Title_6), (@Clicks_7, @Title_7), (@Clicks_8, @Title_8), (@Clicks_9, @Title_9)", sql);
|
||||||
|
|
||||||
|
sql = insert.AppendData(items).InsertColumns(a => a.Title).AsTable(a => "Topic_InsertAsTable").ToSql();
|
||||||
|
Assert.Equal("INSERT INTO \"Topic_InsertAsTable\"(\"Title\") VALUES(@Title_0), (@Title_1), (@Title_2), (@Title_3), (@Title_4), (@Title_5), (@Title_6), (@Title_7), (@Title_8), (@Title_9)", 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(@Clicks_0, @Title_0), (@Clicks_1, @Title_1), (@Clicks_2, @Title_2), (@Clicks_3, @Title_3), (@Clicks_4, @Title_4), (@Clicks_5, @Title_5), (@Clicks_6, @Title_6), (@Clicks_7, @Title_7), (@Clicks_8, @Title_8), (@Clicks_9, @Title_9)", sql);
|
||||||
|
|
||||||
|
sql = insert.AppendData(items).IgnoreColumns(a => a.CreateTime).AsTable(a => "Topic_InsertAsTable").ToSql();
|
||||||
|
Assert.Equal("INSERT INTO \"Topic_InsertAsTable\"(\"Clicks\", \"Title\") VALUES(@Clicks_0, @Title_0), (@Clicks_1, @Title_1), (@Clicks_2, @Title_2), (@Clicks_3, @Title_3), (@Clicks_4, @Title_4), (@Clicks_5, @Title_5), (@Clicks_6, @Title_6), (@Clicks_7, @Title_7), (@Clicks_8, @Title_8), (@Clicks_9, @Title_9)", 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(@Clicks_0), (@Clicks_1), (@Clicks_2), (@Clicks_3), (@Clicks_4), (@Clicks_5), (@Clicks_6), (@Clicks_7), (@Clicks_8), (@Clicks_9)", sql);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,243 @@
|
|||||||
|
using FreeSql.DataAnnotations;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using Xunit;
|
||||||
|
|
||||||
|
namespace FreeSql.Tests.Sqlite
|
||||||
|
{
|
||||||
|
public class SqliteUpdateTest
|
||||||
|
{
|
||||||
|
IUpdate<Topic> update => g.sqlite.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; }
|
||||||
|
}
|
||||||
|
[Table(Name = "tb_topic_setsource")]
|
||||||
|
class Topic22
|
||||||
|
{
|
||||||
|
[Column(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.sqlite.Update<Topic>().ToSql());
|
||||||
|
Assert.Equal("UPDATE \"tb_topic\" SET title='test' \r\nWHERE (\"Id\" IN (1,2))", g.sqlite.Update<Topic>(new[] { 1, 2 }).SetRaw("title='test'").ToSql());
|
||||||
|
Assert.Equal("UPDATE \"tb_topic\" SET title='test1' \r\nWHERE (\"Id\" = 1)", g.sqlite.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.sqlite.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.sqlite.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\" = @p_0, \"Title\" = @p_1, \"CreateTime\" = @p_2 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 @p_0 WHEN 2 THEN @p_1 WHEN 3 THEN @p_2 WHEN 4 THEN @p_3 WHEN 5 THEN @p_4 WHEN 6 THEN @p_5 WHEN 7 THEN @p_6 WHEN 8 THEN @p_7 WHEN 9 THEN @p_8 WHEN 10 THEN @p_9 END, \"Title\" = CASE \"Id\" WHEN 1 THEN @p_10 WHEN 2 THEN @p_11 WHEN 3 THEN @p_12 WHEN 4 THEN @p_13 WHEN 5 THEN @p_14 WHEN 6 THEN @p_15 WHEN 7 THEN @p_16 WHEN 8 THEN @p_17 WHEN 9 THEN @p_18 WHEN 10 THEN @p_19 END, \"CreateTime\" = CASE \"Id\" WHEN 1 THEN @p_20 WHEN 2 THEN @p_21 WHEN 3 THEN @p_22 WHEN 4 THEN @p_23 WHEN 5 THEN @p_24 WHEN 6 THEN @p_25 WHEN 7 THEN @p_26 WHEN 8 THEN @p_27 WHEN 9 THEN @p_28 WHEN 10 THEN @p_29 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 @p_0 WHEN 2 THEN @p_1 WHEN 3 THEN @p_2 WHEN 4 THEN @p_3 WHEN 5 THEN @p_4 WHEN 6 THEN @p_5 WHEN 7 THEN @p_6 WHEN 8 THEN @p_7 WHEN 9 THEN @p_8 WHEN 10 THEN @p_9 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\" = @p_0 WHERE (\"Id\" IN (1,2,3,4,5,6,7,8,9,10))", sql);
|
||||||
|
|
||||||
|
sql = g.sqlite.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 SetSourceNoIdentity()
|
||||||
|
{
|
||||||
|
var fsql = g.sqlite;
|
||||||
|
fsql.Delete<Topic22>().Where("1=1").ExecuteAffrows();
|
||||||
|
var sql = fsql.Update<Topic22>().SetSource(new Topic22 { Id = 1, Title = "newtitle" }).IgnoreColumns(a => a.TypeGuid).ToSql().Replace("\r\n", "");
|
||||||
|
Assert.Equal("UPDATE \"tb_topic_setsource\" SET \"Clicks\" = @p_0, \"Title\" = @p_1, \"CreateTime\" = @p_2 WHERE (\"Id\" = 1)", sql);
|
||||||
|
|
||||||
|
var items = new List<Topic22>();
|
||||||
|
for (var a = 0; a < 10; a++) items.Add(new Topic22 { Id = a + 1, Title = $"newtitle{a}", Clicks = a * 100 });
|
||||||
|
Assert.Equal(10, fsql.Insert(items).ExecuteAffrows());
|
||||||
|
items[0].Clicks = null;
|
||||||
|
|
||||||
|
sql = fsql.Update<Topic22>().SetSource(items).IgnoreColumns(a => a.TypeGuid).ToSql().Replace("\r\n", "");
|
||||||
|
Assert.Equal("UPDATE \"tb_topic_setsource\" SET \"Clicks\" = CASE \"Id\" WHEN 1 THEN @p_0 WHEN 2 THEN @p_1 WHEN 3 THEN @p_2 WHEN 4 THEN @p_3 WHEN 5 THEN @p_4 WHEN 6 THEN @p_5 WHEN 7 THEN @p_6 WHEN 8 THEN @p_7 WHEN 9 THEN @p_8 WHEN 10 THEN @p_9 END, \"Title\" = CASE \"Id\" WHEN 1 THEN @p_10 WHEN 2 THEN @p_11 WHEN 3 THEN @p_12 WHEN 4 THEN @p_13 WHEN 5 THEN @p_14 WHEN 6 THEN @p_15 WHEN 7 THEN @p_16 WHEN 8 THEN @p_17 WHEN 9 THEN @p_18 WHEN 10 THEN @p_19 END, \"CreateTime\" = CASE \"Id\" WHEN 1 THEN @p_20 WHEN 2 THEN @p_21 WHEN 3 THEN @p_22 WHEN 4 THEN @p_23 WHEN 5 THEN @p_24 WHEN 6 THEN @p_25 WHEN 7 THEN @p_26 WHEN 8 THEN @p_27 WHEN 9 THEN @p_28 WHEN 10 THEN @p_29 END WHERE (\"Id\" IN (1,2,3,4,5,6,7,8,9,10))", sql);
|
||||||
|
|
||||||
|
sql = fsql.Update<Topic22>().SetSource(items).IgnoreColumns(a => new { a.Clicks, a.CreateTime, a.TypeGuid }).ToSql().Replace("\r\n", "");
|
||||||
|
Assert.Equal("UPDATE \"tb_topic_setsource\" SET \"Title\" = CASE \"Id\" WHEN 1 THEN @p_0 WHEN 2 THEN @p_1 WHEN 3 THEN @p_2 WHEN 4 THEN @p_3 WHEN 5 THEN @p_4 WHEN 6 THEN @p_5 WHEN 7 THEN @p_6 WHEN 8 THEN @p_7 WHEN 9 THEN @p_8 WHEN 10 THEN @p_9 END WHERE (\"Id\" IN (1,2,3,4,5,6,7,8,9,10))", sql);
|
||||||
|
|
||||||
|
sql = fsql.Update<Topic22>().SetSource(items).IgnoreColumns(a => a.TypeGuid).Set(a => a.CreateTime, new DateTime(2020, 1, 1)).ToSql().Replace("\r\n", "");
|
||||||
|
Assert.Equal("UPDATE \"tb_topic_setsource\" SET \"CreateTime\" = @p_0 WHERE (\"Id\" IN (1,2,3,4,5,6,7,8,9,10))", sql);
|
||||||
|
}
|
||||||
|
[Fact]
|
||||||
|
public void SetSourceIgnore()
|
||||||
|
{
|
||||||
|
Assert.Equal("UPDATE \"tssi01\" SET \"tint\" = 10 WHERE (\"id\" = '00000000-0000-0000-0000-000000000000')",
|
||||||
|
g.sqlite.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\" = @p_0 WHERE (\"Id\" = 1)", sql);
|
||||||
|
|
||||||
|
sql = update.SetSource(new Topic { Id = 1, Title = "newtitle" }).IgnoreColumns(a => new object[] { a.Clicks, a.CreateTime, a.TypeGuid }).ToSql().Replace("\r\n", "");
|
||||||
|
Assert.Equal("UPDATE \"tb_topic\" SET \"Title\" = @p_0 WHERE (\"Id\" = 1)", sql);
|
||||||
|
|
||||||
|
sql = update.SetSource(new Topic { Id = 1, Title = "newtitle" }).IgnoreColumns(a => new[] { "Clicks", "CreateTime", "TypeGuid" }).ToSql().Replace("\r\n", "");
|
||||||
|
Assert.Equal("UPDATE \"tb_topic\" SET \"Title\" = @p_0 WHERE (\"Id\" = 1)", sql);
|
||||||
|
|
||||||
|
var cols = new[] { "Clicks", "CreateTime", "TypeGuid" };
|
||||||
|
sql = update.SetSource(new Topic { Id = 1, Title = "newtitle" }).IgnoreColumns(a => cols).ToSql().Replace("\r\n", "");
|
||||||
|
Assert.Equal("UPDATE \"tb_topic\" SET \"Title\" = @p_0 WHERE (\"Id\" = 1)", sql);
|
||||||
|
|
||||||
|
cols = new[] { "Clicks", "CreateTime", "TypeGuid" };
|
||||||
|
sql = update.SetSource(new Topic { Id = 1, Title = "newtitle" }).IgnoreColumns(cols).ToSql().Replace("\r\n", "");
|
||||||
|
Assert.Equal("UPDATE \"tb_topic\" SET \"Title\" = @p_0 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\" = @p_0 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\" = @p_0 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\" = @p_0, \"CreateTime\" = @p_1 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 / 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 / 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.CreateTime.AddYears(1)).Where(a => a.Id == 1).ToSql().Replace("\r\n", "");
|
||||||
|
Assert.Equal("UPDATE \"tb_topic\" SET \"CreateTime\" = datetime(\"CreateTime\",(1)||' years') 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' 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 + :incrClick", new { incrClick = 1 }).ToSql().Replace("\r\n", "");
|
||||||
|
Assert.Equal("UPDATE \"tb_topic\" SET clicks = clicks + :incrClick 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\" = @p_0, \"Title\" = @p_1 WHERE (\"Id\" = 1)", sql);
|
||||||
|
sql = update.NoneParameter().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\" = @p_0, \"Title\" = @p_1 WHERE (\"Id\" = 1)", sql);
|
||||||
|
sql = update.NoneParameter().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 = :id", new { id = 1 }).SetRaw("title='newtitle'").ToSql().Replace("\r\n", "");
|
||||||
|
Assert.Equal("UPDATE \"tb_topic\" SET title='newtitle' WHERE (id = :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.sqlite.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.sqlite.Update<Topic>().ToSql());
|
||||||
|
Assert.Equal("UPDATE \"tb_topicAsTable\" SET title='test' \r\nWHERE (\"Id\" IN (1,2))", g.sqlite.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.sqlite.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.sqlite.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.sqlite.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.SqliteMapType
|
||||||
|
{
|
||||||
|
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.sqlite;
|
||||||
|
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.SqliteMapType
|
||||||
|
{
|
||||||
|
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.sqlite;
|
||||||
|
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.sqlite;
|
||||||
|
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.sqlite;
|
||||||
|
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.sqlite;
|
||||||
|
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.SqliteMapType
|
||||||
|
{
|
||||||
|
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.sqlite;
|
||||||
|
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.sqlite;
|
||||||
|
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.sqlite;
|
||||||
|
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.sqlite;
|
||||||
|
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.sqlite;
|
||||||
|
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.sqlite;
|
||||||
|
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.sqlite;
|
||||||
|
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.sqlite;
|
||||||
|
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.sqlite;
|
||||||
|
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.sqlite;
|
||||||
|
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,90 @@
|
|||||||
|
using FreeSql.DataAnnotations;
|
||||||
|
using System;
|
||||||
|
using Xunit;
|
||||||
|
|
||||||
|
namespace FreeSql.Tests.Sqlite
|
||||||
|
{
|
||||||
|
public class SqliteAdoTest
|
||||||
|
{
|
||||||
|
[Fact]
|
||||||
|
public void Pool()
|
||||||
|
{
|
||||||
|
var t1 = g.sqlite.Ado.MasterPool.StatisticsFullily;
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void SlavePools()
|
||||||
|
{
|
||||||
|
var t2 = g.sqlite.Ado.SlavePools.Count;
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void ExecuteTest()
|
||||||
|
{
|
||||||
|
Assert.True(g.sqlite.Ado.ExecuteConnectTest());
|
||||||
|
}
|
||||||
|
[Fact]
|
||||||
|
public void ExecuteReader()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
[Fact]
|
||||||
|
public void ExecuteArray()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
[Fact]
|
||||||
|
public void ExecuteNonQuery()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
[Fact]
|
||||||
|
public void ExecuteScalar()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void Query()
|
||||||
|
{
|
||||||
|
g.sqlite.CodeFirst.SyncStructure<Song>();
|
||||||
|
var t0 = g.sqlite.Ado.Query<testallDto>("select * from \"song\"");
|
||||||
|
|
||||||
|
var t1 = g.sqlite.Ado.Query<testallDto>("select id, url, create_time from \"song\"");
|
||||||
|
|
||||||
|
var t2 = g.sqlite.Ado.Query<testallDto>("select id, url, create_time test_time from \"song\"");
|
||||||
|
|
||||||
|
var t3 = g.sqlite.Ado.Query<xxx>("select * from \"song\"");
|
||||||
|
|
||||||
|
var t4 = g.sqlite.Ado.Query<(int, string, string)>("select * from \"song\"");
|
||||||
|
|
||||||
|
var t5 = g.sqlite.Ado.Query<dynamic>("select * from \"song\"");
|
||||||
|
|
||||||
|
var t6 = g.sqlite.Ado.Query<xxx>("select * from song where id in @ids", new { ids = new[] { 1, 2, 3 } });
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void QueryMultipline()
|
||||||
|
{
|
||||||
|
g.sqlite.CodeFirst.SyncStructure<Song>();
|
||||||
|
var t3 = g.sqlite.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; }
|
||||||
|
}
|
||||||
|
|
||||||
|
class testallDto
|
||||||
|
{
|
||||||
|
public int Id { get; set; }
|
||||||
|
public string Title { get; set; }
|
||||||
|
public string Url { get; set; }
|
||||||
|
public DateTime Test_time { get; set; }
|
||||||
|
public DateTime Create_time { get; set; }
|
||||||
|
public bool Is_deleted { get; set; }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,40 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Reflection;
|
||||||
|
using System.Text;
|
||||||
|
using Xunit;
|
||||||
|
|
||||||
|
namespace FreeSql.Tests.Sqlite
|
||||||
|
{
|
||||||
|
public class SqliteAopTest
|
||||||
|
{
|
||||||
|
|
||||||
|
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.sqlite.Aop.AuditValue += audit;
|
||||||
|
|
||||||
|
g.sqlite.Insert(item).ExecuteAffrows();
|
||||||
|
|
||||||
|
g.sqlite.Aop.AuditValue -= audit;
|
||||||
|
|
||||||
|
Assert.Equal(item.createtime, date);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,420 @@
|
|||||||
|
using FreeSql.DataAnnotations;
|
||||||
|
using Newtonsoft.Json;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.ComponentModel.DataAnnotations;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using Xunit;
|
||||||
|
|
||||||
|
namespace FreeSql.Tests.Sqlite
|
||||||
|
{
|
||||||
|
public class SqliteCodeFirstTest
|
||||||
|
{
|
||||||
|
[Fact]
|
||||||
|
public void InsertUpdateParameter()
|
||||||
|
{
|
||||||
|
var fsql = g.sqlite;
|
||||||
|
fsql.CodeFirst.SyncStructure<ts_iupstr_bak>();
|
||||||
|
var item = new ts_iupstr { id = Guid.NewGuid(), title = string.Join(",", Enumerable.Range(0, 2000).Select(a => "我是中国人")) };
|
||||||
|
Assert.Equal(1, fsql.Insert(item).ExecuteAffrows());
|
||||||
|
var find = fsql.Select<ts_iupstr>().Where(a => a.id == item.id).First();
|
||||||
|
Assert.NotNull(find);
|
||||||
|
Assert.Equal(find.id, item.id);
|
||||||
|
Assert.Equal(find.title, item.title);
|
||||||
|
}
|
||||||
|
[Table(Name = "ts_iupstr_bak", DisableSyncStructure = true)]
|
||||||
|
class ts_iupstr
|
||||||
|
{
|
||||||
|
public Guid id { get; set; }
|
||||||
|
public string title { get; set; }
|
||||||
|
}
|
||||||
|
class ts_iupstr_bak
|
||||||
|
{
|
||||||
|
public Guid id { get; set; }
|
||||||
|
[Column(StringLength = -1)]
|
||||||
|
public string title { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void Blob()
|
||||||
|
{
|
||||||
|
var str1 = string.Join(",", Enumerable.Range(0, 10000).Select(a => "我是中国人"));
|
||||||
|
var data1 = Encoding.UTF8.GetBytes(str1);
|
||||||
|
|
||||||
|
var item1 = new TS_BLB01 { Data = data1 };
|
||||||
|
Assert.Equal(1, g.sqlite.Insert(item1).ExecuteAffrows());
|
||||||
|
|
||||||
|
var item2 = g.sqlite.Select<TS_BLB01>().Where(a => a.Id == item1.Id).First();
|
||||||
|
Assert.Equal(item1.Data.Length, item2.Data.Length);
|
||||||
|
|
||||||
|
var str2 = Encoding.UTF8.GetString(item2.Data);
|
||||||
|
Assert.Equal(str1, str2);
|
||||||
|
|
||||||
|
//NoneParameter
|
||||||
|
item1 = new TS_BLB01 { Data = data1 };
|
||||||
|
Assert.Equal(1, g.sqlite.Insert<TS_BLB01>().NoneParameter().AppendData(item1).ExecuteAffrows());
|
||||||
|
|
||||||
|
item2 = g.sqlite.Select<TS_BLB01>().Where(a => a.Id == item1.Id).First();
|
||||||
|
Assert.Equal(item1.Data.Length, item2.Data.Length);
|
||||||
|
|
||||||
|
str2 = Encoding.UTF8.GetString(item2.Data);
|
||||||
|
Assert.Equal(str1, str2);
|
||||||
|
|
||||||
|
Assert.Equal(1, g.sqlite.InsertOrUpdate<TS_BLB01>().SetSource(new TS_BLB01 { Data = data1 }).ExecuteAffrows());
|
||||||
|
item2 = g.sqlite.Select<TS_BLB01>().Where(a => a.Id == item1.Id).First();
|
||||||
|
Assert.Equal(item1.Data.Length, item2.Data.Length);
|
||||||
|
|
||||||
|
str2 = Encoding.UTF8.GetString(item2.Data);
|
||||||
|
Assert.Equal(str1, str2);
|
||||||
|
}
|
||||||
|
class TS_BLB01
|
||||||
|
{
|
||||||
|
public Guid Id { get; set; }
|
||||||
|
[MaxLength(-1)]
|
||||||
|
public byte[] Data { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void StringLength()
|
||||||
|
{
|
||||||
|
var dll = g.sqlite.CodeFirst.GetComparisonDDLStatements<TS_SLTB>();
|
||||||
|
g.sqlite.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.sqlite.Insert(item).ExecuteAffrows();
|
||||||
|
|
||||||
|
var find = g.sqlite.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.sqlite.Update<tbdot01>().Set(a => a.name == "update").Where(a => a.id == item.id).ExecuteAffrows());
|
||||||
|
find = g.sqlite.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.sqlite.Delete<tbdot01>().Where(a => a.id == item.id).ExecuteAffrows());
|
||||||
|
find = g.sqlite.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.sqlite.CodeFirst.GetComparisonDDLStatements<测试中文表>();
|
||||||
|
g.sqlite.CodeFirst.SyncStructure<测试中文表>();
|
||||||
|
|
||||||
|
var item = new 测试中文表
|
||||||
|
{
|
||||||
|
标题 = "测试标题",
|
||||||
|
创建时间 = DateTime.Now
|
||||||
|
};
|
||||||
|
Assert.Equal(1, g.sqlite.Insert<测试中文表>().AppendData(item).ExecuteAffrows());
|
||||||
|
Assert.NotEqual(Guid.Empty, item.编号);
|
||||||
|
var item2 = g.sqlite.Select<测试中文表>().Where(a => a.编号 == item.编号).First();
|
||||||
|
Assert.NotNull(item2);
|
||||||
|
Assert.Equal(item.编号, item2.编号);
|
||||||
|
Assert.Equal(item.标题, item2.标题);
|
||||||
|
|
||||||
|
item.标题 = "测试标题更新";
|
||||||
|
Assert.Equal(1, g.sqlite.Update<测试中文表>().SetSource(item).ExecuteAffrows());
|
||||||
|
item2 = g.sqlite.Select<测试中文表>().Where(a => a.编号 == item.编号).First();
|
||||||
|
Assert.NotNull(item2);
|
||||||
|
Assert.Equal(item.编号, item2.编号);
|
||||||
|
Assert.Equal(item.标题, item2.标题);
|
||||||
|
|
||||||
|
item.标题 = "测试标题更新_repo";
|
||||||
|
var repo = g.sqlite.GetRepository<测试中文表>();
|
||||||
|
Assert.Equal(1, repo.Update(item));
|
||||||
|
item2 = g.sqlite.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.sqlite.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; }
|
||||||
|
|
||||||
|
[Column(ServerTime = DateTimeKind.Local, CanUpdate = false)]
|
||||||
|
public DateTime 创建时间 { get; set; }
|
||||||
|
|
||||||
|
[Column(ServerTime = DateTimeKind.Local)]
|
||||||
|
public DateTime 更新时间 { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void AddUniques()
|
||||||
|
{
|
||||||
|
var sql = g.sqlite.CodeFirst.GetComparisonDDLStatements<AddUniquesInfo>();
|
||||||
|
g.sqlite.CodeFirst.SyncStructure<AddUniquesInfo>();
|
||||||
|
g.sqlite.CodeFirst.SyncStructure(typeof(AddUniquesInfo), "AddUniquesInfo1");
|
||||||
|
}
|
||||||
|
[Table(Name = "AddUniquesInfo2", OldName = "AddUniquesInfo")]
|
||||||
|
[Index("{tablename}_uk_phone", "phone", true)]
|
||||||
|
[Index("{tablename}_uk_group_index", "group,index", true)]
|
||||||
|
[Index("{tablename}_uk_group_index22", "group desc, 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; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public class Topic
|
||||||
|
{
|
||||||
|
public Guid Id { get; set; }
|
||||||
|
public string Title { get; set; }
|
||||||
|
public string Content { get; set; }
|
||||||
|
public DateTime CreateTime { get; set; }
|
||||||
|
}
|
||||||
|
[Table(Name = "Comment")]
|
||||||
|
public class Comment
|
||||||
|
{
|
||||||
|
public Guid Id { get; set; }
|
||||||
|
public Guid TopicId { get; set; }
|
||||||
|
public virtual Topic Topic { get; set; }
|
||||||
|
public string Nickname { get; set; }
|
||||||
|
public string Content { get; set; }
|
||||||
|
public DateTime CreateTime { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void AddField()
|
||||||
|
{
|
||||||
|
|
||||||
|
//秀一波 FreeSql.Repository 扩展包,dotnet add package FreeSql.Repository
|
||||||
|
var topicRepository = g.sqlite.GetGuidRepository<Topic>();
|
||||||
|
var commentRepository = g.sqlite.GetGuidRepository<Comment>();
|
||||||
|
|
||||||
|
//添加测试文章
|
||||||
|
var topic = topicRepository.Insert(new Topic
|
||||||
|
{
|
||||||
|
Title = "文章标题1",
|
||||||
|
Content = "文章内容1",
|
||||||
|
CreateTime = DateTime.Now
|
||||||
|
});
|
||||||
|
|
||||||
|
//添加10条测试评论
|
||||||
|
var comments = Enumerable.Range(0, 10).Select(a => new Comment
|
||||||
|
{
|
||||||
|
TopicId = topic.Id,
|
||||||
|
Nickname = $"昵称{a}",
|
||||||
|
Content = $"评论内容{a}",
|
||||||
|
CreateTime = DateTime.Now
|
||||||
|
}).ToArray();
|
||||||
|
var affrows = commentRepository.Insert(comments);
|
||||||
|
|
||||||
|
var find = commentRepository.Select.Where(a => a.Topic.Title == "文章标题1").ToList();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
var sql = g.sqlite.CodeFirst.GetComparisonDDLStatements<TopicAddField>();
|
||||||
|
|
||||||
|
var id = g.sqlite.Insert<TopicAddField>().AppendData(new TopicAddField { }).ExecuteIdentity();
|
||||||
|
|
||||||
|
//var inserted = g.Sqlite.Insert<TopicAddField>().AppendData(new TopicAddField { }).ExecuteInserted();
|
||||||
|
}
|
||||||
|
|
||||||
|
[Table(Name = "TopicAddField", OldName = "TopicAddField")]
|
||||||
|
public class TopicAddField
|
||||||
|
{
|
||||||
|
[Column(IsIdentity = true)]
|
||||||
|
public int Id { get; set; }
|
||||||
|
|
||||||
|
public string name { get; set; }
|
||||||
|
|
||||||
|
[Column(DbType = "varchar(200) not null", OldName = "title2")]
|
||||||
|
public string title3223 { get; set; } = "10";
|
||||||
|
|
||||||
|
[Column(IsIgnore = true)]
|
||||||
|
public DateTime ct { get; set; } = DateTime.Now;
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void GetComparisonDDLStatements()
|
||||||
|
{
|
||||||
|
|
||||||
|
var sql = g.sqlite.CodeFirst.GetComparisonDDLStatements<TableAllType>();
|
||||||
|
Assert.True(string.IsNullOrEmpty(sql)); //测试运行两次后
|
||||||
|
//sql = g.Sqlite.CodeFirst.GetComparisonDDLStatements<Tb_alltype>();
|
||||||
|
}
|
||||||
|
|
||||||
|
IInsert<TableAllType> insert => g.sqlite.Insert<TableAllType>();
|
||||||
|
ISelect<TableAllType> select => g.sqlite.Select<TableAllType>();
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void CurdAllField()
|
||||||
|
{
|
||||||
|
var item = new TableAllType { };
|
||||||
|
item.Id = (int)insert.AppendData(item).ExecuteIdentity();
|
||||||
|
|
||||||
|
var newitem = select.Where(a => a.Id == item.Id).ToOne();
|
||||||
|
|
||||||
|
var item2 = new TableAllType
|
||||||
|
{
|
||||||
|
Bool = true,
|
||||||
|
BoolNullable = true,
|
||||||
|
Byte = 255,
|
||||||
|
ByteNullable = 127,
|
||||||
|
Bytes = Encoding.UTF8.GetBytes("我是中国人"),
|
||||||
|
DateTime = DateTime.Now,
|
||||||
|
DateTimeNullable = DateTime.Now.AddHours(-1),
|
||||||
|
Decimal = 99.99M,
|
||||||
|
DecimalNullable = 99.98M,
|
||||||
|
Double = 999.99,
|
||||||
|
DoubleNullable = 999.98,
|
||||||
|
Enum1 = TableAllTypeEnumType1.e5,
|
||||||
|
Enum1Nullable = TableAllTypeEnumType1.e3,
|
||||||
|
Enum2 = TableAllTypeEnumType2.f2,
|
||||||
|
Enum2Nullable = TableAllTypeEnumType2.f3,
|
||||||
|
Float = 19.99F,
|
||||||
|
FloatNullable = 19.98F,
|
||||||
|
Guid = Guid.NewGuid(),
|
||||||
|
GuidNullable = Guid.NewGuid(),
|
||||||
|
Int = int.MaxValue,
|
||||||
|
IntNullable = int.MinValue,
|
||||||
|
SByte = 100,
|
||||||
|
SByteNullable = 99,
|
||||||
|
Short = short.MaxValue,
|
||||||
|
ShortNullable = short.MinValue,
|
||||||
|
String = "我是中国人string'\\?!@#$%^&*()_+{}}{~?><<>",
|
||||||
|
Char = 'X',
|
||||||
|
TimeSpan = TimeSpan.FromSeconds(999),
|
||||||
|
TimeSpanNullable = TimeSpan.FromSeconds(60),
|
||||||
|
//UInt = uint.MaxValue,
|
||||||
|
//UIntNullable = uint.MinValue,
|
||||||
|
//ULong = ulong.MaxValue - 10000000,
|
||||||
|
//ULongNullable = ulong.MinValue,
|
||||||
|
//UShort = ushort.MaxValue,
|
||||||
|
//UShortNullable = ushort.MinValue,
|
||||||
|
//testFielLongNullable = long.MinValue
|
||||||
|
};
|
||||||
|
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();
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void UpdateSetFlag()
|
||||||
|
{
|
||||||
|
var sql1 = g.sqlite.Update<TableAllType>()
|
||||||
|
.Set(a => a.Enum2 | TableAllTypeEnumType2.f2)
|
||||||
|
.Where(a => a.Id == 10)
|
||||||
|
.ToSql();
|
||||||
|
Assert.Equal(@"UPDATE ""tb_alltype"" SET ""Enum2"" = (""Enum2"" | 1), ""DateTime"" = datetime(current_timestamp,'localtime'), ""DateTimeOffSet"" = datetime(current_timestamp,'localtime'), ""DateTimeNullable"" = datetime(current_timestamp,'localtime'), ""DateTimeOffSetNullable"" = datetime(current_timestamp,'localtime')
|
||||||
|
WHERE (""Id"" = 10)", sql1);
|
||||||
|
}
|
||||||
|
|
||||||
|
[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; }
|
||||||
|
|
||||||
|
[Column(ServerTime = DateTimeKind.Local)]
|
||||||
|
public DateTime DateTime { get; set; }
|
||||||
|
[Column(ServerTime = DateTimeKind.Local)]
|
||||||
|
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; }
|
||||||
|
|
||||||
|
[Column(ServerTime = DateTimeKind.Local)]
|
||||||
|
public DateTime? DateTimeNullable { get; set; }
|
||||||
|
[Column(ServerTime = DateTimeKind.Local)]
|
||||||
|
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 TableAllTypeEnumType3 testFieldEnum3 { get; set; }
|
||||||
|
public TableAllTypeEnumType3? testFieldEnum3Nullable { get; set; }
|
||||||
|
|
||||||
|
public enum TableAllTypeEnumType3 { }
|
||||||
|
}
|
||||||
|
|
||||||
|
public enum TableAllTypeEnumType1 { e1, e2, e3, e5 }
|
||||||
|
[Flags] public enum TableAllTypeEnumType2 { f1, f2, f3 }
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,83 @@
|
|||||||
|
using FreeSql.DataAnnotations;
|
||||||
|
using System;
|
||||||
|
using Xunit;
|
||||||
|
|
||||||
|
namespace FreeSql.Tests.Sqlite
|
||||||
|
{
|
||||||
|
public class SqliteDbFirstTest
|
||||||
|
{
|
||||||
|
[Fact]
|
||||||
|
public void GetDatabases()
|
||||||
|
{
|
||||||
|
var t1 = g.sqlite.DbFirst.GetDatabases();
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void GetTablesByDatabase()
|
||||||
|
{
|
||||||
|
var t2 = g.sqlite.DbFirst.GetTablesByDatabase();
|
||||||
|
Assert.True(t2.Count > 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void GetTableByName()
|
||||||
|
{
|
||||||
|
var fsql = g.sqlite;
|
||||||
|
var t1 = fsql.DbFirst.GetTableByName("tb_alltype");
|
||||||
|
var t2 = fsql.DbFirst.GetTableByName("main.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.sqlite;
|
||||||
|
Assert.False(fsql.DbFirst.ExistsTable("test_existstb01"));
|
||||||
|
Assert.False(fsql.DbFirst.ExistsTable("main.test_existstb01"));
|
||||||
|
Assert.False(fsql.DbFirst.ExistsTable("test_existstb01", false));
|
||||||
|
Assert.False(fsql.DbFirst.ExistsTable("main.test_existstb01", false));
|
||||||
|
fsql.CodeFirst.SyncStructure(typeof(test_existstb01));
|
||||||
|
Assert.True(fsql.DbFirst.ExistsTable("test_existstb01"));
|
||||||
|
Assert.True(fsql.DbFirst.ExistsTable("main.test_existstb01"));
|
||||||
|
Assert.False(fsql.DbFirst.ExistsTable("Test_existstb01", false));
|
||||||
|
Assert.False(fsql.DbFirst.ExistsTable("main.Test_existstb01", false));
|
||||||
|
fsql.Ado.ExecuteNonQuery("drop table test_existstb01");
|
||||||
|
|
||||||
|
//Assert.False(fsql.DbFirst.ExistsTable("xxxtb.test_existstb01"));
|
||||||
|
//Assert.False(fsql.DbFirst.ExistsTable("xxxtb.test_existstb01", false));
|
||||||
|
//fsql.CodeFirst.SyncStructure(typeof(test_existstb01), "xxxtb.test_existstb01");
|
||||||
|
//Assert.True(fsql.DbFirst.ExistsTable("xxxtb.test_existstb01"));
|
||||||
|
//Assert.False(fsql.DbFirst.ExistsTable("xxxtb.Test_existstb01", false));
|
||||||
|
//fsql.Ado.ExecuteNonQuery("drop table xxxtb.test_existstb01");
|
||||||
|
}
|
||||||
|
class test_existstb01
|
||||||
|
{
|
||||||
|
public Guid id { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void TestIdentity()
|
||||||
|
{
|
||||||
|
var fsql = g.sqlite;
|
||||||
|
fsql.CodeFirst.SyncStructure<ts_identity01>();
|
||||||
|
|
||||||
|
var tb = fsql.DbFirst.GetTableByName("ts_identity01");
|
||||||
|
Assert.NotNull(tb);
|
||||||
|
Assert.True(tb.Primarys.Count == 1);
|
||||||
|
Assert.True(tb.Primarys[0].IsIdentity);
|
||||||
|
}
|
||||||
|
class ts_identity01
|
||||||
|
{
|
||||||
|
[Column(IsIdentity = true)]
|
||||||
|
public int id { get; set; }
|
||||||
|
|
||||||
|
public string name { get; set; }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,169 @@
|
|||||||
|
using FreeSql.DataAnnotations;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using Xunit;
|
||||||
|
|
||||||
|
namespace FreeSql.Tests.SqliteExpression
|
||||||
|
{
|
||||||
|
public class ConvertTest
|
||||||
|
{
|
||||||
|
|
||||||
|
ISelect<Topic> select => g.sqlite.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,721 @@
|
|||||||
|
using FreeSql.DataAnnotations;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using Xunit;
|
||||||
|
|
||||||
|
namespace FreeSql.Tests.SqliteExpression
|
||||||
|
{
|
||||||
|
public class DateTimeTest
|
||||||
|
{
|
||||||
|
|
||||||
|
ISelect<Topic> select => g.sqlite.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.sqlite.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());
|
||||||
|
//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 (((strftime('%s',a."CreateTime")-strftime('%s',datetime(current_timestamp,'localtime')))) > 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 (((strftime('%s',a__Type."Time")-strftime('%s',datetime(current_timestamp,'localtime')))) > 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 (((strftime('%s',a__Type__Parent."Time2")-strftime('%s',datetime(current_timestamp,'localtime')))) > 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 (datetime(a."CreateTime",(-((1)*86400))||' seconds') > 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 (datetime(a__Type."Time",(-((1)*86400))||' seconds') > 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 (datetime(a__Type__Parent."Time2",(-((1)*86400))||' seconds') > 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 (((strftime('%s',a."CreateTime")-strftime('%s',datetime(current_timestamp,'localtime')))) > 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 (((strftime('%s',a__Type."Time")-strftime('%s',datetime(current_timestamp,'localtime')))) > 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 (((strftime('%s',a__Type__Parent."Time2")-strftime('%s',datetime(current_timestamp,'localtime')))) > 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 (datetime(a."CreateTime",(-((1)*86400))||' seconds') > 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 (datetime(a__Type."Time",(-((1)*86400))||' seconds') > 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 (datetime(a__Type__Parent."Time2",(-((1)*86400))||' seconds') > 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.SqliteExpression
|
||||||
|
{
|
||||||
|
public class MathTest
|
||||||
|
{
|
||||||
|
|
||||||
|
ISelect<Topic> select => g.sqlite.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,164 @@
|
|||||||
|
using FreeSql.DataAnnotations;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using Xunit;
|
||||||
|
|
||||||
|
namespace FreeSql.Tests.SqliteExpression
|
||||||
|
{
|
||||||
|
public class OtherTest
|
||||||
|
{
|
||||||
|
|
||||||
|
ISelect<TableAllType> select => g.sqlite.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,818 @@
|
|||||||
|
using FreeSql.DataAnnotations;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using Xunit;
|
||||||
|
|
||||||
|
namespace FreeSql.Tests.SqliteExpression
|
||||||
|
{
|
||||||
|
public class StringTest
|
||||||
|
{
|
||||||
|
|
||||||
|
ISelect<Topic> select => g.sqlite.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.sqlite.Select<TestEqualsGuid>().Where(a => a.id.Equals(Guid.Empty)).ToList());
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void StringJoin()
|
||||||
|
{
|
||||||
|
var fsql = g.sqlite;
|
||||||
|
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.sqlite.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'||ifnull((a.""Id"" + 1), '')||'z-'||ifnull(strftime('%Y%m',a.""CreateTime""), '')||''||ifnull(a.""Title"", '')||'' as1, ''||ifnull((a.""Id"" + 1), '')||'x'||ifnull((a.""Id"" + 1), '')||'z-'||ifnull(strftime('%Y%m',a.""CreateTime""), '')||''||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.sqlite.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'||ifnull((a.""Id"" + 1), '')||'z-'||ifnull(strftime('%Y%m',a.""CreateTime""), '')||''||ifnull(a.""Title"", '')||''||ifnull(a.""Title"", '')||'' as1, ''||ifnull((a.""Id"" + 1), '')||'x'||ifnull((a.""Id"" + 1), '')||'z-'||ifnull(strftime('%Y%m',a.""CreateTime""), '')||''||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`, '%'))
|
||||||
|
}
|
||||||
|
[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.SqliteExpression
|
||||||
|
{
|
||||||
|
public class TimeSpanTest
|
||||||
|
{
|
||||||
|
|
||||||
|
ISelect<Topic> select => g.sqlite.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,93 @@
|
|||||||
|
using FreeSql.DataAnnotations;
|
||||||
|
using Microsoft.Data.Sqlite;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.IO;
|
||||||
|
using Xunit;
|
||||||
|
|
||||||
|
[Table(Name = "TestTypeInfoT1")]
|
||||||
|
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; }
|
||||||
|
}
|
||||||
|
|
||||||
|
[Table(Name = "TestTypeParentInfoT1")]
|
||||||
|
class TestTypeParentInfo
|
||||||
|
{
|
||||||
|
[Column(IsIdentity = true)]
|
||||||
|
public int Id { get; set; }
|
||||||
|
public string Name { get; set; }
|
||||||
|
|
||||||
|
public int ParentId { get; set; }
|
||||||
|
public TestTypeParentInfo Parent { get; set; }
|
||||||
|
public ICollection<TestTypeParentInfo> Childs { get; set; }
|
||||||
|
|
||||||
|
public List<TestTypeInfo> Types { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
|
[Table(Name = "TestInfoT1")]
|
||||||
|
class TestInfo
|
||||||
|
{
|
||||||
|
[Column(IsIdentity = true, IsPrimary = true)]
|
||||||
|
public int Id { get; set; }
|
||||||
|
public int TypeGuid { get; set; }
|
||||||
|
public TestTypeInfo Type { get; set; }
|
||||||
|
public string Title { get; set; }
|
||||||
|
public DateTime CreateTime { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public partial class Song
|
||||||
|
{
|
||||||
|
[Column(IsIdentity = true)]
|
||||||
|
public int Id { get; set; }
|
||||||
|
public DateTime? Create_time { get; set; }
|
||||||
|
public bool? Is_deleted { get; set; }
|
||||||
|
public string Title { get; set; }
|
||||||
|
public string Url { get; set; }
|
||||||
|
|
||||||
|
public virtual ICollection<Tag> Tags { get; set; }
|
||||||
|
}
|
||||||
|
public partial class Song_tag
|
||||||
|
{
|
||||||
|
public int Song_id { get; set; }
|
||||||
|
public virtual Song Song { get; set; }
|
||||||
|
|
||||||
|
public int Tag_id { get; set; }
|
||||||
|
public virtual Tag Tag { get; set; }
|
||||||
|
}
|
||||||
|
public partial class Tag
|
||||||
|
{
|
||||||
|
[Column(IsIdentity = true)]
|
||||||
|
public int Id { get; set; }
|
||||||
|
public int? Parent_id { get; set; }
|
||||||
|
public virtual Tag Parent { get; set; }
|
||||||
|
|
||||||
|
public decimal? Ddd { get; set; }
|
||||||
|
public string Name { get; set; }
|
||||||
|
|
||||||
|
public virtual ICollection<Song> Songs { get; set; }
|
||||||
|
public virtual ICollection<Tag> Tags { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public class UnitTest1
|
||||||
|
{
|
||||||
|
[Fact]
|
||||||
|
public void Test()
|
||||||
|
{
|
||||||
|
string dataSubDirectory = Path.Combine(AppContext.BaseDirectory);
|
||||||
|
|
||||||
|
if (!Directory.Exists(dataSubDirectory))
|
||||||
|
Directory.CreateDirectory(dataSubDirectory);
|
||||||
|
|
||||||
|
AppDomain.CurrentDomain.SetData("DataDirectory", dataSubDirectory);
|
||||||
|
using (var connection = new SqliteConnection("Data Source=|DataDirectory|local.db"))
|
||||||
|
{
|
||||||
|
connection.Open();
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
46
FreeSql.Tests/FreeSql.Tests.Provider.Sqlite.Data/g.cs
Normal file
46
FreeSql.Tests/FreeSql.Tests.Provider.Sqlite.Data/g.cs
Normal file
@ -0,0 +1,46 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Diagnostics;
|
||||||
|
using System.IO;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading;
|
||||||
|
|
||||||
|
public class g
|
||||||
|
{
|
||||||
|
|
||||||
|
static Lazy<IFreeSql> sqliteLazy = new Lazy<IFreeSql>(() =>
|
||||||
|
{
|
||||||
|
|
||||||
|
string dataSubDirectory = Path.Combine(AppContext.BaseDirectory);
|
||||||
|
|
||||||
|
if (!Directory.Exists(dataSubDirectory))
|
||||||
|
Directory.CreateDirectory(dataSubDirectory);
|
||||||
|
|
||||||
|
AppDomain.CurrentDomain.SetData("DataDirectory", dataSubDirectory);
|
||||||
|
|
||||||
|
var fsql = new FreeSql.FreeSqlBuilder()
|
||||||
|
.UseConnectionString(FreeSql.DataType.Sqlite, @"Data Source=|DataDirectory|local.db")
|
||||||
|
//.UseConnectionFactory(FreeSql.DataType.Sqlite, () =>
|
||||||
|
//{
|
||||||
|
// var conn = new System.Data.SQLite.SQLiteConnection(@"Data Source=|DataDirectory|\document.db;Pooling=true;");
|
||||||
|
// //conn.Open();
|
||||||
|
// //var cmd = conn.CreateCommand();
|
||||||
|
// //cmd.CommandText = $"attach database [xxxtb.db] as [xxxtb];\r\n";
|
||||||
|
// //cmd.ExecuteNonQuery();
|
||||||
|
// //cmd.Dispose();
|
||||||
|
// return conn;
|
||||||
|
//})
|
||||||
|
.UseAutoSyncStructure(true)
|
||||||
|
//.UseGenerateCommandParameterWithLambda(true)
|
||||||
|
.UseLazyLoading(true)
|
||||||
|
.UseMonitorCommand(
|
||||||
|
cmd => Trace.WriteLine("\r\n线程" + Thread.CurrentThread.ManagedThreadId + ": " + cmd.CommandText) //监听SQL命令对象,在执行前
|
||||||
|
//, (cmd, traceLog) => Console.WriteLine(traceLog)
|
||||||
|
)
|
||||||
|
.Build();
|
||||||
|
|
||||||
|
return fsql;
|
||||||
|
}
|
||||||
|
);
|
||||||
|
public static IFreeSql sqlite => sqliteLazy.Value;
|
||||||
|
}
|
@ -6,7 +6,7 @@ using Xunit;
|
|||||||
namespace FreeSql.Tests.AdoNetExtensions.SqlConnectionExtensions {
|
namespace FreeSql.Tests.AdoNetExtensions.SqlConnectionExtensions {
|
||||||
public class Methods {
|
public class Methods {
|
||||||
|
|
||||||
string _connectString = "Data Source=.;Integrated Security=True;Initial Catalog=freesqlTest;Pooling=true;Max Pool Size=5";
|
string _connectString = "Data Source=.;Integrated Security=True;Initial Catalog=freesqlTest;Pooling=true;Max Pool Size=5;TrustServerCertificate=true";
|
||||||
|
|
||||||
public Methods() {
|
public Methods() {
|
||||||
g.sqlserver.CodeFirst.SyncStructure<TestConnectionExt>();
|
g.sqlserver.CodeFirst.SyncStructure<TestConnectionExt>();
|
||||||
|
319
FreeSql.Tests/FreeSql.Tests/ClickHouse/ClickHouseTest1.cs
Normal file
319
FreeSql.Tests/FreeSql.Tests/ClickHouse/ClickHouseTest1.cs
Normal file
@ -0,0 +1,319 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Reflection;
|
||||||
|
using System.Text;
|
||||||
|
using Xunit;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Collections;
|
||||||
|
using System.Diagnostics;
|
||||||
|
using XY.Model.Business;
|
||||||
|
using System.ComponentModel.DataAnnotations;
|
||||||
|
using FreeSql.DataAnnotations;
|
||||||
|
|
||||||
|
namespace FreeSql.Tests.MySql
|
||||||
|
{
|
||||||
|
public class ClickHouseTest1
|
||||||
|
{
|
||||||
|
private class TestAuditValue
|
||||||
|
{
|
||||||
|
[FreeSql.DataAnnotations.Column(IsPrimary = true)]
|
||||||
|
public long Id { get; set; }
|
||||||
|
|
||||||
|
[Now]
|
||||||
|
public DateTime CreateTime { get; set; }
|
||||||
|
|
||||||
|
[FreeSql.DataAnnotations.Column(IsNullable = true)]
|
||||||
|
public string Name { get; set; }
|
||||||
|
|
||||||
|
[FreeSql.DataAnnotations.Column(IsNullable = false)]
|
||||||
|
public int Age { get; set; }
|
||||||
|
|
||||||
|
public bool State { get; set; }
|
||||||
|
|
||||||
|
[FreeSql.DataAnnotations.Column(IsNullable = true)]
|
||||||
|
public bool Enable { get; set; }
|
||||||
|
|
||||||
|
public DateTime? UpdateTime { get; set; }
|
||||||
|
|
||||||
|
public int? Points { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
|
[FreeSql.DataAnnotations.Table(Name = "ClickHouseTest")]
|
||||||
|
public class TestClickHouse
|
||||||
|
{
|
||||||
|
[FreeSql.DataAnnotations.Column(IsPrimary = true, IsIdentity = true)]
|
||||||
|
[Now]
|
||||||
|
public long Id { get; set; }
|
||||||
|
|
||||||
|
public string Name { get; set; }
|
||||||
|
public Decimal Money { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
|
private class NowAttribute : Attribute
|
||||||
|
{ }
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void AuditValue()
|
||||||
|
{
|
||||||
|
var id = BitConverter.ToInt64(Guid.NewGuid().ToByteArray(), 0);
|
||||||
|
var item = new TestClickHouse();
|
||||||
|
item.Id = id;
|
||||||
|
item.Name = "李四";
|
||||||
|
EventHandler<Aop.AuditValueEventArgs> audit = (s, e) =>
|
||||||
|
{
|
||||||
|
if (e.Property.GetCustomAttribute<NowAttribute>(false) != null)
|
||||||
|
e.Value = BitConverter.ToInt64(Guid.NewGuid().ToByteArray(), 0);
|
||||||
|
};
|
||||||
|
g.clickHouse.Aop.AuditValue += audit;
|
||||||
|
|
||||||
|
g.clickHouse.Insert(item).ExecuteAffrows();
|
||||||
|
|
||||||
|
g.clickHouse.Aop.AuditValue -= audit;
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void CreateTalbe()
|
||||||
|
{
|
||||||
|
g.clickHouse.CodeFirst.SyncStructure<TestAuditValue>();
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void TestInsert()
|
||||||
|
{
|
||||||
|
Stopwatch stopwatch = new Stopwatch();
|
||||||
|
var fsql = g.clickHouse;
|
||||||
|
List<TestClickHouse> list = new List<TestClickHouse>();
|
||||||
|
List<CollectDataEntity> list1 = new List<CollectDataEntity>();
|
||||||
|
var date = DateTime.Now;
|
||||||
|
for (int i = 1; i < 1000000; i++)
|
||||||
|
{
|
||||||
|
//list.Add(new TestClickHouse
|
||||||
|
//{
|
||||||
|
// Id=i, Name=i.ToString()
|
||||||
|
//});
|
||||||
|
|
||||||
|
list1.Add(new CollectDataEntity
|
||||||
|
{
|
||||||
|
Id = new Random().Next(),
|
||||||
|
CollectTime = DateTime.Now,
|
||||||
|
DataFlag = "1",
|
||||||
|
EquipmentCode = "11",
|
||||||
|
Guid = "11111",
|
||||||
|
UnitStr = "111",
|
||||||
|
PropertyCode = "1111"
|
||||||
|
});
|
||||||
|
}
|
||||||
|
fsql.Delete<CollectDataEntity>().Where(t => 1 == 1).ExecuteAffrows();
|
||||||
|
stopwatch.Start();
|
||||||
|
var insert = fsql.Insert(list1);
|
||||||
|
stopwatch.Stop();
|
||||||
|
Debug.WriteLine("审计数据用时:" + stopwatch.ElapsedMilliseconds.ToString());
|
||||||
|
stopwatch.Restart();
|
||||||
|
insert.ExecuteAffrows();
|
||||||
|
//fsql.GetRepository<CollectDataEntity>().Insert(list1);
|
||||||
|
stopwatch.Stop();
|
||||||
|
Debug.WriteLine("转换并插入用时:" + stopwatch.ElapsedMilliseconds.ToString());
|
||||||
|
//var items = fsql.Select<TestClickHouse>().Where(o=>o.Id>900).OrderByDescending(o=>o.Id).ToList();
|
||||||
|
//Assert.Equal(100, items.Count);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void TestPage()
|
||||||
|
{
|
||||||
|
var fsql = g.clickHouse;
|
||||||
|
|
||||||
|
var list = fsql.Select<TestClickHouse>()
|
||||||
|
.Page(1, 100)
|
||||||
|
.Where(o => o.Id > 200 && o.Id < 500)
|
||||||
|
.Count(out var count).ToList();
|
||||||
|
//Assert.Equal(100, list.Count);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void TestDelete()
|
||||||
|
{
|
||||||
|
var fsql = g.clickHouse;
|
||||||
|
var count1 = fsql.Select<TestClickHouse>().Count();
|
||||||
|
fsql.Delete<TestClickHouse>().Where(o => o.Id < 500).ExecuteAffrows();
|
||||||
|
var count2 = fsql.Select<TestClickHouse>().Count();
|
||||||
|
//Assert.NotEqual(count1, count2);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void TestUpdate()
|
||||||
|
{
|
||||||
|
var fsql = g.clickHouse;
|
||||||
|
fsql.Update<TestClickHouse>().Where(o => o.Id > 900)
|
||||||
|
.Set(o => o.Name, "修改后的值")
|
||||||
|
.ExecuteAffrows();
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void TestRepositorySelect()
|
||||||
|
{
|
||||||
|
var fsql = g.clickHouse;
|
||||||
|
var list = fsql.GetRepository<TestClickHouse>().Where(o => o.Id > 900)
|
||||||
|
.ToList();
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void TestRepositoryInsert()
|
||||||
|
{
|
||||||
|
var fsql = g.clickHouse;
|
||||||
|
long id = BitConverter.ToInt64(Guid.NewGuid().ToByteArray(), 0);
|
||||||
|
var list = fsql.GetRepository<TestClickHouse>().Insert(new TestClickHouse { Id = id, Name = "张三" });
|
||||||
|
var data = fsql.GetRepository<TestClickHouse, long>().Get(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void TestDateTime()
|
||||||
|
{
|
||||||
|
var fsql = g.clickHouse;
|
||||||
|
long id = BitConverter.ToInt64(Guid.NewGuid().ToByteArray(), 0);
|
||||||
|
DateTime createTime = DateTime.Now;
|
||||||
|
fsql.Insert(new TestAuditValue
|
||||||
|
{
|
||||||
|
Id = id,
|
||||||
|
CreateTime = createTime,
|
||||||
|
Age = 18,
|
||||||
|
Name = "张三"
|
||||||
|
}).ExecuteAffrows();
|
||||||
|
|
||||||
|
var date1 = fsql.GetRepository<TestAuditValue>().Where(o => o.CreateTime == createTime)
|
||||||
|
.ToList();
|
||||||
|
var date2 = fsql.GetRepository<TestAuditValue>().Where(o => o.CreateTime.Date == createTime.Date)
|
||||||
|
.ToList();
|
||||||
|
var date3 = fsql.GetRepository<TestAuditValue>().Where(o => o.CreateTime.Year == createTime.Year)
|
||||||
|
.ToList();
|
||||||
|
var date4 = fsql.GetRepository<TestAuditValue>().Where(o => o.CreateTime.Month == createTime.Month)
|
||||||
|
.ToList();
|
||||||
|
var date5 = fsql.GetRepository<TestAuditValue>().Where(o => o.CreateTime.Second == createTime.Second)
|
||||||
|
.ToList();
|
||||||
|
var date6 = fsql.GetRepository<TestAuditValue>().Where(o => o.CreateTime.Millisecond == createTime.Millisecond)
|
||||||
|
.ToList();
|
||||||
|
var date7 = fsql.GetRepository<TestAuditValue>().Where(o => o.CreateTime.AddSeconds(10) < createTime)
|
||||||
|
.ToList();
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void TestUpdateTime()
|
||||||
|
{
|
||||||
|
var fsql = g.clickHouse;
|
||||||
|
var state = fsql.GetRepository<TestAuditValue>().UpdateDiy.Set(o => o.UpdateTime, DateTime.Now).Where(o => 1 == 1).ExecuteAffrows();
|
||||||
|
//var state1 = fsql.GetRepository<TestAuditValue>().UpdateDiy.Set(o => o.UpdateTime, null).Where(o => 1 == 1).ExecuteAffrows();
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void TestRepositoryUpdateTime()
|
||||||
|
{
|
||||||
|
Stopwatch stopwatch = new Stopwatch();
|
||||||
|
var fsql = g.clickHouse;
|
||||||
|
var repository = fsql.GetRepository<TestAuditValue>();
|
||||||
|
List<TestAuditValue> list = new List<TestAuditValue>();
|
||||||
|
for (int i = 1; i < 5; i++)
|
||||||
|
{
|
||||||
|
list.Add(new TestAuditValue
|
||||||
|
{
|
||||||
|
Id = new Random().Next(),
|
||||||
|
Age = 1,
|
||||||
|
Name = i.ToString(),
|
||||||
|
State = true,
|
||||||
|
CreateTime = DateTime.Now,
|
||||||
|
UpdateTime = DateTime.Now,
|
||||||
|
Enable = false
|
||||||
|
});
|
||||||
|
}
|
||||||
|
list = repository.Insert(list);
|
||||||
|
//var list = repository.Select.ToList();
|
||||||
|
list.ForEach(o => o.UpdateTime = DateTime.Now);
|
||||||
|
list.ForEach(o => o.Enable = true);
|
||||||
|
stopwatch.Start();
|
||||||
|
repository.Update(list);
|
||||||
|
stopwatch.Stop();
|
||||||
|
Debug.WriteLine("更新用时:" + stopwatch.ElapsedMilliseconds.ToString());
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public async void TestInsertUpdateData()
|
||||||
|
{
|
||||||
|
//g.clickHouse.CodeFirst.SyncStructure<CollectDataEntity>();
|
||||||
|
Stopwatch stopwatch = new Stopwatch();
|
||||||
|
var fsql = g.clickHouse;
|
||||||
|
var repository = fsql.GetRepository<CollectDataEntity>();
|
||||||
|
await repository.DeleteAsync(o => o.Id > 0);
|
||||||
|
List<CollectDataEntity> tables = new List<CollectDataEntity>();
|
||||||
|
for (int i = 1; i < 3; i++)
|
||||||
|
{
|
||||||
|
tables.Add(new CollectDataEntity
|
||||||
|
{
|
||||||
|
Id = new Random().Next(),
|
||||||
|
CollectTime = DateTime.Now,
|
||||||
|
DataFlag = "1",
|
||||||
|
EquipmentCode = "11",
|
||||||
|
UnitStr = "111",
|
||||||
|
PropertyCode = "1111",
|
||||||
|
NumericValue = 1111.1119999912500M
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
var insert = repository.Orm.Insert(tables);
|
||||||
|
insert.ExecuteAffrows();
|
||||||
|
var list = repository.Orm.Select<CollectDataEntity>().ToList();
|
||||||
|
//var list = repository.Insert(tables);
|
||||||
|
//var list = repository.Select.ToList();
|
||||||
|
//list.ForEach(o=>o.EquipmentCode = "666");
|
||||||
|
//stopwatch.Start();
|
||||||
|
//await repository.UpdateAsync(list);
|
||||||
|
//stopwatch.Stop();
|
||||||
|
Debug.WriteLine("更新用时:" + stopwatch.ElapsedMilliseconds.ToString());
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public async void TestInsertDecimalData()
|
||||||
|
{
|
||||||
|
//g.clickHouse.CodeFirst.SyncStructure<CollectDataEntity>();
|
||||||
|
Stopwatch stopwatch = new Stopwatch();
|
||||||
|
var fsql = g.clickHouse;
|
||||||
|
var repository = fsql.GetRepository<CollectDataEntity>();
|
||||||
|
await repository.DeleteAsync(o => o.Id > 0);
|
||||||
|
|
||||||
|
var insert = repository.Insert(new CollectDataEntity
|
||||||
|
{
|
||||||
|
Id = new Random().Next(),
|
||||||
|
CollectTime = DateTime.Now,
|
||||||
|
DataFlag = "1",
|
||||||
|
EquipmentCode = "11",
|
||||||
|
UnitStr = "111",
|
||||||
|
PropertyCode = "1111",
|
||||||
|
NumericValue = 1111.1119999912500M
|
||||||
|
});
|
||||||
|
var list = repository.Orm.Select<CollectDataEntity>().ToList();
|
||||||
|
//var list = repository.Insert(tables);
|
||||||
|
//var list = repository.Select.ToList();
|
||||||
|
//list.ForEach(o=>o.EquipmentCode = "666");
|
||||||
|
//stopwatch.Start();
|
||||||
|
//await repository.UpdateAsync(list);
|
||||||
|
//stopwatch.Stop();
|
||||||
|
Debug.WriteLine("更新用时:" + stopwatch.ElapsedMilliseconds.ToString());
|
||||||
|
}
|
||||||
|
|
||||||
|
internal class Entity
|
||||||
|
{
|
||||||
|
[Required]
|
||||||
|
public string Id { get; set; }
|
||||||
|
|
||||||
|
[Column(StringLength = -2)]
|
||||||
|
public string Content { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void TestInsertNoneParameter()
|
||||||
|
{
|
||||||
|
var json = "[{\"date\":\"2021-12-19T02:47:53.4365075 08:00\",\"temperatureC\":6,\"temperatureF\":42,\"summary\":\"Balmy\"},{\"date\":\"2021-12-20T02:47:53.4366893 08:00\",\"temperatureC\":36,\"temperatureF\":96,\"summary\":\"Bracing\"},{\"date\":\"2021-12-21T02:47:53.4366903 08:00\",\"temperatureC\":-15,\"temperatureF\":6,\"summary\":\"Bracing\"},{\"date\":\"2021-12-22T02:47:53.4366904 08:00\",\"temperatureC\":14,\"temperatureF\":57,\"summary\":\"Cool\"},{\"date\":\"2021-12-23T02:47:53.4366905 08:00\",\"temperatureC\":29,\"temperatureF\":84,\"summary\":\"Mild\"}]";
|
||||||
|
var data = new Entity { Id = Guid.NewGuid().ToString(), Content = json };
|
||||||
|
|
||||||
|
var fsql = g.clickHouse;
|
||||||
|
fsql.Insert(data).NoneParameter().ExecuteAffrows();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
168
FreeSql.Tests/FreeSql.Tests/ClickHouse/CollectDataEntity.cs
Normal file
168
FreeSql.Tests/FreeSql.Tests/ClickHouse/CollectDataEntity.cs
Normal file
@ -0,0 +1,168 @@
|
|||||||
|
using FreeSql.DataAnnotations;
|
||||||
|
using Newtonsoft.Json;
|
||||||
|
using System;
|
||||||
|
using System.ComponentModel;
|
||||||
|
namespace XY.Model.Business
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// 实时数据
|
||||||
|
/// </summary>
|
||||||
|
[Table(Name = "CollectData")]
|
||||||
|
[Index("idx_{tablename}_01", nameof(Guid), true)]
|
||||||
|
public partial class CollectDataEntity
|
||||||
|
{
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Guid
|
||||||
|
/// </summary>
|
||||||
|
[Column(StringLength = 50)]
|
||||||
|
public string Guid { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 租户Id
|
||||||
|
/// </summary>
|
||||||
|
[Description("租户Id")]
|
||||||
|
[Column(CanUpdate = false)]
|
||||||
|
public virtual long? TenantId { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 版本
|
||||||
|
/// </summary>
|
||||||
|
[Description("版本")]
|
||||||
|
[Column(IsVersion = false)]
|
||||||
|
public long Version { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 是否删除
|
||||||
|
/// </summary>
|
||||||
|
[Description("是否删除")]
|
||||||
|
[Column()]
|
||||||
|
public bool IsDeleted { get; set; } = false;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 创建者Id
|
||||||
|
/// </summary>
|
||||||
|
[Description("创建者Id")]
|
||||||
|
[Column(CanUpdate = false)]
|
||||||
|
public long? CreatedUserId { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 创建者
|
||||||
|
/// </summary>
|
||||||
|
[Description("创建者")]
|
||||||
|
[Column(CanUpdate = false, StringLength = 50)]
|
||||||
|
public string CreatedUserName { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 创建时间
|
||||||
|
/// </summary>
|
||||||
|
[Description("创建时间")]
|
||||||
|
[Column(CanUpdate = false, ServerTime = DateTimeKind.Local)]
|
||||||
|
public DateTime? CreatedTime { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 修改者Id
|
||||||
|
/// </summary>
|
||||||
|
[Description("修改者Id")]
|
||||||
|
[Column(CanInsert = false)]
|
||||||
|
public long? ModifiedUserId { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 修改者
|
||||||
|
/// </summary>
|
||||||
|
[Description("修改者")]
|
||||||
|
[Column(CanInsert = false, StringLength = 50)]
|
||||||
|
public string ModifiedUserName { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 修改时间
|
||||||
|
/// </summary>
|
||||||
|
[Description("修改时间")]
|
||||||
|
[Column(CanInsert = false, ServerTime = DateTimeKind.Local)]
|
||||||
|
public DateTime? ModifiedTime { get; set; }
|
||||||
|
/// <summary>
|
||||||
|
/// 数据标识
|
||||||
|
/// </summary>
|
||||||
|
[Description("数据标识")]
|
||||||
|
[Column(CanInsert = false, StringLength = 2)]
|
||||||
|
public string DataFlag { get; set; }
|
||||||
|
/// <summary>
|
||||||
|
/// 主键Id
|
||||||
|
/// </summary>
|
||||||
|
[Description("主键Id")]
|
||||||
|
[Column(Position = 1)]
|
||||||
|
public long Id { get; set; }
|
||||||
|
/// <summary>
|
||||||
|
/// 设备编号
|
||||||
|
/// </summary>
|
||||||
|
[Column(StringLength = 50)]
|
||||||
|
public string EquipmentCode { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 数据编号,如为空使用默认数据
|
||||||
|
/// </summary>
|
||||||
|
[Column(StringLength = 50)]
|
||||||
|
public string PropertyCode { get; set; }
|
||||||
|
/// <summary>
|
||||||
|
/// 数据名称,如为空使用默认数据
|
||||||
|
/// </summary>
|
||||||
|
[Column(StringLength = 50)]
|
||||||
|
public string PropertyName { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 数值或状态是否变更
|
||||||
|
/// </summary>
|
||||||
|
public bool IsValueOrStateChanged { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 采集数值
|
||||||
|
/// </summary>
|
||||||
|
[Column(StringLength = 18)]
|
||||||
|
public decimal? NumericValue { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 备注
|
||||||
|
/// </summary>
|
||||||
|
[Column(StringLength = 200)]
|
||||||
|
public string Remark { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 服务标记
|
||||||
|
/// </summary>
|
||||||
|
[Column(StringLength = 20)]
|
||||||
|
public string ServiceFlag { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 状态
|
||||||
|
/// </summary>
|
||||||
|
[Column(StringLength = 50)]
|
||||||
|
public string StrState { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 文本数值
|
||||||
|
/// </summary>
|
||||||
|
[Column(StringLength = 50)]
|
||||||
|
public string StrValue { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 单位
|
||||||
|
/// </summary>
|
||||||
|
[Column(StringLength = 10)]
|
||||||
|
public string UnitStr { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 采集时间
|
||||||
|
/// </summary>
|
||||||
|
public DateTime CollectTime { get; set; }
|
||||||
|
|
||||||
|
|
||||||
|
public string FieldKey
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
return EquipmentCode +"_"+ PropertyCode;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -22,6 +22,37 @@ namespace FreeSql.Tests.Dameng
|
|||||||
public DateTime CreateTime { get; set; }
|
public DateTime CreateTime { get; set; }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void InsertDictionary()
|
||||||
|
{
|
||||||
|
var fsql = g.dameng;
|
||||||
|
Dictionary<string, object> dic = new Dictionary<string, object>();
|
||||||
|
dic.Add("id", 1);
|
||||||
|
dic.Add("name", "xxxx");
|
||||||
|
var diclist = new List<Dictionary<string, object>>();
|
||||||
|
diclist.Add(dic);
|
||||||
|
diclist.Add(new Dictionary<string, object>
|
||||||
|
{
|
||||||
|
["id"] = 2,
|
||||||
|
["name"] = "yyyy"
|
||||||
|
});
|
||||||
|
|
||||||
|
var sql1 = fsql.InsertDict(dic).AsTable("table1").ToSql();
|
||||||
|
Assert.Equal(@"INSERT INTO ""TABLE1""(""ID"", ""NAME"") VALUES(:id_0, :name_0)", sql1);
|
||||||
|
var sql2 = fsql.InsertDict(diclist).AsTable("table1").ToSql();
|
||||||
|
Assert.Equal(@"INSERT ALL
|
||||||
|
INTO ""TABLE1""(""ID"", ""NAME"") VALUES(:id_0, :name_0)
|
||||||
|
INTO ""TABLE1""(""ID"", ""NAME"") VALUES(:id_1, :name_1)
|
||||||
|
SELECT 1 FROM DUAL", sql2);
|
||||||
|
var sql3 = fsql.InsertDict(dic).AsTable("table1").NoneParameter().ToSql();
|
||||||
|
Assert.Equal(@"INSERT INTO ""TABLE1""(""ID"", ""NAME"") VALUES(1, 'xxxx')", sql3);
|
||||||
|
var sql4 = fsql.InsertDict(diclist).AsTable("table1").NoneParameter().ToSql();
|
||||||
|
Assert.Equal(@"INSERT ALL
|
||||||
|
INTO ""TABLE1""(""ID"", ""NAME"") VALUES(1, 'xxxx')
|
||||||
|
INTO ""TABLE1""(""ID"", ""NAME"") VALUES(2, 'yyyy')
|
||||||
|
SELECT 1 FROM DUAL", sql4);
|
||||||
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void AppendData()
|
public void AppendData()
|
||||||
{
|
{
|
||||||
|
@ -11,7 +11,7 @@ namespace FreeSql.Tests.DataContext.SqlServer
|
|||||||
public SqlServerFixture()
|
public SqlServerFixture()
|
||||||
{
|
{
|
||||||
sqlServerLazy = new Lazy<IFreeSql>(() => new FreeSql.FreeSqlBuilder()
|
sqlServerLazy = new Lazy<IFreeSql>(() => new FreeSql.FreeSqlBuilder()
|
||||||
.UseConnectionString(FreeSql.DataType.SqlServer, "Data Source=.;Integrated Security=True;Initial Catalog=freesqlTest;Pooling=true;Max Pool Size=2")
|
.UseConnectionString(FreeSql.DataType.SqlServer, "Data Source=.;Integrated Security=True;Initial Catalog=freesqlTest;Pooling=true;Max Pool Size=2;TrustServerCertificate=true")
|
||||||
//.UseConnectionString(FreeSql.DataType.SqlServer, "Data Source=(localdb)\\mssqllocaldb;Integrated Security=True;Initial Catalog=freesqlTest;Pooling=true;Max Pool Size=10")
|
//.UseConnectionString(FreeSql.DataType.SqlServer, "Data Source=(localdb)\\mssqllocaldb;Integrated Security=True;Initial Catalog=freesqlTest;Pooling=true;Max Pool Size=10")
|
||||||
.UseAutoSyncStructure(true)
|
.UseAutoSyncStructure(true)
|
||||||
.UseLazyLoading(true)
|
.UseLazyLoading(true)
|
||||||
|
@ -22,6 +22,35 @@ namespace FreeSql.Tests.Firebird
|
|||||||
public DateTime CreateTime { get; set; }
|
public DateTime CreateTime { get; set; }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void InsertDictionary()
|
||||||
|
{
|
||||||
|
var fsql = g.firebird;
|
||||||
|
Dictionary<string, object> dic = new Dictionary<string, object>();
|
||||||
|
dic.Add("id", 1);
|
||||||
|
dic.Add("name", "xxxx");
|
||||||
|
var diclist = new List<Dictionary<string, object>>();
|
||||||
|
diclist.Add(dic);
|
||||||
|
diclist.Add(new Dictionary<string, object>
|
||||||
|
{
|
||||||
|
["id"] = 2,
|
||||||
|
["name"] = "yyyy"
|
||||||
|
});
|
||||||
|
|
||||||
|
var sql1 = fsql.InsertDict(dic).AsTable("table1").ToSql();
|
||||||
|
Assert.Equal(@"INSERT INTO ""TABLE1""(""ID"", ""NAME"") VALUES(@id_0, @name_0)", sql1);
|
||||||
|
var sql2 = fsql.InsertDict(diclist).AsTable("table1").ToSql();
|
||||||
|
Assert.Equal(@"INSERT INTO ""TABLE1""(""ID"", ""NAME"") SELECT FIRST 1 @id_0, @name_0 FROM rdb$database
|
||||||
|
UNION ALL
|
||||||
|
SELECT FIRST 1 @id_1, @name_1 FROM rdb$database", sql2);
|
||||||
|
var sql3 = fsql.InsertDict(dic).AsTable("table1").NoneParameter().ToSql();
|
||||||
|
Assert.Equal(@"INSERT INTO ""TABLE1""(""ID"", ""NAME"") VALUES(1, 'xxxx')", sql3);
|
||||||
|
var sql4 = fsql.InsertDict(diclist).AsTable("table1").NoneParameter().ToSql();
|
||||||
|
Assert.Equal(@"INSERT INTO ""TABLE1""(""ID"", ""NAME"") SELECT FIRST 1 1, 'xxxx' FROM rdb$database
|
||||||
|
UNION ALL
|
||||||
|
SELECT FIRST 1 2, 'yyyy' FROM rdb$database", sql4);
|
||||||
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void AppendData()
|
public void AppendData()
|
||||||
{
|
{
|
||||||
|
@ -14,16 +14,17 @@
|
|||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="Dapper" Version="2.0.123" />
|
<PackageReference Include="Dapper" Version="2.0.123" />
|
||||||
<PackageReference Include="IdleBus" Version="1.5.2" />
|
<PackageReference Include="IdleBus" Version="1.5.2" />
|
||||||
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="6.0.0" />
|
<PackageReference Include="Microsoft.Data.Sqlite" Version="6.0.1" />
|
||||||
<PackageReference Include="Microsoft.Data.SqlClient" Version="3.0.1" />
|
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="6.0.0" />
|
||||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.8.3" />
|
<PackageReference Include="Microsoft.Data.SqlClient" Version="4.0.0" />
|
||||||
<PackageReference Include="xunit" Version="2.4.1" />
|
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.8.3" />
|
||||||
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.3">
|
<PackageReference Include="xunit" Version="2.4.1" />
|
||||||
<PrivateAssets>all</PrivateAssets>
|
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.3">
|
||||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
<PrivateAssets>all</PrivateAssets>
|
||||||
</PackageReference>
|
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||||
|
</PackageReference>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
@ -37,6 +38,7 @@
|
|||||||
<ProjectReference Include="..\..\Extensions\FreeSql.Extensions.Linq\FreeSql.Extensions.Linq.csproj" />
|
<ProjectReference Include="..\..\Extensions\FreeSql.Extensions.Linq\FreeSql.Extensions.Linq.csproj" />
|
||||||
<ProjectReference Include="..\..\FreeSql.DbContext\FreeSql.DbContext.csproj" />
|
<ProjectReference Include="..\..\FreeSql.DbContext\FreeSql.DbContext.csproj" />
|
||||||
<ProjectReference Include="..\..\FreeSql\FreeSql.csproj" />
|
<ProjectReference Include="..\..\FreeSql\FreeSql.csproj" />
|
||||||
|
<ProjectReference Include="..\..\Providers\FreeSql.Provider.ClickHouse\FreeSql.Provider.ClickHouse.csproj" />
|
||||||
<ProjectReference Include="..\..\Providers\FreeSql.Provider.Dameng\FreeSql.Provider.Dameng.csproj" />
|
<ProjectReference Include="..\..\Providers\FreeSql.Provider.Dameng\FreeSql.Provider.Dameng.csproj" />
|
||||||
<ProjectReference Include="..\..\Providers\FreeSql.Provider.Firebird\FreeSql.Provider.Firebird.csproj" />
|
<ProjectReference Include="..\..\Providers\FreeSql.Provider.Firebird\FreeSql.Provider.Firebird.csproj" />
|
||||||
<ProjectReference Include="..\..\Providers\FreeSql.Provider.KingbaseES\FreeSql.Provider.KingbaseES.csproj" />
|
<ProjectReference Include="..\..\Providers\FreeSql.Provider.KingbaseES\FreeSql.Provider.KingbaseES.csproj" />
|
||||||
|
@ -4,6 +4,11 @@
|
|||||||
<name>FreeSql.Tests</name>
|
<name>FreeSql.Tests</name>
|
||||||
</assembly>
|
</assembly>
|
||||||
<members>
|
<members>
|
||||||
|
<member name="M:FreeSql.Tests.MySql.MySqlCodeFirstTest.Tb_alltype.Save">
|
||||||
|
<summary>
|
||||||
|
保存或添加,如果主键有值则尝试 Update,如果影响的行为 0 则尝试 Insert
|
||||||
|
</summary>
|
||||||
|
</member>
|
||||||
<member name="P:FreeSql.Tests.Firebird.FirebirdCodeFirstTest.AddUniquesInfo.id">
|
<member name="P:FreeSql.Tests.Firebird.FirebirdCodeFirstTest.AddUniquesInfo.id">
|
||||||
<summary>
|
<summary>
|
||||||
编号
|
编号
|
||||||
@ -287,11 +292,6 @@
|
|||||||
修改人
|
修改人
|
||||||
</summary>
|
</summary>
|
||||||
</member>
|
</member>
|
||||||
<member name="M:FreeSql.Tests.MySql.MySqlCodeFirstTest.Tb_alltype.Save">
|
|
||||||
<summary>
|
|
||||||
保存或添加,如果主键有值则尝试 Update,如果影响的行为 0 则尝试 Insert
|
|
||||||
</summary>
|
|
||||||
</member>
|
|
||||||
<member name="T:FreeSql.Tests.SqlServer.SqlServerCodeFirstTest.tbdot01">
|
<member name="T:FreeSql.Tests.SqlServer.SqlServerCodeFirstTest.tbdot01">
|
||||||
<summary>
|
<summary>
|
||||||
表中带点
|
表中带点
|
||||||
@ -945,6 +945,126 @@
|
|||||||
新打印模块
|
新打印模块
|
||||||
</summary>
|
</summary>
|
||||||
</member>
|
</member>
|
||||||
|
<member name="T:XY.Model.Business.CollectDataEntity">
|
||||||
|
<summary>
|
||||||
|
实时数据
|
||||||
|
</summary>
|
||||||
|
</member>
|
||||||
|
<member name="P:XY.Model.Business.CollectDataEntity.Guid">
|
||||||
|
<summary>
|
||||||
|
Guid
|
||||||
|
</summary>
|
||||||
|
</member>
|
||||||
|
<member name="P:XY.Model.Business.CollectDataEntity.TenantId">
|
||||||
|
<summary>
|
||||||
|
租户Id
|
||||||
|
</summary>
|
||||||
|
</member>
|
||||||
|
<member name="P:XY.Model.Business.CollectDataEntity.Version">
|
||||||
|
<summary>
|
||||||
|
版本
|
||||||
|
</summary>
|
||||||
|
</member>
|
||||||
|
<member name="P:XY.Model.Business.CollectDataEntity.IsDeleted">
|
||||||
|
<summary>
|
||||||
|
是否删除
|
||||||
|
</summary>
|
||||||
|
</member>
|
||||||
|
<member name="P:XY.Model.Business.CollectDataEntity.CreatedUserId">
|
||||||
|
<summary>
|
||||||
|
创建者Id
|
||||||
|
</summary>
|
||||||
|
</member>
|
||||||
|
<member name="P:XY.Model.Business.CollectDataEntity.CreatedUserName">
|
||||||
|
<summary>
|
||||||
|
创建者
|
||||||
|
</summary>
|
||||||
|
</member>
|
||||||
|
<member name="P:XY.Model.Business.CollectDataEntity.CreatedTime">
|
||||||
|
<summary>
|
||||||
|
创建时间
|
||||||
|
</summary>
|
||||||
|
</member>
|
||||||
|
<member name="P:XY.Model.Business.CollectDataEntity.ModifiedUserId">
|
||||||
|
<summary>
|
||||||
|
修改者Id
|
||||||
|
</summary>
|
||||||
|
</member>
|
||||||
|
<member name="P:XY.Model.Business.CollectDataEntity.ModifiedUserName">
|
||||||
|
<summary>
|
||||||
|
修改者
|
||||||
|
</summary>
|
||||||
|
</member>
|
||||||
|
<member name="P:XY.Model.Business.CollectDataEntity.ModifiedTime">
|
||||||
|
<summary>
|
||||||
|
修改时间
|
||||||
|
</summary>
|
||||||
|
</member>
|
||||||
|
<member name="P:XY.Model.Business.CollectDataEntity.DataFlag">
|
||||||
|
<summary>
|
||||||
|
数据标识
|
||||||
|
</summary>
|
||||||
|
</member>
|
||||||
|
<member name="P:XY.Model.Business.CollectDataEntity.Id">
|
||||||
|
<summary>
|
||||||
|
主键Id
|
||||||
|
</summary>
|
||||||
|
</member>
|
||||||
|
<member name="P:XY.Model.Business.CollectDataEntity.EquipmentCode">
|
||||||
|
<summary>
|
||||||
|
设备编号
|
||||||
|
</summary>
|
||||||
|
</member>
|
||||||
|
<member name="P:XY.Model.Business.CollectDataEntity.PropertyCode">
|
||||||
|
<summary>
|
||||||
|
数据编号,如为空使用默认数据
|
||||||
|
</summary>
|
||||||
|
</member>
|
||||||
|
<member name="P:XY.Model.Business.CollectDataEntity.PropertyName">
|
||||||
|
<summary>
|
||||||
|
数据名称,如为空使用默认数据
|
||||||
|
</summary>
|
||||||
|
</member>
|
||||||
|
<member name="P:XY.Model.Business.CollectDataEntity.IsValueOrStateChanged">
|
||||||
|
<summary>
|
||||||
|
数值或状态是否变更
|
||||||
|
</summary>
|
||||||
|
</member>
|
||||||
|
<member name="P:XY.Model.Business.CollectDataEntity.NumericValue">
|
||||||
|
<summary>
|
||||||
|
采集数值
|
||||||
|
</summary>
|
||||||
|
</member>
|
||||||
|
<member name="P:XY.Model.Business.CollectDataEntity.Remark">
|
||||||
|
<summary>
|
||||||
|
备注
|
||||||
|
</summary>
|
||||||
|
</member>
|
||||||
|
<member name="P:XY.Model.Business.CollectDataEntity.ServiceFlag">
|
||||||
|
<summary>
|
||||||
|
服务标记
|
||||||
|
</summary>
|
||||||
|
</member>
|
||||||
|
<member name="P:XY.Model.Business.CollectDataEntity.StrState">
|
||||||
|
<summary>
|
||||||
|
状态
|
||||||
|
</summary>
|
||||||
|
</member>
|
||||||
|
<member name="P:XY.Model.Business.CollectDataEntity.StrValue">
|
||||||
|
<summary>
|
||||||
|
文本数值
|
||||||
|
</summary>
|
||||||
|
</member>
|
||||||
|
<member name="P:XY.Model.Business.CollectDataEntity.UnitStr">
|
||||||
|
<summary>
|
||||||
|
单位
|
||||||
|
</summary>
|
||||||
|
</member>
|
||||||
|
<member name="P:XY.Model.Business.CollectDataEntity.CollectTime">
|
||||||
|
<summary>
|
||||||
|
采集时间
|
||||||
|
</summary>
|
||||||
|
</member>
|
||||||
<member name="T:SaleIDO.Entity.Storeage.AdjustPriceOrder">
|
<member name="T:SaleIDO.Entity.Storeage.AdjustPriceOrder">
|
||||||
<summary>
|
<summary>
|
||||||
调价单
|
调价单
|
||||||
|
50
FreeSql.Tests/FreeSql.Tests/Internal/UtilsTest.cs
Normal file
50
FreeSql.Tests/FreeSql.Tests/Internal/UtilsTest.cs
Normal file
@ -0,0 +1,50 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Data.Common;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using Microsoft.Data.SqlClient;
|
||||||
|
using Xunit;
|
||||||
|
|
||||||
|
namespace FreeSql.Tests.Internal
|
||||||
|
{
|
||||||
|
|
||||||
|
public class UtilsTest
|
||||||
|
{
|
||||||
|
[Fact]
|
||||||
|
public void TestGetDbParamtersByObject()
|
||||||
|
{
|
||||||
|
var ps = FreeSql.Internal.Utils.
|
||||||
|
GetDbParamtersByObject<DbParameter>("select @p",
|
||||||
|
new { p = (DbParameter)new SqlParameter() { ParameterName = "p", Value = "test" } },
|
||||||
|
"@",
|
||||||
|
(name, type, value) =>
|
||||||
|
{
|
||||||
|
if (value?.Equals(DateTime.MinValue) == true) value = new DateTime(1970, 1, 1);
|
||||||
|
var ret = new SqlParameter { ParameterName = $"@{name}", Value = value };
|
||||||
|
return ret;
|
||||||
|
});
|
||||||
|
Assert.Single(ps);
|
||||||
|
Assert.Equal("test", ps[0].Value);
|
||||||
|
Assert.Equal("p", ps[0].ParameterName);
|
||||||
|
Assert.Equal(typeof(SqlParameter), ps[0].GetType());
|
||||||
|
|
||||||
|
|
||||||
|
var ps2 = FreeSql.Internal.Utils.
|
||||||
|
GetDbParamtersByObject<DbParameter>("select @p",
|
||||||
|
new Dictionary<string, DbParameter> { { "p", (DbParameter)new SqlParameter() { ParameterName = "p", Value = "test" } } },
|
||||||
|
"@",
|
||||||
|
(name, type, value) =>
|
||||||
|
{
|
||||||
|
if (value?.Equals(DateTime.MinValue) == true) value = new DateTime(1970, 1, 1);
|
||||||
|
var ret = new SqlParameter { ParameterName = $"@{name}", Value = value };
|
||||||
|
return ret;
|
||||||
|
});
|
||||||
|
Assert.Single(ps2);
|
||||||
|
Assert.Equal("test", ps2[0].Value);
|
||||||
|
Assert.Equal("p", ps2[0].ParameterName);
|
||||||
|
Assert.Equal(typeof(SqlParameter), ps2[0].GetType());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -22,6 +22,27 @@ namespace FreeSql.Tests.MsAccess
|
|||||||
public DateTime CreateTime { get; set; }
|
public DateTime CreateTime { get; set; }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void InsertDictionary()
|
||||||
|
{
|
||||||
|
var fsql = g.msaccess;
|
||||||
|
Dictionary<string, object> dic = new Dictionary<string, object>();
|
||||||
|
dic.Add("id", 1);
|
||||||
|
dic.Add("name", "xxxx");
|
||||||
|
var diclist = new List<Dictionary<string, object>>();
|
||||||
|
diclist.Add(dic);
|
||||||
|
diclist.Add(new Dictionary<string, object>
|
||||||
|
{
|
||||||
|
["id"] = 2,
|
||||||
|
["name"] = "yyyy"
|
||||||
|
});
|
||||||
|
|
||||||
|
var sql1 = fsql.InsertDict(dic).AsTable("table1").ToSql();
|
||||||
|
Assert.Equal(@"INSERT INTO [table1]([id], [name]) VALUES(1, 'xxxx')", sql1);
|
||||||
|
var sql2 = fsql.InsertDict(diclist).AsTable("table1").ToSql();
|
||||||
|
Assert.Equal(@"INSERT INTO [table1]([id], [name]) VALUES(1, 'xxxx'), (2, 'yyyy')", sql2);
|
||||||
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void AppendData()
|
public void AppendData()
|
||||||
{
|
{
|
||||||
|
@ -30,6 +30,31 @@ namespace FreeSql.Tests.MySql
|
|||||||
}
|
}
|
||||||
enum TestEnumInserTbType { str1, biggit, sum211 }
|
enum TestEnumInserTbType { str1, biggit, sum211 }
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void InsertDictionary()
|
||||||
|
{
|
||||||
|
var fsql = g.mysql;
|
||||||
|
Dictionary<string, object> dic = new Dictionary<string, object>();
|
||||||
|
dic.Add("id", 1);
|
||||||
|
dic.Add("name", "xxxx");
|
||||||
|
var diclist = new List<Dictionary<string, object>>();
|
||||||
|
diclist.Add(dic);
|
||||||
|
diclist.Add(new Dictionary<string, object>
|
||||||
|
{
|
||||||
|
["id"] = 2,
|
||||||
|
["name"] = "yyyy"
|
||||||
|
});
|
||||||
|
|
||||||
|
var sql1 = fsql.InsertDict(dic).AsTable("table1").ToSql();
|
||||||
|
Assert.Equal(@"INSERT INTO `table1`(`id`, `name`) VALUES(?id_0, ?name_0)", sql1);
|
||||||
|
var sql2 = fsql.InsertDict(diclist).AsTable("table1").ToSql();
|
||||||
|
Assert.Equal(@"INSERT INTO `table1`(`id`, `name`) VALUES(?id_0, ?name_0), (?id_1, ?name_1)", sql2);
|
||||||
|
var sql3 = fsql.InsertDict(dic).AsTable("table1").NoneParameter().ToSql();
|
||||||
|
Assert.Equal(@"INSERT INTO `table1`(`id`, `name`) VALUES(1, 'xxxx')", sql3);
|
||||||
|
var sql4 = fsql.InsertDict(diclist).AsTable("table1").NoneParameter().ToSql();
|
||||||
|
Assert.Equal(@"INSERT INTO `table1`(`id`, `name`) VALUES(1, 'xxxx'), (2, 'yyyy')", sql4);
|
||||||
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void AppendData()
|
public void AppendData()
|
||||||
{
|
{
|
||||||
|
@ -11,6 +11,49 @@ namespace FreeSql.Tests.MySql
|
|||||||
{
|
{
|
||||||
public class MySqlCodeFirstTest
|
public class MySqlCodeFirstTest
|
||||||
{
|
{
|
||||||
|
public enum EnumTest009
|
||||||
|
{
|
||||||
|
A, B, C
|
||||||
|
}
|
||||||
|
|
||||||
|
[Flags]
|
||||||
|
public enum SetTest009
|
||||||
|
{
|
||||||
|
A = 1, B = 2, C = 4
|
||||||
|
}
|
||||||
|
|
||||||
|
public class TestTable009
|
||||||
|
{
|
||||||
|
[Column(IsPrimary = true, IsIdentity = true)]
|
||||||
|
public int Id { get; set; }
|
||||||
|
|
||||||
|
public EnumTest009 ColEnumTest { get; set; }
|
||||||
|
|
||||||
|
public SetTest009 ColSetTest { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void TestEnumToSet009()
|
||||||
|
{
|
||||||
|
var fsql = g.mysql;
|
||||||
|
//²åÈë
|
||||||
|
//insert into TestTable(ColEnumTest,ColSetTest) values('B','A,B');
|
||||||
|
//insert into TestTable(ColEnumTest,ColSetTest) values(1,3);
|
||||||
|
var sql1 = fsql.Insert<TestTable009>().NoneParameter().AppendData(new TestTable009
|
||||||
|
{
|
||||||
|
ColEnumTest = EnumTest009.B,
|
||||||
|
ColSetTest = SetTest009.A | SetTest009.B
|
||||||
|
}).ToSql();
|
||||||
|
Assert.Equal("INSERT INTO `TestTable009`(`ColEnumTest`, `ColSetTest`) VALUES('B', 'A,B')", sql1);
|
||||||
|
|
||||||
|
//²éѯ À©Õ¹·½·¨ contains
|
||||||
|
//select * from TestTable t where FIND_IN_SET('A',t.ColSetTest)>0
|
||||||
|
//select * from TestTable t where t.ColSetTest&1
|
||||||
|
var sql2 = fsql.Select<TestTable009>().Where(i => (i.ColSetTest & SetTest009.A) == SetTest009.A).ToSql();
|
||||||
|
var sql3 = fsql.Select<TestTable009>().Where(i => (i.ColSetTest & SetTest009.C) == SetTest009.C).ToSql();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void InsertUpdateParameter()
|
public void InsertUpdateParameter()
|
||||||
{
|
{
|
||||||
|
@ -22,6 +22,37 @@ namespace FreeSql.Tests.Oracle
|
|||||||
public DateTime CreateTime { get; set; }
|
public DateTime CreateTime { get; set; }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void InsertDictionary()
|
||||||
|
{
|
||||||
|
var fsql = g.oracle;
|
||||||
|
Dictionary<string, object> dic = new Dictionary<string, object>();
|
||||||
|
dic.Add("id", 1);
|
||||||
|
dic.Add("name", "xxxx");
|
||||||
|
var diclist = new List<Dictionary<string, object>>();
|
||||||
|
diclist.Add(dic);
|
||||||
|
diclist.Add(new Dictionary<string, object>
|
||||||
|
{
|
||||||
|
["id"] = 2,
|
||||||
|
["name"] = "yyyy"
|
||||||
|
});
|
||||||
|
|
||||||
|
var sql1 = fsql.InsertDict(dic).AsTable("table1").ToSql();
|
||||||
|
Assert.Equal(@"INSERT INTO ""TABLE1""(""ID"", ""NAME"") VALUES(:id_0, :name_0)", sql1);
|
||||||
|
var sql2 = fsql.InsertDict(diclist).AsTable("table1").ToSql();
|
||||||
|
Assert.Equal(@"INSERT ALL
|
||||||
|
INTO ""TABLE1""(""ID"", ""NAME"") VALUES(:id_0, :name_0)
|
||||||
|
INTO ""TABLE1""(""ID"", ""NAME"") VALUES(:id_1, :name_1)
|
||||||
|
SELECT 1 FROM DUAL", sql2);
|
||||||
|
var sql3 = fsql.InsertDict(dic).AsTable("table1").NoneParameter().ToSql();
|
||||||
|
Assert.Equal(@"INSERT INTO ""TABLE1""(""ID"", ""NAME"") VALUES(1, 'xxxx')", sql3);
|
||||||
|
var sql4 = fsql.InsertDict(diclist).AsTable("table1").NoneParameter().ToSql();
|
||||||
|
Assert.Equal(@"INSERT ALL
|
||||||
|
INTO ""TABLE1""(""ID"", ""NAME"") VALUES(1, 'xxxx')
|
||||||
|
INTO ""TABLE1""(""ID"", ""NAME"") VALUES(2, 'yyyy')
|
||||||
|
SELECT 1 FROM DUAL", sql4);
|
||||||
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void AppendData()
|
public void AppendData()
|
||||||
{
|
{
|
||||||
|
@ -22,6 +22,31 @@ namespace FreeSql.Tests.PostgreSQL
|
|||||||
public DateTime CreateTime { get; set; }
|
public DateTime CreateTime { get; set; }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void InsertDictionary()
|
||||||
|
{
|
||||||
|
var fsql = g.pgsql;
|
||||||
|
Dictionary<string, object> dic = new Dictionary<string, object>();
|
||||||
|
dic.Add("id", 1);
|
||||||
|
dic.Add("name", "xxxx");
|
||||||
|
var diclist = new List<Dictionary<string, object>>();
|
||||||
|
diclist.Add(dic);
|
||||||
|
diclist.Add(new Dictionary<string, object>
|
||||||
|
{
|
||||||
|
["id"] = 2,
|
||||||
|
["name"] = "yyyy"
|
||||||
|
});
|
||||||
|
|
||||||
|
var sql1 = fsql.InsertDict(dic).AsTable("table1").ToSql();
|
||||||
|
Assert.Equal(@"INSERT INTO ""table1""(""id"", ""name"") VALUES(@id_0, @name_0)", sql1);
|
||||||
|
var sql2 = fsql.InsertDict(diclist).AsTable("table1").ToSql();
|
||||||
|
Assert.Equal(@"INSERT INTO ""table1""(""id"", ""name"") VALUES(@id_0, @name_0), (@id_1, @name_1)", sql2);
|
||||||
|
var sql3 = fsql.InsertDict(dic).AsTable("table1").NoneParameter().ToSql();
|
||||||
|
Assert.Equal(@"INSERT INTO ""table1""(""id"", ""name"") VALUES(1, 'xxxx')", sql3);
|
||||||
|
var sql4 = fsql.InsertDict(diclist).AsTable("table1").NoneParameter().ToSql();
|
||||||
|
Assert.Equal(@"INSERT INTO ""table1""(""id"", ""name"") VALUES(1, 'xxxx'), (2, 'yyyy')", sql4);
|
||||||
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void AppendData()
|
public void AppendData()
|
||||||
{
|
{
|
||||||
|
@ -24,6 +24,17 @@ namespace FreeSql.Tests.PostgreSQL
|
|||||||
public void GetTableByName()
|
public void GetTableByName()
|
||||||
{
|
{
|
||||||
var fsql = g.pgsql;
|
var fsql = g.pgsql;
|
||||||
|
|
||||||
|
fsql.Ado.ExecuteNonQuery(@"CREATE TABLE IF NOT EXISTS public.table_test
|
||||||
|
(
|
||||||
|
id integer NOT NULL,
|
||||||
|
coin_list money[],
|
||||||
|
PRIMARY KEY (id)
|
||||||
|
)");
|
||||||
|
var t111 = fsql.DbFirst.GetTableByName("table_test");
|
||||||
|
Assert.True(t111.Columns.Find(a => a.Name == "id").IsPrimary);
|
||||||
|
Assert.False(t111.Columns.Find(a => a.Name == "coin_list").IsPrimary);
|
||||||
|
|
||||||
var t1 = fsql.DbFirst.GetTableByName("tb_alltype");
|
var t1 = fsql.DbFirst.GetTableByName("tb_alltype");
|
||||||
var t2 = fsql.DbFirst.GetTableByName("public.tb_alltype");
|
var t2 = fsql.DbFirst.GetTableByName("public.tb_alltype");
|
||||||
Assert.NotNull(t1);
|
Assert.NotNull(t1);
|
||||||
|
@ -22,6 +22,31 @@ namespace FreeSql.Tests.ShenTong
|
|||||||
public DateTime CreateTime { get; set; }
|
public DateTime CreateTime { get; set; }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void InsertDictionary()
|
||||||
|
{
|
||||||
|
var fsql = g.shentong;
|
||||||
|
Dictionary<string, object> dic = new Dictionary<string, object>();
|
||||||
|
dic.Add("id", 1);
|
||||||
|
dic.Add("name", "xxxx");
|
||||||
|
var diclist = new List<Dictionary<string, object>>();
|
||||||
|
diclist.Add(dic);
|
||||||
|
diclist.Add(new Dictionary<string, object>
|
||||||
|
{
|
||||||
|
["id"] = 2,
|
||||||
|
["name"] = "yyyy"
|
||||||
|
});
|
||||||
|
|
||||||
|
var sql1 = fsql.InsertDict(dic).AsTable("table1").ToSql();
|
||||||
|
Assert.Equal(@"INSERT INTO ""TABLE1""(""ID"", ""NAME"") VALUES(@id_0, @name_0)", sql1);
|
||||||
|
var sql2 = fsql.InsertDict(diclist).AsTable("table1").ToSql();
|
||||||
|
Assert.Equal(@"INSERT INTO ""TABLE1""(""ID"", ""NAME"") VALUES(@id_0, @name_0), (@id_1, @name_1)", sql2);
|
||||||
|
var sql3 = fsql.InsertDict(dic).AsTable("table1").NoneParameter().ToSql();
|
||||||
|
Assert.Equal(@"INSERT INTO ""TABLE1""(""ID"", ""NAME"") VALUES(1, 'xxxx')", sql3);
|
||||||
|
var sql4 = fsql.InsertDict(diclist).AsTable("table1").NoneParameter().ToSql();
|
||||||
|
Assert.Equal(@"INSERT INTO ""TABLE1""(""ID"", ""NAME"") VALUES(1, 'xxxx'), (2, 'yyyy')", sql4);
|
||||||
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void AppendData()
|
public void AppendData()
|
||||||
{
|
{
|
||||||
|
@ -32,6 +32,60 @@ namespace FreeSql.Tests.SqlServer
|
|||||||
public DateTime CreateTime { get; set; }
|
public DateTime CreateTime { get; set; }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void InsertDictionary()
|
||||||
|
{
|
||||||
|
var fsql = g.sqlserver;
|
||||||
|
fsql.Delete<object>().AsTable("table1dict").Where("1=1").ExecuteAffrows();
|
||||||
|
|
||||||
|
Dictionary<string, object> dic = new Dictionary<string, object>();
|
||||||
|
dic.Add("id", 1);
|
||||||
|
dic.Add("name", "xxxx");
|
||||||
|
var diclist = new List<Dictionary<string, object>>();
|
||||||
|
diclist.Add(dic);
|
||||||
|
diclist.Add(new Dictionary<string, object>
|
||||||
|
{
|
||||||
|
["id"] = 2,
|
||||||
|
["name"] = "yyyy"
|
||||||
|
});
|
||||||
|
|
||||||
|
var sql1 = fsql.InsertDict(dic).AsTable("table1").ToSql();
|
||||||
|
Assert.Equal(@"INSERT INTO [table1]([id], [name]) VALUES(@id_0, @name_0)", sql1);
|
||||||
|
var sql2 = fsql.InsertDict(diclist).AsTable("table1").ToSql();
|
||||||
|
Assert.Equal(@"INSERT INTO [table1]([id], [name]) VALUES(@id_0, @name_0), (@id_1, @name_1)", sql2);
|
||||||
|
var sql3 = fsql.InsertDict(dic).AsTable("table1").NoneParameter().ToSql();
|
||||||
|
Assert.Equal(@"INSERT INTO [table1]([id], [name]) VALUES(1, N'xxxx')", sql3);
|
||||||
|
var sql4 = fsql.InsertDict(diclist).AsTable("table1").NoneParameter().ToSql();
|
||||||
|
Assert.Equal(@"INSERT INTO [table1]([id], [name]) VALUES(1, N'xxxx'), (2, N'yyyy')", sql4);
|
||||||
|
|
||||||
|
Assert.Equal(1, fsql.InsertDict(dic).AsTable("table1dict").ExecuteAffrows());
|
||||||
|
Assert.Equal(1, fsql.DeleteDict(dic).AsTable("table1dict").ExecuteAffrows());
|
||||||
|
Assert.Equal(1, fsql.InsertDict(dic).AsTable("table1dict").NoneParameter().ExecuteAffrows());
|
||||||
|
Assert.Equal(1, fsql.DeleteDict(dic).AsTable("table1dict").ExecuteAffrows());
|
||||||
|
|
||||||
|
Assert.Equal(2, fsql.InsertDict(diclist).AsTable("table1dict").ExecuteAffrows());
|
||||||
|
Assert.Equal(2, fsql.DeleteDict(diclist).AsTable("table1dict").ExecuteAffrows());
|
||||||
|
Assert.Equal(2, fsql.InsertDict(diclist).AsTable("table1dict").NoneParameter().ExecuteAffrows());
|
||||||
|
Assert.Equal(2, fsql.DeleteDict(diclist).AsTable("table1dict").ExecuteAffrows());
|
||||||
|
|
||||||
|
|
||||||
|
var dicRet = fsql.InsertDict(dic).AsTable("table1dict").ExecuteInserted();
|
||||||
|
dicRet = fsql.DeleteDict(dic).AsTable("table1dict").ExecuteDeleted();
|
||||||
|
dicRet = fsql.InsertDict(dic).AsTable("table1dict").NoneParameter().ExecuteInserted();
|
||||||
|
dicRet = fsql.DeleteDict(dic).AsTable("table1dict").ExecuteDeleted();
|
||||||
|
|
||||||
|
dicRet = fsql.InsertDict(diclist).AsTable("table1dict").ExecuteInserted();
|
||||||
|
dicRet = fsql.DeleteDict(diclist).AsTable("table1dict").ExecuteDeleted();
|
||||||
|
dicRet = fsql.InsertDict(diclist).AsTable("table1dict").NoneParameter().ExecuteInserted();
|
||||||
|
dicRet = fsql.DeleteDict(diclist).AsTable("table1dict").ExecuteDeleted();
|
||||||
|
|
||||||
|
sql1 = fsql.InsertOrUpdateDict(dic).AsTable("table1").WherePrimary("id").ToSql();
|
||||||
|
sql2 = fsql.InsertOrUpdateDict(diclist).AsTable("table1").WherePrimary("id").ToSql();
|
||||||
|
|
||||||
|
sql1 = fsql.InsertOrUpdateDict(dic).AsTable("table1").WherePrimary("name").ToSql();
|
||||||
|
sql2 = fsql.InsertOrUpdateDict(diclist).AsTable("table1").WherePrimary("name").ToSql();
|
||||||
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void AppendData()
|
public void AppendData()
|
||||||
{
|
{
|
||||||
|
@ -22,6 +22,31 @@ namespace FreeSql.Tests.Sqlite
|
|||||||
public DateTime CreateTime { get; set; }
|
public DateTime CreateTime { get; set; }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void InsertDictionary()
|
||||||
|
{
|
||||||
|
var fsql = g.sqlite;
|
||||||
|
Dictionary<string, object> dic = new Dictionary<string, object>();
|
||||||
|
dic.Add("id", 1);
|
||||||
|
dic.Add("name", "xxxx");
|
||||||
|
var diclist = new List<Dictionary<string, object>>();
|
||||||
|
diclist.Add(dic);
|
||||||
|
diclist.Add(new Dictionary<string, object>
|
||||||
|
{
|
||||||
|
["id"] = 2,
|
||||||
|
["name"] = "yyyy"
|
||||||
|
});
|
||||||
|
|
||||||
|
var sql1 = fsql.InsertDict(dic).AsTable("table1").ToSql();
|
||||||
|
Assert.Equal(@"INSERT INTO ""table1""(""id"", ""name"") VALUES(@id_0, @name_0)", sql1);
|
||||||
|
var sql2 = fsql.InsertDict(diclist).AsTable("table1").ToSql();
|
||||||
|
Assert.Equal(@"INSERT INTO ""table1""(""id"", ""name"") VALUES(@id_0, @name_0), (@id_1, @name_1)", sql2);
|
||||||
|
var sql3 = fsql.InsertDict(dic).AsTable("table1").NoneParameter().ToSql();
|
||||||
|
Assert.Equal(@"INSERT INTO ""table1""(""id"", ""name"") VALUES(1, 'xxxx')", sql3);
|
||||||
|
var sql4 = fsql.InsertDict(diclist).AsTable("table1").NoneParameter().ToSql();
|
||||||
|
Assert.Equal(@"INSERT INTO ""table1""(""id"", ""name"") VALUES(1, 'xxxx'), (2, 'yyyy')", sql4);
|
||||||
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void AppendData()
|
public void AppendData()
|
||||||
{
|
{
|
||||||
|
@ -1,12 +1,15 @@
|
|||||||
using FreeSql.DataAnnotations;
|
using FreeSql.DataAnnotations;
|
||||||
using FreeSql.Internal.Model;
|
using FreeSql.Internal.Model;
|
||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
|
using Newtonsoft.Json.Linq;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
using System.Text;
|
||||||
using Xunit;
|
using Xunit;
|
||||||
|
using FreeSql.Internal.CommonProvider;
|
||||||
|
|
||||||
namespace FreeSql.Tests.Sqlite
|
namespace FreeSql.Tests.Sqlite
|
||||||
{
|
{
|
||||||
@ -147,6 +150,7 @@ namespace FreeSql.Tests.Sqlite
|
|||||||
var dt1 = select.Limit(10).ToDataTable();
|
var dt1 = select.Limit(10).ToDataTable();
|
||||||
var dt2 = select.Limit(10).ToDataTable("id, 111222");
|
var dt2 = select.Limit(10).ToDataTable("id, 111222");
|
||||||
var dt3 = select.Limit(10).ToDataTable(a => new { a.Id, a.Type.Name, now = DateTime.Now });
|
var dt3 = select.Limit(10).ToDataTable(a => new { a.Id, a.Type.Name, now = DateTime.Now });
|
||||||
|
var dt4 = select.Limit(10).ToDataTableByPropertyName(new[] { "a.Id", "a.Type.Name", "Title", "clicks" });
|
||||||
}
|
}
|
||||||
class TestDto
|
class TestDto
|
||||||
{
|
{
|
||||||
@ -366,6 +370,9 @@ namespace FreeSql.Tests.Sqlite
|
|||||||
var query = select.LeftJoin(a => a.Type.Guid == a.TypeGuid);
|
var query = select.LeftJoin(a => a.Type.Guid == a.TypeGuid);
|
||||||
var sql = query.ToSql().Replace("\r\n", "");
|
var sql = query.ToSql().Replace("\r\n", "");
|
||||||
Assert.Equal("SELECT a.\"Id\", a.\"Clicks\", a.\"TypeGuid\", a__Type.\"Guid\", a__Type.\"ParentId\", a__Type.\"Name\", a.\"Title\", a.\"CreateTime\" FROM \"tb_topic22\" a LEFT JOIN \"TestTypeInfo\" a__Type ON a__Type.\"Guid\" = a.\"TypeGuid\"", sql);
|
Assert.Equal("SELECT a.\"Id\", a.\"Clicks\", a.\"TypeGuid\", a__Type.\"Guid\", a__Type.\"ParentId\", a__Type.\"Name\", a.\"Title\", a.\"CreateTime\" FROM \"tb_topic22\" a LEFT JOIN \"TestTypeInfo\" a__Type ON a__Type.\"Guid\" = a.\"TypeGuid\"", sql);
|
||||||
|
(query as Select0Provider)._tables.Where(a => a.Table.Type == typeof(TestTypeInfo))
|
||||||
|
.First()
|
||||||
|
.Type = SelectTableInfoType.InnerJoin;
|
||||||
query.ToList();
|
query.ToList();
|
||||||
|
|
||||||
query = select.LeftJoin(a => a.Type.Guid == a.TypeGuid && a.Type.Name == "xxx");
|
query = select.LeftJoin(a => a.Type.Guid == a.TypeGuid && a.Type.Name == "xxx");
|
||||||
@ -682,6 +689,18 @@ namespace FreeSql.Tests.Sqlite
|
|||||||
.Any()
|
.Any()
|
||||||
).Any()
|
).Any()
|
||||||
).ToList();
|
).ToList();
|
||||||
|
|
||||||
|
sql2222 = select.Where(a =>
|
||||||
|
select.Where(b => b.Id == a.Id &&
|
||||||
|
select
|
||||||
|
.Where(c => c.Id == b.Id)
|
||||||
|
.Where(d => d.Id == a.Id)
|
||||||
|
.Where(e => e.Id == b.Id)
|
||||||
|
.WhereIf(!sql2222.Any(), e => e.Id > 0)
|
||||||
|
.WhereIf(sql2222.Any(), e => e.Id >= 0)
|
||||||
|
.Any()
|
||||||
|
).Any()
|
||||||
|
).ToList();
|
||||||
}
|
}
|
||||||
[Fact]
|
[Fact]
|
||||||
public void GroupBy()
|
public void GroupBy()
|
||||||
@ -693,6 +712,7 @@ namespace FreeSql.Tests.Sqlite
|
|||||||
.Having(a => a.Count() > 0 && a.Avg(a.Key.mod4) > 0 && a.Max(a.Key.mod4) > 0)
|
.Having(a => a.Count() > 0 && a.Avg(a.Key.mod4) > 0 && a.Max(a.Key.mod4) > 0)
|
||||||
.Having(a => a.Count() < 300 || a.Avg(a.Key.mod4) < 100)
|
.Having(a => a.Count() < 300 || a.Avg(a.Key.mod4) < 100)
|
||||||
.OrderBy(a => a.Key.tt2)
|
.OrderBy(a => a.Key.tt2)
|
||||||
|
.OrderByDescending(a => new { a.Key.tt2, a.Key.mod4 })
|
||||||
.OrderByDescending(a => a.Count())
|
.OrderByDescending(a => a.Count())
|
||||||
.Offset(10)
|
.Offset(10)
|
||||||
.Limit(2)
|
.Limit(2)
|
||||||
@ -804,7 +824,17 @@ namespace FreeSql.Tests.Sqlite
|
|||||||
[Fact]
|
[Fact]
|
||||||
public void OrderBy()
|
public void OrderBy()
|
||||||
{
|
{
|
||||||
var sql = select.OrderBy(a => new Random().NextDouble()).ToList();
|
var sql = select.OrderBy(a => new Random().NextDouble()).ToSql();
|
||||||
|
|
||||||
|
sql = select.OrderBy(a => a.Id).OrderBy(a => a.Title).OrderByDescending(a => a.CreateTime).ToSql();
|
||||||
|
Assert.Equal(@"SELECT a.""Id"", a.""Clicks"", a.""TypeGuid"", a.""Title"", a.""CreateTime""
|
||||||
|
FROM ""tb_topic22"" a
|
||||||
|
ORDER BY a.""Id"", a.""Title"", a.""CreateTime"" DESC", sql);
|
||||||
|
|
||||||
|
sql = select.OrderBy(a => new { a.Id, a.Title }).OrderByDescending(a => a.CreateTime).ToSql();
|
||||||
|
Assert.Equal(@"SELECT a.""Id"", a.""Clicks"", a.""TypeGuid"", a.""Title"", a.""CreateTime""
|
||||||
|
FROM ""tb_topic22"" a
|
||||||
|
ORDER BY a.""Id"", a.""Title"", a.""CreateTime"" DESC", sql);
|
||||||
}
|
}
|
||||||
[Fact]
|
[Fact]
|
||||||
public void OrderByRandom()
|
public void OrderByRandom()
|
||||||
@ -1222,7 +1252,7 @@ WHERE (((cast(a.""Id"" as character)) in (SELECT b.""Title""
|
|||||||
//---- Select ----
|
//---- Select ----
|
||||||
|
|
||||||
var at0 = g.sqlite.Select<TestInclude_OneToManyModel2>()
|
var at0 = g.sqlite.Select<TestInclude_OneToManyModel2>()
|
||||||
.IncludeMany(a => a.childs.Where(m3 => m3.model2111Idaaa == a.model2id).Select(m3 => new TestInclude_OneToManyModel3 { id = m3.id }))
|
.IncludeMany(a => a.childs.Where(m3 => m3.model2111Idaaa == a.model2id).Select(m3 => new TestInclude_OneToManyModel3 { id = m3.id }))
|
||||||
.Where(a => a.model2id <= model1.id)
|
.Where(a => a.model2id <= model1.id)
|
||||||
.ToList();
|
.ToList();
|
||||||
var at001 = g.sqlite.Select<TestInclude_OneToManyModel2>()
|
var at001 = g.sqlite.Select<TestInclude_OneToManyModel2>()
|
||||||
@ -1230,19 +1260,23 @@ WHERE (((cast(a.""Id"" as character)) in (SELECT b.""Title""
|
|||||||
.Where(a => a.model2id <= model1.id)
|
.Where(a => a.model2id <= model1.id)
|
||||||
.ToList(a => new
|
.ToList(a => new
|
||||||
{
|
{
|
||||||
a.model2id, a.childs, childs2 = a.childs
|
a.model2id,
|
||||||
|
a.childs,
|
||||||
|
childs2 = a.childs
|
||||||
});
|
});
|
||||||
|
|
||||||
var at1 = g.sqlite.Select<TestInclude_OneToManyModel1>()
|
var at1 = g.sqlite.Select<TestInclude_OneToManyModel1>()
|
||||||
.IncludeMany(a => a.model2.childs.Where(m3 => m3.model2111Idaaa == a.model2.model2id).Select(m3 => new TestInclude_OneToManyModel3 { id = m3.id }))
|
.IncludeMany(a => a.model2.childs.Where(m3 => m3.model2111Idaaa == a.model2.model2id).Select(m3 => new TestInclude_OneToManyModel3 { id = m3.id }))
|
||||||
.Where(a => a.id <= model1.id)
|
.Where(a => a.id <= model1.id)
|
||||||
.ToList();
|
.ToList();
|
||||||
var at111 = g.sqlite.Select<TestInclude_OneToManyModel1>()
|
var at111 = g.sqlite.Select<TestInclude_OneToManyModel1>()
|
||||||
.IncludeMany(a => a.model2.childs.Where(m3 => m3.model2111Idaaa == a.model2.model2id).Select(m3 => new TestInclude_OneToManyModel3 { id = m3.id }))
|
.IncludeMany(a => a.model2.childs.Where(m3 => m3.model2111Idaaa == a.model2.model2id).Select(m3 => new TestInclude_OneToManyModel3 { id = m3.id }))
|
||||||
.Where(a => a.id <= model1.id)
|
.Where(a => a.id <= model1.id)
|
||||||
.ToList(a => new
|
.ToList(a => new
|
||||||
{
|
{
|
||||||
a.id, a.model2.childs, childs2 = a.model2.childs
|
a.id,
|
||||||
|
a.model2.childs,
|
||||||
|
childs2 = a.model2.childs
|
||||||
});
|
});
|
||||||
|
|
||||||
var at2 = g.sqlite.Select<TestInclude_OneToManyModel1>()
|
var at2 = g.sqlite.Select<TestInclude_OneToManyModel1>()
|
||||||
@ -1256,7 +1290,9 @@ WHERE (((cast(a.""Id"" as character)) in (SELECT b.""Title""
|
|||||||
.Where(a => a.id <= model1.id)
|
.Where(a => a.id <= model1.id)
|
||||||
.ToList(a => new
|
.ToList(a => new
|
||||||
{
|
{
|
||||||
a.id, a.model2.childs, childs2 = a.model2.childs
|
a.id,
|
||||||
|
a.model2.childs,
|
||||||
|
childs2 = a.model2.childs
|
||||||
});
|
});
|
||||||
|
|
||||||
var at00 = g.sqlite.Select<TestInclude_OneToManyModel2>()
|
var at00 = g.sqlite.Select<TestInclude_OneToManyModel2>()
|
||||||
@ -1268,7 +1304,9 @@ WHERE (((cast(a.""Id"" as character)) in (SELECT b.""Title""
|
|||||||
.Where(a => a.model2id <= model1.id)
|
.Where(a => a.model2id <= model1.id)
|
||||||
.ToList(a => new
|
.ToList(a => new
|
||||||
{
|
{
|
||||||
a.model2id, a.childs, childs2 = a.childs
|
a.model2id,
|
||||||
|
a.childs,
|
||||||
|
childs2 = a.childs
|
||||||
});
|
});
|
||||||
|
|
||||||
var at11 = g.sqlite.Select<TestInclude_OneToManyModel1>()
|
var at11 = g.sqlite.Select<TestInclude_OneToManyModel1>()
|
||||||
@ -1279,9 +1317,11 @@ WHERE (((cast(a.""Id"" as character)) in (SELECT b.""Title""
|
|||||||
.IncludeMany(a => a.model2.childs.Take(1).Where(m3 => m3.model2111Idaaa == a.model2.model2id).Select(m3 => new TestInclude_OneToManyModel3 { id = m3.id }))
|
.IncludeMany(a => a.model2.childs.Take(1).Where(m3 => m3.model2111Idaaa == a.model2.model2id).Select(m3 => new TestInclude_OneToManyModel3 { id = m3.id }))
|
||||||
.Where(a => a.id <= model1.id)
|
.Where(a => a.id <= model1.id)
|
||||||
.ToList(a => new
|
.ToList(a => new
|
||||||
{
|
{
|
||||||
a.id, a.model2.childs, childs2 = a.model2.childs
|
a.id,
|
||||||
});
|
a.model2.childs,
|
||||||
|
childs2 = a.model2.childs
|
||||||
|
});
|
||||||
|
|
||||||
var at22 = g.sqlite.Select<TestInclude_OneToManyModel1>()
|
var at22 = g.sqlite.Select<TestInclude_OneToManyModel1>()
|
||||||
.IncludeMany(a => a.model2.childs.Take(1).Where(m3 => m3.model2111Idaaa == a.model2.model2id).Select(m3 => new TestInclude_OneToManyModel3 { id = m3.id }),
|
.IncludeMany(a => a.model2.childs.Take(1).Where(m3 => m3.model2111Idaaa == a.model2.model2id).Select(m3 => new TestInclude_OneToManyModel3 { id = m3.id }),
|
||||||
@ -1294,7 +1334,9 @@ WHERE (((cast(a.""Id"" as character)) in (SELECT b.""Title""
|
|||||||
.Where(a => a.id <= model1.id)
|
.Where(a => a.id <= model1.id)
|
||||||
.ToList(a => new
|
.ToList(a => new
|
||||||
{
|
{
|
||||||
a.id, a.model2.childs, childs2 = a.model2.childs
|
a.id,
|
||||||
|
a.model2.childs,
|
||||||
|
childs2 = a.model2.childs
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1713,7 +1755,9 @@ WHERE (((cast(a.""Id"" as character)) in (SELECT b.""Title""
|
|||||||
.Where(a => a.Id == song1.Id || a.Id == song2.Id || a.Id == song3.Id)
|
.Where(a => a.Id == song1.Id || a.Id == song2.Id || a.Id == song3.Id)
|
||||||
.ToList(a => new
|
.ToList(a => new
|
||||||
{
|
{
|
||||||
a.Id, a.Is_deleted, a.Tags
|
a.Id,
|
||||||
|
a.Is_deleted,
|
||||||
|
a.Tags
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2470,6 +2514,33 @@ ORDER BY a__Parent.""Name""", sql);
|
|||||||
Assert.Equal(@"SELECT a.""id"", a.""name"", a.""no"", a.""status""
|
Assert.Equal(@"SELECT a.""id"", a.""name"", a.""no"", a.""status""
|
||||||
FROM ""ts_dyfilter_enum01"" a
|
FROM ""ts_dyfilter_enum01"" a
|
||||||
WHERE ((not((a.""name"") LIKE '%testname01') OR not((a.""no"") LIKE '%testname01') OR not((a.""id"") LIKE '%testname01') OR a.""status"" = 2))", sql);
|
WHERE ((not((a.""name"") LIKE '%testname01') OR not((a.""no"") LIKE '%testname01') OR not((a.""id"") LIKE '%testname01') OR a.""status"" = 2))", sql);
|
||||||
|
|
||||||
|
sql = fsql.Select<ts_dyfilter_enum01>().WhereDynamicFilter(JsonConvert.DeserializeObject<DynamicFilterInfo>(@"
|
||||||
|
{
|
||||||
|
""Logic"" : ""Or"",
|
||||||
|
""Filters"" :
|
||||||
|
[
|
||||||
|
{
|
||||||
|
""Field"" : ""MyRawSql FreeSql.Tests.Sqlite.DynamicFilterMyCustom,FreeSql.Tests"",
|
||||||
|
""Operator"" : ""Custom"",
|
||||||
|
""Value"" : ""(name,no) in (('testname01','testname01'))""
|
||||||
|
},
|
||||||
|
{
|
||||||
|
""Field"" : ""no"",
|
||||||
|
""Operator"" : ""NotEndsWith"",
|
||||||
|
""Value"" : ""testname01""
|
||||||
|
},
|
||||||
|
{
|
||||||
|
""Field"" : ""MyRawSql FreeSql.Tests.Sqlite.DynamicFilterMyCustom,FreeSql.Tests"",
|
||||||
|
""Operator"" : ""Custom"",
|
||||||
|
""Value"" : ""(id,status) in (('testname01','finished'))""
|
||||||
|
},
|
||||||
|
]
|
||||||
|
}
|
||||||
|
")).ToSql();
|
||||||
|
Assert.Equal(@"SELECT a.""id"", a.""name"", a.""no"", a.""status""
|
||||||
|
FROM ""ts_dyfilter_enum01"" a
|
||||||
|
WHERE (((name,no) in (('testname01','testname01')) OR not((a.""no"") LIKE '%testname01') OR (id,status) in (('testname01','finished'))))", sql);
|
||||||
}
|
}
|
||||||
|
|
||||||
class ts_dyfilter_enum01
|
class ts_dyfilter_enum01
|
||||||
@ -2481,4 +2552,37 @@ WHERE ((not((a.""name"") LIKE '%testname01') OR not((a.""no"") LIKE '%testname01
|
|||||||
}
|
}
|
||||||
public enum ts_dyfilter_enum01_status { staring, stoped, finished }
|
public enum ts_dyfilter_enum01_status { staring, stoped, finished }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public class DynamicFilterMyCustom
|
||||||
|
{
|
||||||
|
[DynamicFilterCustom]
|
||||||
|
public static string MyRawSql(string value) => value;
|
||||||
|
|
||||||
|
public static string TupleIn(string value)
|
||||||
|
{
|
||||||
|
var sb = new StringBuilder();
|
||||||
|
var array = JArray.Parse(value);
|
||||||
|
var row = 0;
|
||||||
|
foreach(JObject item in array)
|
||||||
|
{
|
||||||
|
if (row++ == 0)
|
||||||
|
{
|
||||||
|
sb.Append("(");
|
||||||
|
var propNames = item.Properties().Select(a => a.Name);
|
||||||
|
sb.Append(string.Join(", ", propNames));
|
||||||
|
sb.Append(") IN (");
|
||||||
|
}
|
||||||
|
if (row == array.Count - 1)
|
||||||
|
{
|
||||||
|
sb.Append(")");
|
||||||
|
}
|
||||||
|
if (row > 1) sb.Append(", ");
|
||||||
|
sb.Append("(");
|
||||||
|
var propValues = item.Values().Select(a => a?.ToString().Replace("'", "''")); //注入处理
|
||||||
|
sb.Append(string.Join(", ", propValues));
|
||||||
|
sb.Append(")");
|
||||||
|
}
|
||||||
|
return sb.ToString();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -24,7 +24,7 @@ namespace FreeSql.Tests
|
|||||||
{
|
{
|
||||||
public static T TryTo<T>(this string that)
|
public static T TryTo<T>(this string that)
|
||||||
{
|
{
|
||||||
return (T)Internal.Utils.GetDataReaderValue(typeof(T), that);
|
return (T)FreeSql.Internal.Utils.GetDataReaderValue(typeof(T), that);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static string FormatDateTime()
|
public static string FormatDateTime()
|
||||||
@ -311,7 +311,7 @@ namespace FreeSql.Tests
|
|||||||
public TaskBuild Parent { get; set; }
|
public TaskBuild Parent { get; set; }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void parseExp(object sender, Aop.ParseExpressionEventArgs e)
|
void parseExp(object sender, Aop.ParseExpressionEventArgs e)
|
||||||
{
|
{
|
||||||
@ -323,7 +323,7 @@ namespace FreeSql.Tests
|
|||||||
if (callExp.Method.Name == "TryTo")
|
if (callExp.Method.Name == "TryTo")
|
||||||
{
|
{
|
||||||
e.Result = Expression.Lambda(
|
e.Result = Expression.Lambda(
|
||||||
typeof(Func<>).MakeGenericType(callExp.Method.GetGenericArguments().FirstOrDefault()),
|
typeof(Func<>).MakeGenericType(callExp.Method.GetGenericArguments().FirstOrDefault()),
|
||||||
e.Expression).Compile().DynamicInvoke()?.ToString();
|
e.Expression).Compile().DynamicInvoke()?.ToString();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -464,10 +464,11 @@ namespace FreeSql.Tests
|
|||||||
emoji = g.sqlserver.Select<TestGuidId>().Where(a => a.Id == testemoji.Id).First();
|
emoji = g.sqlserver.Select<TestGuidId>().Where(a => a.Id == testemoji.Id).First();
|
||||||
Assert.Equal("💐🌸💮🌹🌺🌻🌼🌷🌱🌿🍀", emoji.xxx);
|
Assert.Equal("💐🌸💮🌹🌺🌻🌼🌷🌱🌿🍀", emoji.xxx);
|
||||||
|
|
||||||
var _model = new TestUpdateModel {
|
var _model = new TestUpdateModel
|
||||||
F_EmpId = "xx11",
|
{
|
||||||
F_RoleType = TestUpdateModelEnum.x2,
|
F_EmpId = "xx11",
|
||||||
F_UseType = TestUpdateModelEnum.x3
|
F_RoleType = TestUpdateModelEnum.x2,
|
||||||
|
F_UseType = TestUpdateModelEnum.x3
|
||||||
};
|
};
|
||||||
var testsql2008 = g.sqlserver.Update<TestUpdateModel>()
|
var testsql2008 = g.sqlserver.Update<TestUpdateModel>()
|
||||||
.Where(a => a.F_EmpId == _model.F_EmpId)
|
.Where(a => a.F_EmpId == _model.F_EmpId)
|
||||||
@ -578,7 +579,7 @@ namespace FreeSql.Tests
|
|||||||
|
|
||||||
var gkjdjd = g.sqlite.Select<AuthorTest>().Where(a => a.Post.AsSelect().Count() > 0).ToList();
|
var gkjdjd = g.sqlite.Select<AuthorTest>().Where(a => a.Post.AsSelect().Count() > 0).ToList();
|
||||||
|
|
||||||
var testrunsql1 = g.mysql.Select<TaskBuild>().Where(a => a.OptionsEntity04 > DateTime.Now.AddDays(0).ToString("yyyyMMdd").TryTo<int>()).ToSql();
|
var testrunsql1 = g.mysql.Select<TaskBuild>().Where(a => a.OptionsEntity04 > DateTime.Now.AddDays(0).ToString("yyyyMMdd").TryTo<int>()).ToSql();
|
||||||
var testrunsql2 = g.pgsql.Select<TaskBuild>().Where(a => a.OptionsEntity04 > DateTime.Now.AddDays(0).ToString("yyyyMMdd").TryTo<int>()).ToSql();
|
var testrunsql2 = g.pgsql.Select<TaskBuild>().Where(a => a.OptionsEntity04 > DateTime.Now.AddDays(0).ToString("yyyyMMdd").TryTo<int>()).ToSql();
|
||||||
var testrunsql3 = g.sqlserver.Select<TaskBuild>().Where(a => a.OptionsEntity04 > DateTime.Now.AddDays(0).ToString("yyyyMMdd").TryTo<int>()).ToSql();
|
var testrunsql3 = g.sqlserver.Select<TaskBuild>().Where(a => a.OptionsEntity04 > DateTime.Now.AddDays(0).ToString("yyyyMMdd").TryTo<int>()).ToSql();
|
||||||
var testrunsql4 = g.oracle.Select<TaskBuild>().Where(a => a.OptionsEntity04 > DateTime.Now.AddDays(0).ToString("yyyyMMdd").TryTo<int>()).ToSql();
|
var testrunsql4 = g.oracle.Select<TaskBuild>().Where(a => a.OptionsEntity04 > DateTime.Now.AddDays(0).ToString("yyyyMMdd").TryTo<int>()).ToSql();
|
||||||
@ -600,18 +601,18 @@ namespace FreeSql.Tests
|
|||||||
|
|
||||||
IFreeSql fsql = new FreeSql.FreeSqlBuilder()
|
IFreeSql fsql = new FreeSql.FreeSqlBuilder()
|
||||||
.UseConnectionString(FreeSql.DataType.PostgreSQL, "Host=192.168.164.10;Port=5432;Username=postgres;Password=123456;Database=tedb;Pooling=true;Maximum Pool Size=7")
|
.UseConnectionString(FreeSql.DataType.PostgreSQL, "Host=192.168.164.10;Port=5432;Username=postgres;Password=123456;Database=tedb;Pooling=true;Maximum Pool Size=7")
|
||||||
.UseNameConvert(Internal.NameConvertType.PascalCaseToUnderscoreWithLower)
|
.UseNameConvert(FreeSql.Internal.NameConvertType.PascalCaseToUnderscoreWithLower)
|
||||||
.UseNoneCommandParameter(true)
|
.UseNoneCommandParameter(true)
|
||||||
.UseAutoSyncStructure(true) //自动同步实体结构到数据库
|
.UseAutoSyncStructure(true) //自动同步实体结构到数据库
|
||||||
.UseMonitorCommand(a => Trace.WriteLine(a.CommandText))
|
.UseMonitorCommand(a => Trace.WriteLine(a.CommandText))
|
||||||
.Build();
|
.Build();
|
||||||
|
|
||||||
var data = fsql.Select<Post>().ToList(r => new
|
var data = fsql.Select<Post>().ToList(r => new
|
||||||
{
|
{
|
||||||
Id = r.Id,
|
Id = r.Id,
|
||||||
Name = r.AuthorId.ToString(),
|
Name = r.AuthorId.ToString(),
|
||||||
AuthorName = r.Author.Name,
|
AuthorName = r.Author.Name,
|
||||||
});
|
});
|
||||||
|
|
||||||
//g.mysql.Aop.AuditValue += (s, e) =>
|
//g.mysql.Aop.AuditValue += (s, e) =>
|
||||||
//{
|
//{
|
||||||
@ -636,8 +637,8 @@ namespace FreeSql.Tests
|
|||||||
.Include(a => a.MedicalRecord)
|
.Include(a => a.MedicalRecord)
|
||||||
.ToSql();
|
.ToSql();
|
||||||
|
|
||||||
var dkdkd = g.mysql.Select<TaskBuild>().AsTable((t,old) => "TaskBuild22")
|
var dkdkd = g.mysql.Select<TaskBuild>().AsTable((t, old) => "TaskBuild22")
|
||||||
.ToList< TestDto>(a => new TestDto()
|
.ToList<TestDto>(a => new TestDto()
|
||||||
{
|
{
|
||||||
Id = a.Id,
|
Id = a.Id,
|
||||||
IsLeaf = g.mysql.Select<TaskBuild>().AsTable((t, old) => "TaskBuild22").Any(b => b.TemplatesId == a.Id)
|
IsLeaf = g.mysql.Select<TaskBuild>().AsTable((t, old) => "TaskBuild22").Any(b => b.TemplatesId == a.Id)
|
||||||
@ -645,13 +646,13 @@ namespace FreeSql.Tests
|
|||||||
|
|
||||||
|
|
||||||
var xxxkdkd = g.oracle.Select<Templates, TaskBuild>()
|
var xxxkdkd = g.oracle.Select<Templates, TaskBuild>()
|
||||||
.InnerJoin((a,b) => true)
|
.InnerJoin((a, b) => true)
|
||||||
.Where((a,b) => (DateTime.Now - a.EditTime).TotalMinutes > 100)
|
.Where((a, b) => (DateTime.Now - a.EditTime).TotalMinutes > 100)
|
||||||
.OrderBy((a,b) => g.oracle.Select<Templates>().Where(c => b.Id == c.Id2).Count())
|
.OrderBy((a, b) => g.oracle.Select<Templates>().Where(c => b.Id == c.Id2).Count())
|
||||||
.ToSql();
|
.ToSql();
|
||||||
|
|
||||||
|
|
||||||
g.oracle.Aop.SyncStructureAfter += (s, e) =>
|
|
||||||
|
g.oracle.Aop.SyncStructureAfter += (s, e) =>
|
||||||
Trace.WriteLine(e.Sql);
|
Trace.WriteLine(e.Sql);
|
||||||
|
|
||||||
g.oracle.CodeFirst.SyncStructure<Class1>();
|
g.oracle.CodeFirst.SyncStructure<Class1>();
|
||||||
@ -729,7 +730,7 @@ namespace FreeSql.Tests
|
|||||||
.ToSql(a => new NewsArticleDto
|
.ToSql(a => new NewsArticleDto
|
||||||
{
|
{
|
||||||
ArticleTitle = a.Key,
|
ArticleTitle = a.Key,
|
||||||
ChannelId = (int)a.Sum(a.Value.Item1.OptionsEntity04)
|
ChannelId = (int)a.Sum(a.Value.Item1.OptionsEntity04)
|
||||||
});
|
});
|
||||||
|
|
||||||
var testgrpsql2 = g.sqlite.Select<TaskBuild>()
|
var testgrpsql2 = g.sqlite.Select<TaskBuild>()
|
||||||
@ -1004,7 +1005,7 @@ namespace FreeSql.Tests
|
|||||||
cou = b.Count(),
|
cou = b.Count(),
|
||||||
sum = b.Sum(b.Key.yyyy),
|
sum = b.Sum(b.Key.yyyy),
|
||||||
sum2 = b.Sum(b.Value.TypeGuid)
|
sum2 = b.Sum(b.Value.TypeGuid)
|
||||||
});
|
});
|
||||||
var aggtolist22 = select
|
var aggtolist22 = select
|
||||||
.GroupBy(a => new { a.Title, yyyy = string.Concat(a.CreateTime.Year, '-', a.CreateTime.Month) })
|
.GroupBy(a => new { a.Title, yyyy = string.Concat(a.CreateTime.Year, '-', a.CreateTime.Month) })
|
||||||
.ToDictionaryAsync(b => new
|
.ToDictionaryAsync(b => new
|
||||||
|
@ -18,7 +18,7 @@ namespace FreeSql.Tests
|
|||||||
public void WithLambdaParameter01()
|
public void WithLambdaParameter01()
|
||||||
{
|
{
|
||||||
using (var fsql = new FreeSql.FreeSqlBuilder()
|
using (var fsql = new FreeSql.FreeSqlBuilder()
|
||||||
.UseConnectionString(FreeSql.DataType.SqlServer, "Data Source=.;Integrated Security=True;Initial Catalog=freesqlTest;Pooling=true;Max Pool Size=6")
|
.UseConnectionString(FreeSql.DataType.SqlServer, "Data Source=.;Integrated Security=True;Initial Catalog=freesqlTest;Pooling=true;Max Pool Size=6;TrustServerCertificate=true")
|
||||||
.UseAutoSyncStructure(true)
|
.UseAutoSyncStructure(true)
|
||||||
.UseGenerateCommandParameterWithLambda(true)
|
.UseGenerateCommandParameterWithLambda(true)
|
||||||
.UseMonitorCommand(
|
.UseMonitorCommand(
|
||||||
@ -339,7 +339,7 @@ GROUP BY a.""code"", a.""seqid"", a.""name""", sql);
|
|||||||
public void SelectLambdaParameter()
|
public void SelectLambdaParameter()
|
||||||
{
|
{
|
||||||
using (var fsql = new FreeSql.FreeSqlBuilder()
|
using (var fsql = new FreeSql.FreeSqlBuilder()
|
||||||
.UseConnectionString(FreeSql.DataType.SqlServer, "Data Source=.;Integrated Security=True;Initial Catalog=freesqlTest;Pooling=true;min pool size=1;Max Pool Size=51")
|
.UseConnectionString(FreeSql.DataType.SqlServer, "Data Source=.;Integrated Security=True;Initial Catalog=freesqlTest;Pooling=true;min pool size=1;Max Pool Size=51;TrustServerCertificate=true")
|
||||||
.UseAutoSyncStructure(true)
|
.UseAutoSyncStructure(true)
|
||||||
.UseGenerateCommandParameterWithLambda(true)
|
.UseGenerateCommandParameterWithLambda(true)
|
||||||
.UseMonitorCommand(
|
.UseMonitorCommand(
|
||||||
|
@ -16,6 +16,74 @@ namespace FreeSql.Tests
|
|||||||
{
|
{
|
||||||
public class UnitTest5
|
public class UnitTest5
|
||||||
{
|
{
|
||||||
|
// DTO
|
||||||
|
public class TestDto
|
||||||
|
{
|
||||||
|
public decimal ratio { get; set; }
|
||||||
|
public bool is_lock { get; set; }
|
||||||
|
}
|
||||||
|
[Fact]
|
||||||
|
public void TestDoubleWhereBug()
|
||||||
|
{
|
||||||
|
var fsql = g.mysql;
|
||||||
|
// 测试例子
|
||||||
|
var test = new TestDto();
|
||||||
|
test.ratio = 2.1M;
|
||||||
|
var sql = fsql.Update<TestDto>().Set(m => new TestDto
|
||||||
|
{
|
||||||
|
is_lock = test.ratio < 1 //这里生成的SQL语句有问题 ratio = 0.9 或 1.9 或 2.1 等等都是生成的是1
|
||||||
|
}).Where(m => test.ratio < 1).ToSql();
|
||||||
|
Assert.Equal(@"UPDATE TestDto SET is_lock = 2.1 < 1
|
||||||
|
WHERE (2.1 < 1)", sql);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void TestLambdaParameterWhereIn()
|
||||||
|
{
|
||||||
|
using (var fsql = new FreeSql.FreeSqlBuilder()
|
||||||
|
.UseConnectionString(FreeSql.DataType.Sqlite, @"Data Source=|DataDirectory|\TestLambdaParameterWhereIn.db")
|
||||||
|
.UseAutoSyncStructure(true)
|
||||||
|
.UseGenerateCommandParameterWithLambda(true)
|
||||||
|
.UseLazyLoading(true)
|
||||||
|
.UseMonitorCommand(
|
||||||
|
cmd => Trace.WriteLine("\r\n线程" + Thread.CurrentThread.ManagedThreadId + ": " + cmd.CommandText) //监听SQL命令对象,在执行前
|
||||||
|
//, (cmd, traceLog) => Console.WriteLine(traceLog)
|
||||||
|
)
|
||||||
|
.Build())
|
||||||
|
{
|
||||||
|
|
||||||
|
string dwId = "123456";
|
||||||
|
string yhId = "654321";
|
||||||
|
|
||||||
|
var sql = fsql.Select<wygl_wygs_gzry_wyglqyModelTest1>()
|
||||||
|
.Where(a => a.dw_id == dwId &&
|
||||||
|
fsql.Select<wygl_wygs_gzry_wyglqyModel>()
|
||||||
|
.Where(b => b.yh_id == yhId).ToList(b => b.wyqy_id).Contains(a.wyqy_id)
|
||||||
|
);
|
||||||
|
|
||||||
|
var sql1 = sql.ToSql();
|
||||||
|
Assert.Equal(@"SELECT a.""dw_id"", a.""wyqy_id""
|
||||||
|
FROM ""wygl_wygs_gzry_wyglqyModelTest1"" a
|
||||||
|
WHERE (a.""dw_id"" = @exp_0 AND ((a.""wyqy_id"") in (SELECT b.""wyqy_id""
|
||||||
|
FROM ""wygl_wygs_gzry_wyglqyModel"" b
|
||||||
|
WHERE (b.""yh_id"" = @exp_1))))", sql1);
|
||||||
|
Assert.Equal(2, (sql as Select0Provider)._params.Count);
|
||||||
|
Assert.Equal("123456", (sql as Select0Provider)._params[0].Value);
|
||||||
|
Assert.Equal("654321", (sql as Select0Provider)._params[1].Value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
class wygl_wygs_gzry_wyglqyModelTest1
|
||||||
|
{
|
||||||
|
public string dw_id { get; set; }
|
||||||
|
public string wyqy_id { get; set; }
|
||||||
|
}
|
||||||
|
class wygl_wygs_gzry_wyglqyModel
|
||||||
|
{
|
||||||
|
public string yh_id { get; set; }
|
||||||
|
public string wyqy_id { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void TestJsonb01()
|
public void TestJsonb01()
|
||||||
@ -34,6 +102,29 @@ namespace FreeSql.Tests
|
|||||||
var items = fsql.Select<TestJsonb01Cls1>().ToList();
|
var items = fsql.Select<TestJsonb01Cls1>().ToList();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void TestClickHouse()
|
||||||
|
{
|
||||||
|
var fsql = g.mysql;
|
||||||
|
fsql.Delete<TestJsonb01Cls1>().Where("1=1").ExecuteAffrows();
|
||||||
|
|
||||||
|
var item = new TestJsonb01Cls1
|
||||||
|
{
|
||||||
|
jsonb01 = new List<int> { 1, 5, 10, 20 },
|
||||||
|
jsonb02 = new List<long> { 11, 51, 101, 201 },
|
||||||
|
jsonb03 = new List<string> { "12", "52", "102", "202" },
|
||||||
|
};
|
||||||
|
fsql.Insert(item).ExecuteAffrows();
|
||||||
|
|
||||||
|
}
|
||||||
|
[FreeSql.DataAnnotations.Table(Name = "ClickHouseTest")]
|
||||||
|
public class ClickHouse
|
||||||
|
{
|
||||||
|
public long Id { get; set; }
|
||||||
|
|
||||||
|
public string Name { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
public class TestJsonb01Cls1
|
public class TestJsonb01Cls1
|
||||||
{
|
{
|
||||||
public Guid id { get; set; }
|
public Guid id { get; set; }
|
||||||
|
@ -7,6 +7,19 @@ using System.Threading;
|
|||||||
|
|
||||||
public class g
|
public class g
|
||||||
{
|
{
|
||||||
|
static Lazy<IFreeSql> clickHouseLazy = new Lazy<IFreeSql>(() => new FreeSql.FreeSqlBuilder()
|
||||||
|
.UseConnectionString(FreeSql.DataType.ClickHouse, "Compress=False;BufferSize=32768;SocketTimeout=10000;CheckCompressedHash=False;Encrypt=False;Compressor=lz4;Host=192.168.0.121;Port=8125;Database=PersonnelLocation;Username=root;Password=+riQ8V9D")
|
||||||
|
//.UseConnectionFactory(FreeSql.DataType.MySql, () => new MySql.Data.MySqlClient.MySqlConnection("Data Source=127.0.0.1;Port=3306;User ID=root;Password=root;Initial Catalog=cccddd;Charset=utf8;SslMode=none;"))
|
||||||
|
//.UseConnectionString(FreeSql.DataType.MySql, "Data Source=192.168.164.10;Port=33061;User ID=root;Password=root;Initial Catalog=cccddd_mysqlconnector;Charset=utf8;SslMode=none;Max pool size=10")
|
||||||
|
//.UseAutoSyncStructure(true)
|
||||||
|
//.UseGenerateCommandParameterWithLambda(true)
|
||||||
|
.UseMonitorCommand(
|
||||||
|
cmd => Debug.WriteLine("\r\n线程" + Thread.CurrentThread.ManagedThreadId + ": " + cmd.CommandText) //监听SQL命令对象,在执行前
|
||||||
|
//, (cmd, traceLog) => Console.WriteLine(traceLog)
|
||||||
|
)
|
||||||
|
.UseLazyLoading(true)
|
||||||
|
.Build());
|
||||||
|
public static IFreeSql clickHouse => clickHouseLazy.Value;
|
||||||
|
|
||||||
static Lazy<IFreeSql> mysqlLazy = new Lazy<IFreeSql>(() => new FreeSql.FreeSqlBuilder()
|
static Lazy<IFreeSql> mysqlLazy = new Lazy<IFreeSql>(() => new FreeSql.FreeSqlBuilder()
|
||||||
.UseConnectionString(FreeSql.DataType.MySql, "Data Source=127.0.0.1;Port=3306;User ID=root;Password=root;Initial Catalog=cccddd;Charset=utf8;SslMode=none;Max pool size=5;Allow User Variables=True")
|
.UseConnectionString(FreeSql.DataType.MySql, "Data Source=127.0.0.1;Port=3306;User ID=root;Password=root;Initial Catalog=cccddd;Charset=utf8;SslMode=none;Max pool size=5;Allow User Variables=True")
|
||||||
@ -41,7 +54,7 @@ public class g
|
|||||||
public static IFreeSql pgsql => pgsqlLazy.Value;
|
public static IFreeSql pgsql => pgsqlLazy.Value;
|
||||||
|
|
||||||
static Lazy<IFreeSql> sqlserverLazy = new Lazy<IFreeSql>(() => new FreeSql.FreeSqlBuilder()
|
static Lazy<IFreeSql> sqlserverLazy = new Lazy<IFreeSql>(() => new FreeSql.FreeSqlBuilder()
|
||||||
.UseConnectionString(FreeSql.DataType.SqlServer, "Data Source=.;Integrated Security=True;Initial Catalog=issues684;Pooling=true;Max Pool Size=3")
|
.UseConnectionString(FreeSql.DataType.SqlServer, "Data Source=.;Integrated Security=True;Initial Catalog=issues684;Pooling=true;Max Pool Size=3;TrustServerCertificate=true")
|
||||||
.UseAutoSyncStructure(true)
|
.UseAutoSyncStructure(true)
|
||||||
.UseMonitorCommand(
|
.UseMonitorCommand(
|
||||||
cmd => Trace.WriteLine("\r\n线程" + Thread.CurrentThread.ManagedThreadId + ": " + cmd.CommandText) //监听SQL命令对象,在执行前
|
cmd => Trace.WriteLine("\r\n线程" + Thread.CurrentThread.ManagedThreadId + ": " + cmd.CommandText) //监听SQL命令对象,在执行前
|
||||||
@ -69,6 +82,7 @@ public class g
|
|||||||
|
|
||||||
static Lazy<IFreeSql> sqliteLazy = new Lazy<IFreeSql>(() => new FreeSql.FreeSqlBuilder()
|
static Lazy<IFreeSql> sqliteLazy = new Lazy<IFreeSql>(() => new FreeSql.FreeSqlBuilder()
|
||||||
.UseConnectionString(FreeSql.DataType.Sqlite, @"Data Source=|DataDirectory|\document.db;Attachs=xxxtb.db;")
|
.UseConnectionString(FreeSql.DataType.Sqlite, @"Data Source=|DataDirectory|\document.db;Attachs=xxxtb.db;")
|
||||||
|
//.UseConnectionFactory(FreeSql.DataType.Sqlite, () => new Microsoft.Data.Sqlite.SqliteConnection(@"Data Source=documentCore.db"))
|
||||||
//.UseConnectionFactory(FreeSql.DataType.Sqlite, () =>
|
//.UseConnectionFactory(FreeSql.DataType.Sqlite, () =>
|
||||||
//{
|
//{
|
||||||
// var conn = new System.Data.SQLite.SQLiteConnection(@"Data Source=|DataDirectory|\document.db;Pooling=true;");
|
// var conn = new System.Data.SQLite.SQLiteConnection(@"Data Source=|DataDirectory|\document.db;Pooling=true;");
|
||||||
|
77
FreeSql.sln
77
FreeSql.sln
@ -1,7 +1,7 @@
|
|||||||
|
|
||||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||||
# Visual Studio Version 16
|
# Visual Studio Version 17
|
||||||
VisualStudioVersion = 16.0.29324.140
|
VisualStudioVersion = 17.0.31903.59
|
||||||
MinimumVisualStudioVersion = 15.0.26124.0
|
MinimumVisualStudioVersion = 15.0.26124.0
|
||||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "FreeSql", "FreeSql\FreeSql.csproj", "{AF9C50EC-6EB6-494B-9B3B-7EDBA6FD0EBB}"
|
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "FreeSql", "FreeSql\FreeSql.csproj", "{AF9C50EC-6EB6-494B-9B3B-7EDBA6FD0EBB}"
|
||||||
EndProject
|
EndProject
|
||||||
@ -101,6 +101,16 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
|
|||||||
README.zh-CN.md = README.zh-CN.md
|
README.zh-CN.md = README.zh-CN.md
|
||||||
EndProjectSection
|
EndProjectSection
|
||||||
EndProject
|
EndProject
|
||||||
|
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "FreeSql.Provider.ClickHouse", "Providers\FreeSql.Provider.ClickHouse\FreeSql.Provider.ClickHouse.csproj", "{86C56235-5D37-4422-807B-B31681C7D01C}"
|
||||||
|
EndProject
|
||||||
|
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "FreeSql.Provider.GBase", "Providers\FreeSql.Provider.GBase\FreeSql.Provider.GBase.csproj", "{BDE8EDC6-2646-45E0-A921-39CD1538A8C5}"
|
||||||
|
EndProject
|
||||||
|
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "FreeSql.Tests.Provider.GBase", "FreeSql.Tests\FreeSql.Tests.Provider.GBase\FreeSql.Tests.Provider.GBase.csproj", "{B887C0DA-01BE-4537-ADC1-92545AC85684}"
|
||||||
|
EndProject
|
||||||
|
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "FreeSql.Tests.Provider.Sqlite.Data", "FreeSql.Tests\FreeSql.Tests.Provider.Sqlite.Data\FreeSql.Tests.Provider.Sqlite.Data.csproj", "{C863551A-4791-4BE2-8741-ABAD7B650C95}"
|
||||||
|
EndProject
|
||||||
|
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "FreeSql.Provider.SqliteCore", "Providers\FreeSql.Provider.SqliteCore\FreeSql.Provider.SqliteCore.csproj", "{D4FEE5C1-6805-4B46-B10B-BE5CC942B883}"
|
||||||
|
EndProject
|
||||||
Global
|
Global
|
||||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||||
Debug|Any CPU = Debug|Any CPU
|
Debug|Any CPU = Debug|Any CPU
|
||||||
@ -579,6 +589,66 @@ Global
|
|||||||
{0DBAA21C-39B2-4AAD-A43D-88E67ED239D1}.Release|x64.Build.0 = Release|Any CPU
|
{0DBAA21C-39B2-4AAD-A43D-88E67ED239D1}.Release|x64.Build.0 = Release|Any CPU
|
||||||
{0DBAA21C-39B2-4AAD-A43D-88E67ED239D1}.Release|x86.ActiveCfg = Release|Any CPU
|
{0DBAA21C-39B2-4AAD-A43D-88E67ED239D1}.Release|x86.ActiveCfg = Release|Any CPU
|
||||||
{0DBAA21C-39B2-4AAD-A43D-88E67ED239D1}.Release|x86.Build.0 = Release|Any CPU
|
{0DBAA21C-39B2-4AAD-A43D-88E67ED239D1}.Release|x86.Build.0 = Release|Any CPU
|
||||||
|
{86C56235-5D37-4422-807B-B31681C7D01C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
|
{86C56235-5D37-4422-807B-B31681C7D01C}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
|
{86C56235-5D37-4422-807B-B31681C7D01C}.Debug|x64.ActiveCfg = Debug|Any CPU
|
||||||
|
{86C56235-5D37-4422-807B-B31681C7D01C}.Debug|x64.Build.0 = Debug|Any CPU
|
||||||
|
{86C56235-5D37-4422-807B-B31681C7D01C}.Debug|x86.ActiveCfg = Debug|Any CPU
|
||||||
|
{86C56235-5D37-4422-807B-B31681C7D01C}.Debug|x86.Build.0 = Debug|Any CPU
|
||||||
|
{86C56235-5D37-4422-807B-B31681C7D01C}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
|
{86C56235-5D37-4422-807B-B31681C7D01C}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
|
{86C56235-5D37-4422-807B-B31681C7D01C}.Release|x64.ActiveCfg = Release|Any CPU
|
||||||
|
{86C56235-5D37-4422-807B-B31681C7D01C}.Release|x64.Build.0 = Release|Any CPU
|
||||||
|
{86C56235-5D37-4422-807B-B31681C7D01C}.Release|x86.ActiveCfg = Release|Any CPU
|
||||||
|
{86C56235-5D37-4422-807B-B31681C7D01C}.Release|x86.Build.0 = Release|Any CPU
|
||||||
|
{BDE8EDC6-2646-45E0-A921-39CD1538A8C5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
|
{BDE8EDC6-2646-45E0-A921-39CD1538A8C5}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
|
{BDE8EDC6-2646-45E0-A921-39CD1538A8C5}.Debug|x64.ActiveCfg = Debug|Any CPU
|
||||||
|
{BDE8EDC6-2646-45E0-A921-39CD1538A8C5}.Debug|x64.Build.0 = Debug|Any CPU
|
||||||
|
{BDE8EDC6-2646-45E0-A921-39CD1538A8C5}.Debug|x86.ActiveCfg = Debug|Any CPU
|
||||||
|
{BDE8EDC6-2646-45E0-A921-39CD1538A8C5}.Debug|x86.Build.0 = Debug|Any CPU
|
||||||
|
{BDE8EDC6-2646-45E0-A921-39CD1538A8C5}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
|
{BDE8EDC6-2646-45E0-A921-39CD1538A8C5}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
|
{BDE8EDC6-2646-45E0-A921-39CD1538A8C5}.Release|x64.ActiveCfg = Release|Any CPU
|
||||||
|
{BDE8EDC6-2646-45E0-A921-39CD1538A8C5}.Release|x64.Build.0 = Release|Any CPU
|
||||||
|
{BDE8EDC6-2646-45E0-A921-39CD1538A8C5}.Release|x86.ActiveCfg = Release|Any CPU
|
||||||
|
{BDE8EDC6-2646-45E0-A921-39CD1538A8C5}.Release|x86.Build.0 = Release|Any CPU
|
||||||
|
{B887C0DA-01BE-4537-ADC1-92545AC85684}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
|
{B887C0DA-01BE-4537-ADC1-92545AC85684}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
|
{B887C0DA-01BE-4537-ADC1-92545AC85684}.Debug|x64.ActiveCfg = Debug|Any CPU
|
||||||
|
{B887C0DA-01BE-4537-ADC1-92545AC85684}.Debug|x64.Build.0 = Debug|Any CPU
|
||||||
|
{B887C0DA-01BE-4537-ADC1-92545AC85684}.Debug|x86.ActiveCfg = Debug|Any CPU
|
||||||
|
{B887C0DA-01BE-4537-ADC1-92545AC85684}.Debug|x86.Build.0 = Debug|Any CPU
|
||||||
|
{B887C0DA-01BE-4537-ADC1-92545AC85684}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
|
{B887C0DA-01BE-4537-ADC1-92545AC85684}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
|
{B887C0DA-01BE-4537-ADC1-92545AC85684}.Release|x64.ActiveCfg = Release|Any CPU
|
||||||
|
{B887C0DA-01BE-4537-ADC1-92545AC85684}.Release|x64.Build.0 = Release|Any CPU
|
||||||
|
{B887C0DA-01BE-4537-ADC1-92545AC85684}.Release|x86.ActiveCfg = Release|Any CPU
|
||||||
|
{B887C0DA-01BE-4537-ADC1-92545AC85684}.Release|x86.Build.0 = Release|Any CPU
|
||||||
|
{C863551A-4791-4BE2-8741-ABAD7B650C95}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
|
{C863551A-4791-4BE2-8741-ABAD7B650C95}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
|
{C863551A-4791-4BE2-8741-ABAD7B650C95}.Debug|x64.ActiveCfg = Debug|Any CPU
|
||||||
|
{C863551A-4791-4BE2-8741-ABAD7B650C95}.Debug|x64.Build.0 = Debug|Any CPU
|
||||||
|
{C863551A-4791-4BE2-8741-ABAD7B650C95}.Debug|x86.ActiveCfg = Debug|Any CPU
|
||||||
|
{C863551A-4791-4BE2-8741-ABAD7B650C95}.Debug|x86.Build.0 = Debug|Any CPU
|
||||||
|
{C863551A-4791-4BE2-8741-ABAD7B650C95}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
|
{C863551A-4791-4BE2-8741-ABAD7B650C95}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
|
{C863551A-4791-4BE2-8741-ABAD7B650C95}.Release|x64.ActiveCfg = Release|Any CPU
|
||||||
|
{C863551A-4791-4BE2-8741-ABAD7B650C95}.Release|x64.Build.0 = Release|Any CPU
|
||||||
|
{C863551A-4791-4BE2-8741-ABAD7B650C95}.Release|x86.ActiveCfg = Release|Any CPU
|
||||||
|
{C863551A-4791-4BE2-8741-ABAD7B650C95}.Release|x86.Build.0 = Release|Any CPU
|
||||||
|
{D4FEE5C1-6805-4B46-B10B-BE5CC942B883}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
|
{D4FEE5C1-6805-4B46-B10B-BE5CC942B883}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
|
{D4FEE5C1-6805-4B46-B10B-BE5CC942B883}.Debug|x64.ActiveCfg = Debug|Any CPU
|
||||||
|
{D4FEE5C1-6805-4B46-B10B-BE5CC942B883}.Debug|x64.Build.0 = Debug|Any CPU
|
||||||
|
{D4FEE5C1-6805-4B46-B10B-BE5CC942B883}.Debug|x86.ActiveCfg = Debug|Any CPU
|
||||||
|
{D4FEE5C1-6805-4B46-B10B-BE5CC942B883}.Debug|x86.Build.0 = Debug|Any CPU
|
||||||
|
{D4FEE5C1-6805-4B46-B10B-BE5CC942B883}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
|
{D4FEE5C1-6805-4B46-B10B-BE5CC942B883}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
|
{D4FEE5C1-6805-4B46-B10B-BE5CC942B883}.Release|x64.ActiveCfg = Release|Any CPU
|
||||||
|
{D4FEE5C1-6805-4B46-B10B-BE5CC942B883}.Release|x64.Build.0 = Release|Any CPU
|
||||||
|
{D4FEE5C1-6805-4B46-B10B-BE5CC942B883}.Release|x86.ActiveCfg = Release|Any CPU
|
||||||
|
{D4FEE5C1-6805-4B46-B10B-BE5CC942B883}.Release|x86.Build.0 = Release|Any CPU
|
||||||
EndGlobalSection
|
EndGlobalSection
|
||||||
GlobalSection(SolutionProperties) = preSolution
|
GlobalSection(SolutionProperties) = preSolution
|
||||||
HideSolutionNode = FALSE
|
HideSolutionNode = FALSE
|
||||||
@ -612,6 +682,9 @@ Global
|
|||||||
{CDD6A896-F6DF-44CB-B430-06B383916EB0} = {2A381C57-2697-427B-9F10-55DA11FD02E4}
|
{CDD6A896-F6DF-44CB-B430-06B383916EB0} = {2A381C57-2697-427B-9F10-55DA11FD02E4}
|
||||||
{101B11D2-7780-4E14-9B72-77F5D69B3DF9} = {2A381C57-2697-427B-9F10-55DA11FD02E4}
|
{101B11D2-7780-4E14-9B72-77F5D69B3DF9} = {2A381C57-2697-427B-9F10-55DA11FD02E4}
|
||||||
{0DBAA21C-39B2-4AAD-A43D-88E67ED239D1} = {2A381C57-2697-427B-9F10-55DA11FD02E4}
|
{0DBAA21C-39B2-4AAD-A43D-88E67ED239D1} = {2A381C57-2697-427B-9F10-55DA11FD02E4}
|
||||||
|
{86C56235-5D37-4422-807B-B31681C7D01C} = {2A381C57-2697-427B-9F10-55DA11FD02E4}
|
||||||
|
{BDE8EDC6-2646-45E0-A921-39CD1538A8C5} = {2A381C57-2697-427B-9F10-55DA11FD02E4}
|
||||||
|
{D4FEE5C1-6805-4B46-B10B-BE5CC942B883} = {2A381C57-2697-427B-9F10-55DA11FD02E4}
|
||||||
EndGlobalSection
|
EndGlobalSection
|
||||||
GlobalSection(ExtensibilityGlobals) = postSolution
|
GlobalSection(ExtensibilityGlobals) = postSolution
|
||||||
SolutionGuid = {089687FD-5D25-40AB-BA8A-A10D1E137F98}
|
SolutionGuid = {089687FD-5D25-40AB-BA8A-A10D1E137F98}
|
||||||
|
@ -60,6 +60,13 @@ namespace FreeSql
|
|||||||
/// 自定义适配器,访问任何数据库<para></para>
|
/// 自定义适配器,访问任何数据库<para></para>
|
||||||
/// 注意:该类型不提供 DbFirst/CodeFirst 功能
|
/// 注意:该类型不提供 DbFirst/CodeFirst 功能
|
||||||
/// </summary>
|
/// </summary>
|
||||||
Custom
|
Custom,
|
||||||
|
|
||||||
|
ClickHouse,
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 天津南大通用数据技术股份有限公司成立于2004年,是国产数据库、大数据领域的知名企业,基于 Odbc 的实现
|
||||||
|
/// </summary>
|
||||||
|
GBase
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -45,9 +45,18 @@ namespace FreeSql.DatabaseModel
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public bool IsNullable { get; set; }
|
public bool IsNullable { get; set; }
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
/// 备注,早期编码时少按了一个字母,请使用 Comment
|
||||||
|
/// </summary>
|
||||||
|
[Obsolete("早期编码时少按了一个字母,请使用 Comment")]
|
||||||
|
public string Coment
|
||||||
|
{
|
||||||
|
get => Comment;
|
||||||
|
set => Comment = value;
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
/// 备注
|
/// 备注
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public string Coment { get; set; }
|
public string Comment { get; set; }
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 数据库默认值
|
/// 数据库默认值
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
@ -59,6 +59,10 @@ namespace FreeSql
|
|||||||
providerType = Type.GetType("FreeSql.Firebird.FirebirdProvider`1,FreeSql.Provider.Firebird")?.MakeGenericType(connType);
|
providerType = Type.GetType("FreeSql.Firebird.FirebirdProvider`1,FreeSql.Provider.Firebird")?.MakeGenericType(connType);
|
||||||
if (providerType == null) throw new Exception("缺少 FreeSql 数据库实现包:FreeSql.Provider.Firebird.dll,可前往 nuget 下载");
|
if (providerType == null) throw new Exception("缺少 FreeSql 数据库实现包:FreeSql.Provider.Firebird.dll,可前往 nuget 下载");
|
||||||
break;
|
break;
|
||||||
|
case "ClickHouseConnection":
|
||||||
|
providerType = Type.GetType("FreeSql.ClickHouse.ClickHouseProvider`1,FreeSql.Provider.ClickHouse")?.MakeGenericType(connType);
|
||||||
|
if (providerType == null) throw new Exception("缺少 FreeSql 数据库实现包:FreeSql.Provider.ClickHouse.dll,可前往 nuget 下载");
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
throw new Exception("未实现");
|
throw new Exception("未实现");
|
||||||
}
|
}
|
||||||
|
@ -140,6 +140,17 @@ namespace FreeSql
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 注意:使用者自己承担【注入风险】
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="sql"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
static bool InternalRawSql([RawValue] string sql)
|
||||||
|
{
|
||||||
|
expContext.Value.Result = sql;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
#region 大小判断
|
#region 大小判断
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 大于 >
|
/// 大于 >
|
||||||
@ -460,6 +471,15 @@ namespace FreeSql
|
|||||||
expContext.Result = $"list({expContext.ParsedContent["column"]},{expContext.ParsedContent["delimiter"]})";
|
expContext.Result = $"list({expContext.ParsedContent["column"]},{expContext.ParsedContent["delimiter"]})";
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
public static string StringJoinGBaseWmConcatText(object column, object delimiter)
|
||||||
|
{
|
||||||
|
if (expContext.ParsedContent["delimiter"] == "','")
|
||||||
|
expContext.Result = $"wm_concat_text({expContext.ParsedContent["column"]})";
|
||||||
|
else
|
||||||
|
throw new NotImplementedException("GBase 暂时不支持逗号以外的分割符");
|
||||||
|
//expContext.Result = $"replace(wm_concat_text({expContext.ParsedContent["column"]}), ',', {expContext.ParsedContent["delimiter"]})";
|
||||||
|
return null;
|
||||||
|
}
|
||||||
#endregion
|
#endregion
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,6 +1,7 @@
|
|||||||
using FreeSql;
|
using FreeSql;
|
||||||
using FreeSql.DataAnnotations;
|
using FreeSql.DataAnnotations;
|
||||||
using FreeSql.Internal.CommonProvider;
|
using FreeSql.Internal.CommonProvider;
|
||||||
|
using FreeSql.Internal.Model;
|
||||||
using FreeSql.Internal.ObjectPool;
|
using FreeSql.Internal.ObjectPool;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections;
|
using System.Collections;
|
||||||
@ -58,7 +59,7 @@ public static partial class FreeSqlGlobalExtensions
|
|||||||
/// <param name="type"></param>
|
/// <param name="type"></param>
|
||||||
/// <param name="isNameSpace"></param>
|
/// <param name="isNameSpace"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
internal static string DisplayCsharp(this Type type, bool isNameSpace = true)
|
public static string DisplayCsharp(this Type type, bool isNameSpace = true)
|
||||||
{
|
{
|
||||||
if (type == null) return null;
|
if (type == null) return null;
|
||||||
if (type == typeof(void)) return "void";
|
if (type == typeof(void)) return "void";
|
||||||
@ -418,9 +419,25 @@ public static partial class FreeSqlGlobalExtensions
|
|||||||
if (select._orm.CodeFirst.IsSyncStructureToLower) cteName = cteName.ToLower();
|
if (select._orm.CodeFirst.IsSyncStructureToLower) cteName = cteName.ToLower();
|
||||||
if (select._orm.CodeFirst.IsSyncStructureToUpper) cteName = cteName.ToUpper();
|
if (select._orm.CodeFirst.IsSyncStructureToUpper) cteName = cteName.ToUpper();
|
||||||
|
|
||||||
switch (select._orm.Ado.DataType) //MySql5.6
|
switch (select._orm.Ado.DataType)
|
||||||
{
|
{
|
||||||
case DataType.MySql:
|
case DataType.GBase:
|
||||||
|
//select t.parentid, t.subid, level
|
||||||
|
//from a_test t
|
||||||
|
//start with subid = '7'
|
||||||
|
//connect by prior subid = parentid;
|
||||||
|
var gbsb = new StringBuilder();
|
||||||
|
var gbsbWhere = select._where.ToString();
|
||||||
|
select._where.Clear();
|
||||||
|
if (gbsbWhere.StartsWith(" AND ")) gbsbWhere = gbsbWhere.Remove(0, 5);
|
||||||
|
gbsb.Append(select._tosqlAppendContent).Append(" \r\nstart with ").Append(gbsbWhere).Append(" \r\nconnect by prior ");
|
||||||
|
if (up) gbsb.Append("a.").Append(select._commonUtils.QuoteSqlName(tbref.Columns[0].Attribute.Name)).Append(" = ").Append("a.").Append(select._commonUtils.QuoteSqlName(tbref.RefColumns[0].Attribute.Name));
|
||||||
|
else gbsb.Append("a.").Append(select._commonUtils.QuoteSqlName(tbref.Columns[0].Attribute.Name)).Append(" = ").Append("a.").Append(select._commonUtils.QuoteSqlName(tbref.RefColumns[0].Attribute.Name));
|
||||||
|
var gbswstr = gbsb.ToString();
|
||||||
|
gbsb.Clear();
|
||||||
|
select.AsAlias((_, old) => $"{old} {gbswstr}");
|
||||||
|
return select;
|
||||||
|
case DataType.MySql: //MySql5.6
|
||||||
case DataType.OdbcMySql:
|
case DataType.OdbcMySql:
|
||||||
var mysqlConnectionString = select._orm.Ado?.ConnectionString ?? select._connection?.ConnectionString ?? "";
|
var mysqlConnectionString = select._orm.Ado?.ConnectionString ?? select._connection?.ConnectionString ?? "";
|
||||||
if (_dicMySqlVersion.TryGetValue(mysqlConnectionString, out var mysqlVersion) == false)
|
if (_dicMySqlVersion.TryGetValue(mysqlConnectionString, out var mysqlVersion) == false)
|
||||||
@ -495,6 +512,7 @@ JOIN {select._commonUtils.QuoteSqlName(tb.DbName)} a ON cte_tbc.cte_id = a.{sele
|
|||||||
case DataType.SqlServer:
|
case DataType.SqlServer:
|
||||||
case DataType.OdbcSqlServer:
|
case DataType.OdbcSqlServer:
|
||||||
case DataType.Firebird:
|
case DataType.Firebird:
|
||||||
|
case DataType.ClickHouse:
|
||||||
sql1ctePath = select._commonExpression.ExpressionWhereLambda(select._tables, Expression.Call(typeof(Convert).GetMethod("ToString", new Type[] { typeof(string) }), pathSelector?.Body), null, null, null);
|
sql1ctePath = select._commonExpression.ExpressionWhereLambda(select._tables, Expression.Call(typeof(Convert).GetMethod("ToString", new Type[] { typeof(string) }), pathSelector?.Body), null, null, null);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
@ -503,11 +521,11 @@ JOIN {select._commonUtils.QuoteSqlName(tb.DbName)} a ON cte_tbc.cte_id = a.{sele
|
|||||||
}
|
}
|
||||||
sql1ctePath = $"{sql1ctePath} as cte_path, ";
|
sql1ctePath = $"{sql1ctePath} as cte_path, ";
|
||||||
}
|
}
|
||||||
var sql1 = select.ToSql($"0 as cte_level, {sql1ctePath}{select.GetAllFieldExpressionTreeLevel2().Field}").Trim();
|
var sql1 = select.ToSql($"0 as cte_level, {sql1ctePath}{select.GetAllFieldExpressionTreeLevel2(false).Field}").Trim();
|
||||||
|
|
||||||
select._where.Clear();
|
select._where.Clear();
|
||||||
select.As("wct2");
|
select.As("wct2");
|
||||||
var sql2Field = select.GetAllFieldExpressionTreeLevel2().Field;
|
var sql2Field = select.GetAllFieldExpressionTreeLevel2(false).Field;
|
||||||
var sql2InnerJoinOn = up == false ?
|
var sql2InnerJoinOn = up == false ?
|
||||||
string.Join(" and ", tbref.Columns.Select((a, z) => $"wct2.{select._commonUtils.QuoteSqlName(tbref.RefColumns[z].Attribute.Name)} = wct1.{select._commonUtils.QuoteSqlName(a.Attribute.Name)}")) :
|
string.Join(" and ", tbref.Columns.Select((a, z) => $"wct2.{select._commonUtils.QuoteSqlName(tbref.RefColumns[z].Attribute.Name)} = wct1.{select._commonUtils.QuoteSqlName(a.Attribute.Name)}")) :
|
||||||
string.Join(" and ", tbref.Columns.Select((a, z) => $"wct2.{select._commonUtils.QuoteSqlName(a.Attribute.Name)} = wct1.{select._commonUtils.QuoteSqlName(tbref.RefColumns[z].Attribute.Name)}"));
|
string.Join(" and ", tbref.Columns.Select((a, z) => $"wct2.{select._commonUtils.QuoteSqlName(a.Attribute.Name)} = wct1.{select._commonUtils.QuoteSqlName(tbref.RefColumns[z].Attribute.Name)}"));
|
||||||
@ -579,6 +597,7 @@ JOIN {select._commonUtils.QuoteSqlName(tb.DbName)} a ON cte_tbc.cte_id = a.{sele
|
|||||||
case DataType.OdbcOracle:
|
case DataType.OdbcOracle:
|
||||||
case DataType.Dameng: //递归 WITH 子句必须具有列别名列表
|
case DataType.Dameng: //递归 WITH 子句必须具有列别名列表
|
||||||
case DataType.OdbcDameng:
|
case DataType.OdbcDameng:
|
||||||
|
case DataType.GBase:
|
||||||
nsselsb.Append($"(cte_level, {(pathSelector == null ? "" : "cte_path, ")}{sql2Field.Replace("wct2.", "")})");
|
nsselsb.Append($"(cte_level, {(pathSelector == null ? "" : "cte_path, ")}{sql2Field.Replace("wct2.", "")})");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -609,6 +628,7 @@ SELECT ");
|
|||||||
{
|
{
|
||||||
case DataType.MySql:
|
case DataType.MySql:
|
||||||
case DataType.OdbcMySql:
|
case DataType.OdbcMySql:
|
||||||
|
case DataType.ClickHouse:
|
||||||
return that.OrderBy("rand()");
|
return that.OrderBy("rand()");
|
||||||
case DataType.SqlServer:
|
case DataType.SqlServer:
|
||||||
case DataType.OdbcSqlServer:
|
case DataType.OdbcSqlServer:
|
||||||
@ -634,4 +654,371 @@ SELECT ");
|
|||||||
throw new NotSupportedException($"{s0p._orm.Ado.DataType} 不支持 OrderByRandom 随机排序");
|
throw new NotSupportedException($"{s0p._orm.Ado.DataType} 不支持 OrderByRandom 随机排序");
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
#region IFreeSql Insert/Update/InsertOrUpdate/Delete Dictionary<string, object>
|
||||||
|
/// <summary>
|
||||||
|
/// 插入数据字典 Dictionary<string, object>
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="source"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public static InsertDictImpl InsertDict(this IFreeSql freesql, Dictionary<string, object> source)
|
||||||
|
{
|
||||||
|
var insertDict = new InsertDictImpl(freesql);
|
||||||
|
insertDict._insertProvider.AppendData(source);
|
||||||
|
return insertDict;
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// 插入数据字典,传入 Dictionary<string, object> 集合
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="source"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public static InsertDictImpl InsertDict(this IFreeSql freesql, IEnumerable<Dictionary<string, object>> source)
|
||||||
|
{
|
||||||
|
var insertDict = new InsertDictImpl(freesql);
|
||||||
|
insertDict._insertProvider.AppendData(source);
|
||||||
|
return insertDict;
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// 更新数据字典 Dictionary<string, object>
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="source"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public static UpdateDictImpl UpdateDict(this IFreeSql freesql, Dictionary<string, object> source)
|
||||||
|
{
|
||||||
|
var updateDict = new UpdateDictImpl(freesql);
|
||||||
|
updateDict._updateProvider.SetSource(source);
|
||||||
|
return updateDict;
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// 更新数据字典,传入 Dictionary<string, object> 集合
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="source"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public static UpdateDictImpl UpdateDict(this IFreeSql freesql, IEnumerable<Dictionary<string, object>> source)
|
||||||
|
{
|
||||||
|
var updateDict = new UpdateDictImpl(freesql);
|
||||||
|
updateDict._updateProvider.SetSource(source);
|
||||||
|
return updateDict;
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// 插入或更新数据字典,此功能依赖数据库特性(低版本可能不支持),参考如下:<para></para>
|
||||||
|
/// MySql 5.6+: on duplicate key update<para></para>
|
||||||
|
/// PostgreSQL 9.4+: on conflict do update<para></para>
|
||||||
|
/// SqlServer 2008+: merge into<para></para>
|
||||||
|
/// Oracle 11+: merge into<para></para>
|
||||||
|
/// Sqlite: replace into<para></para>
|
||||||
|
/// 达梦: merge into<para></para>
|
||||||
|
/// 人大金仓:on conflict do update<para></para>
|
||||||
|
/// 神通:merge into<para></para>
|
||||||
|
/// MsAccess:不支持<para></para>
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="source"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public static InsertOrUpdateDictImpl InsertOrUpdateDict(this IFreeSql freesql, Dictionary<string, object> source)
|
||||||
|
{
|
||||||
|
var insertOrUpdateDict = new InsertOrUpdateDictImpl(freesql);
|
||||||
|
insertOrUpdateDict._insertOrUpdateProvider.SetSource(source);
|
||||||
|
return insertOrUpdateDict;
|
||||||
|
}
|
||||||
|
public static InsertOrUpdateDictImpl InsertOrUpdateDict(this IFreeSql freesql, IEnumerable<Dictionary<string, object>> source)
|
||||||
|
{
|
||||||
|
var insertOrUpdateDict = new InsertOrUpdateDictImpl(freesql);
|
||||||
|
insertOrUpdateDict._insertOrUpdateProvider.SetSource(source);
|
||||||
|
return insertOrUpdateDict;
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// 删除数据字典 Dictionary<string, object>
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="source"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public static DeleteDictImpl DeleteDict(this IFreeSql freesql, Dictionary<string, object> source)
|
||||||
|
{
|
||||||
|
var deleteDict = new DeleteDictImpl(freesql);
|
||||||
|
UpdateProvider<Dictionary<string, object>>.GetDictionaryTableInfo(source, deleteDict._deleteProvider._orm, ref deleteDict._deleteProvider._table);
|
||||||
|
var primarys = UpdateDictImpl.GetPrimarys(deleteDict._deleteProvider._table, source.Keys.ToArray());
|
||||||
|
deleteDict._deleteProvider.Where(deleteDict._deleteProvider._commonUtils.WhereItems(primarys, "", new[] { source }));
|
||||||
|
return deleteDict;
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// 删除数据字典,传入 Dictionary<string, object> 集合
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="source"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public static DeleteDictImpl DeleteDict(this IFreeSql freesql, IEnumerable<Dictionary<string, object>> source)
|
||||||
|
{
|
||||||
|
DeleteDictImpl deleteDict = null;
|
||||||
|
if (source.Select(a => string.Join(",", a.Keys)).Distinct().Count() == 1)
|
||||||
|
{
|
||||||
|
deleteDict = new DeleteDictImpl(freesql);
|
||||||
|
var sourceFirst = source.FirstOrDefault();
|
||||||
|
UpdateProvider<Dictionary<string, object>>.GetDictionaryTableInfo(sourceFirst, deleteDict._deleteProvider._orm, ref deleteDict._deleteProvider._table);
|
||||||
|
var primarys = UpdateDictImpl.GetPrimarys(deleteDict._deleteProvider._table, sourceFirst.Keys.ToArray());
|
||||||
|
deleteDict._deleteProvider.Where(deleteDict._deleteProvider._commonUtils.WhereItems(primarys, "", source));
|
||||||
|
return deleteDict;
|
||||||
|
}
|
||||||
|
foreach (var item in source)
|
||||||
|
{
|
||||||
|
var tmpDelteDict = DeleteDict(freesql, item);
|
||||||
|
if (deleteDict == null) deleteDict = tmpDelteDict;
|
||||||
|
else deleteDict._deleteProvider._where.Append(" OR ").Append(tmpDelteDict._deleteProvider._where);
|
||||||
|
}
|
||||||
|
return deleteDict ?? new DeleteDictImpl(freesql);
|
||||||
|
}
|
||||||
|
|
||||||
|
#region InsertDictImpl
|
||||||
|
public class InsertDictImpl
|
||||||
|
{
|
||||||
|
internal readonly InsertProvider<Dictionary<string, object>> _insertProvider;
|
||||||
|
internal InsertDictImpl(IFreeSql orm)
|
||||||
|
{
|
||||||
|
_insertProvider = (orm as BaseDbProvider ?? throw new Exception("IFreeSql 无法转换成 BaseDbProvider"))
|
||||||
|
.CreateInsertProvider<Dictionary<string, object>>() as InsertProvider<Dictionary<string, object>>;
|
||||||
|
}
|
||||||
|
|
||||||
|
public InsertDictImpl AsTable(string tableName)
|
||||||
|
{
|
||||||
|
_insertProvider.AsTable(tableName);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public InsertDictImpl BatchOptions(int valuesLimit, int parameterLimit, bool autoTransaction = true)
|
||||||
|
{
|
||||||
|
_insertProvider.BatchOptions(valuesLimit, parameterLimit, autoTransaction);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
public InsertDictImpl BatchProgress(Action<BatchProgressStatus<Dictionary<string, object>>> callback)
|
||||||
|
{
|
||||||
|
_insertProvider.BatchProgress(callback);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public InsertDictImpl CommandTimeout(int timeout)
|
||||||
|
{
|
||||||
|
_insertProvider.CommandTimeout(timeout);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int ExecuteAffrows() => _insertProvider.ExecuteAffrows();
|
||||||
|
public long ExecuteIdentity() => _insertProvider.ExecuteIdentity();
|
||||||
|
public List<Dictionary<string, object>> ExecuteInserted() => _insertProvider.ExecuteInserted();
|
||||||
|
|
||||||
|
#if net40
|
||||||
|
#else
|
||||||
|
public Task<int> ExecuteAffrowsAsync(CancellationToken cancellationToken = default) => _insertProvider.ExecuteAffrowsAsync(cancellationToken);
|
||||||
|
public Task<long> ExecuteIdentityAsync(CancellationToken cancellationToken = default) => _insertProvider.ExecuteIdentityAsync(cancellationToken);
|
||||||
|
public Task<List<Dictionary<string, object>>> ExecuteInsertedAsync(CancellationToken cancellationToken = default) => _insertProvider.ExecuteInsertedAsync(cancellationToken);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
public InsertDictImpl NoneParameter(bool isNotCommandParameter = true)
|
||||||
|
{
|
||||||
|
_insertProvider.NoneParameter(isNotCommandParameter);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public DataTable ToDataTable() => _insertProvider.ToDataTable();
|
||||||
|
public string ToSql() => _insertProvider.ToSql();
|
||||||
|
|
||||||
|
public InsertDictImpl WithConnection(DbConnection connection)
|
||||||
|
{
|
||||||
|
_insertProvider.WithConnection(connection);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
public InsertDictImpl WithTransaction(DbTransaction transaction)
|
||||||
|
{
|
||||||
|
_insertProvider.WithTransaction(transaction);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region UpdateDictImpl
|
||||||
|
public class UpdateDictImpl
|
||||||
|
{
|
||||||
|
internal readonly UpdateProvider<Dictionary<string, object>> _updateProvider;
|
||||||
|
internal UpdateDictImpl(IFreeSql orm)
|
||||||
|
{
|
||||||
|
_updateProvider = (orm as BaseDbProvider ?? throw new Exception("IFreeSql 无法转换成 BaseDbProvider"))
|
||||||
|
.CreateUpdateProvider<Dictionary<string, object>>(null) as UpdateProvider<Dictionary<string, object>>;
|
||||||
|
}
|
||||||
|
|
||||||
|
public UpdateDictImpl WherePrimary(params string[] primarys)
|
||||||
|
{
|
||||||
|
_updateProvider._tempPrimarys = GetPrimarys(_updateProvider._table, primarys);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
public static ColumnInfo[] GetPrimarys(TableInfo table, params string[] primarys)
|
||||||
|
{
|
||||||
|
if (primarys?.Any() != true) throw new ArgumentException(nameof(primarys));
|
||||||
|
var pks = new List<ColumnInfo>();
|
||||||
|
foreach (var primary in primarys)
|
||||||
|
{
|
||||||
|
if (table.ColumnsByCs.TryGetValue(string.Concat(primary), out var col)) pks.Add(col);
|
||||||
|
else throw new Exception($"GetPrimarys 传递的参数 \"{primary}\" 不正确,它不属于字典数据的键名");
|
||||||
|
}
|
||||||
|
return pks.ToArray();
|
||||||
|
}
|
||||||
|
public static void SetTablePrimary(TableInfo table, params string[] primarys)
|
||||||
|
{
|
||||||
|
foreach (var primary in primarys)
|
||||||
|
{
|
||||||
|
if (table.ColumnsByCs.TryGetValue(string.Concat(primary), out var col)) col.Attribute.IsPrimary = true;
|
||||||
|
else throw new Exception($"GetPrimarys 传递的参数 \"{primary}\" 不正确,它不属于字典数据的键名");
|
||||||
|
}
|
||||||
|
table.Primarys = table.Columns.Where(a => a.Value.Attribute.IsPrimary).Select(a => a.Value).ToArray();
|
||||||
|
}
|
||||||
|
|
||||||
|
public UpdateDictImpl AsTable(string tableName)
|
||||||
|
{
|
||||||
|
_updateProvider.AsTable(tableName);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public UpdateDictImpl BatchOptions(int rowsLimit, int parameterLimit, bool autoTransaction = true)
|
||||||
|
{
|
||||||
|
_updateProvider.BatchOptions(rowsLimit, parameterLimit, autoTransaction);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
public UpdateDictImpl BatchProgress(Action<BatchProgressStatus<Dictionary<string, object>>> callback)
|
||||||
|
{
|
||||||
|
_updateProvider.BatchProgress(callback);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public UpdateDictImpl CommandTimeout(int timeout)
|
||||||
|
{
|
||||||
|
_updateProvider.CommandTimeout(timeout);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int ExecuteAffrows() => _updateProvider.ExecuteAffrows();
|
||||||
|
public List<Dictionary<string, object>> ExecuteUpdated() => _updateProvider.ExecuteUpdated();
|
||||||
|
|
||||||
|
#if net40
|
||||||
|
#else
|
||||||
|
public Task<int> ExecuteAffrowsAsync(CancellationToken cancellationToken = default) => _updateProvider.ExecuteAffrowsAsync(cancellationToken);
|
||||||
|
public Task<List<Dictionary<string, object>>> ExecuteUpdatedAsync(CancellationToken cancellationToken = default) => _updateProvider.ExecuteUpdatedAsync(cancellationToken);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
public UpdateDictImpl NoneParameter(bool isNotCommandParameter = true)
|
||||||
|
{
|
||||||
|
_updateProvider.NoneParameter(isNotCommandParameter);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public string ToSql() => _updateProvider.ToSql();
|
||||||
|
|
||||||
|
public UpdateDictImpl WithConnection(DbConnection connection)
|
||||||
|
{
|
||||||
|
_updateProvider.WithConnection(connection);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
public UpdateDictImpl WithTransaction(DbTransaction transaction)
|
||||||
|
{
|
||||||
|
_updateProvider.WithTransaction(transaction);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region InsertOrUpdateDictImpl
|
||||||
|
public class InsertOrUpdateDictImpl
|
||||||
|
{
|
||||||
|
internal readonly InsertOrUpdateProvider<Dictionary<string, object>> _insertOrUpdateProvider;
|
||||||
|
internal InsertOrUpdateDictImpl(IFreeSql orm)
|
||||||
|
{
|
||||||
|
_insertOrUpdateProvider = (orm as BaseDbProvider ?? throw new Exception("IFreeSql 无法转换成 BaseDbProvider"))
|
||||||
|
.CreateInsertOrUpdateProvider<Dictionary<string, object>>() as InsertOrUpdateProvider<Dictionary<string, object>>;
|
||||||
|
}
|
||||||
|
|
||||||
|
public InsertOrUpdateDictImpl WherePrimary(params string[] primarys)
|
||||||
|
{
|
||||||
|
UpdateDictImpl.SetTablePrimary(_insertOrUpdateProvider._table, primarys);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public InsertOrUpdateDictImpl AsTable(string tableName)
|
||||||
|
{
|
||||||
|
_insertOrUpdateProvider.AsTable(tableName);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public InsertOrUpdateDictImpl CommandTimeout(int timeout)
|
||||||
|
{
|
||||||
|
_insertOrUpdateProvider.CommandTimeout(timeout);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int ExecuteAffrows() => _insertOrUpdateProvider.ExecuteAffrows();
|
||||||
|
#if net40
|
||||||
|
#else
|
||||||
|
public Task<int> ExecuteAffrowsAsync(CancellationToken cancellationToken = default) => _insertOrUpdateProvider.ExecuteAffrowsAsync(cancellationToken);
|
||||||
|
#endif
|
||||||
|
public InsertOrUpdateDictImpl IfExistsDoNothing()
|
||||||
|
{
|
||||||
|
_insertOrUpdateProvider.IfExistsDoNothing();
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public string ToSql() => _insertOrUpdateProvider.ToSql();
|
||||||
|
|
||||||
|
public InsertOrUpdateDictImpl WithConnection(DbConnection connection)
|
||||||
|
{
|
||||||
|
_insertOrUpdateProvider.WithConnection(connection);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
public InsertOrUpdateDictImpl WithTransaction(DbTransaction transaction)
|
||||||
|
{
|
||||||
|
_insertOrUpdateProvider.WithTransaction(transaction);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region DeleteDictImpl
|
||||||
|
public class DeleteDictImpl
|
||||||
|
{
|
||||||
|
internal readonly DeleteProvider<Dictionary<string, object>> _deleteProvider;
|
||||||
|
internal DeleteDictImpl(IFreeSql orm)
|
||||||
|
{
|
||||||
|
_deleteProvider = (orm as BaseDbProvider ?? throw new Exception("IFreeSql 无法转换成 BaseDbProvider"))
|
||||||
|
.CreateDeleteProvider<Dictionary<string, object>>(null) as DeleteProvider<Dictionary<string, object>>;
|
||||||
|
}
|
||||||
|
|
||||||
|
public DeleteDictImpl AsTable(string tableName)
|
||||||
|
{
|
||||||
|
_deleteProvider.AsTable(tableName);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public DeleteDictImpl CommandTimeout(int timeout)
|
||||||
|
{
|
||||||
|
_deleteProvider.CommandTimeout(timeout);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int ExecuteAffrows() => _deleteProvider.ExecuteAffrows();
|
||||||
|
public List<Dictionary<string, object>> ExecuteDeleted() => _deleteProvider.ExecuteDeleted();
|
||||||
|
|
||||||
|
#if net40
|
||||||
|
#else
|
||||||
|
public Task<int> ExecuteAffrowsAsync(CancellationToken cancellationToken = default) => _deleteProvider.ExecuteAffrowsAsync(cancellationToken);
|
||||||
|
public Task<List<Dictionary<string, object>>> ExecuteDeletedAsync(CancellationToken cancellationToken = default) => _deleteProvider.ExecuteDeletedAsync(cancellationToken);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
public string ToSql() => _deleteProvider.ToSql();
|
||||||
|
|
||||||
|
public DeleteDictImpl WithConnection(DbConnection connection)
|
||||||
|
{
|
||||||
|
_deleteProvider.WithConnection(connection);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
public DeleteDictImpl WithTransaction(DbTransaction transaction)
|
||||||
|
{
|
||||||
|
_deleteProvider.WithTransaction(transaction);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#endregion
|
||||||
}
|
}
|
||||||
|
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