brianmario/mysql2 — Issue #244: Add ability to call mysql_info C API
Author: jeremyevans
Created: 2012-02-22 21:20:18+00:00
State: open

mysql-ruby has the Mysql#info method which returns the output of the mysql_info C API. This is necessary if you want to get an accurate number of rows matched by update statements, since mysql_info returns a string like "Rows matched: 1 Changed: 0 Warnings: 0".

The Mysql2::Client#affected_rows method does not provide the number of matched rows, it only provides the number of changed rows (a matched row is not changed if for all of the fields in the SET clause, the value in the query is the same as the value already in the row). This difference can be important. For example, Sequel needs to know if the underlying database row was matched when updating Sequel::Model objects. Without an accurate number of matched rows, it doesn't know if a return code of 0 means that no such row exists (i.e. the row was previously deleted, and an error should be raised), or that all the values were the same (in which case no error should be raised).