-
Notifications
You must be signed in to change notification settings - Fork 333
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
Affected rows count is inconsistent with other database drivers #600
Comments
Pomelo EF Core modifies the connection string to work around this very issue. History for the reason it is defaulted to |
Well if they're not the only one doing it, I don't feel so bad. |
Is there a way to determine from the MySQLConnection object which mode you are in? Or better yet, a way to override the behavior of a particular MySqlCommand object for the duration of a single query? |
No, this is not possible, because the flag is set in the initial handshake with the server and can't be changed for the lifetime of the connection. |
The behaviour of the MySQL engine itself appears to be by design:
I'm a little surprised to hear that all other database engines count a "no-op update" as an affected row. |
Further down in the Pomelo file it does this by parsing the connection string associated with the connection. If the connection has not been opened yet then it modifies the connection string associated with the connection. |
That's how SQL Server works. And since it was the first ADO.NET database driver, I bet everyone else just followed the same pattern.
That's not a perfect solution for me, but it will cover most of my use cases so I'm ok with closing this ticket if no one objects. |
The primary reasons for defaulting to I was also trying to follow the [ However, "affected" in that documentation could either be interpreted strictly (as MySQL Server does, i.e., rows that are changed to different values), or loosely (as all other databases do, i.e., rows that are matched by the Since making that decision, we've learnt:
It seems like This is obviously a breaking change (users would have to review any @caleblloyd you helped picked the default; any thoughts on this change? |
I added a test (to AdoNetApiTest) to check the return value of Only MySqlConnector and dotConnect failed: This reinforces the suggestion that it would be best to match the behaviour of other ADO.NET libraries. |
It's a tough call.
|
Compatibility with other languages' drivers' defaults is (much) less important to me. The scenarios I'm more concerned about are:
|
It appears to be unique to MySQL AFAICT.
Most people seem to recommend changing the query to This workaround lets you get either "found rows" (default) or "affected rows" (add the extra predicate) behaviour with |
Changing it to |
Default changed in 0.49.0. |
Thank you for taking a look at this. Even if the decision hadn't gone my way, I would still respect you all for the careful thought you all put into the question. |
Here's a Connector/NET user who would have wanted the default to be true (possibly for compatibility with non-.NET tools): https://bugs.mysql.com/bug.php?id=96572 |
I'm working on an ORM. And one of the things it does is check the affected rows count after performing an update using ExecuteAsNonQuery(). If the count isn't 1, it throws an error saying the row couldn't be found.
Currently I've tested this design with
So far MySqlConnector is the only one that doesn't return 1 when the record was found, but no changes were made.
If I add "UseAffectedRows=false" to the connection string, it will work. But this means modifying the connection string I'm given, which would be weird from the user's perspective.
I don't know what the right answer if for MySqlConnector, but I felt that I should bring the inconsistency to your attention.
The text was updated successfully, but these errors were encountered: