mirror of
https://github.com/nsnail/FreeSql.git
synced 2025-06-19 04:18:16 +08:00
- 优化 IUpdate 批量 case when 同值的 SQL 生成;#1393
This commit is contained in:
@ -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();
|
||||
|
@ -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();
|
||||
}
|
||||
|
||||
|
@ -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
|
||||
|
@ -59,10 +59,7 @@ ON CONFLICT(""id"") DO UPDATE SET
|
||||
Assert.Equal(@"INSERT INTO ""testonconflictdoupdateinfo""(""id"", ""title"") VALUES(200, 'title-200'), (201, 'title-201'), (202, 'title-202')
|
||||
ON CONFLICT(""id"") DO UPDATE SET
|
||||
""title"" = EXCLUDED.""title"",
|
||||
""time"" = CASE EXCLUDED.""id""
|
||||
WHEN 200 THEN '2000-01-01 00:00:00.000000'
|
||||
WHEN 201 THEN '2000-01-01 00:00:00.000000'
|
||||
WHEN 202 THEN '2000-01-01 00:00:00.000000' END::timestamp", odku2.ToSql());
|
||||
""time"" = '2000-01-01 00:00:00.000000'", odku2.ToSql());
|
||||
odku2.ExecuteAffrows();
|
||||
|
||||
|
||||
@ -80,10 +77,7 @@ ON CONFLICT(""id"") DO UPDATE SET
|
||||
}).IgnoreColumns(a => a.time).NoneParameter().InsertIdentity()).IgnoreColumns(a => a.title);
|
||||
Assert.Equal(@"INSERT INTO ""testonconflictdoupdateinfo""(""id"", ""title"") VALUES(200, 'title-200'), (201, 'title-201'), (202, 'title-202')
|
||||
ON CONFLICT(""id"") DO UPDATE SET
|
||||
""time"" = CASE EXCLUDED.""id""
|
||||
WHEN 200 THEN '2000-01-01 00:00:00.000000'
|
||||
WHEN 201 THEN '2000-01-01 00:00:00.000000'
|
||||
WHEN 202 THEN '2000-01-01 00:00:00.000000' END::timestamp", odku2.ToSql());
|
||||
""time"" = '2000-01-01 00:00:00.000000'", odku2.ToSql());
|
||||
odku2.ExecuteAffrows();
|
||||
}
|
||||
|
||||
@ -106,10 +100,7 @@ ON CONFLICT(""id"") DO UPDATE SET
|
||||
Assert.Equal(@"INSERT INTO ""testonconflictdoupdateinfo""(""id"", ""title"") VALUES(300, 'title-300'), (301, 'title-301'), (302, 'title-302')
|
||||
ON CONFLICT(""id"") DO UPDATE SET
|
||||
""title"" = EXCLUDED.""title"",
|
||||
""time"" = CASE EXCLUDED.""id""
|
||||
WHEN 300 THEN '2000-01-01 00:00:00.000000'
|
||||
WHEN 301 THEN '2000-01-01 00:00:00.000000'
|
||||
WHEN 302 THEN '2000-01-01 00:00:00.000000' END::timestamp", odku2.ToSql());
|
||||
""time"" = '2000-01-01 00:00:00.000000'", odku2.ToSql());
|
||||
odku2.ExecuteAffrows();
|
||||
|
||||
|
||||
@ -127,10 +118,7 @@ ON CONFLICT(""id"") DO UPDATE SET
|
||||
}).InsertColumns(a => a.title).NoneParameter().InsertIdentity()).UpdateColumns(a => a.time);
|
||||
Assert.Equal(@"INSERT INTO ""testonconflictdoupdateinfo""(""id"", ""title"") VALUES(300, 'title-300'), (301, 'title-301'), (302, 'title-302')
|
||||
ON CONFLICT(""id"") DO UPDATE SET
|
||||
""time"" = CASE EXCLUDED.""id""
|
||||
WHEN 300 THEN '2000-01-01 00:00:00.000000'
|
||||
WHEN 301 THEN '2000-01-01 00:00:00.000000'
|
||||
WHEN 302 THEN '2000-01-01 00:00:00.000000' END::timestamp", odku2.ToSql());
|
||||
""time"" = '2000-01-01 00:00:00.000000'", odku2.ToSql());
|
||||
odku2.ExecuteAffrows();
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user