Skip to content

Commit 66f63ad

Browse files
committed
Add IgnorePrepare connection string setting.
Signed-off-by: Bradley Grainger <[email protected]>
1 parent 8af47e3 commit 66f63ad

File tree

5 files changed

+20
-0
lines changed

5 files changed

+20
-0
lines changed

src/MySqlConnector/Core/ConnectionSettings.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ public ConnectionSettings(MySqlConnectionStringBuilder csb)
7070
DefaultCommandTimeout = (int) csb.DefaultCommandTimeout;
7171
ForceSynchronous = csb.ForceSynchronous;
7272
IgnoreCommandTransaction = csb.IgnoreCommandTransaction;
73+
IgnorePrepare = csb.IgnorePrepare;
7374
InteractiveSession = csb.InteractiveSession;
7475
GuidFormat = GetEffectiveGuidFormat(csb.GuidFormat, csb.OldGuids);
7576
Keepalive = csb.Keepalive;
@@ -145,6 +146,7 @@ private static MySqlGuidFormat GetEffectiveGuidFormat(MySqlGuidFormat guidFormat
145146
public bool ForceSynchronous { get; }
146147
public MySqlGuidFormat GuidFormat { get; }
147148
public bool IgnoreCommandTransaction { get; }
149+
public bool IgnorePrepare { get; }
148150
public bool InteractiveSession { get; }
149151
public uint Keepalive { get; }
150152
public bool PersistSecurityInfo { get; }

src/MySqlConnector/MySql.Data.MySqlClient/MySqlCommand.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,11 +78,14 @@ public override void Prepare()
7878
throw new InvalidOperationException("Connection must be Open; current state is {0}".FormatInvariant(Connection.State));
7979
if (string.IsNullOrWhiteSpace(CommandText))
8080
throw new InvalidOperationException("CommandText must be specified");
81+
if (Connection.IgnorePrepare)
82+
return;
8183

8284
// NOTE: Prepared statements in MySQL are not currently supported.
8385
// 1) Only a subset of statements are actually preparable by the server: http://dev.mysql.com/worklog/task/?id=2871
8486
// 2) Although CLIENT_MULTI_STATEMENTS is supposed to mean that the Server "Can handle multiple statements per COM_QUERY and COM_STMT_PREPARE" (https://dev.mysql.com/doc/internals/en/capability-flags.html#flag-CLIENT_MULTI_STATEMENTS),
8587
// this is not actually true because "Prepared statement handles are defined to work only with strings that contain a single statement" (http://dev.mysql.com/doc/refman/5.7/en/c-api-multiple-queries.html).
88+
throw new NotSupportedException("Prepared commands are not supported.");
8689
}
8790

8891
public override string CommandText

src/MySqlConnector/MySql.Data.MySqlClient/MySqlConnection.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -352,6 +352,7 @@ internal async Task<CachedProcedure> GetCachedProcedure(IOBehavior ioBehavior, s
352352
internal int DefaultCommandTimeout => GetConnectionSettings().DefaultCommandTimeout;
353353
internal MySqlGuidFormat GuidFormat => m_connectionSettings.GuidFormat;
354354
internal bool IgnoreCommandTransaction => m_connectionSettings.IgnoreCommandTransaction;
355+
internal bool IgnorePrepare => m_connectionSettings.IgnorePrepare;
355356
internal bool TreatTinyAsBoolean => m_connectionSettings.TreatTinyAsBoolean;
356357
internal IOBehavior AsyncIOBehavior => GetConnectionSettings().ForceSynchronous ? IOBehavior.Synchronous : IOBehavior.Asynchronous;
357358

src/MySqlConnector/MySql.Data.MySqlClient/MySqlConnectionStringBuilder.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,12 @@ public bool IgnoreCommandTransaction
207207
set => MySqlConnectionStringOption.IgnoreCommandTransaction.SetValue(this, value);
208208
}
209209

210+
public bool IgnorePrepare
211+
{
212+
get => MySqlConnectionStringOption.IgnorePrepare.GetValue(this);
213+
set => MySqlConnectionStringOption.IgnorePrepare.SetValue(this, value);
214+
}
215+
210216
public bool InteractiveSession
211217
{
212218
get => MySqlConnectionStringOption.InteractiveSession.GetValue(this);
@@ -338,6 +344,7 @@ internal abstract class MySqlConnectionStringOption
338344
public static readonly MySqlConnectionStringOption<bool> ForceSynchronous;
339345
public static readonly MySqlConnectionStringOption<MySqlGuidFormat> GuidFormat;
340346
public static readonly MySqlConnectionStringOption<bool> IgnoreCommandTransaction;
347+
public static readonly MySqlConnectionStringOption<bool> IgnorePrepare;
341348
public static readonly MySqlConnectionStringOption<bool> InteractiveSession;
342349
public static readonly MySqlConnectionStringOption<uint> Keepalive;
343350
public static readonly MySqlConnectionStringOption<bool> OldGuids;
@@ -501,6 +508,10 @@ static MySqlConnectionStringOption()
501508
keys: new[] { "IgnoreCommandTransaction", "Ignore Command Transaction" },
502509
defaultValue: false));
503510

511+
AddOption(IgnorePrepare = new MySqlConnectionStringOption<bool>(
512+
keys: new[] { "IgnorePrepare", "Ignore Prepare" },
513+
defaultValue: true));
514+
504515
AddOption(InteractiveSession = new MySqlConnectionStringOption<bool>(
505516
keys: new[] { "InteractiveSession", "Interactive", "Interactive Session" },
506517
defaultValue: false));

tests/MySqlConnector.Tests/MySqlConnectionStringBuilderTests.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ public void Defaults()
4242
Assert.Null(csb.CACertificateFile);
4343
Assert.Equal(MySqlLoadBalance.RoundRobin, csb.LoadBalance);
4444
#endif
45+
Assert.True(csb.IgnorePrepare);
4546
Assert.False(csb.InteractiveSession);
4647
Assert.Equal(0u, csb.Keepalive);
4748
Assert.Equal(100u, csb.MaximumPoolSize);
@@ -104,6 +105,7 @@ public void ParseConnectionString()
104105
"load balance=random;" +
105106
"guidformat=timeswapbinary16;" +
106107
#endif
108+
"ignore prepare=false;" +
107109
"interactive=true;" +
108110
"Keep Alive=90;" +
109111
"minpoolsize=5;" +
@@ -147,6 +149,7 @@ public void ParseConnectionString()
147149
Assert.Equal(MySqlLoadBalance.Random, csb.LoadBalance);
148150
Assert.Equal(MySqlGuidFormat.TimeSwapBinary16, csb.GuidFormat);
149151
#endif
152+
Assert.False(csb.IgnorePrepare);
150153
Assert.True(csb.InteractiveSession);
151154
Assert.Equal(90u, csb.Keepalive);
152155
Assert.Equal(15u, csb.MaximumPoolSize);

0 commit comments

Comments
 (0)