- 优化 IUpdate 批量 case when 同值的 SQL 生成;#1393

This commit is contained in:
2881099
2023-01-06 01:59:28 +08:00
parent 050a00104a
commit 1d9cd1f59d
10 changed files with 46 additions and 129 deletions

View File

@ -87,7 +87,7 @@ ON DUPLICATE KEY UPDATE
Assert.Equal(@"INSERT INTO `tbiou022`(`id`, `name`) VALUES(1, '01'), (2, '02'), (3, '03'), (4, '04')
ON DUPLICATE KEY UPDATE
`name` = VALUES(`name`)", sql);
Assert.Equal(4, iou.ExecuteAffrows());
Assert.Equal(5, 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();

View File

@ -59,10 +59,7 @@ ON DUPLICATE KEY UPDATE
Assert.Equal(@"INSERT INTO `TestOnDuplicateKeyUpdateInfo`(`id`, `title`) VALUES(200, 'title-200'), (201, 'title-201'), (202, 'title-202')
ON DUPLICATE KEY UPDATE
`title` = VALUES(`title`),
`time` = CASE `id`
WHEN 200 THEN '2000-01-01 00:00:00.000'
WHEN 201 THEN '2000-01-01 00:00:00.000'
WHEN 202 THEN '2000-01-01 00:00:00.000' END", odku2.ToSql());
`time` = '2000-01-01 00:00:00.000'", odku2.ToSql());
odku2.ExecuteAffrows();
@ -80,10 +77,7 @@ ON DUPLICATE KEY UPDATE
}).IgnoreColumns(a => a.time).NoneParameter().InsertIdentity()).IgnoreColumns(a => a.title);
Assert.Equal(@"INSERT INTO `TestOnDuplicateKeyUpdateInfo`(`id`, `title`) VALUES(200, 'title-200'), (201, 'title-201'), (202, 'title-202')
ON DUPLICATE KEY UPDATE
`time` = CASE `id`
WHEN 200 THEN '2000-01-01 00:00:00.000'
WHEN 201 THEN '2000-01-01 00:00:00.000'
WHEN 202 THEN '2000-01-01 00:00:00.000' END", odku2.ToSql());
`time` = '2000-01-01 00:00:00.000'", odku2.ToSql());
odku2.ExecuteAffrows();
}
@ -106,10 +100,7 @@ ON DUPLICATE KEY UPDATE
Assert.Equal(@"INSERT INTO `TestOnDuplicateKeyUpdateInfo`(`id`, `title`) VALUES(300, 'title-300'), (301, 'title-301'), (302, 'title-302')
ON DUPLICATE KEY UPDATE
`title` = VALUES(`title`),
`time` = CASE `id`
WHEN 300 THEN '2000-01-01 00:00:00.000'
WHEN 301 THEN '2000-01-01 00:00:00.000'
WHEN 302 THEN '2000-01-01 00:00:00.000' END", odku2.ToSql());
`time` = '2000-01-01 00:00:00.000'", odku2.ToSql());
odku2.ExecuteAffrows();
@ -127,10 +118,7 @@ ON DUPLICATE KEY UPDATE
}).InsertColumns(a => a.title).NoneParameter().InsertIdentity()).UpdateColumns(a => a.time);
Assert.Equal(@"INSERT INTO `TestOnDuplicateKeyUpdateInfo`(`id`, `title`) VALUES(300, 'title-300'), (301, 'title-301'), (302, 'title-302')
ON DUPLICATE KEY UPDATE
`time` = CASE `id`
WHEN 300 THEN '2000-01-01 00:00:00.000'
WHEN 301 THEN '2000-01-01 00:00:00.000'
WHEN 302 THEN '2000-01-01 00:00:00.000' END", odku2.ToSql());
`time` = '2000-01-01 00:00:00.000'", odku2.ToSql());
odku2.ExecuteAffrows();
}

View File

@ -1,4 +1,4 @@
using FreeSql.DataAnnotations;
using FreeSql.DataAnnotations;
using System;
using System.Data.Odbc;
using Xunit;
@ -58,7 +58,7 @@ namespace FreeSql.Tests.Custom.MySql
[Fact]
public void QueryMultipline()
{
Assert.Throws<Exception>(() => g.mysql.Ado.Query<xxx, (int, string, string), dynamic>("select * from song; select * from song; select * from song"));
g.mysql.Ado.Query<xxx, (int, string, string), dynamic>("select * from song; select * from song; select * from song");
}
class xxx