mirror of
https://github.com/nsnail/FreeSql.git
synced 2025-04-22 02:32:50 +08:00
修复clickHouse设置NoneParameter会报错问题
This commit is contained in:
parent
0212577933
commit
20bbcc8210
@ -538,14 +538,5 @@
|
|||||||
<param name="that"></param>
|
<param name="that"></param>
|
||||||
<returns></returns>
|
<returns></returns>
|
||||||
</member>
|
</member>
|
||||||
<member name="M:Microsoft.Extensions.DependencyInjection.FreeSqlRepositoryDependencyInjection.AddFreeRepository(Microsoft.Extensions.DependencyInjection.IServiceCollection,System.Action{FreeSql.FluentDataFilter},System.Reflection.Assembly[])">
|
|
||||||
<summary>
|
|
||||||
批量注入 Repository,可以参考代码自行调整
|
|
||||||
</summary>
|
|
||||||
<param name="services"></param>
|
|
||||||
<param name="globalDataFilter"></param>
|
|
||||||
<param name="assemblies"></param>
|
|
||||||
<returns></returns>
|
|
||||||
</member>
|
|
||||||
</members>
|
</members>
|
||||||
</doc>
|
</doc>
|
||||||
|
@ -7,20 +7,22 @@ using System.Linq;
|
|||||||
using System.Collections;
|
using System.Collections;
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
using XY.Model.Business;
|
using XY.Model.Business;
|
||||||
|
using System.ComponentModel.DataAnnotations;
|
||||||
|
using FreeSql.DataAnnotations;
|
||||||
|
|
||||||
namespace FreeSql.Tests.MySql
|
namespace FreeSql.Tests.MySql
|
||||||
{
|
{
|
||||||
public class ClickHouseTest1
|
public class ClickHouseTest1
|
||||||
{
|
{
|
||||||
|
private class TestAuditValue
|
||||||
class TestAuditValue
|
|
||||||
{
|
{
|
||||||
[FreeSql.DataAnnotations.Column(IsPrimary = true)]
|
[FreeSql.DataAnnotations.Column(IsPrimary = true)]
|
||||||
public long Id { get; set; }
|
public long Id { get; set; }
|
||||||
|
|
||||||
[Now]
|
[Now]
|
||||||
public DateTime CreateTime { get; set; }
|
public DateTime CreateTime { get; set; }
|
||||||
|
|
||||||
[FreeSql.DataAnnotations.Column(IsNullable = true )]
|
[FreeSql.DataAnnotations.Column(IsNullable = true)]
|
||||||
public string Name { get; set; }
|
public string Name { get; set; }
|
||||||
|
|
||||||
[FreeSql.DataAnnotations.Column(IsNullable = false)]
|
[FreeSql.DataAnnotations.Column(IsNullable = false)]
|
||||||
@ -35,6 +37,7 @@ namespace FreeSql.Tests.MySql
|
|||||||
|
|
||||||
public int? Points { get; set; }
|
public int? Points { get; set; }
|
||||||
}
|
}
|
||||||
|
|
||||||
[FreeSql.DataAnnotations.Table(Name = "ClickHouseTest")]
|
[FreeSql.DataAnnotations.Table(Name = "ClickHouseTest")]
|
||||||
public class TestClickHouse
|
public class TestClickHouse
|
||||||
{
|
{
|
||||||
@ -45,12 +48,14 @@ namespace FreeSql.Tests.MySql
|
|||||||
public string Name { get; set; }
|
public string Name { get; set; }
|
||||||
public Decimal Money { get; set; }
|
public Decimal Money { get; set; }
|
||||||
}
|
}
|
||||||
class NowAttribute: Attribute { }
|
|
||||||
|
private class NowAttribute : Attribute
|
||||||
|
{ }
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void AuditValue()
|
public void AuditValue()
|
||||||
{
|
{
|
||||||
var id = BitConverter.ToInt64(Guid.NewGuid().ToByteArray(), 0);
|
var id = BitConverter.ToInt64(Guid.NewGuid().ToByteArray(), 0);
|
||||||
var item = new TestClickHouse();
|
var item = new TestClickHouse();
|
||||||
item.Id = id;
|
item.Id = id;
|
||||||
item.Name = "李四";
|
item.Name = "李四";
|
||||||
@ -66,7 +71,6 @@ namespace FreeSql.Tests.MySql
|
|||||||
g.clickHouse.Aop.AuditValue -= audit;
|
g.clickHouse.Aop.AuditValue -= audit;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void CreateTalbe()
|
public void CreateTalbe()
|
||||||
{
|
{
|
||||||
@ -76,11 +80,11 @@ namespace FreeSql.Tests.MySql
|
|||||||
[Fact]
|
[Fact]
|
||||||
public void TestInsert()
|
public void TestInsert()
|
||||||
{
|
{
|
||||||
Stopwatch stopwatch =new Stopwatch();
|
Stopwatch stopwatch = new Stopwatch();
|
||||||
var fsql = g.clickHouse;
|
var fsql = g.clickHouse;
|
||||||
List<TestClickHouse> list=new List<TestClickHouse>();
|
List<TestClickHouse> list = new List<TestClickHouse>();
|
||||||
List<CollectDataEntity> list1=new List<CollectDataEntity>();
|
List<CollectDataEntity> list1 = new List<CollectDataEntity>();
|
||||||
var date=DateTime.Now;
|
var date = DateTime.Now;
|
||||||
for (int i = 1; i < 1000000; i++)
|
for (int i = 1; i < 1000000; i++)
|
||||||
{
|
{
|
||||||
//list.Add(new TestClickHouse
|
//list.Add(new TestClickHouse
|
||||||
@ -101,14 +105,14 @@ namespace FreeSql.Tests.MySql
|
|||||||
}
|
}
|
||||||
fsql.Delete<CollectDataEntity>().Where(t => 1 == 1).ExecuteAffrows();
|
fsql.Delete<CollectDataEntity>().Where(t => 1 == 1).ExecuteAffrows();
|
||||||
stopwatch.Start();
|
stopwatch.Start();
|
||||||
var insert=fsql.Insert(list1);
|
var insert = fsql.Insert(list1);
|
||||||
stopwatch.Stop();
|
stopwatch.Stop();
|
||||||
Debug.WriteLine("审计数据用时:" + stopwatch.ElapsedMilliseconds.ToString());
|
Debug.WriteLine("审计数据用时:" + stopwatch.ElapsedMilliseconds.ToString());
|
||||||
stopwatch.Restart();
|
stopwatch.Restart();
|
||||||
insert.ExecuteAffrows();
|
insert.ExecuteAffrows();
|
||||||
//fsql.GetRepository<CollectDataEntity>().Insert(list1);
|
//fsql.GetRepository<CollectDataEntity>().Insert(list1);
|
||||||
stopwatch.Stop();
|
stopwatch.Stop();
|
||||||
Debug.WriteLine("转换并插入用时:" +stopwatch.ElapsedMilliseconds.ToString());
|
Debug.WriteLine("转换并插入用时:" + stopwatch.ElapsedMilliseconds.ToString());
|
||||||
//var items = fsql.Select<TestClickHouse>().Where(o=>o.Id>900).OrderByDescending(o=>o.Id).ToList();
|
//var items = fsql.Select<TestClickHouse>().Where(o=>o.Id>900).OrderByDescending(o=>o.Id).ToList();
|
||||||
//Assert.Equal(100, items.Count);
|
//Assert.Equal(100, items.Count);
|
||||||
}
|
}
|
||||||
@ -118,9 +122,9 @@ namespace FreeSql.Tests.MySql
|
|||||||
{
|
{
|
||||||
var fsql = g.clickHouse;
|
var fsql = g.clickHouse;
|
||||||
|
|
||||||
var list=fsql.Select<TestClickHouse>()
|
var list = fsql.Select<TestClickHouse>()
|
||||||
.Page(1,100)
|
.Page(1, 100)
|
||||||
.Where(o=>o.Id>200&&o.Id<500)
|
.Where(o => o.Id > 200 && o.Id < 500)
|
||||||
.Count(out var count).ToList();
|
.Count(out var count).ToList();
|
||||||
//Assert.Equal(100, list.Count);
|
//Assert.Equal(100, list.Count);
|
||||||
}
|
}
|
||||||
@ -129,7 +133,7 @@ namespace FreeSql.Tests.MySql
|
|||||||
public void TestDelete()
|
public void TestDelete()
|
||||||
{
|
{
|
||||||
var fsql = g.clickHouse;
|
var fsql = g.clickHouse;
|
||||||
var count1=fsql.Select<TestClickHouse>().Count();
|
var count1 = fsql.Select<TestClickHouse>().Count();
|
||||||
fsql.Delete<TestClickHouse>().Where(o => o.Id < 500).ExecuteAffrows();
|
fsql.Delete<TestClickHouse>().Where(o => o.Id < 500).ExecuteAffrows();
|
||||||
var count2 = fsql.Select<TestClickHouse>().Count();
|
var count2 = fsql.Select<TestClickHouse>().Count();
|
||||||
//Assert.NotEqual(count1, count2);
|
//Assert.NotEqual(count1, count2);
|
||||||
@ -140,27 +144,25 @@ namespace FreeSql.Tests.MySql
|
|||||||
{
|
{
|
||||||
var fsql = g.clickHouse;
|
var fsql = g.clickHouse;
|
||||||
fsql.Update<TestClickHouse>().Where(o => o.Id > 900)
|
fsql.Update<TestClickHouse>().Where(o => o.Id > 900)
|
||||||
.Set(o=>o.Name,"修改后的值")
|
.Set(o => o.Name, "修改后的值")
|
||||||
.ExecuteAffrows();
|
.ExecuteAffrows();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void TestRepositorySelect()
|
public void TestRepositorySelect()
|
||||||
{
|
{
|
||||||
var fsql = g.clickHouse;
|
var fsql = g.clickHouse;
|
||||||
var list=fsql.GetRepository<TestClickHouse>().Where(o => o.Id > 900)
|
var list = fsql.GetRepository<TestClickHouse>().Where(o => o.Id > 900)
|
||||||
.ToList();
|
.ToList();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void TestRepositoryInsert()
|
public void TestRepositoryInsert()
|
||||||
{
|
{
|
||||||
var fsql = g.clickHouse;
|
var fsql = g.clickHouse;
|
||||||
long id = BitConverter.ToInt64(Guid.NewGuid().ToByteArray(),0);
|
long id = BitConverter.ToInt64(Guid.NewGuid().ToByteArray(), 0);
|
||||||
var list=fsql.GetRepository<TestClickHouse>().Insert(new TestClickHouse { Id= id, Name="张三"});
|
var list = fsql.GetRepository<TestClickHouse>().Insert(new TestClickHouse { Id = id, Name = "张三" });
|
||||||
var data=fsql.GetRepository<TestClickHouse,long>().Get(id);
|
var data = fsql.GetRepository<TestClickHouse, long>().Get(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
@ -168,9 +170,13 @@ namespace FreeSql.Tests.MySql
|
|||||||
{
|
{
|
||||||
var fsql = g.clickHouse;
|
var fsql = g.clickHouse;
|
||||||
long id = BitConverter.ToInt64(Guid.NewGuid().ToByteArray(), 0);
|
long id = BitConverter.ToInt64(Guid.NewGuid().ToByteArray(), 0);
|
||||||
DateTime createTime=DateTime.Now;
|
DateTime createTime = DateTime.Now;
|
||||||
fsql.Insert(new TestAuditValue {
|
fsql.Insert(new TestAuditValue
|
||||||
Id = id, CreateTime = createTime, Age =18,Name="张三"
|
{
|
||||||
|
Id = id,
|
||||||
|
CreateTime = createTime,
|
||||||
|
Age = 18,
|
||||||
|
Name = "张三"
|
||||||
}).ExecuteAffrows();
|
}).ExecuteAffrows();
|
||||||
|
|
||||||
var date1 = fsql.GetRepository<TestAuditValue>().Where(o => o.CreateTime == createTime)
|
var date1 = fsql.GetRepository<TestAuditValue>().Where(o => o.CreateTime == createTime)
|
||||||
@ -187,54 +193,54 @@ namespace FreeSql.Tests.MySql
|
|||||||
.ToList();
|
.ToList();
|
||||||
var date7 = fsql.GetRepository<TestAuditValue>().Where(o => o.CreateTime.AddSeconds(10) < createTime)
|
var date7 = fsql.GetRepository<TestAuditValue>().Where(o => o.CreateTime.AddSeconds(10) < createTime)
|
||||||
.ToList();
|
.ToList();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void TestUpdateTime()
|
public void TestUpdateTime()
|
||||||
{
|
{
|
||||||
var fsql = g.clickHouse;
|
var fsql = g.clickHouse;
|
||||||
var state = fsql.GetRepository<TestAuditValue>().UpdateDiy.Set(o => o.UpdateTime, DateTime.Now).Where(o => 1 == 1).ExecuteAffrows();
|
var state = fsql.GetRepository<TestAuditValue>().UpdateDiy.Set(o => o.UpdateTime, DateTime.Now).Where(o => 1 == 1).ExecuteAffrows();
|
||||||
//var state1 = fsql.GetRepository<TestAuditValue>().UpdateDiy.Set(o => o.UpdateTime, null).Where(o => 1 == 1).ExecuteAffrows();
|
//var state1 = fsql.GetRepository<TestAuditValue>().UpdateDiy.Set(o => o.UpdateTime, null).Where(o => 1 == 1).ExecuteAffrows();
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void TestRepositoryUpdateTime()
|
public void TestRepositoryUpdateTime()
|
||||||
{
|
{
|
||||||
Stopwatch stopwatch = new Stopwatch();
|
Stopwatch stopwatch = new Stopwatch();
|
||||||
var fsql = g.clickHouse;
|
var fsql = g.clickHouse;
|
||||||
var repository=fsql.GetRepository<TestAuditValue>();
|
var repository = fsql.GetRepository<TestAuditValue>();
|
||||||
List<TestAuditValue> list=new List<TestAuditValue>();
|
List<TestAuditValue> list = new List<TestAuditValue>();
|
||||||
for (int i = 1; i < 5; i++)
|
for (int i = 1; i < 5; i++)
|
||||||
{
|
{
|
||||||
list.Add(new TestAuditValue
|
list.Add(new TestAuditValue
|
||||||
{
|
{
|
||||||
Id = new Random().Next(),
|
Id = new Random().Next(),
|
||||||
Age=1, Name=i.ToString(), State=true, CreateTime=DateTime.Now,
|
Age = 1,
|
||||||
UpdateTime=DateTime.Now,
|
Name = i.ToString(),
|
||||||
|
State = true,
|
||||||
|
CreateTime = DateTime.Now,
|
||||||
|
UpdateTime = DateTime.Now,
|
||||||
Enable = false
|
Enable = false
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
list = repository.Insert(list);
|
list = repository.Insert(list);
|
||||||
//var list = repository.Select.ToList();
|
//var list = repository.Select.ToList();
|
||||||
list.ForEach(o=>o.UpdateTime = DateTime.Now);
|
list.ForEach(o => o.UpdateTime = DateTime.Now);
|
||||||
list.ForEach(o => o.Enable = true);
|
list.ForEach(o => o.Enable = true);
|
||||||
stopwatch.Start();
|
stopwatch.Start();
|
||||||
repository.Update(list);
|
repository.Update(list);
|
||||||
stopwatch.Stop();
|
stopwatch.Stop();
|
||||||
Debug.WriteLine("更新用时:" + stopwatch.ElapsedMilliseconds.ToString());
|
Debug.WriteLine("更新用时:" + stopwatch.ElapsedMilliseconds.ToString());
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public async void TestInsertUpdateData()
|
public async void TestInsertUpdateData()
|
||||||
{
|
{
|
||||||
//g.clickHouse.CodeFirst.SyncStructure<CollectDataEntity>();
|
//g.clickHouse.CodeFirst.SyncStructure<CollectDataEntity>();
|
||||||
Stopwatch stopwatch = new Stopwatch();
|
Stopwatch stopwatch = new Stopwatch();
|
||||||
var fsql = g.clickHouse;
|
var fsql = g.clickHouse;
|
||||||
var repository=fsql.GetRepository<CollectDataEntity>();
|
var repository = fsql.GetRepository<CollectDataEntity>();
|
||||||
await repository.DeleteAsync(o=>o.Id>0);
|
await repository.DeleteAsync(o => o.Id > 0);
|
||||||
List<CollectDataEntity> tables = new List<CollectDataEntity>();
|
List<CollectDataEntity> tables = new List<CollectDataEntity>();
|
||||||
for (int i = 1; i < 3; i++)
|
for (int i = 1; i < 3; i++)
|
||||||
{
|
{
|
||||||
@ -246,7 +252,7 @@ namespace FreeSql.Tests.MySql
|
|||||||
EquipmentCode = "11",
|
EquipmentCode = "11",
|
||||||
UnitStr = "111",
|
UnitStr = "111",
|
||||||
PropertyCode = "1111",
|
PropertyCode = "1111",
|
||||||
NumericValue=1111.1119999912500M
|
NumericValue = 1111.1119999912500M
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -260,8 +266,54 @@ namespace FreeSql.Tests.MySql
|
|||||||
//await repository.UpdateAsync(list);
|
//await repository.UpdateAsync(list);
|
||||||
//stopwatch.Stop();
|
//stopwatch.Stop();
|
||||||
Debug.WriteLine("更新用时:" + stopwatch.ElapsedMilliseconds.ToString());
|
Debug.WriteLine("更新用时:" + stopwatch.ElapsedMilliseconds.ToString());
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public async void TestInsertDecimalData()
|
||||||
|
{
|
||||||
|
//g.clickHouse.CodeFirst.SyncStructure<CollectDataEntity>();
|
||||||
|
Stopwatch stopwatch = new Stopwatch();
|
||||||
|
var fsql = g.clickHouse;
|
||||||
|
var repository = fsql.GetRepository<CollectDataEntity>();
|
||||||
|
await repository.DeleteAsync(o => o.Id > 0);
|
||||||
|
|
||||||
|
var insert = repository.Insert(new CollectDataEntity
|
||||||
|
{
|
||||||
|
Id = new Random().Next(),
|
||||||
|
CollectTime = DateTime.Now,
|
||||||
|
DataFlag = "1",
|
||||||
|
EquipmentCode = "11",
|
||||||
|
UnitStr = "111",
|
||||||
|
PropertyCode = "1111",
|
||||||
|
NumericValue = 1111.1119999912500M
|
||||||
|
});
|
||||||
|
var list = repository.Orm.Select<CollectDataEntity>().ToList();
|
||||||
|
//var list = repository.Insert(tables);
|
||||||
|
//var list = repository.Select.ToList();
|
||||||
|
//list.ForEach(o=>o.EquipmentCode = "666");
|
||||||
|
//stopwatch.Start();
|
||||||
|
//await repository.UpdateAsync(list);
|
||||||
|
//stopwatch.Stop();
|
||||||
|
Debug.WriteLine("更新用时:" + stopwatch.ElapsedMilliseconds.ToString());
|
||||||
|
}
|
||||||
|
|
||||||
|
internal class Entity
|
||||||
|
{
|
||||||
|
[Required]
|
||||||
|
public string Id { get; set; }
|
||||||
|
|
||||||
|
[Column(StringLength = -2)]
|
||||||
|
public string Content { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void TestInsertNoneParameter()
|
||||||
|
{
|
||||||
|
var json = "[{\"date\":\"2021-12-19T02:47:53.4365075 08:00\",\"temperatureC\":6,\"temperatureF\":42,\"summary\":\"Balmy\"},{\"date\":\"2021-12-20T02:47:53.4366893 08:00\",\"temperatureC\":36,\"temperatureF\":96,\"summary\":\"Bracing\"},{\"date\":\"2021-12-21T02:47:53.4366903 08:00\",\"temperatureC\":-15,\"temperatureF\":6,\"summary\":\"Bracing\"},{\"date\":\"2021-12-22T02:47:53.4366904 08:00\",\"temperatureC\":14,\"temperatureF\":57,\"summary\":\"Cool\"},{\"date\":\"2021-12-23T02:47:53.4366905 08:00\",\"temperatureC\":29,\"temperatureF\":84,\"summary\":\"Mild\"}]";
|
||||||
|
var data = new Entity { Id = Guid.NewGuid().ToString(), Content = json };
|
||||||
|
|
||||||
|
var fsql = g.clickHouse;
|
||||||
|
fsql.Insert(data).NoneParameter().ExecuteAffrows();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -7,11 +7,11 @@ using System.Data.Common;
|
|||||||
using System.Globalization;
|
using System.Globalization;
|
||||||
using System.Data;
|
using System.Data;
|
||||||
using ClickHouse.Client.ADO.Parameters;
|
using ClickHouse.Client.ADO.Parameters;
|
||||||
|
using System.Text.RegularExpressions;
|
||||||
|
|
||||||
namespace FreeSql.ClickHouse
|
namespace FreeSql.ClickHouse
|
||||||
{
|
{
|
||||||
|
internal class ClickHouseUtils : CommonUtils
|
||||||
class ClickHouseUtils : CommonUtils
|
|
||||||
{
|
{
|
||||||
public ClickHouseUtils(IFreeSql orm) : base(orm)
|
public ClickHouseUtils(IFreeSql orm) : base(orm)
|
||||||
{
|
{
|
||||||
@ -21,7 +21,7 @@ namespace FreeSql.ClickHouse
|
|||||||
{
|
{
|
||||||
if (string.IsNullOrEmpty(parameterName)) parameterName = $"p_{_params?.Count}";
|
if (string.IsNullOrEmpty(parameterName)) parameterName = $"p_{_params?.Count}";
|
||||||
var dbtype = (DbType)_orm.CodeFirst.GetDbInfo(type)?.type;
|
var dbtype = (DbType)_orm.CodeFirst.GetDbInfo(type)?.type;
|
||||||
DbParameter ret = new ClickHouseDbParameter { ParameterName = parameterName, DbType= dbtype, Value = value };//QuoteParamterName(parameterName)
|
DbParameter ret = new ClickHouseDbParameter { ParameterName = parameterName, DbType = dbtype, Value = value };//QuoteParamterName(parameterName)
|
||||||
if (col != null)
|
if (col != null)
|
||||||
{
|
{
|
||||||
var dbtype2 = (DbType)_orm.DbFirst.GetDbType(new DatabaseModel.DbColumnInfo { DbTypeText = col.DbTypeText, DbTypeTextFull = col.Attribute.DbType, MaxLength = col.DbSize });
|
var dbtype2 = (DbType)_orm.DbFirst.GetDbType(new DatabaseModel.DbColumnInfo { DbTypeText = col.DbTypeText, DbTypeTextFull = col.Attribute.DbType, MaxLength = col.DbSize });
|
||||||
@ -53,19 +53,28 @@ namespace FreeSql.ClickHouse
|
|||||||
var tp = _orm.CodeFirst.GetDbInfo(type)?.type;
|
var tp = _orm.CodeFirst.GetDbInfo(type)?.type;
|
||||||
if (tp != null)
|
if (tp != null)
|
||||||
{
|
{
|
||||||
|
ret.DbType = (DbType)tp.Value;
|
||||||
ret.DbType = (DbType)tp.Value;
|
|
||||||
}
|
}
|
||||||
return ret;
|
return ret;
|
||||||
});
|
});
|
||||||
|
|
||||||
public override string RewriteColumn(ColumnInfo col, string sql)
|
public override string RewriteColumn(ColumnInfo col, string sql)
|
||||||
{
|
{
|
||||||
col.Attribute.DbType = col.Attribute.DbType.Replace(" NOT NULL", "");
|
col.Attribute.DbType = col.Attribute.DbType.Replace(" NOT NULL", "");
|
||||||
if (string.IsNullOrWhiteSpace(col?.Attribute.RewriteSql) == false)
|
if (string.IsNullOrWhiteSpace(col?.Attribute.RewriteSql) == false)
|
||||||
return string.Format(col.Attribute.RewriteSql, sql);
|
return string.Format(col.Attribute.RewriteSql, sql);
|
||||||
return string.Format(sql, col.Attribute.DbType);
|
if (Regex.IsMatch(sql, @"\{\{[\w\d]+_+\d:\{\d\}\}\}"))
|
||||||
|
{
|
||||||
|
return string.Format(sql, col.Attribute.DbType);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return sql;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public override string FormatSql(string sql, params object[] args) => sql?.FormatClickHouse(args);
|
public override string FormatSql(string sql, params object[] args) => sql?.FormatClickHouse(args);
|
||||||
|
|
||||||
public override string QuoteSqlName(params string[] name)
|
public override string QuoteSqlName(params string[] name)
|
||||||
{
|
{
|
||||||
if (name.Length == 1)
|
if (name.Length == 1)
|
||||||
@ -79,6 +88,7 @@ namespace FreeSql.ClickHouse
|
|||||||
}
|
}
|
||||||
return $"`{string.Join("`.`", name)}`";
|
return $"`{string.Join("`.`", name)}`";
|
||||||
}
|
}
|
||||||
|
|
||||||
public override string TrimQuoteSqlName(string name)
|
public override string TrimQuoteSqlName(string name)
|
||||||
{
|
{
|
||||||
var nametrim = name.Trim();
|
var nametrim = name.Trim();
|
||||||
@ -86,12 +96,19 @@ namespace FreeSql.ClickHouse
|
|||||||
return nametrim; //原生SQL
|
return nametrim; //原生SQL
|
||||||
return $"{nametrim.Trim('`').Replace("`.`", ".").Replace(".`", ".")}";
|
return $"{nametrim.Trim('`').Replace("`.`", ".").Replace(".`", ".")}";
|
||||||
}
|
}
|
||||||
|
|
||||||
public override string[] SplitTableName(string name) => GetSplitTableNames(name, '`', '`', 2);
|
public override string[] SplitTableName(string name) => GetSplitTableNames(name, '`', '`', 2);
|
||||||
|
|
||||||
public override string QuoteParamterName(string name) => $"{{{{{name}:{{0}}}}}}";
|
public override string QuoteParamterName(string name) => $"{{{{{name}:{{0}}}}}}";
|
||||||
|
|
||||||
public override string IsNull(string sql, object value) => $"ifnull({sql}, {value})";
|
public override string IsNull(string sql, object value) => $"ifnull({sql}, {value})";
|
||||||
|
|
||||||
public override string StringConcat(string[] objs, Type[] types) => $"concat({string.Join(", ", objs)})";
|
public override string StringConcat(string[] objs, Type[] types) => $"concat({string.Join(", ", objs)})";
|
||||||
|
|
||||||
public override string Mod(string left, string right, Type leftType, Type rightType) => $"{left} % {right}";
|
public override string Mod(string left, string right, Type leftType, Type rightType) => $"{left} % {right}";
|
||||||
|
|
||||||
public override string Div(string left, string right, Type leftType, Type rightType) => $"{left} div {right}";
|
public override string Div(string left, string right, Type leftType, Type rightType) => $"{left} div {right}";
|
||||||
|
|
||||||
public override string Now => "now()";
|
public override string Now => "now()";
|
||||||
public override string NowUtc => "now('UTC')";
|
public override string NowUtc => "now('UTC')";
|
||||||
|
|
||||||
@ -108,6 +125,7 @@ namespace FreeSql.ClickHouse
|
|||||||
}
|
}
|
||||||
return paramterName;
|
return paramterName;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override string QuoteReadColumnAdapter(Type type, Type mapType, string columnName)
|
protected override string QuoteReadColumnAdapter(Type type, Type mapType, string columnName)
|
||||||
{
|
{
|
||||||
switch (mapType.FullName)
|
switch (mapType.FullName)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user