@@ -154,10 +154,12 @@ public override string CommandText
154
154
if ( m_connection ? . HasActiveReader ?? false )
155
155
throw new InvalidOperationException ( "Cannot set MySqlCommand.CommandText when there is an open DataReader for this command; it must be closed first." ) ;
156
156
m_commandText = value ;
157
- m_statements = null ;
157
+ ClearPreparedStatements ( ) ;
158
158
}
159
159
}
160
160
161
+ public bool IsPrepared => m_statements != null ;
162
+
161
163
public new MySqlTransaction Transaction { get ; set ; }
162
164
163
165
public new MySqlConnection Connection
@@ -168,6 +170,7 @@ public override string CommandText
168
170
if ( m_connection ? . HasActiveReader ?? false )
169
171
throw new InvalidOperationException ( "Cannot set MySqlCommand.Connection when there is an open DataReader for this command; it must be closed first." ) ;
170
172
m_connection = value ;
173
+ ClearPreparedStatements ( ) ;
171
174
}
172
175
}
173
176
@@ -185,6 +188,7 @@ public override CommandType CommandType
185
188
if ( value != CommandType . Text && value != CommandType . StoredProcedure )
186
189
throw new ArgumentException ( "CommandType must be Text or StoredProcedure." , nameof ( value ) ) ;
187
190
m_commandType = value ;
191
+ ClearPreparedStatements ( ) ;
188
192
}
189
193
}
190
194
@@ -290,8 +294,7 @@ protected override void Dispose(bool disposing)
290
294
if ( disposing )
291
295
{
292
296
m_parameterCollection = null ;
293
- m_parsedStatements ? . Dispose ( ) ;
294
- m_parsedStatements = null ;
297
+ ClearPreparedStatements ( ) ;
295
298
}
296
299
}
297
300
finally
@@ -397,6 +400,13 @@ private bool IsValid(out Exception exception)
397
400
return exception == null ;
398
401
}
399
402
403
+ private void ClearPreparedStatements ( )
404
+ {
405
+ m_parsedStatements ? . Dispose ( ) ;
406
+ m_parsedStatements = null ;
407
+ m_statements = null ;
408
+ }
409
+
400
410
internal void ReaderClosed ( ) => ( m_commandExecutor as StoredProcedureCommandExecutor ) ? . SetParams ( ) ;
401
411
402
412
static int s_commandId = 1 ;
0 commit comments