Skip to content

feat: add ability to set or unset the CLIENT_FOUND_ROWS flag#4334

Open
andreastedile wants to merge 1 commit into
transact-rs:mainfrom
andreastedile:client-found-rows
Open

feat: add ability to set or unset the CLIENT_FOUND_ROWS flag#4334
andreastedile wants to merge 1 commit into
transact-rs:mainfrom
andreastedile:client-found-rows

Conversation

@andreastedile

@andreastedile andreastedile commented Jul 10, 2026

Copy link
Copy Markdown

Closes #3063.

Is this a breaking change?

No: it preserves current SQLx behavior.

Context

We are developing an application with "upsert" (update or insert) semantics: each request should either update an existing row or insert a new one if no matching row exists.

To implement this behavior, we use MySQL statements of the form INSERT ... ON DUPLICATE KEY UPDATE:
https://dev.mysql.com/doc/refman/8.4/en/insert-on-duplicate.html

With ON DUPLICATE KEY UPDATE, the affected-rows value per row is 1 if the row is inserted as a new row, 2 if an existing row is updated, and 0 if an existing row is set to its current values. If you specify the CLIENT_FOUND_ROWS flag to the mysql_real_connect() C API function when connecting to mysqld, the affected-rows value is 1 (not 0) if an existing row is set to its current values.

SQLx currently enables the MySQL CLIENT_FOUND_ROWS flag by default:
https://github.com/transact-rs/sqlx/blob/main/sqlx-mysql/src/connection/stream.rs#L38

which makes it impossible to distinguish whether a row was inserted as a new row or set to its current values,
because in both cases MySQL reports affected_rows = 1 when CLIENT_FOUND_ROWS is enabled.

This PR preserves current SQLx behavior, as the found_rows variable is set to true by default.

@andreastedile andreastedile changed the title feat: add ability to set CLIENT_FOUND_ROWS flag in MySqlConnectOptions feat: add ability to set or unset the CLIENT_FOUND_ROWS flag Jul 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Make the Capabilities::FOUND_ROWS flag of mysql connection an option.

1 participant