summaryrefslogtreecommitdiff
path: root/mysql-test/t/insert.test
diff options
context:
space:
mode:
authorunknown <dlenev@mysql.com>2006-06-16 20:21:25 +0400
committerunknown <dlenev@mysql.com>2006-06-16 20:21:25 +0400
commite08a2b326b143cc5b3dead51f981559aef2c2e95 (patch)
tree49bb7960457e95a5453761b6d5d335e206cc9265 /mysql-test/t/insert.test
parent9b871930a9189cce16b39dc5576f3592a34959ba (diff)
downloadmariadb-git-e08a2b326b143cc5b3dead51f981559aef2c2e95.tar.gz
Fix for bug#13479 "REPLACE activates UPDATE trigger, not the DELETE and
INSERT triggers". In cases when REPLACE was internally executed via update and table had on update (on delete) triggers defined we exposed the fact that such optimization used by callng on update (not calling on delete) triggers. Such behavior contradicts our documentation which describes REPLACE as INSERT with optional DELETE. This fix just disables this optimization for tables with on delete triggers. The optimization is still applied for tables which have on update but have no on delete triggers, we just don't invoke on update triggers in this case and thus don't expose information about optimization to user. Also added test coverage for values returned by ROW_COUNT() function (and thus for values returned by mysql_affected_rows()) for various forms of INSERT. mysql-test/r/insert.result: Added test for values returned by ROW_COUNT() function (and thus for values returned by mysql_affected_rows()) for various forms of INSERT. We didn't have coverage for this before and since this fix touches related code it is better to add it now. mysql-test/r/trigger.result: Adjusted test after fixing bug#13479 "REPLACE activates UPDATE trigger, not the DELETE and INSERT triggers". mysql-test/t/insert.test: Added test for values returned by ROW_COUNT() function (and thus for values returned by mysql_affected_rows()) for various forms of INSERT. We didn't have coverage for this before and since this fix touches related code it is better to add it now. mysql-test/t/trigger.test: Adjusted test after fixing bug#13479 "REPLACE activates UPDATE trigger, not the DELETE and INSERT triggers". sql/sql_insert.cc: write_record(): We should not expose that internally we sometimes execute REPLACE via UPDATE instead of documented INSERT + DELETE pair. So we should not use this optimization for tables with on delete triggers. OTOH it is ok to use it for tables which have on update but have no on delete triggers, we just should not invoke on update triggers in this case.
Diffstat (limited to 'mysql-test/t/insert.test')
-rw-r--r--mysql-test/t/insert.test23
1 files changed, 23 insertions, 0 deletions
diff --git a/mysql-test/t/insert.test b/mysql-test/t/insert.test
index 0c64dd80bec..ac43d0bc818 100644
--- a/mysql-test/t/insert.test
+++ b/mysql-test/t/insert.test
@@ -187,3 +187,26 @@ create view v1 as select * from t1;
insert delayed into v1 values (1);
drop table t1;
drop view v1;
+
+#
+# Test for values returned by ROW_COUNT() function
+# (and thus for values returned by mysql_affected_rows())
+# for various forms of INSERT
+#
+create table t1 (id int primary key, data int);
+insert into t1 values (1, 1), (2, 2), (3, 3);
+select row_count();
+insert ignore into t1 values (1, 1);
+select row_count();
+# Reports that 2 rows are affected (1 deleted + 1 inserted)
+replace into t1 values (1, 11);
+select row_count();
+replace into t1 values (4, 4);
+select row_count();
+# Reports that 2 rows are affected. This conforms to documentation.
+# (Useful for differentiating inserts from updates).
+insert into t1 values (2, 2) on duplicate key update data= data + 10;
+select row_count();
+insert into t1 values (5, 5) on duplicate key update data= data + 10;
+select row_count();
+drop table t1;