Browse Source

MySql BUG

pull/12/MERGE
sunkaixuan 6 years ago
parent
commit
1f4fdeeea2
  1. 6
      Src/Asp.Net/MySqlTest/Config.cs
  2. 4
      Src/Asp.Net/MySqlTest/Demos/1_Query.cs
  3. 32
      Src/Asp.Net/SqlSugar/Realization/MySql/SqlBuilder/MySqlQueryBuilder.cs

6
Src/Asp.Net/MySqlTest/Config.cs

@ -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";
} }
} }

4
Src/Asp.Net/MySqlTest/Demos/1_Query.cs

@ -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

32
Src/Asp.Net/SqlSugar/Realization/MySql/SqlBuilder/MySqlQueryBuilder.cs

@ -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…
Cancel
Save