According to mysql 5.0(or other version) reference manual, chapter of c api: <Why mysql_store_result()="" Sometimes="" Returns="" NULL="" After="" mysql_query()="" Returns="" Success="">(http://dev.mysql.com/doc/refman/5.0/en/null-mysql-store-result.html), there are 2 situations when mysql_store_result() return NULL: (1) query data successful, but no data(for example, it was an INSERT, UPDATE, or DELETE); (2) an ERROR occurred!
But in _mysql.c, there is no testing for error after calling mysql_store_result(), it may cause strange result somethings. An case I met is:
CREATE TABLE test
(
name
varchar(32) default NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1
If no key in name
, or, not a primary key/unique key in name
, when starting a transaction and locking the table just like:
SELECT * FROM test WHERE name = 'a' FOR UPDATE; / name = 'a' is in the table, so locked /
When another transaction starts and query the same statement above, it will be waiting and timeout. At that time, mysql_query() will return success and mysql_store_result() will return NULL, and an error occur: 'Lock wait timeout exceeded; try restarting transaction'. But if using MySQLdb, it will return no exception but just a empty result. It's incorrect.
The patch fixed this bug (test using mysql_errno() after mysql_store_result() return NULL).
fixed bug: handling error when mysql_store_result() return NULL