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

Transaction update RowsAffected is 0 #6795

Closed
JamesYuan opened this issue Jan 15, 2024 · 2 comments
Closed

Transaction update RowsAffected is 0 #6795

JamesYuan opened this issue Jan 15, 2024 · 2 comments
Assignees
Labels
type:question general questions

Comments

@JamesYuan
Copy link

Your Question

Gorm: v1.25.5
Go: 1.21.4
MySQL: 8.0.31

A similar issue from #2038, and use the test case from it. Please refer to the following screenshot.

image

So even if there are 12 rows which have "name == 5" in database (statement 1 in screenshot), but the transaction update RowsAffected is 0 (statement 2 in screenshot).

The SQL "UPDATE user_tests SET password = '12345' WHERE (name = '5')" works well in MySQL Console and "12 rows affected".

The document you expected this should be explained

Expected answer

It is a normal scenario or a bug?

Thank you.

@JamesYuan JamesYuan added the type:question general questions label Jan 15, 2024
@ivila
Copy link
Contributor

ivila commented Jan 17, 2024

I think you might misunderstand the behavior of MySQL(or any other SQL servers).
By reading your codes and your console output of your snapshot, I think there is no bug in gorm, but misunderstanding on your side.

At first, you have 12 records that they are all the same, password is '12345', and name is '5'.

Then, you execute update query, set password to '12345' where name is '5', when executing, MySQL did found 12 rows with name '5', but it won't change anything as you are updating name to what it is now. so the result of mysql server returned should be Rows matched: 12 Changed: 0 Warnings: 0 (I don't think it works well in MySQL Console and "12 rows affected")

Last, you execute update query, set password to '44444' where name is '4', nothing matched, so nothing changed.

Everything works as expected on both MySQL server and gorm, you may need to check your mysql console as it works well in MySQL Console and "12 rows affected"

@JamesYuan
Copy link
Author

@ivila Thank you the details. I have understood the reasons.

Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type:question general questions
Projects
None yet
Development

No branches or pull requests

3 participants