假設如果EVENT
內的查詢不是OK
,EVENT
會立即失敗嗎?如果查詢在事件中失敗,EVENT是否失敗?
DELETE
是破壞性的,所以我想確保在(相同記錄)是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 ;
在這種情況下,如果EXECUTE insert_stmt;
失敗,將EVENT
停止執行DO
塊?
完美的感謝! 'DECLAREing'' EXIT HANDLER'來處理特定的'SQLSTATE'將是另一種選擇,但在這種情況下是不必要的。由於系統限制,賞金將在3小時內頒發。 – mbrownnyc