Skip to content

Commit 39bff0a

Browse files
committed
add support CommandTimeout
add support return DictionaryStringObject
1 parent 3ea23d0 commit 39bff0a

File tree

13 files changed

+42
-7
lines changed

13 files changed

+42
-7
lines changed

build/version.props

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<PropertyGroup>
33
<VersionMajor>4</VersionMajor>
44
<VersionMinor>0</VersionMinor>
5-
<VersionPatch>41</VersionPatch>
5+
<VersionPatch>42</VersionPatch>
66
<VersionPrefix>$(VersionMajor).$(VersionMinor).$(VersionPatch)</VersionPrefix>
77
</PropertyGroup>
88
</Project>

doc/Schema/SmartSql.Schema.nuspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<metadata>
44
<id>SmartSql.Schema</id>
55
<title>SmartSql Schema for Intellisense(TM)</title>
6-
<version>4.0.35</version>
6+
<version>4.0.42</version>
77
<authors>Ahoo Wang</authors>
88
<owners>Ahoo Wang</owners>
99
<requireLicenseAcceptance>false</requireLicenseAcceptance>

doc/Schema/SmartSqlMap.xsd

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -921,6 +921,7 @@
921921
<xs:attribute name="SourceChoice" type="DataSourceChoice" use="optional"/>
922922
<xs:attribute name="Transaction" type="Transaction" use="optional"/>
923923
<xs:attribute name="ReadDb" type="xs:string" use="optional"/>
924+
<xs:attribute name="CommandTimeout" type="xs:int" use="optional"/>
924925
</xs:complexType>
925926
</xs:element>
926927
<xs:element name="Statements">
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Text;
4+
5+
namespace SmartSql.Test.Performance.Query
6+
{
7+
public class QueryRequest
8+
{
9+
public int Taken { get; set; }
10+
}
11+
}

src/SmartSql.Test.Unit/Deserializer/DynamicDeserializerTest.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,17 @@ public void Query_Dynamic()
4141
Assert.NotEqual(0, result.FirstOrDefault().Id);
4242
}
4343
[Fact]
44+
public void Query_Dictionary()
45+
{
46+
var result = SqlMapper.Query<IDictionary<String,Object>>(new RequestContext
47+
{
48+
Scope = nameof(AllPrimitive),
49+
SqlId = "Query",
50+
Request = new { Taken = 10 }
51+
});
52+
Assert.NotEqual(0, result.FirstOrDefault()["Id"]);
53+
}
54+
[Fact]
4455
public void Query_Dynamic_AsHashtable()
4556
{
4657
var result = SqlMapper.Query<dynamic>(new RequestContext

src/SmartSql/Command/CommandExecuter.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,10 @@ private DbCommand CreateCmd(ExecutionContext executionContext)
3030
dbCmd.CommandType = executionContext.Request.CommandType;
3131
dbCmd.Transaction = dbSession.Transaction;
3232
dbCmd.CommandText = executionContext.Request.RealSql;
33+
if (executionContext.Request.CommandTimeout.HasValue)
34+
{
35+
dbCmd.CommandTimeout = executionContext.Request.CommandTimeout.Value;
36+
}
3337
foreach (var dbParam in executionContext.Request.Parameters.DbParameters.Values)
3438
{
3539
dbCmd.Parameters.Add(dbParam);

src/SmartSql/ConfigBuilder/SqlMapBuilder.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -378,6 +378,12 @@ private void BuildStatement(XmlNode statementNode)
378378
statementNode.Attributes.TryGetValueAsString("ParameterMap", out var parameterId, SmartSqlConfig.Properties);
379379
statementNode.Attributes.TryGetValueAsString("ResultMap", out var resultMapId, SmartSqlConfig.Properties);
380380
statementNode.Attributes.TryGetValueAsString("MultipleResultMap", out var multipleResultMapId, SmartSqlConfig.Properties);
381+
int? commandTimeout=null;
382+
if (statementNode.Attributes.TryGetValueAsInt32(nameof(Statement.CommandTimeout), out var cmdTimeout, SmartSqlConfig.Properties))
383+
{
384+
commandTimeout = cmdTimeout;
385+
}
386+
381387
var statement = new Statement
382388
{
383389
Id = id,
@@ -387,6 +393,7 @@ private void BuildStatement(XmlNode statementNode)
387393
CacheId = cacheId,
388394
ParameterMapId = parameterId,
389395
ResultMapId = resultMapId,
396+
CommandTimeout = commandTimeout,
390397
MultipleResultMapId = multipleResultMapId,
391398
IncludeDependencies = new List<Include>()
392399
};

src/SmartSql/Configuration/Statement.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ public class Statement
1515
public DataSourceChoice? SourceChoice { get; set; }
1616
public IsolationLevel? Transaction { get; set; }
1717
public String ReadDb { get; set; }
18+
public int? CommandTimeout { get; set; }
1819
public String FullSqlId => $"{SqlMap.Scope}.{Id}";
1920
public IList<ITag> SqlTags { get; set; }
2021
#region Map

src/SmartSql/Deserializer/DynamicDeserializer.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
using SmartSql.Data;
22
using System;
33
using System.Collections.Generic;
4-
using System.Dynamic;
54
using System.Linq;
65
using System.Threading.Tasks;
76
using SmartSql.Reflection.TypeConstants;
@@ -12,7 +11,7 @@ public class DynamicDeserializer : IDataReaderDeserializer
1211
{
1312
public bool CanDeserialize(ExecutionContext executionContext, Type resultType, bool isMultiple = false)
1413
{
15-
return resultType == CommonType.Object;
14+
return resultType == CommonType.Object || resultType == CommonType.DictionaryStringObject;
1615
}
1716

1817
public TResult ToSinge<TResult>(ExecutionContext executionContext)

src/SmartSql/Middlewares/InitializerMiddleware.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ private void InitByStatement(AbstractRequestContext requestContext, SqlMap sqlMa
6969
requestContext.CommandType = requestContext.Statement.CommandType.Value;
7070
}
7171
requestContext.Transaction = requestContext.Transaction ?? requestContext.Statement.Transaction;
72+
requestContext.CommandTimeout = requestContext.CommandTimeout ?? requestContext.Statement.CommandTimeout;
7273
requestContext.ReadDb = requestContext.Statement.ReadDb;
7374
requestContext.CacheId = requestContext.Statement.CacheId;
7475
requestContext.Cache = requestContext.Statement.Cache;

0 commit comments

Comments
 (0)