2

Is it safe to assume that if a query within an EVENT returns not OK, the EVENT will fail immediately?

DELETE is destructive, so I want to make sure that the previous query succeeds before the (same records) are DELETEd.

use argus_dnsdb;
DELIMITER |
CREATE EVENT `dnsdb_rotator`
ON SCHEDULE
EVERY 1 DAY
STARTS date_format(now(), '%Y-%m-%d 00:00:05')
ON COMPLETION NOT PRESERVE
ENABLE
DO BEGIN
set @target_table_name=CONCAT('`argus_dnsdb`.`',date_format(date_sub(now(),interval 1 day), '%Y%m%d'),'`');
set @create_table_stmt_str = CONCAT('CREATE TABLE ',@target_table_name,' like `argus_dnsdb`.`main`;');
PREPARE create_table_stmt FROM @create_table_stmt_str;
EXECUTE create_table_stmt;
DEALLOCATE PREPARE create_table_stmt;
set @a=unix_timestamp(date_format(now(), '%Y-%m-%d 00:00:00'));
set @insert_stmt_str = CONCAT('INSERT INTO ',@target_table_name,' SELECT * FROM `argus_dnsdb`.`main` WHERE qtime < ',@a,' ;');
PREPARE insert_stmt FROM @insert_stmt_str;
EXECUTE insert_stmt;
DEALLOCATE PREPARE insert_stmt;
DELETE FROM `argus_dnsdb`.`main` WHERE qtime < @a ;
END;
|
DELIMITER ;

In this instance, if EXECUTE insert_stmt; fails, will the EVENT stop executing the DO block?

4

1 回答 1

1

这取决于错误的类型。如手册所述

如果发生未声明任何处理程序的 [错误]条件,则采取的操作取决于条件类:

对于 SQLEXCEPTION 条件,存储的程序在引发条件的语句处终止,就好像有一个 EXIT 处理程序[即程序返回]。如果该程序被另一个存储的程序调用,则调用程序使用应用于其自己的处理程序的处理程序选择规则来处理该条件。

对于 SQLWARNING 条件,程序继续执行,就好像有一个 CONTINUE 处理程序一样。

对于 NOT FOUND 条件,如果条件正常引发,则操作为 CONTINUE。如果它是由 SIGNAL 或 RESIGNAL 提出的,则动作为 EXIT。

插入失败会引发SQLEXCEPTION,因此程序终止(或触发自定义错误处理程序,如果存在此类处理程序)。

( 和 的定义在同一手册页中提供SQLEXCEPTIONSQLWARNINGNOT FOUND

于 2013-08-01T21:27:48.077 回答