Skip to content

Commit 849d7e1

Browse files
committed
Add parentheses to checks in Prepare, factor out check for stored procedure and text command without parameters
1 parent e0456b2 commit 849d7e1

File tree

1 file changed

+7
-5
lines changed
  • src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient

1 file changed

+7
-5
lines changed

src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/SqlCommand.cs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,10 @@ private bool IsDirty
155155
// @TODO: IsPrepared is part of IsDirty - this is confusing.
156156
private bool IsUserPrepared => IsPrepared && !_hiddenPrepare && !IsDirty;
157157

158+
private bool IsStoredProcedure => CommandType is CommandType.StoredProcedure;
159+
160+
private bool IsSimpleTextQuery => CommandType is CommandType.Text && _parameters?.Count == 0;
161+
158162
#endregion
159163

160164
#region Public/Internal Methods
@@ -182,11 +186,9 @@ public override void Prepare()
182186
{
183187
statistics = SqlStatistics.StartTimer(Statistics);
184188

185-
// Only prepare batch has parameters
186-
// @TODO: Factor out stored proc/text+parameter count to property
187-
// @TODO: Not using parentheses is confusing here b/c it relies on order of operations knowledge
188-
if (IsPrepared && !IsDirty || CommandType == CommandType.StoredProcedure
189-
|| (CommandType == CommandType.Text && GetParameterCount(_parameters) == 0))
189+
// Only prepare batch that has parameters
190+
// @TODO: IsPrepared is part of IsDirty - this is confusing.
191+
if ((IsPrepared && !IsDirty) || IsStoredProcedure || IsSimpleTextQuery)
190192
{
191193
// @TODO: Make a simpler SafeIncrementPrepares
192194
Statistics?.SafeIncrement(ref Statistics._prepares);

0 commit comments

Comments
 (0)