From 3528c01c5b0a2674b967020112155c325aff7125 Mon Sep 17 00:00:00 2001 From: d4ilys <963922242@qq.com> Date: Tue, 21 Nov 2023 09:39:34 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B5=8B=E8=AF=95ClickHouse=20Bool=E6=98=A0?= =?UTF-8?q?=E5=B0=84=E6=8F=92=E5=85=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ClickHouse/ClickHouseTest2.cs | 4 + .../ClickHouse/ClickHouseTest3.cs | 87 +++++++++++++++++++ .../ClickHouseUtils.cs | 5 +- 3 files changed, 94 insertions(+), 2 deletions(-) create mode 100644 FreeSql.Tests/FreeSql.Tests/ClickHouse/ClickHouseTest3.cs diff --git a/FreeSql.Tests/FreeSql.Tests/ClickHouse/ClickHouseTest2.cs b/FreeSql.Tests/FreeSql.Tests/ClickHouse/ClickHouseTest2.cs index 9bc76f41..b96e8e9d 100644 --- a/FreeSql.Tests/FreeSql.Tests/ClickHouse/ClickHouseTest2.cs +++ b/FreeSql.Tests/FreeSql.Tests/ClickHouse/ClickHouseTest2.cs @@ -8,11 +8,14 @@ using System.Diagnostics; using System.ComponentModel.DataAnnotations; using FreeSql.DataAnnotations; using Xunit; +using Xunit.Abstractions; namespace FreeSql.Tests.ClickHouse { public class ClickHouseTest2 { + + private static IFreeSql fsql = new FreeSqlBuilder().UseConnectionString(DataType.ClickHouse, "Host=127.0.0.1;Port=8123;Database=test;Compress=True;Min Pool Size=1") .UseMonitorCommand(cmd => Console.WriteLine($"线程:{cmd.CommandText}\r\n")) @@ -29,6 +32,7 @@ namespace FreeSql.Tests.ClickHouse { fsql.CodeFirst.SyncStructure(typeof(PositionInfoModel)); } + [Fact] public void Issuse1587TestOnePrimary() { diff --git a/FreeSql.Tests/FreeSql.Tests/ClickHouse/ClickHouseTest3.cs b/FreeSql.Tests/FreeSql.Tests/ClickHouse/ClickHouseTest3.cs new file mode 100644 index 00000000..fc990939 --- /dev/null +++ b/FreeSql.Tests/FreeSql.Tests/ClickHouse/ClickHouseTest3.cs @@ -0,0 +1,87 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using FreeSql.DataAnnotations; +using Xunit; +using Xunit.Abstractions; + +namespace FreeSql.Tests.ClickHouse +{ + public class ClickHouseTest3 + { + private static ITestOutputHelper _output; + private static IFreeSql _fsql; + + public ClickHouseTest3(ITestOutputHelper output) + { + _output = output; + _fsql = new FreeSqlBuilder().UseConnectionString(DataType.ClickHouse, + "Host=192.168.1.123;Port=8123;Database=test;Compress=True;Min Pool Size=1") + .UseMonitorCommand(cmd => _output.WriteLine($"线程:{cmd.CommandText}\r\n")) + .UseNoneCommandParameter(false) + .Build(); + } + + /// + /// 测试bool类型映射 + /// + [Fact] + public void TestBoolMappingSync() + { + _fsql.CodeFirst.SyncStructure(typeof(BoolMappingTest)); + + } + + /// + /// 测试bool类型映射 + /// + [Fact] + public void TestBoolMappingInsert() + { + _fsql.Insert(new BoolMappingTest + { + Name = "Tom", + Age = 20, + Id = Guid.NewGuid().ToString(), + IsDelete = true, + IsEnable = true + }).ExecuteAffrows(); + + _fsql.Insert(new BoolMappingTest + { + Name = "Jess", + Age = 21, + Id = Guid.NewGuid().ToString(), + IsDelete = true, + IsEnable = false + }).ExecuteAffrows(); + + _fsql.Insert(new BoolMappingTest + { + Name = "Daily", + Age = 22, + Id = Guid.NewGuid().ToString(), + IsDelete = true, + IsEnable = null + }).ExecuteAffrows(); + } + + } + + [Table(Name = "table_test_bool")] + public class BoolMappingTest + { + [Column(IsPrimary = true, Name = "id")] + public string Id { set; get; } + + [Column(Name = "name")] public string Name { get; set; } + + [Column(Name = "age")] public int Age { get; set; } + + [Column(Name = "is_delete")] public bool IsDelete { get; set; } + + [Column(Name = "is_enable")] public bool? IsEnable { get; set; } + } +} \ No newline at end of file diff --git a/Providers/FreeSql.Provider.ClickHouse/ClickHouseUtils.cs b/Providers/FreeSql.Provider.ClickHouse/ClickHouseUtils.cs index 126b0704..c2ec7634 100644 --- a/Providers/FreeSql.Provider.ClickHouse/ClickHouseUtils.cs +++ b/Providers/FreeSql.Provider.ClickHouse/ClickHouseUtils.cs @@ -43,8 +43,9 @@ namespace FreeSql.ClickHouse if (col.DbScale != 0) ret.Scale = col.DbScale; break; } - if (value is bool) - ret.Value = (bool)value ? 1 : 0; + //直接使用Bool + //if (value is bool) + // ret.Value = (bool)value ? 1 : 0; } _params?.Add(ret); return ret;