mirror of
https://gitee.com/dotnetchina/SqlSugar.git
synced 2025-09-19 10:08:19 +08:00
Gobal Filter BUG in MySql Sqlite
This commit is contained in:
@@ -39,7 +39,7 @@ namespace OrmTest.Demo
|
||||
|
||||
public static SqlSugarClient GetInstance1()
|
||||
{
|
||||
SqlSugarClient db = new SqlSugarClient(new ConnectionConfig() { ConnectionString = Config.ConnectionString, DbType = DbType.SqlServer, IsAutoCloseConnection = true });
|
||||
SqlSugarClient db = new SqlSugarClient(new ConnectionConfig() { ConnectionString = Config.ConnectionString, DbType = DbType.MySql, IsAutoCloseConnection = true });
|
||||
db.QueryFilter
|
||||
.Add(new SqlFilterItem()
|
||||
{
|
||||
|
@@ -225,6 +225,37 @@ namespace SqlSugar
|
||||
{
|
||||
string oldOrderBy = this.OrderByValue;
|
||||
string externalOrderBy = oldOrderBy;
|
||||
AppendFilter();
|
||||
sql = new StringBuilder();
|
||||
if (this.OrderByValue == null && (Skip != null || Take != null)) this.OrderByValue = " ORDER BY GetDate() ";
|
||||
if (this.PartitionByValue.IsValuable())
|
||||
{
|
||||
this.OrderByValue = this.PartitionByValue + this.OrderByValue;
|
||||
}
|
||||
var isRowNumber = Skip != null || Take != null;
|
||||
var rowNumberString = string.Format(",ROW_NUMBER() OVER({0}) AS RowIndex ", GetOrderByString);
|
||||
string groupByValue = GetGroupByString + HavingInfos;
|
||||
string orderByValue = (!isRowNumber && this.OrderByValue.IsValuable()) ? GetOrderByString : null;
|
||||
if (this.IsCount) { orderByValue = null; }
|
||||
sql.AppendFormat(SqlTemplate, GetSelectValue, GetTableNameString, GetWhereValueString, groupByValue, orderByValue);
|
||||
sql.Replace("{$:OrderByString:$}", isRowNumber ? (this.IsCount ? null : rowNumberString) : null);
|
||||
if (this.IsCount) { return sql.ToString(); }
|
||||
var result = ToPageSql(sql.ToString(), this.Take, this.Skip);
|
||||
if (ExternalPageIndex > 0)
|
||||
{
|
||||
if (externalOrderBy.IsNullOrEmpty())
|
||||
{
|
||||
externalOrderBy = " ORDER BY GetDate() ";
|
||||
}
|
||||
result = string.Format("SELECT *,ROW_NUMBER() OVER({0}) AS RowIndex2 FROM ({1}) ExternalTable ", GetExternalOrderBy(externalOrderBy), result);
|
||||
result = ToPageSql2(result, ExternalPageIndex, ExternalPageSize, true);
|
||||
}
|
||||
this.OrderByValue = oldOrderBy;
|
||||
return result;
|
||||
}
|
||||
|
||||
public virtual void AppendFilter()
|
||||
{
|
||||
if (!IsDisabledGobalFilter && this.Context.QueryFilter.GeFilterList.IsValuable())
|
||||
{
|
||||
var gobalFilterList = this.Context.QueryFilter.GeFilterList.Where(it => it.FilterName.IsNullOrEmpty()).ToList();
|
||||
@@ -239,31 +270,6 @@ namespace SqlSugar
|
||||
}
|
||||
}
|
||||
}
|
||||
sql = new StringBuilder();
|
||||
if (this.OrderByValue == null && (Skip != null || Take != null)) this.OrderByValue = " ORDER BY GetDate() ";
|
||||
if (this.PartitionByValue.IsValuable())
|
||||
{
|
||||
this.OrderByValue = this.PartitionByValue + this.OrderByValue;
|
||||
}
|
||||
var isRowNumber = Skip != null || Take != null;
|
||||
var rowNumberString = string.Format(",ROW_NUMBER() OVER({0}) AS RowIndex ", GetOrderByString);
|
||||
string groupByValue = GetGroupByString + HavingInfos;
|
||||
string orderByValue = (!isRowNumber && this.OrderByValue.IsValuable()) ? GetOrderByString : null;
|
||||
if (this.IsCount) { orderByValue = null; }
|
||||
sql.AppendFormat(SqlTemplate, GetSelectValue, GetTableNameString, GetWhereValueString, groupByValue, orderByValue);
|
||||
sql.Replace("{$:OrderByString:$}", isRowNumber ? (this.IsCount ? null : rowNumberString) : null);
|
||||
if (this.IsCount) { return sql.ToString(); }
|
||||
var result = ToPageSql(sql.ToString(), this.Take, this.Skip);
|
||||
if (ExternalPageIndex > 0)
|
||||
{
|
||||
if (externalOrderBy.IsNullOrEmpty()) {
|
||||
externalOrderBy = " ORDER BY GetDate() ";
|
||||
}
|
||||
result = string.Format("SELECT *,ROW_NUMBER() OVER({0}) AS RowIndex2 FROM ({1}) ExternalTable ", GetExternalOrderBy(externalOrderBy),result);
|
||||
result = ToPageSql2(result,ExternalPageIndex, ExternalPageSize, true);
|
||||
}
|
||||
this.OrderByValue = oldOrderBy;
|
||||
return result;
|
||||
}
|
||||
|
||||
public virtual string GetExternalOrderBy(string externalOrderBy)
|
||||
|
@@ -35,6 +35,7 @@ namespace SqlSugar
|
||||
}
|
||||
public override string ToSqlString()
|
||||
{
|
||||
base.AppendFilter();
|
||||
string oldOrderValue = this.OrderByValue;
|
||||
string result = null;
|
||||
sql = new StringBuilder();
|
||||
|
@@ -35,6 +35,7 @@ namespace SqlSugar
|
||||
}
|
||||
public override string ToSqlString()
|
||||
{
|
||||
base.AppendFilter();
|
||||
string result = null;
|
||||
string oldOrderBy = this.OrderByValue;
|
||||
sql = new StringBuilder();
|
||||
|
Reference in New Issue
Block a user