Skip to content

Instantly share code, notes, and snippets.

Created January 25, 2018 19:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/ee94694a0d3c617cc236bc479fdd399f to your computer and use it in GitHub Desktop.
Save anonymous/ee94694a0d3c617cc236bc479fdd399f to your computer and use it in GitHub Desktop.
bug in StatementPreparer
using MySql.Data.MySqlClient;
using MySqlConnector.Core;
using Xunit;
namespace MySqlConnector.Tests
{
public class StatementPreparerTests
{
[Theory]
[InlineData(GoodSqlText)]
[InlineData(AnotherGoodSqlText)]
[InlineData(BadSqlText)]
public void PrepareQuery(string sql)
{
var parameters = new MySqlParameterCollection();
parameters.AddWithValue("c2", 3);
var parsedRequest1 = System.Text.Encoding.Default.GetString(new StatementPreparer(sql, parameters, StatementPreparerOptions.None).ParseAndBindParameters().Array);
Assert.Matches("column2 = 3", parsedRequest1);
}
private const string BadSqlText = @"SELECT
Id
FROM mytable
WHERE column1 = 2 -- mycomment
AND column2 = @c2";
private const string GoodSqlText = @"SELECT
Id
FROM mytable
WHERE column1 = 2
AND column2 = @c2";
private const string AnotherGoodSqlText = @"SELECT
Id
FROM mytable
WHERE column1 = 2 -- mycomment
AND column2 = @c2";
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment