- 优化 MySqlConnector MySqlDataTime 读取;

This commit is contained in:
2881099
2022-12-20 22:01:51 +08:00
parent 637bff767a
commit 40a6e11457
5 changed files with 41 additions and 15 deletions

View File

@@ -15,14 +15,13 @@ namespace FreeSql.Tests.MySql
public void InsertOrUpdate_OnePrimary()
{
fsql.Delete<tbiou02>().Where("1=1").ExecuteAffrows();
var iou = fsql.InsertOrUpdate<tbiou02>().SetSource(fsql.Select<tbiou022>().ToSql(a => new { id = a.id + 1, name = "xxx" }, FieldAliasOptions.AsProperty));
var iou = fsql.InsertOrUpdate<tbiou02>().SetSource(fsql.Select<tbiou022>().ToSql(a => new { id = a.id + 1, name = "'xxx'" }, FieldAliasOptions.AsProperty));
var sql = iou.ToSql();
Assert.Equal(@"INSERT INTO `tbiou02`(`id`, `name`)
SELECT (a.`id` + 1) `id`, xxx `name`
SELECT (a.`id` + 1) `id`, 'xxx' `name`
FROM `tbiou022` a
ON DUPLICATE KEY UPDATE
`name` = VALUES(`name`)", sql);
Assert.Equal(0, iou.ExecuteAffrows());
iou = fsql.InsertOrUpdate<tbiou02>().SetSource(new tbiou02 { id = 1, name = "01" });
sql = iou.ToSql();

View File

@@ -11,7 +11,7 @@ namespace FreeSql.Tests.PostgreSQL
IInsert<Topic> insert => g.pgsql.Insert<Topic>();
[Table(Name = "tb_topic_insert")]
[Table(Name = "tb_topic_insert2")]
class Topic
{
[Column(IsIdentity = true, IsPrimary = true)]
@@ -137,21 +137,33 @@ namespace FreeSql.Tests.PostgreSQL
insert.AppendData(items.First()).ExecuteInserted();
}
[Table(Name = "tb_topic_insert_pgcopy")]
class TopicPgCopy
{
[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 ExecutePgCopy()
{
var maxId = g.pgsql.Select<Topic>().Max(a => a.Id);
var items = new List<Topic>();
for (var a = 0; a < 10; a++) items.Add(new Topic { Id = maxId + a + 1, Title = $"newtitle{a}", Clicks = a * 100, CreateTime = DateTime.Now });
var maxId = g.pgsql.Select<TopicPgCopy>().Max(a => a.Id);
var items = new List<TopicPgCopy>();
for (var a = 0; a < 10; a++) items.Add(new TopicPgCopy { Id = maxId + a + 1, Title = $"newtitle{a}", Clicks = a * 100, CreateTime = DateTime.Now });
insert.AppendData(items).InsertIdentity().ExecutePgCopy();
g.pgsql.Insert(items).InsertIdentity().ExecutePgCopy();
items = g.pgsql.Select<Topic>().OrderByDescending(a => a.Id).Limit(1000).ToList();
items = g.pgsql.Select<TopicPgCopy>().OrderByDescending(a => a.Id).Limit(1000).ToList();
var sql = g.pgsql.Insert(items).InsertIdentity().NoneParameter().ToSql();
g.pgsql.Update<Topic>().SetSource(items).ExecutePgCopy();
g.pgsql.Update<Topic>().SetSource(items, a => new { a.Id, a.Clicks }).ExecutePgCopy();
g.pgsql.Update<Topic>().SetSource(items).UpdateColumns(a => new { a.Title }).ExecutePgCopy();
g.pgsql.Update<Topic>().SetSource(items, a => new { a.Id, a.Clicks }).UpdateColumns(a => new { a.Title }).ExecutePgCopy();
g.pgsql.Update<TopicPgCopy>().SetSource(items).ExecutePgCopy();
g.pgsql.Update<TopicPgCopy>().SetSource(items, a => new { a.Id, a.Clicks }).ExecutePgCopy();
g.pgsql.Update<TopicPgCopy>().SetSource(items).UpdateColumns(a => new { a.Title }).ExecutePgCopy();
g.pgsql.Update<TopicPgCopy>().SetSource(items, a => new { a.Id, a.Clicks }).UpdateColumns(a => new { a.Title }).ExecutePgCopy();
}
[Fact]