Skip to content

Commit 9efc679

Browse files
committed
Add test for literal @ in SQL command.
This was identified as a potential bug at https://stackoverflow.com/a/78463231/23633; although it doesn't appear to be a current problem, adding a test to catch regressions.
1 parent 82c9d61 commit 9efc679

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

tests/MySqlConnector.Tests/StatementPreparerTests.cs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,29 @@ public void FormatParameter(object parameterValue, string replacedValue, bool no
142142
Assert.Equal(sql.Replace("@param", replacedValue), parsedSql);
143143
}
144144

145+
[Theory]
146+
[InlineData(true)]
147+
[InlineData(false)]
148+
public void AlterUserHardcoded(bool noBackslashEscapes)
149+
{
150+
const string sql = "ALTER USER 'root'@'%' IDENTIFIED BY 'password';";
151+
var options = noBackslashEscapes ? StatementPreparerOptions.NoBackslashEscapes : StatementPreparerOptions.None;
152+
var parsedSql = GetParsedSql(sql, options: options);
153+
Assert.Equal(sql, parsedSql);
154+
}
155+
156+
[Theory]
157+
[InlineData(true)]
158+
[InlineData(false)]
159+
public void AlterUserWithParameters(bool noBackslashEscapes)
160+
{
161+
const string sql = "ALTER USER @user@'localhost' IDENTIFIED BY @password;";
162+
var parameters = new MySqlParameterCollection { new("@user", "root"), new("@password", "P@ssw0rd") };
163+
var options = noBackslashEscapes ? StatementPreparerOptions.NoBackslashEscapes : StatementPreparerOptions.None;
164+
var parsedSql = GetParsedSql(sql, parameters, options);
165+
Assert.Equal("ALTER USER 'root'@'localhost' IDENTIFIED BY 'P@ssw0rd';", parsedSql);
166+
}
167+
145168
public static IEnumerable<object[]> FormatParameterData =>
146169
new[]
147170
{

0 commit comments

Comments
 (0)