Fault in GenTest::Transform::ExecuteAsUpdateDelete
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
Random Query Generator |
New
|
Undecided
|
Unassigned |
Bug Description
The following code in ExecuteAsUpdate
=====
( $original_
"UPDATE $table_name SET `$col_name` = ( $original_query ) WHERE `$col_name` IN ( $original_query ) " :
"UPDATE $table_name SET `$col_name` = $col_name WHERE `$col_name` IN ( $original_query ) "
),
# The queries above should have updated all rows
"SELECT IF(ROW_COUNT() = ".$original_
=====
Is incorrect. Example:
=====
mysql> show create table id4\G
*******
Table: id4
Create Table: CREATE TABLE `id4` (
`id` int(11) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1
1 row in set (0.00 sec)
mysql> select * from id4\G
*******
id: 1
1 row in set (0.01 sec)
mysql> update id4 set id=id where id=1\G
Query OK, 0 rows affected (0.00 sec)
Rows matched: 1 Changed: 0 Warnings: 0
mysql> select row_count();
+-------------+
| row_count() |
+-------------+
| 0 |
+-------------+
1 row in set (0.00 sec)
=====
Reason (** highlight added):
ROW_COUNT()
[...]
DML statements other than SELECT: The number of **affected rows**. This applies to statements such as UPDATE, INSERT, or DELETE (as before), but now also to statements such as ALTER TABLE and LOAD DATA INFILE.
Source: http://
So the IF line should be:
"SELECT IF(ROW_COUNT() = 0 OR ROW_COUNT() = -1, 1, 0) /* TRANSFORM_
Instead.
Did some more testing. 5.1 and 5.5 both react like this:
mysql> update id4 set id=id where id=1\G
Query OK, 0 rows affected (0.06 sec)
Rows matched: 1 Changed: 0 Warnings: 0
mysql> select row_count();
+-------------+
| row_count() |
+-------------+
| 0 |
+-------------+
1 row in set (0.03 sec)
mysql> update id4 set id=10 where id=1\G
Query OK, 1 row affected (0.00 sec)
Rows matched: 1 Changed: 1 Warnings: 0
mysql> select row_count();
+-------------+
| row_count() |
+-------------+
| 1 |
+-------------+
1 row in set (0.00 sec)
Now, what worries me a bit before changing this is that in the orginal two queries I am not exactly sure if the query will always be in the form of id=id instead of id=value, as per the examples above.
I'd like a second opinion here.
Is there maybe another way around this? Why do we need the == 1 check? Maybe we can just always use SET `$col_name` = $col_name? Why no quotes around the second $col_name?