Skip to content

Commit 65a4bf5

Browse files
committed
1. optimized storage procedure name transfer: From XML / RealSql
1 parent bb821b8 commit 65a4bf5

File tree

7 files changed

+52
-13
lines changed

7 files changed

+52
-13
lines changed

src/SmartSql.UTests/DyRepository/DyRepository_Tests.cs

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public DyRepository_Tests()
2424

2525

2626
[Fact]
27-
public void SP_QueryByPage()
27+
public void SP_QueryByPage_From_XML()
2828
{
2929
DbParameterCollection dbParameterCollection = new DbParameterCollection();
3030
dbParameterCollection.Add(new DbParameter
@@ -33,7 +33,20 @@ public void SP_QueryByPage()
3333
DbType = System.Data.DbType.Int32,
3434
Direction = System.Data.ParameterDirection.Output
3535
});
36-
var list = _repository.SP_QueryByPage(dbParameterCollection);
36+
var list = _repository.SP_QueryByPage_From_XML(dbParameterCollection);
37+
var total = dbParameterCollection.GetValue<int>("Total");
38+
}
39+
[Fact]
40+
public void SP_QueryByPage_From_RealSql()
41+
{
42+
DbParameterCollection dbParameterCollection = new DbParameterCollection();
43+
dbParameterCollection.Add(new DbParameter
44+
{
45+
Name = "Total",
46+
DbType = System.Data.DbType.Int32,
47+
Direction = System.Data.ParameterDirection.Output
48+
});
49+
var list = _repository.SP_QueryByPage_From_RealSql(dbParameterCollection);
3750
var total = dbParameterCollection.GetValue<int>("Total");
3851
}
3952
[Fact]

src/SmartSql.UTests/DyRepository/IEntityRepository.cs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,11 @@ public interface IEntityRepository : IRepository<T_Entity, long>, IRepositoryAsy
4444
Task<DataSet> QueryDataSetAsync();
4545
[Statement(Sql = "Select Top(@taken) T.* From T_Entity T With(NoLock);")]
4646
Task<IEnumerable<T_Entity>> QueryBySqlAsync(int taken);
47-
[Statement(CommandType = CommandType.StoredProcedure)]
48-
IEnumerable<T_Entity> SP_QueryByPage(DbParameterCollection dbParameterCollection);
47+
48+
[Statement(Id = "SP_QueryByPage", CommandType = CommandType.StoredProcedure)]
49+
IEnumerable<T_Entity> SP_QueryByPage_From_XML(DbParameterCollection dbParameterCollection);
50+
51+
[Statement(Sql = "SP_QueryByPage", CommandType = CommandType.StoredProcedure)]
52+
IEnumerable<T_Entity> SP_QueryByPage_From_RealSql(DbParameterCollection dbParameterCollection);
4953
}
5054
}

src/SmartSql.UTests/Maps/T_Entity.xml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@
1919
<Arg Column="FLong" Type="Int64" />
2020
<Arg Column="FDecimal" Type="Decimal" />
2121
</Constructor>
22+
2223
</ResultMap>
2324
</ResultMaps>
24-
2525
<ParameterMaps>
2626
<ParameterMap Id="ParameterMap">
2727
<Parameter Property="" TypeHandler="Json" />
@@ -30,6 +30,9 @@
3030

3131

3232
<Statements>
33+
<Statement Id="SP_QueryByPage">
34+
SP_QueryByPage
35+
</Statement>
3336
<Statement Id="QueryForPlaceholder">
3437
SELECT Top(10) T.* From <Placeholder Property="TableName"></Placeholder> T With(NoLock)
3538
</Statement>

src/SmartSql.UTests/SmartSqlMapper_Test.cs

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ public void QuerySingle()
170170
}
171171

172172
[Fact]
173-
public void StoredProcedure()
173+
public void StoredProcedure_From_XML()
174174
{
175175
DbParameterCollection dbParameterCollection = new DbParameterCollection();
176176
dbParameterCollection.Add(new DbParameter
@@ -182,12 +182,34 @@ public void StoredProcedure()
182182
RequestContext context = new RequestContext
183183
{
184184
CommandType = System.Data.CommandType.StoredProcedure,
185+
Scope = Scope,
185186
SqlId = "SP_QueryByPage",
186187
Request = dbParameterCollection
187188
};
188189
var list = _sqlMapper.Query<T_Entity>(context);
189190
var total = dbParameterCollection.GetValue<int>("Total");
190191
}
192+
193+
[Fact]
194+
public void StoredProcedure_From_RealSql()
195+
{
196+
DbParameterCollection dbParameterCollection = new DbParameterCollection();
197+
dbParameterCollection.Add(new DbParameter
198+
{
199+
Name = "Total",
200+
DbType = System.Data.DbType.Int32,
201+
Direction = System.Data.ParameterDirection.Output
202+
});
203+
RequestContext context = new RequestContext
204+
{
205+
CommandType = System.Data.CommandType.StoredProcedure,
206+
RealSql = "SP_QueryByPage",
207+
Request = dbParameterCollection
208+
};
209+
var list = _sqlMapper.Query<T_Entity>(context);
210+
var total = dbParameterCollection.GetValue<int>("Total");
211+
}
212+
191213
[Fact]
192214
public void QueryMultiple()
193215
{

src/SmartSql/Command/PreparedCommand.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ public IDbCommand Prepare(IDbConnectionSession dbSession, RequestContext context
103103
case CommandType.StoredProcedure:
104104
{
105105
AddDbParameterCollection(dbCommand, context.RequestParameters);
106-
dbCommand.CommandText = context.SqlId;
106+
dbCommand.CommandText = context.RealSql;
107107
break;
108108
}
109109
}

src/SmartSql/SmartSql.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@
1111
<PackageProjectUrl>https://github.com/Ahoo-Wang/SmartSql</PackageProjectUrl>
1212
<RepositoryUrl>https://github.com/Ahoo-Wang/SmartSql</RepositoryUrl>
1313
<PackageRequireLicenseAcceptance>False</PackageRequireLicenseAcceptance>
14-
<Version>3.5.8</Version>
14+
<Version>3.5.9</Version>
1515
<PackageTags>orm sql read-write-separation cache redis dotnet-core cross-platform high-performance distributed-computing zookeeper</PackageTags>
1616
<PackageReleaseNotes>
17-
1. fix the cache penetration problem with the cache value of null
17+
1. optimized storage procedure name transfer: From XML / RealSql
1818
</PackageReleaseNotes>
1919
<PackageIconUrl>https://raw.githubusercontent.com/Ahoo-Wang/SmartSql/master/SmartSql.png</PackageIconUrl>
2020
<PackageLicenseUrl>https://raw.githubusercontent.com/Ahoo-Wang/SmartSql/master/LICENSE</PackageLicenseUrl>

src/SmartSql/SmartSqlMapper.cs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,7 @@ public SmartSqlMapper(SmartSqlOptions options)
5454
private void SetupRequestContext(RequestContext context)
5555
{
5656
context.Setup(SmartSqlOptions.SmartSqlContext);
57-
if (context.CommandType == CommandType.Text)
58-
{
59-
SqlBuilder.BuildSql(context);
60-
}
57+
SqlBuilder.BuildSql(context);
6158
}
6259
private void SetWriteSourceIfUnknow(RequestContext context)
6360
{

0 commit comments

Comments
 (0)