DROP TRIGGER IF EXISTS stock_products_BEFORE_INSERT;
DELIMITER |
CREATE TRIGGER stock_products_BEFORE_INSERT BEFORE INSERT ON stock_products
FOR EACH ROW
BEGIN
DECLARE msg VARCHAR(255);
if new.purchase_price = 0 then
SET msg = concat('Cannot INSERT row: purchase price cannot be 0 - stock_product_id:', new.id);
SIGNAL SQLSTATE '45000'
set MESSAGE_TEXT= msg;
end if;
if new.purchase_price is null AND new.is_approved=1 then
SET msg = concat('Cannot INSERT row: purchase price cannot be NULL - stock_product_id:', new.id);
SIGNAL SQLSTATE '45000'
SET MESSAGE_TEXT = msg;
end if;
if new.original_purchase_price = 0 then
SET msg = concat('Cannot INSERT row: original purchase price cannot be 0 - stock_product_id:', new.id);
SIGNAL SQLSTATE '45000'
SET MESSAGE_TEXT = msg;
end if;
END |
running it in any SQL management tool like mysql workbench works perfectly well.
But it allways return error on migration and I couldn't be able to fix it.
I use dibi driver and allways get:
fatal error: Uncaught Dibi\DriverException: You have an error in your SQL syntax; check the manual that corresponds t
o your MariaDB server version for the right syntax to use near 'DELIMITER |
CREATE TRIGGER stock_products_BEFOREINSERT BEFORE INSERT ON stock' at line 1
so consider this code:
running it in any SQL management tool like mysql workbench works perfectly well. But it allways return error on migration and I couldn't be able to fix it. I use dibi driver and allways get: