Synchronization code

This commit is contained in:
sunkaixuan 2024-05-31 21:41:54 +08:00
parent 32f4e37189
commit 0f5bd42e58
2 changed files with 21 additions and 2 deletions

View File

@ -28,6 +28,18 @@ namespace SqlSugar.Access
{ {
throw new Exception("sqlite no support partition by"); throw new Exception("sqlite no support partition by");
} }
var top = 0;
if (Skip == null && Take > 0 && this.OrderByValue == " ORDER BY now() ")
{
top = Take.Value;
this.OrderByValue = null;
Skip = null;
Take = null;
}
else if (Skip == null && Take > 0)
{
Skip = 0;
}
var isFirst = (Skip == 0 || Skip == null) && Take == 1 && DisableTop == false; var isFirst = (Skip == 0 || Skip == null) && Take == 1 && DisableTop == false;
var isRowNumber = (Skip != null || Take != null) && !isFirst; var isRowNumber = (Skip != null || Take != null) && !isFirst;
var isPage = isRowNumber; var isPage = isRowNumber;
@ -40,7 +52,14 @@ namespace SqlSugar.Access
string groupByValue = GetGroupByString + HavingInfos; string groupByValue = GetGroupByString + HavingInfos;
string orderByValue = (!isRowNumber && this.OrderByValue.HasValue()) ? GetOrderByString : null; string orderByValue = (!isRowNumber && this.OrderByValue.HasValue()) ? GetOrderByString : null;
if (isIgnoreOrderBy) { orderByValue = null; } if (isIgnoreOrderBy) { orderByValue = null; }
if (top > 0)
{
sql.AppendFormat(SqlTemplate, (" TOP "+top+" " + GetSelectValue) , GetTableNameString, GetWhereValueString, groupByValue, orderByValue);
}
else
{
sql.AppendFormat(SqlTemplate, isFirst ? (" TOP 1 " + GetSelectValue) : GetSelectValue, GetTableNameString, GetWhereValueString, groupByValue, orderByValue); sql.AppendFormat(SqlTemplate, isFirst ? (" TOP 1 " + GetSelectValue) : GetSelectValue, GetTableNameString, GetWhereValueString, groupByValue, orderByValue);
}
sql.Replace(UtilConstants.ReplaceKey, isRowNumber ? (isIgnoreOrderBy ? null : rowNumberString) : null); sql.Replace(UtilConstants.ReplaceKey, isRowNumber ? (isIgnoreOrderBy ? null : rowNumberString) : null);
if (isIgnoreOrderBy) { this.OrderByValue = oldOrderBy; return sql.ToString(); } if (isIgnoreOrderBy) { this.OrderByValue = oldOrderBy; return sql.ToString(); }
var result = isFirst ? sql.ToString() : ToPageSql(sql.ToString(), this.Take, this.Skip); var result = isFirst ? sql.ToString() : ToPageSql(sql.ToString(), this.Take, this.Skip);

View File

@ -2,7 +2,7 @@
<package > <package >
<metadata> <metadata>
<id>SqlSugar.AccessCore</id> <id>SqlSugar.AccessCore</id>
<version>5.10.4.42</version> <version>5.10.4.159</version>
<authors>sunkaixuan</authors> <authors>sunkaixuan</authors>
<owners>Landa</owners> <owners>Landa</owners>
<licenseUrl>http://www.apache.org/licenses/LICENSE-2.0.html</licenseUrl> <licenseUrl>http://www.apache.org/licenses/LICENSE-2.0.html</licenseUrl>