mirror of
https://github.com/nsnail/FreeSql.git
synced 2025-06-18 03:53:21 +08:00
Clickhouse 数组参数化测试
This commit is contained in:
parent
d91c7fbdfd
commit
8e2aa2b44b
@ -5,6 +5,7 @@ using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using FreeSql.DataAnnotations;
|
||||
using Newtonsoft.Json;
|
||||
using Xunit;
|
||||
using Xunit.Abstractions;
|
||||
|
||||
@ -21,7 +22,7 @@ namespace FreeSql.Tests.ClickHouse
|
||||
_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(true)
|
||||
.UseNoneCommandParameter(false)
|
||||
.Build();
|
||||
}
|
||||
|
||||
@ -118,18 +119,32 @@ namespace FreeSql.Tests.ClickHouse
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 测试Array类型映射
|
||||
/// 测试Array类型插入
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public void ArrayBoolMappingInsert()
|
||||
{
|
||||
_ = _fsql.Insert(new ArrayMappingTestSimple
|
||||
var source = new List<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();
|
||||
new ArrayMappingTestSimple
|
||||
{
|
||||
Name = "daily",
|
||||
Tags1 = new [] { "e", "f", "g" },
|
||||
Tags2 = new [] { 3, 45, 100, 400 },
|
||||
Tags3 = new [] { false, true, false }
|
||||
}
|
||||
};
|
||||
var str = _fsql.Insert(source).ExecuteAffrows();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 测试Array类型映射
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public void ArrayBoolMappingSelect()
|
||||
{
|
||||
var list = _fsql.Select<ArrayMappingTestSimple>().ToList();
|
||||
_output.WriteLine(JsonConvert.SerializeObject(list));
|
||||
}
|
||||
}
|
||||
|
||||
@ -176,10 +191,10 @@ namespace FreeSql.Tests.ClickHouse
|
||||
[Column(Name = "name", IsPrimary = true)]
|
||||
public string Name { get; set; }
|
||||
|
||||
[Column(Name = "tags1")] public IEnumerable<string> Tags1 { get; set; }
|
||||
[Column(Name = "tags1")] public string [] Tags1 { get; set; }
|
||||
|
||||
[Column(Name = "tags2")] public List<int> Tags2 { get; set; }
|
||||
[Column(Name = "tags2")] public int[] Tags2 { get; set; }
|
||||
|
||||
[Column(Name = "tags3")] public IEnumerable<bool> Tags3 { get; set; }
|
||||
[Column(Name = "tags3")] public bool [] Tags3 { get; set; }
|
||||
}
|
||||
}
|
@ -35,6 +35,11 @@
|
||||
</summary>
|
||||
</member>
|
||||
<member name="M:FreeSql.Tests.ClickHouse.ClickHouseTest3.ArrayBoolMappingInsert">
|
||||
<summary>
|
||||
测试Array类型插入
|
||||
</summary>
|
||||
</member>
|
||||
<member name="M:FreeSql.Tests.ClickHouse.ClickHouseTest3.ArrayBoolMappingSelect">
|
||||
<summary>
|
||||
测试Array类型映射
|
||||
</summary>
|
||||
|
@ -85,7 +85,7 @@ namespace FreeSql.ClickHouse
|
||||
trydc.defaultValue);
|
||||
|
||||
//判断是否是集合
|
||||
var isCollection = IsCollection(type);
|
||||
var isCollection = IsArray(type);
|
||||
if (isCollection.Item1)
|
||||
{
|
||||
var genericType = isCollection.Item2;
|
||||
@ -102,6 +102,21 @@ namespace FreeSql.ClickHouse
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
private Tuple<bool, Type> IsArray(Type type)
|
||||
{
|
||||
var flag = false;
|
||||
Type resultType = null;
|
||||
|
||||
if (type.IsArray)
|
||||
{
|
||||
flag = true;
|
||||
resultType = type.GetElementType();
|
||||
}
|
||||
|
||||
return new Tuple<bool, Type>(flag, resultType);
|
||||
}
|
||||
|
||||
private Tuple<bool, Type> IsCollection(Type type)
|
||||
{
|
||||
var flag = false;
|
||||
|
@ -6,6 +6,7 @@ using System.Collections.Generic;
|
||||
using System.Data.Common;
|
||||
using System.Globalization;
|
||||
using System.Data;
|
||||
using System.Text.Json;
|
||||
using ClickHouse.Client.ADO.Parameters;
|
||||
using System.Text.RegularExpressions;
|
||||
|
||||
@ -18,7 +19,7 @@ namespace FreeSql.ClickHouse
|
||||
}
|
||||
|
||||
public override DbParameter AppendParamter(List<DbParameter> _params, string parameterName, ColumnInfo col, Type type, object value)
|
||||
{
|
||||
{
|
||||
if (value is string str)
|
||||
value = str?.Replace("\t", "\\t")
|
||||
.Replace("\r\n", "\\r\\n")
|
||||
@ -43,9 +44,10 @@ namespace FreeSql.ClickHouse
|
||||
if (col.DbScale != 0) ret.Scale = col.DbScale;
|
||||
break;
|
||||
}
|
||||
//直接使用Bool
|
||||
//if (value is bool)
|
||||
// ret.Value = (bool)value ? 1 : 0;
|
||||
//if (value.GetType().IsArray)
|
||||
//{
|
||||
// ret.DbType = DbType.Object;
|
||||
//}
|
||||
}
|
||||
_params?.Add(ret);
|
||||
return ret;
|
||||
|
Loading…
x
Reference in New Issue
Block a user