Skip to content

Instantly share code, notes, and snippets.

@jamesrcounts
Created October 3, 2014 02:42
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jamesrcounts/503faad5ba2dc53124c9 to your computer and use it in GitHub Desktop.
Save jamesrcounts/503faad5ba2dc53124c9 to your computer and use it in GitHub Desktop.
IDatabaseToExecuteableQueryAdaptor for MySql
// 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