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.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using FreeSql.DataAnnotations;
|
using FreeSql.DataAnnotations;
|
||||||
|
using Newtonsoft.Json;
|
||||||
using Xunit;
|
using Xunit;
|
||||||
using Xunit.Abstractions;
|
using Xunit.Abstractions;
|
||||||
|
|
||||||
@ -21,7 +22,7 @@ namespace FreeSql.Tests.ClickHouse
|
|||||||
_fsql = new FreeSqlBuilder().UseConnectionString(DataType.ClickHouse,
|
_fsql = new FreeSqlBuilder().UseConnectionString(DataType.ClickHouse,
|
||||||
"Host=192.168.1.123;Port=8123;Database=test;Compress=True;Min Pool Size=1")
|
"Host=192.168.1.123;Port=8123;Database=test;Compress=True;Min Pool Size=1")
|
||||||
.UseMonitorCommand(cmd => _output.WriteLine($"线程:{cmd.CommandText}\r\n"))
|
.UseMonitorCommand(cmd => _output.WriteLine($"线程:{cmd.CommandText}\r\n"))
|
||||||
.UseNoneCommandParameter(true)
|
.UseNoneCommandParameter(false)
|
||||||
.Build();
|
.Build();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -118,18 +119,32 @@ namespace FreeSql.Tests.ClickHouse
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 测试Array类型映射
|
/// 测试Array类型插入
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[Fact]
|
[Fact]
|
||||||
public void ArrayBoolMappingInsert()
|
public void ArrayBoolMappingInsert()
|
||||||
{
|
{
|
||||||
_ = _fsql.Insert(new ArrayMappingTestSimple
|
var source = new List<ArrayMappingTestSimple>()
|
||||||
{
|
{
|
||||||
Name = "daily",
|
new ArrayMappingTestSimple
|
||||||
Tags1 = new List<string>() { "a", "b", "c" },
|
{
|
||||||
Tags2 = new List<int>() { 1, 2, 3, 4 },
|
Name = "daily",
|
||||||
Tags3 = new List<bool>() { true, true, false }
|
Tags1 = new [] { "e", "f", "g" },
|
||||||
}).ExecuteAffrows();
|
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)]
|
[Column(Name = "name", IsPrimary = true)]
|
||||||
public string Name { get; set; }
|
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>
|
</summary>
|
||||||
</member>
|
</member>
|
||||||
<member name="M:FreeSql.Tests.ClickHouse.ClickHouseTest3.ArrayBoolMappingInsert">
|
<member name="M:FreeSql.Tests.ClickHouse.ClickHouseTest3.ArrayBoolMappingInsert">
|
||||||
|
<summary>
|
||||||
|
测试Array类型插入
|
||||||
|
</summary>
|
||||||
|
</member>
|
||||||
|
<member name="M:FreeSql.Tests.ClickHouse.ClickHouseTest3.ArrayBoolMappingSelect">
|
||||||
<summary>
|
<summary>
|
||||||
测试Array类型映射
|
测试Array类型映射
|
||||||
</summary>
|
</summary>
|
||||||
|
@ -85,7 +85,7 @@ namespace FreeSql.ClickHouse
|
|||||||
trydc.defaultValue);
|
trydc.defaultValue);
|
||||||
|
|
||||||
//判断是否是集合
|
//判断是否是集合
|
||||||
var isCollection = IsCollection(type);
|
var isCollection = IsArray(type);
|
||||||
if (isCollection.Item1)
|
if (isCollection.Item1)
|
||||||
{
|
{
|
||||||
var genericType = isCollection.Item2;
|
var genericType = isCollection.Item2;
|
||||||
@ -102,6 +102,21 @@ namespace FreeSql.ClickHouse
|
|||||||
return null;
|
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)
|
private Tuple<bool, Type> IsCollection(Type type)
|
||||||
{
|
{
|
||||||
var flag = false;
|
var flag = false;
|
||||||
|
@ -6,6 +6,7 @@ using System.Collections.Generic;
|
|||||||
using System.Data.Common;
|
using System.Data.Common;
|
||||||
using System.Globalization;
|
using System.Globalization;
|
||||||
using System.Data;
|
using System.Data;
|
||||||
|
using System.Text.Json;
|
||||||
using ClickHouse.Client.ADO.Parameters;
|
using ClickHouse.Client.ADO.Parameters;
|
||||||
using System.Text.RegularExpressions;
|
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)
|
public override DbParameter AppendParamter(List<DbParameter> _params, string parameterName, ColumnInfo col, Type type, object value)
|
||||||
{
|
{
|
||||||
if (value is string str)
|
if (value is string str)
|
||||||
value = str?.Replace("\t", "\\t")
|
value = str?.Replace("\t", "\\t")
|
||||||
.Replace("\r\n", "\\r\\n")
|
.Replace("\r\n", "\\r\\n")
|
||||||
@ -43,9 +44,10 @@ namespace FreeSql.ClickHouse
|
|||||||
if (col.DbScale != 0) ret.Scale = col.DbScale;
|
if (col.DbScale != 0) ret.Scale = col.DbScale;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
//直接使用Bool
|
//if (value.GetType().IsArray)
|
||||||
//if (value is bool)
|
//{
|
||||||
// ret.Value = (bool)value ? 1 : 0;
|
// ret.DbType = DbType.Object;
|
||||||
|
//}
|
||||||
}
|
}
|
||||||
_params?.Add(ret);
|
_params?.Add(ret);
|
||||||
return ret;
|
return ret;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user