Skip to content

Commit

Permalink
优化SQLBuilder
Browse files Browse the repository at this point in the history
  • Loading branch information
junjie-sun committed Oct 22, 2019
1 parent f459243 commit 2d3ee93
Show file tree
Hide file tree
Showing 8 changed files with 20 additions and 14 deletions.
8 changes: 7 additions & 1 deletion doc/更新日志.txt
Original file line number Diff line number Diff line change
Expand Up @@ -123,4 +123,10 @@ XDbAccess.MySql
1.3.1
����ע��

--------------------------------------------------------------------------------
--------------------------------------------------------------------------------

2019-10-23
XDbAccess Tag��1.3.2

XDbAccess.Common
MSSqlSQLBuilder��MySqlSQLBuilder���BuidlPagedQuerySql��BuildQueryCountSql�����Ż�Where�Ӿ�������߼�
2 changes: 1 addition & 1 deletion src/XDbAccess.AutoTrans/XDbAccess.AutoTrans.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<PackageLicenseUrl>https://github.com/junjie-sun/XDbAccess/blob/master/LICENSE.txt</PackageLicenseUrl>
<PackageProjectUrl>https://github.com/junjie-sun/XDbAccess</PackageProjectUrl>
<PackageTags>xdbaccess,db,transaction</PackageTags>
<Version>1.3.1</Version>
<Version>1.3.2</Version>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
Expand Down
8 changes: 4 additions & 4 deletions src/XDbAccess.Common/SQLBuilder/MSSqlSQLBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -187,10 +187,10 @@ public string BuidlPagedQuerySql(PagedQueryOptions options)

var sql = string.Format(@"SELECT * FROM (
SELECT {0},ROW_NUMBER() OVER(ORDER BY {1}) AS RowNumber FROM {2}
WHERE 1=1 {3}
WHERE {3}
) as pageTable where RowNumber>={4} and RowNumber<={5};",
options.SqlFieldsPart, options.SqlOrderPart, options.SqlFromPart,
string.IsNullOrEmpty(options.SqlConditionPart) ? string.Empty : "AND " + options.SqlConditionPart, pageStartIndex, pageEndIndex);
options.SqlConditionPart, pageStartIndex, pageEndIndex);

return sql;
}
Expand All @@ -208,8 +208,8 @@ public string BuildQueryCountSql(string sqlFromPart, string sqlConditionPart = n
throw new ArgumentNullException("Need to specify sqlFromPart");
}

var sql = string.Format(" SELECT COUNT(1) FROM {0} where 1=1 {1} ;"
, sqlFromPart, string.IsNullOrEmpty(sqlConditionPart) ? string.Empty : "AND " + sqlConditionPart);
var sql = string.Format(" SELECT COUNT(1) FROM {0} where {1};"
, sqlFromPart, sqlConditionPart);

return sql;
}
Expand Down
8 changes: 4 additions & 4 deletions src/XDbAccess.Common/SQLBuilder/MySqlSQLBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -185,8 +185,8 @@ public string BuidlPagedQuerySql(PagedQueryOptions options)
int pageStartIndex = options.PageSize * options.PageIndex;
int currentPageCount = options.PageSize;

var sql = string.Format(@"SELECT {0} FROM {1} WHERE 1=1 {2} {3} LIMIT {4},{5};",
options.SqlFieldsPart, options.SqlFromPart, string.IsNullOrEmpty(options.SqlConditionPart) ? string.Empty : "AND " + options.SqlConditionPart,
var sql = string.Format(@"SELECT {0} FROM {1} WHERE {2} {3} LIMIT {4},{5};",
options.SqlFieldsPart, options.SqlFromPart, options.SqlConditionPart,
string.IsNullOrEmpty(options.SqlOrderPart) ? string.Empty : "ORDER BY " + options.SqlOrderPart, pageStartIndex, currentPageCount);

return sql;
Expand All @@ -205,8 +205,8 @@ public string BuildQueryCountSql(string sqlFromPart, string sqlConditionPart = n
throw new ArgumentNullException("Need to specify sqlFromPart");
}

var sql = string.Format(" SELECT COUNT(1) FROM {0} where 1=1 {1} ;"
, sqlFromPart, string.IsNullOrEmpty(sqlConditionPart) ? string.Empty : "AND " + sqlConditionPart);
var sql = string.Format(" SELECT COUNT(1) FROM {0} where {1};"
, sqlFromPart, sqlConditionPart);

return sql;
}
Expand Down
2 changes: 1 addition & 1 deletion src/XDbAccess.Common/XDbAccess.Common.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<PackageLicenseUrl>https://github.com/junjie-sun/XDbAccess/blob/master/LICENSE.txt</PackageLicenseUrl>
<PackageProjectUrl>https://github.com/junjie-sun/XDbAccess</PackageProjectUrl>
<PackageTags>xdbaccess,db</PackageTags>
<Version>1.3.1</Version>
<Version>1.3.2</Version>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
Expand Down
2 changes: 1 addition & 1 deletion src/XDbAccess.Dapper/XDbAccess.Dapper.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<PackageLicenseUrl>https://github.com/junjie-sun/XDbAccess/blob/master/LICENSE.txt</PackageLicenseUrl>
<PackageProjectUrl>https://github.com/junjie-sun/XDbAccess</PackageProjectUrl>
<PackageTags>xdbaccess,db,dapper</PackageTags>
<Version>1.3.1</Version>
<Version>1.3.2</Version>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
Expand Down
2 changes: 1 addition & 1 deletion src/XDbAccess.MSSql/XDbAccess.MSSql.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<PackageTags>xdbaccess</PackageTags>
<PackageLicenseUrl>https://github.com/junjie-sun/XDbAccess/blob/master/LICENSE.txt</PackageLicenseUrl>
<PackageProjectUrl>https://github.com/junjie-sun/XDbAccess</PackageProjectUrl>
<Version>1.3.1</Version>
<Version>1.3.2</Version>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
Expand Down
2 changes: 1 addition & 1 deletion src/XDbAccess.MySql/XDbAccess.MySql.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<PackageLicenseUrl>https://github.com/junjie-sun/XDbAccess/blob/master/LICENSE.txt</PackageLicenseUrl>
<PackageProjectUrl>https://github.com/junjie-sun/XDbAccess</PackageProjectUrl>
<PackageTags>xdbaccess</PackageTags>
<Version>1.3.1</Version>
<Version>1.3.2</Version>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
Expand Down

0 comments on commit 2d3ee93

Please sign in to comment.