mirror of
https://gitee.com/dotnetchina/SqlSugar.git
synced 2025-08-24 07:22:57 +08:00
MySql BUG
This commit is contained in:
parent
6b6682900b
commit
1f4fdeeea2
@ -8,8 +8,8 @@ namespace OrmTest
|
|||||||
{
|
{
|
||||||
public class Config
|
public class Config
|
||||||
{
|
{
|
||||||
public static string ConnectionString = "server=localhost;Database=SqlSugar4xTest;Uid=root;Pwd=haosql";
|
public static string ConnectionString = "server=localhost;Database=SqlSugar4xTest;Uid=root;Pwd=root";
|
||||||
public static string ConnectionString2 = "server=localhost;Database=SQLSUGAR4XTEST;Uid=root;Pwd=haosql";
|
public static string ConnectionString2 = "server=localhost;Database=SQLSUGAR4XTEST;Uid=root;Pwd=root";
|
||||||
public static string ConnectionString3 = "server=localhost;Database=sqlsugar4xtest;Uid=root;Pwd=haosql";
|
public static string ConnectionString3 = "server=localhost;Database=sqlsugar4xtest;Uid=root;Pwd=root";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -58,13 +58,13 @@ namespace OrmTest.Demo
|
|||||||
id = SqlFunc.Subqueryable<School>().Where(s => s.Id == st.Id).Select(s => s.Id)
|
id = SqlFunc.Subqueryable<School>().Where(s => s.Id == st.Id).Select(s => s.Id)
|
||||||
})
|
})
|
||||||
.ToList();
|
.ToList();
|
||||||
|
int count = 0;
|
||||||
var getAll4 = db.Queryable<Student>().Select(it =>
|
var getAll4 = db.Queryable<Student>().Select(it =>
|
||||||
new
|
new
|
||||||
{
|
{
|
||||||
name = it.Name,
|
name = it.Name,
|
||||||
id = SqlFunc.Subqueryable<School>().Where(s => s.Id == it.Id).Select(s => s.Id)
|
id = SqlFunc.Subqueryable<School>().Where(s => s.Id == it.Id).Select(s => s.Id)
|
||||||
}).ToList();
|
}).ToPageList(1, 2, ref count);
|
||||||
|
|
||||||
var getAll5 = db.Queryable<Student>().Select(it =>
|
var getAll5 = db.Queryable<Student>().Select(it =>
|
||||||
new Student
|
new Student
|
||||||
|
@ -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
|
||||||
|
Loading…
Reference in New Issue
Block a user