|
@ -63,6 +63,36 @@ namespace SqlSugar |
|
|
this.OrderByValue = oldOrderValue; |
|
|
this.OrderByValue = oldOrderValue; |
|
|
return result; |
|
|
return result; |
|
|
} |
|
|
} |
|
|
|
|
|
private string ToCountSqlString() |
|
|
|
|
|
{ |
|
|
|
|
|
base.AppendFilter(); |
|
|
|
|
|
string oldOrderValue = this.OrderByValue; |
|
|
|
|
|
string result = null; |
|
|
|
|
|
sql = new StringBuilder(); |
|
|
|
|
|
sql.AppendFormat(SqlTemplate, "Count(*)", GetTableNameString, GetWhereValueString, GetGroupByString + HavingInfos, (Skip != null || Take != null) ? null : GetOrderByString); |
|
|
|
|
|
if (IsCount) { return sql.ToString(); } |
|
|
|
|
|
if (Skip != null && Take == null) |
|
|
|
|
|
{ |
|
|
|
|
|
if (this.OrderByValue == "ORDER BY ") this.OrderByValue += GetSelectValue.Split(',')[0]; |
|
|
|
|
|
result = string.Format(PageTempalte, GetSelectValue, GetTableNameString, GetWhereValueString, GetGroupByString + HavingInfos, (Skip != null || Take != null) ? null : GetOrderByString, Skip.ObjToInt(), long.MaxValue); |
|
|
|
|
|
} |
|
|
|
|
|
else if (Skip == null && Take != null) |
|
|
|
|
|
{ |
|
|
|
|
|
if (this.OrderByValue == "ORDER BY ") this.OrderByValue += GetSelectValue.Split(',')[0]; |
|
|
|
|
|
result = string.Format(PageTempalte, GetSelectValue, GetTableNameString, GetWhereValueString, GetGroupByString + HavingInfos, GetOrderByString, 0, Take.ObjToInt()); |
|
|
|
|
|
} |
|
|
|
|
|
else if (Skip != null && Take != null) |
|
|
|
|
|
{ |
|
|
|
|
|
if (this.OrderByValue == "ORDER BY ") this.OrderByValue += GetSelectValue.Split(',')[0]; |
|
|
|
|
|
result = string.Format(PageTempalte, GetSelectValue, GetTableNameString, GetWhereValueString, GetGroupByString + HavingInfos, GetOrderByString, Skip.ObjToInt() > 0 ? Skip.ObjToInt() : 0, Take); |
|
|
|
|
|
} |
|
|
|
|
|
else |
|
|
|
|
|
{ |
|
|
|
|
|
result = sql.ToString(); |
|
|
|
|
|
} |
|
|
|
|
|
this.OrderByValue = oldOrderValue; |
|
|
|
|
|
return result; |
|
|
|
|
|
} |
|
|
public override string ToCountSql(string sql) |
|
|
public override string ToCountSql(string sql) |
|
|
{ |
|
|
{ |
|
|
if (this.GroupByValue.HasValue()) |
|
|
if (this.GroupByValue.HasValue()) |
|
@ -71,7 +101,7 @@ namespace SqlSugar |
|
|
} |
|
|
} |
|
|
else |
|
|
else |
|
|
{ |
|
|
{ |
|
|
return Regex.Replace(sql, "^SELECT .+? FROM ", "SELECT COUNT(*) FROM "); |
|
|
return ToCountSqlString(); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
#endregion
|
|
|
#endregion
|
|
|