Clickhouse Final

This commit is contained in:
sunkaixuan
2024-09-19 11:27:32 +08:00
parent 606b791918
commit 153dfc24a0
3 changed files with 22 additions and 2 deletions

View File

@@ -39,7 +39,25 @@ namespace SqlSugar.ClickHouse
string oldOrderValue = this.OrderByValue; string oldOrderValue = this.OrderByValue;
string result = ""; string result = "";
sql = new StringBuilder(); sql = new StringBuilder();
var isFinal = this.Context.CurrentConnectionConfig?.MoreSettings?.ClickHouseEnableFinal==true;
var final = " Final ";
var finalGlobal = " FINAL GLOBAL ";
if (isFinal&&this.IsSingle())
{
sql.AppendFormat(SqlTemplate, GetSelectValue, GetTableNameString+" "+ final, GetWhereValueString, GetGroupByString + HavingInfos, (Skip != null || Take != null) ? null : GetOrderByString);
}
else if (isFinal && !this.IsSingle())
{
var tableName = GetTableNameString;
var shortName = $" {this.Builder.GetTranslationColumnName(this.TableShortName)} ";
tableName = tableName.Replace(shortName, shortName+finalGlobal);
tableName = tableName.Replace("\" ON ( \"", "\" "+final+" ON ( \"");
sql.AppendFormat(SqlTemplate, GetSelectValue, tableName, GetWhereValueString, GetGroupByString + HavingInfos, (Skip != null || Take != null) ? null : GetOrderByString);
}
else
{
sql.AppendFormat(SqlTemplate, GetSelectValue, GetTableNameString, GetWhereValueString, GetGroupByString + HavingInfos, (Skip != null || Take != null) ? null : GetOrderByString); sql.AppendFormat(SqlTemplate, GetSelectValue, GetTableNameString, GetWhereValueString, GetGroupByString + HavingInfos, (Skip != null || Take != null) ? null : GetOrderByString);
}
if (IsCount) { return sql.ToString(); } if (IsCount) { return sql.ToString(); }
if (Skip != null && Take == null) if (Skip != null && Take == null)
{ {

View File

@@ -36,5 +36,6 @@ namespace SqlSugar
public int MaxParameterNameLength { get; set; } public int MaxParameterNameLength { get; set; }
public bool DisableQueryWhereColumnRemoveTrim { get; set; } public bool DisableQueryWhereColumnRemoveTrim { get; set; }
public DbType? DatabaseModel { get;set; } public DbType? DatabaseModel { get;set; }
public bool ClickHouseEnableFinal { get; set; }
} }
} }

View File

@@ -711,7 +711,8 @@ namespace SqlSugar
MaxParameterNameLength=it.MoreSettings.MaxParameterNameLength, MaxParameterNameLength=it.MoreSettings.MaxParameterNameLength,
DisableQueryWhereColumnRemoveTrim=it.MoreSettings.DisableQueryWhereColumnRemoveTrim, DisableQueryWhereColumnRemoveTrim=it.MoreSettings.DisableQueryWhereColumnRemoveTrim,
DatabaseModel=it.MoreSettings.DatabaseModel, DatabaseModel=it.MoreSettings.DatabaseModel,
EnableILike=it.MoreSettings.EnableILike EnableILike=it.MoreSettings.EnableILike,
ClickHouseEnableFinal=it.MoreSettings.ClickHouseEnableFinal
}, },
SqlMiddle = it.SqlMiddle == null ? null : new SqlMiddle SqlMiddle = it.SqlMiddle == null ? null : new SqlMiddle