Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Setting ParameterName after adding to DbCommand #811

Closed
tznind opened this issue May 6, 2020 · 2 comments
Closed

Setting ParameterName after adding to DbCommand #811

tznind opened this issue May 6, 2020 · 2 comments
Labels

Comments

@tznind
Copy link

@tznind tznind commented May 6, 2020

I think I have hit an issue changing from MySql.Data to MySqlConnector that appears to be down to me changing a DbParameter name after adding it to the command (HicServices/RdmpDicom@3436074).

I have written the following unit test that seems to repro the issue.

[TestCase(true)]
[TestCase(false)]
public void TestNamingParameterBeforeAdding(bool nameBeforeAdd)
{
    var cmd = new MySqlCommand();
    var p = cmd.CreateParameter();

    if(nameBeforeAdd)
        p.ParameterName = "@ff";

    cmd.Parameters.Add(p);

    if(!nameBeforeAdd) 
        p.ParameterName = "@ff";
        
    p.Value = "bb";

    Assert.AreEqual("bb",cmd.Parameters["@ff"].Value);
}

Results are:

Rdmp.Dicom.Tests.Unit.Test.TestNamingParameterBeforeAdding(True):
    Outcome: Passed
    
Rdmp.Dicom.Tests.Unit.Test.TestNamingParameterBeforeAdding(False):
    Outcome: Failed
    Error Message:
    System.ArgumentException : Parameter '@ff' not found in the collection
Parameter name: parameterName
    Stack Trace:
       at MySql.Data.MySqlClient.MySqlParameterCollection.GetParameter(String parameterName) in C:\projects\mysqlconnector\src\MySqlConnector\MySql.Data.MySqlClient\MySqlParameterCollection.cs:line 86
   at MySql.Data.MySqlClient.MySqlParameterCollection.get_Item(String name) in C:\projects\mysqlconnector\src\MySqlConnector\MySql.Data.MySqlClient\MySqlParameterCollection.cs:line 152
   at Rdmp.Dicom.Tests.Unit.Test.TestNamingParameterBeforeAdding(Boolean nameBeforeAdd) in /home/thomas/RdmpDicom/Rdmp.Dicom.Tests/Unit/AmbiguousFilePathTests.cs:line 33
    
Total tests: 2. Passed: 1. Failed: 1. Skipped: 0
@bgrainger bgrainger added the bug label May 6, 2020
@bgrainger
Copy link
Member

@bgrainger bgrainger commented May 6, 2020

Thanks for the bug report and a unit test to repro it. (And thanks for using MySqlConnector!)

@bgrainger
Copy link
Member

@bgrainger bgrainger commented May 7, 2020

Fixed in 0.66.0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

No branches or pull requests

2 participants