Clickhouse Array泛型插入测试

This commit is contained in:
d4ilys 2023-11-21 11:40:22 +08:00
parent 322332cf73
commit d91c7fbdfd
4 changed files with 37 additions and 3 deletions

View File

@ -114,7 +114,22 @@ namespace FreeSql.Tests.ClickHouse
[Fact] [Fact]
public void ArrayBoolMappingSync() public void ArrayBoolMappingSync()
{ {
_fsql.CodeFirst.SyncStructure(typeof(ArrayMappingTest)); _fsql.CodeFirst.SyncStructure(typeof(ArrayMappingTestSimple));
}
/// <summary>
/// 测试Array类型映射
/// </summary>
[Fact]
public void ArrayBoolMappingInsert()
{
_ = _fsql.Insert(new ArrayMappingTestSimple
{
Name = "daily",
Tags1 = new List<string>() { "a", "b", "c" },
Tags2 = new List<int>() { 1, 2, 3, 4 },
Tags3 = new List<bool>() { true, true, false }
}).ExecuteAffrows();
} }
} }
@ -153,4 +168,18 @@ namespace FreeSql.Tests.ClickHouse
[Column(Name = "tags7")] public IEnumerable<bool> Tags7 { get; set; } [Column(Name = "tags7")] public IEnumerable<bool> Tags7 { get; set; }
} }
[Table(Name = "table_test_array_simple")]
public class ArrayMappingTestSimple
{
[Column(Name = "name", IsPrimary = true)]
public string Name { get; set; }
[Column(Name = "tags1")] public IEnumerable<string> Tags1 { get; set; }
[Column(Name = "tags2")] public List<int> Tags2 { get; set; }
[Column(Name = "tags3")] public IEnumerable<bool> Tags3 { get; set; }
}
} }

View File

@ -34,6 +34,11 @@
测试Array类型映射 测试Array类型映射
</summary> </summary>
</member> </member>
<member name="M:FreeSql.Tests.ClickHouse.ClickHouseTest3.ArrayBoolMappingInsert">
<summary>
测试Array类型映射
</summary>
</member>
<member name="T:FreeSql.Tests.ClickHouse.CollectDataEntityUpdate01"> <member name="T:FreeSql.Tests.ClickHouse.CollectDataEntityUpdate01">
<summary> <summary>
实时数据 实时数据

View File

@ -43,7 +43,7 @@ namespace FreeSql.Internal.CommonProvider
sb.Append(AddslashesProcessParam(z, mapType, mapColumn)); sb.Append(AddslashesProcessParam(z, mapType, mapColumn));
} }
return sb.Length == 0 ? "(NULL)" : sb.Remove(0, 1).Insert(0, "(").Append(")").ToString(); return sb.Length == 0 ? "(NULL)" : sb.Remove(0, 1).Insert(0, "[").Append("]").ToString();
} }
public static bool IsFromSlave(string cmdText) public static bool IsFromSlave(string cmdText)

View File

@ -146,7 +146,7 @@ namespace FreeSql.ClickHouse
} }
public override string GetNoneParamaterSqlValue(List<DbParameter> specialParams, string specialParamFlag, ColumnInfo col, Type type, object value) public override string GetNoneParamaterSqlValue(List<DbParameter> specialParams, string specialParamFlag, ColumnInfo col, Type type, object value)
{ {
if (value == null) return "NULL"; if (value == null) return "NULL";
if (type.IsNumberType()) return string.Format(CultureInfo.InvariantCulture, "{0}", value); if (type.IsNumberType()) return string.Format(CultureInfo.InvariantCulture, "{0}", value);
if (type == typeof(byte[])) return $"0x{CommonUtils.BytesSqlRaw(value as byte[])}"; if (type == typeof(byte[])) return $"0x{CommonUtils.BytesSqlRaw(value as byte[])}";