Created
October 3, 2014 02:42
-
-
Save jamesrcounts/503faad5ba2dc53124c9 to your computer and use it in GitHub Desktop.
IDatabaseToExecuteableQueryAdaptor for MySql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Note: Connection string must include the following option: Allow User Variables=True | |
using System; | |
using System.Data.Common; | |
using System.Linq; | |
using ApprovalUtilities.Persistence.Database; | |
using MySql.Data.MySqlClient; | |
public class MySqlCommandAdapter : IDatabaseToExecuteableQueryAdaptor | |
{ | |
private readonly MySqlCommand mySqlCommand; | |
public MySqlCommandAdapter(MySqlCommand mySqlCommand) | |
{ | |
this.mySqlCommand = mySqlCommand; | |
} | |
public string GetQuery() | |
{ | |
return | |
mySqlCommand.Parameters.Cast<MySqlParameter>() | |
.Select(p => "SET " + p.ParameterName + " = '" + p.Value + "';" + Environment.NewLine) | |
.Aggregate(mySqlCommand.CommandText, (s, s1) => s1 + s); | |
} | |
public DbConnection GetConnection() | |
{ | |
return mySqlCommand.Connection; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment