Skip to content

Commit

Permalink
add min/max DateTime IsNull Tests #1140
Browse files Browse the repository at this point in the history
  • Loading branch information
2881099 committed Jun 2, 2022
1 parent f3b79bf commit 8263379
Show file tree
Hide file tree
Showing 18 changed files with 233 additions and 112 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1085,15 +1085,18 @@ public void Min()
var subquery = select.ToSql(a => new
{
all = a,
count = select.As("b").Min(b => b.Id)
min = select.As("b").Min(b => b.Id),
min2 = select.As("b").Min(b => b.CreateTime)
});
Assert.Equal(@"SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5, ifnull((SELECT min(b.`Id`)
FROM `tb_topic` b), 0) as6
FROM `tb_topic` b), 0) as6, ifnull((SELECT min(b.`CreateTime`)
FROM `tb_topic` b), '0001-01-01 00:00:00.000') as7
FROM `tb_topic` a", subquery);
var subqueryList = select.ToList(a => new
{
all = a,
count = select.As("b").Min(b => b.Id)
min = select.As("b").Min(b => b.Id),
min2 = select.As("b").Min(b => b.CreateTime)
});
}
[Fact]
Expand All @@ -1102,15 +1105,18 @@ public void Max()
var subquery = select.ToSql(a => new
{
all = a,
count = select.As("b").Max(b => b.Id)
max = select.As("b").Max(b => b.Id),
max2 = select.As("b").Max(b => b.CreateTime)
});
Assert.Equal(@"SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5, ifnull((SELECT max(b.`Id`)
FROM `tb_topic` b), 0) as6
FROM `tb_topic` b), 0) as6, ifnull((SELECT max(b.`CreateTime`)
FROM `tb_topic` b), '0001-01-01 00:00:00.000') as7
FROM `tb_topic` a", subquery);
var subqueryList = select.ToList(a => new
{
all = a,
count = select.As("b").Max(b => b.Id)
max = select.As("b").Max(b => b.Id),
max2 = select.As("b").Max(b => b.CreateTime)
});
}
[Fact]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -879,15 +879,18 @@ public void Min()
var subquery = select.ToSql(a => new
{
all = a,
count = select.As("b").Min(b => b.Id)
min = select.As("b").Min(b => b.Id),
min2 = select.As("b").Min(b => b.CreateTime)
});
Assert.Equal(@"SELECT a.""ID"" as1, a.""CLICKS"" as2, a.""TYPEGUID"" as3, a.""TITLE"" as4, a.""CREATETIME"" as5, nvl((SELECT min(b.""ID"")
FROM ""TB_TOPIC22"" b), 0) as6
FROM ""TB_TOPIC22"" b), 0) as6, nvl((SELECT min(b.""CREATETIME"")
FROM ""TB_TOPIC22"" b), to_timestamp('0001-01-01 00:00:00.000000','YYYY-MM-DD HH24:MI:SS.FF6')) as7
FROM ""TB_TOPIC22"" a", subquery);
var subqueryList = select.ToList(a => new
{
all = a,
count = select.As("b").Min(b => b.Id)
min = select.As("b").Min(b => b.Id),
min2 = select.As("b").Min(b => b.CreateTime)
});
}
[Fact]
Expand All @@ -896,15 +899,18 @@ public void Max()
var subquery = select.ToSql(a => new
{
all = a,
count = select.As("b").Max(b => b.Id)
max = select.As("b").Max(b => b.Id),
max2 = select.As("b").Max(b => b.CreateTime)
});
Assert.Equal(@"SELECT a.""ID"" as1, a.""CLICKS"" as2, a.""TYPEGUID"" as3, a.""TITLE"" as4, a.""CREATETIME"" as5, nvl((SELECT max(b.""ID"")
FROM ""TB_TOPIC22"" b), 0) as6
FROM ""TB_TOPIC22"" b), 0) as6, nvl((SELECT max(b.""CREATETIME"")
FROM ""TB_TOPIC22"" b), to_timestamp('0001-01-01 00:00:00.000000','YYYY-MM-DD HH24:MI:SS.FF6')) as7
FROM ""TB_TOPIC22"" a", subquery);
var subqueryList = select.ToList(a => new
{
all = a,
count = select.As("b").Max(b => b.Id)
max = select.As("b").Max(b => b.Id),
max2 = select.As("b").Max(b => b.CreateTime)
});
}
[Fact]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -844,15 +844,18 @@ public void Min()
var subquery = select.ToSql(a => new
{
all = a,
count = select.As("b").Min(b => b.Id)
min = select.As("b").Min(b => b.Id),
min2 = select.As("b").Min(b => b.CreateTime)
});
Assert.Equal(@"SELECT a.[Id] as1, a.[Clicks] as2, a.[TypeGuid] as3, a.[Title] as4, a.[CreateTime] as5, isnull((SELECT min(b.[Id])
FROM [tb_topic22] b), 0) as6
FROM [tb_topic22] b), 0) as6, isnull((SELECT min(b.[CreateTime])
FROM [tb_topic22] b), '1970-01-01 00:00:00.000') as7
FROM [tb_topic22] a", subquery);
var subqueryList = select.ToList(a => new
{
all = a,
count = select.As("b").Min(b => b.Id)
min = select.As("b").Min(b => b.Id),
min2 = select.As("b").Min(b => b.CreateTime)
});
}
[Fact]
Expand All @@ -861,15 +864,18 @@ public void Max()
var subquery = select.ToSql(a => new
{
all = a,
count = select.As("b").Max(b => b.Id)
max = select.As("b").Max(b => b.Id),
max2 = select.As("b").Max(b => b.CreateTime)
});
Assert.Equal(@"SELECT a.[Id] as1, a.[Clicks] as2, a.[TypeGuid] as3, a.[Title] as4, a.[CreateTime] as5, isnull((SELECT max(b.[Id])
FROM [tb_topic22] b), 0) as6
FROM [tb_topic22] b), 0) as6, isnull((SELECT max(b.[CreateTime])
FROM [tb_topic22] b), '1970-01-01 00:00:00.000') as7
FROM [tb_topic22] a", subquery);
var subqueryList = select.ToList(a => new
{
all = a,
count = select.As("b").Max(b => b.Id)
max = select.As("b").Max(b => b.Id),
max2 = select.As("b").Max(b => b.CreateTime)
});
}
[Fact]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -845,15 +845,18 @@ public void Min()
var subquery = select.ToSql(a => new
{
all = a,
count = select.As("b").Min(b => b.Id)
min = select.As("b").Min(b => b.Id),
min2 = select.As("b").Min(b => b.CreateTime)
});
Assert.Equal(@"SELECT a.""ID"" as1, a.""CLICKS"" as2, a.""TYPEGUID"" as3, a.""TITLE"" as4, a.""CREATETIME"" as5, coalesce((SELECT min(b.""ID"")
FROM ""TB_TOPIC22"" b), 0) as6
FROM ""TB_TOPIC22"" a", subquery);
FROM ""TB_TOPIC"" b), 0) as6, coalesce((SELECT min(b.""CREATETIME"")
FROM ""TB_TOPIC"" b), '0001-01-01 00:00:00.000000') as7
FROM ""TB_TOPIC"" a", subquery);
var subqueryList = select.ToList(a => new
{
all = a,
count = select.As("b").Min(b => b.Id)
min = select.As("b").Min(b => b.Id),
min2 = select.As("b").Min(b => b.CreateTime)
});
}
[Fact]
Expand All @@ -862,15 +865,18 @@ public void Max()
var subquery = select.ToSql(a => new
{
all = a,
count = select.As("b").Max(b => b.Id)
max = select.As("b").Max(b => b.Id),
max2 = select.As("b").Max(b => b.CreateTime)
});
Assert.Equal(@"SELECT a.""ID"" as1, a.""CLICKS"" as2, a.""TYPEGUID"" as3, a.""TITLE"" as4, a.""CREATETIME"" as5, coalesce((SELECT max(b.""ID"")
FROM ""TB_TOPIC22"" b), 0) as6
FROM ""TB_TOPIC22"" a", subquery);
FROM ""TB_TOPIC"" b), 0) as6, coalesce((SELECT max(b.""CREATETIME"")
FROM ""TB_TOPIC"" b), '0001-01-01 00:00:00.000000') as7
FROM ""TB_TOPIC"" a", subquery);
var subqueryList = select.ToList(a => new
{
all = a,
count = select.As("b").Max(b => b.Id)
max = select.As("b").Max(b => b.Id),
max2 = select.As("b").Max(b => b.CreateTime)
});
}
[Fact]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -965,15 +965,18 @@ public void Min()
var subquery = select.ToSql(a => new
{
all = a,
count = select.As("b").Min(b => b.Id)
min = select.As("b").Min(b => b.Id),
min2 = select.As("b").Min(b => b.CreateTime)
});
Assert.Equal(@"SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5, ifnull((SELECT min(b.`Id`)
FROM `tb_topic` b), 0) as6
FROM `tb_topic` b), 0) as6, ifnull((SELECT min(b.`CreateTime`)
FROM `tb_topic` b), '0001-01-01 00:00:00.000') as7
FROM `tb_topic` a", subquery);
var subqueryList = select.ToList(a => new
{
all = a,
count = select.As("b").Min(b => b.Id)
min = select.As("b").Min(b => b.Id),
min2 = select.As("b").Min(b => b.CreateTime)
});
}
[Fact]
Expand All @@ -982,15 +985,18 @@ public void Max()
var subquery = select.ToSql(a => new
{
all = a,
count = select.As("b").Max(b => b.Id)
max = select.As("b").Max(b => b.Id),
max2 = select.As("b").Max(b => b.CreateTime)
});
Assert.Equal(@"SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5, ifnull((SELECT max(b.`Id`)
FROM `tb_topic` b), 0) as6
FROM `tb_topic` b), 0) as6, ifnull((SELECT max(b.`CreateTime`)
FROM `tb_topic` b), '0001-01-01 00:00:00.000') as7
FROM `tb_topic` a", subquery);
var subqueryList = select.ToList(a => new
{
all = a,
count = select.As("b").Max(b => b.Id)
max = select.As("b").Max(b => b.Id),
max2 = select.As("b").Max(b => b.CreateTime)
});
}
[Fact]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -880,15 +880,18 @@ public void Min()
var subquery = select.ToSql(a => new
{
all = a,
count = select.As("b").Min(b => b.Id)
min = select.As("b").Min(b => b.Id),
min2 = select.As("b").Min(b => b.CreateTime)
});
Assert.Equal(@"SELECT a.""ID"" as1, a.""CLICKS"" as2, a.""TYPEGUID"" as3, a.""TITLE"" as4, a.""CREATETIME"" as5, nvl((SELECT min(b.""ID"")
FROM ""TB_TOPIC22"" b), 0) as6
FROM ""TB_TOPIC22"" b), 0) as6, nvl((SELECT min(b.""CREATETIME"")
FROM ""TB_TOPIC22"" b), to_timestamp('0001-01-01 00:00:00.000000','YYYY-MM-DD HH24:MI:SS.FF6')) as7
FROM ""TB_TOPIC22"" a", subquery);
var subqueryList = select.ToList(a => new
{
all = a,
count = select.As("b").Min(b => b.Id)
min = select.As("b").Min(b => b.Id),
min2 = select.As("b").Min(b => b.CreateTime)
});
}
[Fact]
Expand All @@ -897,15 +900,18 @@ public void Max()
var subquery = select.ToSql(a => new
{
all = a,
count = select.As("b").Max(b => b.Id)
max = select.As("b").Max(b => b.Id),
max2 = select.As("b").Max(b => b.CreateTime)
});
Assert.Equal(@"SELECT a.""ID"" as1, a.""CLICKS"" as2, a.""TYPEGUID"" as3, a.""TITLE"" as4, a.""CREATETIME"" as5, nvl((SELECT max(b.""ID"")
FROM ""TB_TOPIC22"" b), 0) as6
FROM ""TB_TOPIC22"" b), 0) as6, nvl((SELECT max(b.""CREATETIME"")
FROM ""TB_TOPIC22"" b), to_timestamp('0001-01-01 00:00:00.000000','YYYY-MM-DD HH24:MI:SS.FF6')) as7
FROM ""TB_TOPIC22"" a", subquery);
var subqueryList = select.ToList(a => new
{
all = a,
count = select.As("b").Max(b => b.Id)
max = select.As("b").Max(b => b.Id),
max2 = select.As("b").Max(b => b.CreateTime)
});
}
[Fact]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -941,15 +941,18 @@ public void Min()
var subquery = select.ToSql(a => new
{
all = a,
count = select.As("b").Min(b => b.Id)
min = select.As("b").Min(b => b.Id),
min2 = select.As("b").Min(b => b.CreateTime)
});
Assert.Equal(@"SELECT a.""id"" as1, a.""clicks"" as2, a.""typeguid"" as3, a.""title"" as4, a.""createtime"" as5, coalesce((SELECT min(b.""id"")
FROM ""tb_topic"" b), 0) as6
FROM ""tb_topic"" b), 0) as6, coalesce((SELECT min(b.""createtime"")
FROM ""tb_topic"" b), '0001-01-01 00:00:00.000000') as7
FROM ""tb_topic"" a", subquery);
var subqueryList = select.ToList(a => new
{
all = a,
count = select.As("b").Min(b => b.Id)
min = select.As("b").Min(b => b.Id),
min2 = select.As("b").Min(b => b.CreateTime)
});
}
[Fact]
Expand All @@ -958,15 +961,18 @@ public void Max()
var subquery = select.ToSql(a => new
{
all = a,
count = select.As("b").Max(b => b.Id)
max = select.As("b").Max(b => b.Id),
max2 = select.As("b").Max(b => b.CreateTime)
});
Assert.Equal(@"SELECT a.""id"" as1, a.""clicks"" as2, a.""typeguid"" as3, a.""title"" as4, a.""createtime"" as5, coalesce((SELECT max(b.""id"")
FROM ""tb_topic"" b), 0) as6
FROM ""tb_topic"" b), 0) as6, coalesce((SELECT max(b.""createtime"")
FROM ""tb_topic"" b), '0001-01-01 00:00:00.000000') as7
FROM ""tb_topic"" a", subquery);
var subqueryList = select.ToList(a => new
{
all = a,
count = select.As("b").Max(b => b.Id)
max = select.As("b").Max(b => b.Id),
max2 = select.As("b").Max(b => b.CreateTime)
});
}
[Fact]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -835,15 +835,19 @@ public void Min()
var subquery = select.ToSql(a => new
{
all = a,
count = select.As("b").Min(b => b.Id)
min = select.As("b").Min(b => b.Id),
min2 = select.As("b").Min(b => b.CreateTime)
});
Assert.Equal(@"SELECT a.[Id] as1, a.[Clicks] as2, a.[TypeGuid] as3, a.[Title] as4, a.[CreateTime] as5, isnull((SELECT min(b.[Id])
FROM [tb_topic22] b), 0) as6
FROM [tb_topic22] b), 0) as6, isnull((SELECT min(b.[CreateTime])
FROM [tb_topic22] b), '1970-01-01 00:00:00.000') as7
FROM [tb_topic22] a", subquery);
var subqueryList = select.ToList(a => new
{
all = a,
count = select.As("b").Min(b => b.Id)
min = select.As("b").Min(b => b.Id),
min2 = select.As("b").Min(b => b.CreateTime),
min3 = select.As("b").Where(b => b.Id < 0).Min(b => b.CreateTime)
});
}
[Fact]
Expand All @@ -852,15 +856,18 @@ public void Max()
var subquery = select.ToSql(a => new
{
all = a,
count = select.As("b").Max(b => b.Id)
max = select.As("b").Max(b => b.Id),
max2 = select.As("b").Max(b => b.CreateTime)
});
Assert.Equal(@"SELECT a.[Id] as1, a.[Clicks] as2, a.[TypeGuid] as3, a.[Title] as4, a.[CreateTime] as5, isnull((SELECT max(b.[Id])
FROM [tb_topic22] b), 0) as6
FROM [tb_topic22] b), 0) as6, isnull((SELECT max(b.[CreateTime])
FROM [tb_topic22] b), '1970-01-01 00:00:00.000') as7
FROM [tb_topic22] a", subquery);
var subqueryList = select.ToList(a => new
{
all = a,
count = select.As("b").Max(b => b.Id)
max = select.As("b").Max(b => b.Id),
max2 = select.As("b").Max(b => b.CreateTime)
});
}
[Fact]
Expand Down
19 changes: 13 additions & 6 deletions FreeSql.Tests/FreeSql.Tests/Dameng/Curd/DamengSelectTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1026,15 +1026,19 @@ public void Min()
var subquery = select.ToSql(a => new
{
all = a,
count = select.As("b").Min(b => b.Id)
min = select.As("b").Min(b => b.Id),
min2 = select.As("b").Min(b => b.CreateTime)
});
Assert.Equal(@"SELECT a.""ID"" as1, a.""CLICKS"" as2, a.""TYPEGUID"" as3, a.""TITLE"" as4, a.""CREATETIME"" as5, nvl((SELECT min(b.""ID"")
FROM ""TB_TOPIC22"" b), 0) as6
FROM ""TB_TOPIC22"" b), 0) as6, nvl((SELECT min(b.""CREATETIME"")
FROM ""TB_TOPIC22"" b), to_timestamp('0001-01-01 00:00:00.000000','YYYY-MM-DD HH24:MI:SS.FF6')) as7
FROM ""TB_TOPIC22"" a", subquery);
var subqueryList = select.ToList(a => new
{
all = a,
count = select.As("b").Min(b => b.Id)
min = select.As("b").Min(b => b.Id),
min2 = select.As("b").Min(b => b.CreateTime),
min3 = select.As("b").Where(b => b.Id < 0).Min(b => b.CreateTime)
});
}
[Fact]
Expand All @@ -1043,15 +1047,18 @@ public void Max()
var subquery = select.ToSql(a => new
{
all = a,
count = select.As("b").Max(b => b.Id)
max = select.As("b").Max(b => b.Id),
max2 = select.As("b").Max(b => b.CreateTime)
});
Assert.Equal(@"SELECT a.""ID"" as1, a.""CLICKS"" as2, a.""TYPEGUID"" as3, a.""TITLE"" as4, a.""CREATETIME"" as5, nvl((SELECT max(b.""ID"")
FROM ""TB_TOPIC22"" b), 0) as6
FROM ""TB_TOPIC22"" b), 0) as6, nvl((SELECT max(b.""CREATETIME"")
FROM ""TB_TOPIC22"" b), to_timestamp('0001-01-01 00:00:00.000000','YYYY-MM-DD HH24:MI:SS.FF6')) as7
FROM ""TB_TOPIC22"" a", subquery);
var subqueryList = select.ToList(a => new
{
all = a,
count = select.As("b").Max(b => b.Id)
max = select.As("b").Max(b => b.Id),
max2 = select.As("b").Max(b => b.CreateTime)
});
}
[Fact]
Expand Down
Loading

0 comments on commit 8263379

Please sign in to comment.