Skip to content
This repository was archived by the owner on Dec 24, 2022. It is now read-only.

Commit c8d8fbc

Browse files
committed
Update to latest version of Dapper
1 parent a5a489d commit c8d8fbc

File tree

1 file changed

+44
-13
lines changed

1 file changed

+44
-13
lines changed

src/ServiceStack.OrmLite/Dapper/SqlMapper.cs

Lines changed: 44 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ public CommandDefinition(string commandText, object parameters = null, IDbTransa
151151
#if ASYNC
152152
, CancellationToken cancellationToken = default(CancellationToken)
153153
#endif
154-
)
154+
)
155155
#endif
156156
{
157157
this.commandText = commandText;
@@ -165,8 +165,7 @@ public CommandDefinition(string commandText, object parameters = null, IDbTransa
165165
#endif
166166
}
167167

168-
private CommandDefinition(object parameters)
169-
: this()
168+
private CommandDefinition(object parameters) : this()
170169
{
171170
this.parameters = parameters;
172171
}
@@ -188,7 +187,13 @@ internal IDbCommand SetupCommand(IDbConnection cnn, Action<IDbCommand, object> p
188187
cmd.Transaction = transaction;
189188
cmd.CommandText = commandText;
190189
if (commandTimeout.HasValue)
190+
{
191191
cmd.CommandTimeout = commandTimeout.Value;
192+
}
193+
else if (SqlMapper.Settings.CommandTimeout.HasValue)
194+
{
195+
cmd.CommandTimeout = SqlMapper.Settings.CommandTimeout.Value;
196+
}
192197
if (commandType.HasValue)
193198
cmd.CommandType = commandType.Value;
194199
if (paramReader != null)
@@ -257,6 +262,30 @@ static MethodInfo GetBasicPropertySetter(Type declaringType, string name, Type e
257262
/// </summary>
258263
static partial class SqlMapper
259264
{
265+
/// <summary>
266+
/// Permits specifying certain SqlMapper values globally.
267+
/// </summary>
268+
public static class Settings
269+
{
270+
static Settings()
271+
{
272+
SetDefaults();
273+
}
274+
275+
/// <summary>
276+
/// Resets all Settings to their default values
277+
/// </summary>
278+
public static void SetDefaults()
279+
{
280+
CommandTimeout = null;
281+
}
282+
283+
/// <summary>
284+
/// Specifies the default Command Timeout for all Queries
285+
/// </summary>
286+
public static int? CommandTimeout { get; set; }
287+
}
288+
260289
/// <summary>
261290
/// Implement this interface to pass an arbitrary db specific set of parameters to Dapper
262291
/// </summary>
@@ -1497,7 +1526,7 @@ public static IEnumerable<object> Query(
14971526
#else
14981527
this IDbConnection cnn, Type type, string sql, object param = null, IDbTransaction transaction = null, bool buffered = true, int? commandTimeout = null, CommandType? commandType = null
14991528
#endif
1500-
)
1529+
)
15011530
{
15021531
if (type == null) throw new ArgumentNullException("type");
15031532
var command = new CommandDefinition(sql, (object)param, transaction, commandTimeout, commandType, buffered ? CommandFlags.Buffered : CommandFlags.None);
@@ -1526,7 +1555,7 @@ public static GridReader QueryMultiple(
15261555
#if CSHARP30
15271556
this IDbConnection cnn, string sql, object param, IDbTransaction transaction, int? commandTimeout, CommandType? commandType
15281557
#else
1529-
this IDbConnection cnn, string sql, object param = null, IDbTransaction transaction = null, int? commandTimeout = null, CommandType? commandType = null
1558+
this IDbConnection cnn, string sql, object param = null, IDbTransaction transaction = null, int? commandTimeout = null, CommandType? commandType = null
15301559
#endif
15311560
)
15321561
{
@@ -1567,7 +1596,8 @@ private static GridReader QueryMultipleImpl(this IDbConnection cnn, ref CommandD
15671596
{
15681597
if (reader != null)
15691598
{
1570-
if (!reader.IsClosed) try { cmd.Cancel(); }
1599+
if (!reader.IsClosed)
1600+
try { cmd.Cancel(); }
15711601
catch { /* don't spoil the existing exception */ }
15721602
reader.Dispose();
15731603
}
@@ -1633,7 +1663,8 @@ private static IEnumerable<T> QueryImpl<T>(this IDbConnection cnn, CommandDefini
16331663
{
16341664
if (reader != null)
16351665
{
1636-
if (!reader.IsClosed) try { cmd.Cancel(); }
1666+
if (!reader.IsClosed)
1667+
try { cmd.Cancel(); }
16371668
catch { /* don't spoil the existing exception */ }
16381669
reader.Dispose();
16391670
}
@@ -4302,8 +4333,8 @@ private IEnumerable<T> ReadImpl<T>(Type type, bool buffered)
43024333

43034334
private IEnumerable<TReturn> MultiReadInternal<TFirst, TSecond, TThird, TFourth, TFifth, TSixth, TSeventh, TReturn>(Delegate func, string splitOn)
43044335
{
4305-
var identity = this.identity.ForGrid(typeof(TReturn), new Type[] {
4306-
typeof(TFirst),
4336+
var identity = this.identity.ForGrid(typeof(TReturn), new Type[] {
4337+
typeof(TFirst),
43074338
typeof(TSecond),
43084339
typeof(TThird),
43094340
typeof(TFourth),
@@ -4495,9 +4526,9 @@ public void Dispose()
44954526
/// </summary>
44964527
public static ICustomQueryParameter AsTableValuedParameter(this DataTable table, string typeName
44974528
#if !CSHARP30
4498-
= null
4529+
= null
44994530
#endif
4500-
)
4531+
)
45014532
{
45024533
return new TableValuedParameter(table, typeName);
45034534
}
@@ -5026,7 +5057,7 @@ public DynamicParameters Output<T>(T target, Expression<Func<T, object>> express
50265057
}
50275058

50285059
// Queue the preparation to be fired off when adding parameters to the DbCommand
5029-
MAKECALLBACK:
5060+
MAKECALLBACK:
50305061
(outputCallbacks ?? (outputCallbacks = new List<Action>())).Add(() =>
50315062
{
50325063
// Finally, prep the parameter and attach the callback to it
@@ -6162,4 +6193,4 @@ public static MethodInfo GetPublicInstanceMethod(this Type type, string name, Ty
61626193

61636194

61646195
}
6165-
}
6196+
}

0 commit comments

Comments
 (0)