Browse Source

Mysql Page Bug

pull/12/MERGE
sunkaixuan 7 years ago
parent
commit
bd431efc1d
  1. 2
      Src/Asp.Net/MySqlTest/Demos/1_Query.cs
  2. 6
      Src/Asp.Net/MySqlTest/UnitTest/Query/SingleQuery.cs
  3. 4
      Src/Asp.Net/SqlSugar/Properties/AssemblyInfo.cs
  4. 4
      Src/Asp.Net/SqlSugar/Realization/MySql/SqlBuilder/MySqlQueryBuilder.cs

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

@ -182,7 +182,7 @@ namespace OrmTest.Demo
public static void Page() public static void Page()
{ {
var db = GetInstance(); var db = GetInstance();
var pageIndex = 1; var pageIndex = 2;
var pageSize = 2; var pageSize = 2;
var totalCount = 0; var totalCount = 0;
//page //page

6
Src/Asp.Net/MySqlTest/UnitTest/Query/SingleQuery.cs

@ -42,12 +42,12 @@ namespace OrmTest.UnitTest
base.Check(@"SELECT `ID`,`SchoolId`,`Name`,`CreateTime` FROM `STudent` ORDER BY `ID` ASC LIMIT 1,3", null, t4.Key, null, "single t4 Error"); base.Check(@"SELECT `ID`,`SchoolId`,`Name`,`CreateTime` FROM `STudent` ORDER BY `ID` ASC LIMIT 1,3", null, t4.Key, null, "single t4 Error");
var t5 = db.Queryable<Student>().OrderBy(it => it.Id).Skip(3).ToSql(); var t5 = db.Queryable<Student>().OrderBy(it => it.Id).Skip(3).ToSql();
base.Check(@"SELECT `ID`,`SchoolId`,`Name`,`CreateTime` FROM `STudent` LIMIT 4,9223372036854775807", null, t5.Key,null, "single t5 Error"); base.Check(@"SELECT `ID`,`SchoolId`,`Name`,`CreateTime` FROM `STudent` LIMIT 3,9223372036854775807", null, t5.Key,null, "single t5 Error");
int pageIndex = 2; int pageIndex = 2;
int pageSize = 10; int pageSize = 10;
var t6 = db.Queryable<Student>().OrderBy(it => it.Id,OrderByType.Desc).Skip((pageIndex-1)*pageSize).Take(pageSize).ToSql(); var t6 = db.Queryable<Student>().OrderBy(it => it.Id,OrderByType.Desc).Skip((pageIndex-1)*pageSize).Take(pageSize).ToSql();
base.Check(@"SELECT `ID`,`SchoolId`,`Name`,`CreateTime` FROM `STudent` ORDER BY `ID` DESC LIMIT 11,10", null, t6.Key, null, "single t6 Error"); base.Check(@"SELECT `ID`,`SchoolId`,`Name`,`CreateTime` FROM `STudent` ORDER BY `ID` DESC LIMIT 10,10", null, t6.Key, null, "single t6 Error");
int studentCount=db.Ado.GetInt("select count(1) from Student"); int studentCount=db.Ado.GetInt("select count(1) from Student");
@ -95,7 +95,7 @@ namespace OrmTest.UnitTest
.Where(it=>it.Id==1) .Where(it=>it.Id==1)
.WhereIF(true,it=> SqlFunc.Contains(it.Name,"a")) .WhereIF(true,it=> SqlFunc.Contains(it.Name,"a"))
.OrderBy(it => it.Id, OrderByType.Desc).Skip((pageIndex - 1) * pageSize).Take(pageSize ).With(SqlWith.NoLock).ToSql(); .OrderBy(it => it.Id, OrderByType.Desc).Skip((pageIndex - 1) * pageSize).Take(pageSize ).With(SqlWith.NoLock).ToSql();
base.Check(@"SELECT `ID`,`SchoolId`,`Name`,`CreateTime` FROM `STudent` WHERE ( `ID` = @Id0 ) AND (`Name` like concat('%',@MethodConst1,'%')) ORDER BY `ID` DESC LIMIT 11,10", new List<SugarParameter>() { base.Check(@"SELECT `ID`,`SchoolId`,`Name`,`CreateTime` FROM `STudent` WHERE ( `ID` = @Id0 ) AND (`Name` like concat('%',@MethodConst1,'%')) ORDER BY `ID` DESC LIMIT 10,10", new List<SugarParameter>() {
new SugarParameter("@Id0",1),new SugarParameter("@MethodConst1","a") new SugarParameter("@Id0",1),new SugarParameter("@MethodConst1","a")
}, t8.Key, t8.Value,"single t8 Error"); }, t8.Key, t8.Value,"single t8 Error");

4
Src/Asp.Net/SqlSugar/Properties/AssemblyInfo.cs

@ -31,5 +31,5 @@ using System.Runtime.InteropServices;
// You can specify all the values or you can default the Build and Revision Numbers // You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below: // by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")] // [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("4.1.0.8")] [assembly: AssemblyVersion("4.1.0.9")]
[assembly: AssemblyFileVersion("4.1.0.8")] [assembly: AssemblyFileVersion("4.1.0.9")]

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

@ -37,7 +37,7 @@ namespace SqlSugar
if (Skip != null && Take == null) if (Skip != null && Take == null)
{ {
if (this.OrderByValue == "ORDER BY ") this.OrderByValue += GetSelectValue.Split(',')[0]; if (this.OrderByValue == "ORDER BY ") this.OrderByValue += GetSelectValue.Split(',')[0];
return string.Format(PageTempalte, GetSelectValue, GetTableNameString, GetWhereValueString, GetGroupByString + HavingInfos, (Skip != null || Take != null) ? null : GetOrderByString, Skip.ObjToInt() + 1, long.MaxValue); return string.Format(PageTempalte, GetSelectValue, GetTableNameString, GetWhereValueString, GetGroupByString + HavingInfos, (Skip != null || Take != null) ? null : GetOrderByString, Skip.ObjToInt(), long.MaxValue);
} }
else if (Skip == null && Take != null) else if (Skip == null && Take != null)
{ {
@ -47,7 +47,7 @@ namespace SqlSugar
else if (Skip != null && Take != null) else if (Skip != null && Take != null)
{ {
if (this.OrderByValue == "ORDER BY ") this.OrderByValue += GetSelectValue.Split(',')[0]; if (this.OrderByValue == "ORDER BY ") this.OrderByValue += GetSelectValue.Split(',')[0];
return string.Format(PageTempalte, GetSelectValue, GetTableNameString, GetWhereValueString, GetGroupByString + HavingInfos, GetOrderByString, Skip.ObjToInt() > 0 ? Skip.ObjToInt() + 1 : 0, Take); return string.Format(PageTempalte, GetSelectValue, GetTableNameString, GetWhereValueString, GetGroupByString + HavingInfos, GetOrderByString, Skip.ObjToInt() > 0 ? Skip.ObjToInt(): 0, Take);
} }
else else
{ {

Loading…
Cancel
Save