Cara mencegah query invalid masuk ke database, Anda dapat mencoba trigger berikut ini.
DELIMITER $$
CREATE
TRIGGER `sms`.`hapusinvalid` BEFORE INSERT ON `sms`.`outbox`
FOR EACH ROW BEGIN
IF NEW.wa_file != '' AND (NEW.wa_media = '' OR ISNULL(NEW.wa_media)) THEN BEGIN
SET NEW.wa_mode = 0;
SET NEW.wa_file = NULL;
SET NEW.wa_media = NULL;
-- DELETE FROM jbssms.outbox WHERE ID = NEW.id;
-- SIGNAL SQLSTATE '02000' SET MESSAGE_TEXT = 'Ada pesan Invalid!';
END; END IF;
END$$
DELIMITER ;
Dengan trigger diatas, maka setiap ditemukan field wa_file terisi dan field wa_media ditemukan kosong, maka trigger akan menset nilai baru berupa nilai NULL.
Post a Comment