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

MySQL driver ClientFoundRows configuration option doesn't change RowsAffected for Update call #6756

Closed
takanuva15 opened this issue Dec 18, 2023 · 1 comment
Assignees
Labels

Comments

@takanuva15
Copy link

GORM Playground Link

go-gorm/playground#1

To be added

Description

To do an update currently, I have to call .Find() to verify the primaryKey exists before calling .Update(). To avoid the first Find call, I thought I could check RowsAffected for the update call, but it will return 0 even if the primaryKey is found but the data I'm updating is the exact same as what's in the DB.

MySQL has an option ClientFoundRows which changes the return result to whether the db found any rows to update, regardless of whether any rows were actually updated. This is what I want to return to indicate that rows were found, so that I don't need to call Find first. Unfortunately, this configuration does not seem to change the result of RowsAffected when testing:

db, err := gorm.Open(
	mysql.New(
		mysql.Config{
			DSN: dbConns[1],
			DSNConfig: &gosqldriver.Config{
				ClientFoundRows: true,
			},
		},
	),
	&gorm.Config{Logger: logger.Default.LogMode(logger.Info)},
)

Thus I think there's a bug in how gorm is handling the ClientFoundRows option for MySQL?

@github-actions github-actions bot added the type:missing reproduction steps missing reproduction steps label Dec 18, 2023
Copy link

The issue has been automatically marked as stale as it missing playground pull request link, which is important to help others understand your issue effectively and make sure the issue hasn't been fixed on latest master, checkout https://github.com/go-gorm/playground for details. it will be closed in 30 days if no further activity occurs. if you are asking question, please use the Question template, most likely your question already answered https://github.com/go-gorm/gorm/issues or described in the document https://gorm.ioSearch Before Asking

@github-actions github-actions bot closed this as not planned Won't fix, can't repro, duplicate, stale Jan 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants