check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 3

孤者浪人 提交于 2019-12-13 07:20:32

问题


Here is my query

CREATE TRIGGER `trigger1234` BEFORE UPDATE ON `oc_product` FOR EACH ROW

BEGIN
SET @json = "new:{";
SET @first = true;

IF (OLD.product_id!=NEW.product_id) THEN
    SET @first = false;
    SET @json = CONCAT(@json, "\"product_id\"", ":", "\"", NEW.product_id, "\"");
END IF;

IF (OLD.model!=NEW.model) THEN
    IF (!@first) THEN
       SET @json = CONCAT(@json, ",");
    END IF;
    SET @first = false;
    SET @json = CONCAT(@json, "\"model\"", ":", "\"", NEW.model, "\"");
END IF;

IF (OLD.sku!=NEW.sku) THEN
    IF (!@first) THEN
       SET @json = CONCAT(@json, ",");
    END IF;
    SET @first = false;
    SET @json = CONCAT(@json, "\"sku\"", ":", "\"", NEW.sku, "\"");
END IF;

IF (OLD.upc!=NEW.upc) THEN
    IF (!@first) THEN
       SET @json = CONCAT(@json, ",");
    END IF;
    SET @first = false;
    SET @json = CONCAT(@json, "\"upc\"", ":", "\"", NEW.upc, "\"");
END IF;

IF (OLD.ean!=NEW.ean) THEN
    IF (!@first) THEN
       SET @json = CONCAT(@json, ",");
    END IF;
    SET @first = false;
    SET @json = CONCAT(@json, "\"ean\"", ":", "\"", NEW.ean, "\"");
END IF;

IF (OLD.jan!=NEW.jan) THEN
    IF (!@first) THEN
       SET @json = CONCAT(@json, ",");
    END IF;
    SET @first = false;
    SET @json = CONCAT(@json, "\"jan\"", ":", "\"", NEW.jan, "\"");
END IF;

IF (OLD.isbn!=NEW.isbn) THEN
    IF (!@first) THEN
       SET @json = CONCAT(@json, ",");
    END IF;
    SET @first = false;
    SET @json = CONCAT(@json, "\"isbn\"", ":", "\"", NEW.isbn, "\"");
END IF;


IF (OLD.mpn!=NEW.mpn) THEN
    IF (!@first) THEN
       SET @json = CONCAT(@json, ",");
    END IF;
    SET @first = false;
    SET @json = CONCAT(@json, "\"mpn\"", ":", "\"", NEW.mpn, "\"");
END IF;

IF (OLD.location!=NEW.location) THEN
    IF (!@first) THEN
       SET @json = CONCAT(@json, ",");
    END IF;
    SET @first = false;
    SET @json = CONCAT(@json, "\"location\"", ":", "\"", NEW.location, "\"");
END IF;

IF (OLD.quantity!=NEW.quantity) THEN
    IF (!@first) THEN
       SET @json = CONCAT(@json, ",");
    END IF;
    SET @first = false;
    SET @json = CONCAT(@json, "\"quantity\"", ":", "\"", NEW.quantity, "\"");
END IF;

IF (OLD.stock_status_id!=NEW.stock_status_id) THEN
    IF (!@first) THEN
       SET @json = CONCAT(@json, ",");
    END IF;
    SET @first = false;
    SET @json = CONCAT(@json, "\"stock_status_id\"", ":", "\"", NEW.stock_status_id, "\"");
END IF;

IF (OLD.image!=NEW.image) THEN
    IF (!@first) THEN
       SET @json = CONCAT(@json, ",");
    END IF;
    SET @first = false;
    SET @json = CONCAT(@json, "\"image\"", ":", "\"", NEW.image, "\"");
END IF;

IF (OLD.manufacturer_id!=NEW.manufacturer_id) THEN
    IF (!@first) THEN
       SET @json = CONCAT(@json, ",");
    END IF;
    SET @first = false;
    SET @json = CONCAT(@json, "\"manufacturer_id\"", ":", "\"", NEW.manufacturer_id, "\"");
END IF;

IF (OLD.shipping!=NEW.shipping) THEN
    IF (!@first) THEN
       SET @json = CONCAT(@json, ",");
    END IF;
    SET @first = false;
    SET @json = CONCAT(@json, "\"shipping\"", ":", "\"", NEW.shipping, "\"");
END IF;

IF (OLD.price!=NEW.price) THEN
    IF (!@first) THEN
       SET @json = CONCAT(@json, ",");
    END IF;
    SET @first = false;
    SET @json = CONCAT(@json, "\"price\"", ":", "\"", NEW.price, "\"");
END IF;

IF (OLD.selling_price!=NEW.selling_price) THEN
    IF (!@first) THEN
       SET @json = CONCAT(@json, ",");
    END IF;
    SET @first = false;
    SET @json = CONCAT(@json, "\"selling_price\"", ":", "\"", NEW.selling_price, "\"");
END IF;

IF (OLD.price_per_set!=NEW.price_per_set) THEN
    IF (!@first) THEN
       SET @json = CONCAT(@json, ",");
    END IF;
    SET @first = false;
    SET @json = CONCAT(@json, "\"price_per_set\"", ":", "\"", NEW.price_per_set, "\"");
END IF;

IF (OLD.piece_in_set!=NEW.piece_in_set) THEN
    IF (!@first) THEN
       SET @json = CONCAT(@json, ",");
    END IF;
    SET @first = false;
    SET @json = CONCAT(@json, "\"piece_in_set\"", ":", "\"", NEW.piece_in_set, "\"");
END IF;

IF (OLD.seller_tax!=NEW.seller_tax) THEN
    IF (!@first) THEN
       SET @json = CONCAT(@json, ",");
    END IF;
    SET @first = false;
    SET @json = CONCAT(@json, "\"seller_tax\"", ":", "\"", NEW.seller_tax, "\"");
END IF;

IF (OLD.commission!=NEW.commission) THEN
    IF (!@first) THEN
       SET @json = CONCAT(@json, ",");
    END IF;
    SET @first = false;
    SET @json = CONCAT(@json, "\"commission\"", ":", "\"", NEW.commission, "\"");
END IF;

IF (OLD.points!=NEW.points) THEN
    IF (!@first) THEN
       SET @json = CONCAT(@json, ",");
    END IF;
    SET @first = false;
    SET @json = CONCAT(@json, "\"points\"", ":", "\"", NEW.points, "\"");
END IF;

IF (OLD.tax_class_id!=NEW.tax_class_id) THEN
    IF (!@first) THEN
       SET @json = CONCAT(@json, ",");
    END IF;
    SET @first = false;
    SET @json = CONCAT(@json, "\"tax_class_id\"", ":", "\"", NEW.tax_class_id, "\"");
END IF;

IF (OLD.date_available!=NEW.date_available) THEN
    IF (!@first) THEN
       SET @json = CONCAT(@json, ",");
    END IF;
    SET @first = false;
    SET @json = CONCAT(@json, "\"date_available\"", ":", "\"", NEW.date_available, "\"");
END IF;

IF (OLD.weight!=NEW.weight) THEN
    IF (!@first) THEN
       SET @json = CONCAT(@json, ",");
    END IF;
    SET @first = false;
    SET @json = CONCAT(@json, "\"weight\"", ":", "\"", NEW.weight, "\"");
END IF;

IF (OLD.weight_class_id!=NEW.weight_class_id) THEN
    IF (!@first) THEN
       SET @json = CONCAT(@json, ",");
    END IF;
    SET @first = false;
    SET @json = CONCAT(@json, "\"weight_class_id\"", ":", "\"", NEW.weight_class_id, "\"");
END IF;

IF (OLD.length!=NEW.length) THEN
    IF (!@first) THEN
       SET @json = CONCAT(@json, ",");
    END IF;
    SET @first = false;
    SET @json = CONCAT(@json, "\"length\"", ":", "\"", NEW.length, "\"");
END IF;

IF (OLD.width!=NEW.width) THEN
    IF (!@first) THEN
       SET @json = CONCAT(@json, ",");
    END IF;
    SET @first = false;
    SET @json = CONCAT(@json, "\"width\"", ":", "\"", NEW.width, "\"");
END IF;

IF (OLD.height!=NEW.height) THEN
    IF (!@first) THEN
       SET @json = CONCAT(@json, ",");
    END IF;
    SET @first = false;
    SET @json = CONCAT(@json, "\"height\"", ":", "\"", NEW.height, "\"");
END IF;

IF (OLD.length_class_id!=NEW.length_class_id) THEN
    IF (!@first) THEN
       SET @json = CONCAT(@json, ",");
    END IF;
    SET @first = false;
    SET @json = CONCAT(@json, "\"length_class_id\"", ":", "\"", NEW.length_class_id, "\"");
END IF;

IF (OLD.subtract!=NEW.subtract) THEN
    IF (!@first) THEN
       SET @json = CONCAT(@json, ",");
    END IF;
    SET @first = false;
    SET @json = CONCAT(@json, "\"subtract\"", ":", "\"", NEW.subtract, "\"");
END IF;

IF (OLD.minimum!=NEW.minimum) THEN
    IF (!@first) THEN
       SET @json = CONCAT(@json, ",");
    END IF;
    SET @first = false;
    SET @json = CONCAT(@json, "\"minimum\"", ":", "\"", NEW.minimum, "\"");
END IF;

IF (OLD.sort_order!=NEW.sort_order) THEN
    IF (!@first) THEN
       SET @json = CONCAT(@json, ",");
    END IF;
    SET @first = false;
    SET @json = CONCAT(@json, "\"sort_order\"", ":", "\"", NEW.sort_order, "\"");
END IF;

IF (OLD.status!=NEW.status) THEN
    IF (!@first) THEN
       SET @json = CONCAT(@json, ",");
    END IF;
    SET @first = false;
    SET @json = CONCAT(@json, "\"status\"", ":", "\"", NEW.status, "\"");
END IF;

IF (OLD.viewed!=NEW.viewed) THEN
    IF (!@first) THEN
       SET @json = CONCAT(@json, ",");
    END IF;
    SET @first = false;
    SET @json = CONCAT(@json, "\"viewed\"", ":", "\"", NEW.viewed, "\"");
END IF;

IF (OLD.date_added!=NEW.date_added) THEN
    IF (!@first) THEN
       SET @json = CONCAT(@json, ",");
    END IF;
    SET @first = false;
    SET @json = CONCAT(@json, "\"date_added\"", ":", "\"", NEW.date_added, "\"");
END IF;

IF (OLD.date_modified!=NEW.date_modified) THEN
    IF (!@first) THEN
       SET @json = CONCAT(@json, ",");
    END IF;
    SET @first = false;
    SET @json = CONCAT(@json, "\"date_modified\"", ":", "\"", NEW.date_modified, "\"");
END IF;

IF (OLD.sold_out!=NEW.sold_out) THEN
    IF (!@first) THEN
       SET @json = CONCAT(@json, ",");
    END IF;
    SET @first = false;
    SET @json = CONCAT(@json, "\"sold_out\"", ":", "\"", NEW.sold_out, "\"");
END IF;

IF (OLD.is_single!=NEW.is_single) THEN
    IF (!@first) THEN
       SET @json = CONCAT(@json, ",");
    END IF;
    SET @first = false;
    SET @json = CONCAT(@json, "\"is_single\"", ":", "\"", NEW.is_single, "\"");
END IF;

IF (OLD.singles_product_id!=NEW.singles_product_id) THEN
    IF (!@first) THEN
       SET @json = CONCAT(@json, ",");
    END IF;
    SET @first = false;
    SET @json = CONCAT(@json, "\"singles_product_id\"", ":", "\"", NEW.singles_product_id, "\"");
END IF;

IF (OLD.date_out_of_stock!=NEW.date_out_of_stock) THEN
    IF (!@first) THEN
       SET @json = CONCAT(@json, ",");
    END IF;
    SET @first = false;
    SET @json = CONCAT(@json, "\"date_out_of_stock\"", ":", "\"", NEW.date_out_of_stock, "\"");
END IF;

IF (OLD.expected_dispatch_date!=NEW.expected_dispatch_date) THEN
    IF (!@first) THEN
       SET @json = CONCAT(@json, ",");
    END IF;
    SET @first = false;
    SET @json = CONCAT(@json, "\"expected_dispatch_date\"", ":", "\"", NEW.expected_dispatch_date, "\"");
END IF;

IF (OLD.mrp!=NEW.mrp) THEN
    IF (!@first) THEN
       SET @json = CONCAT(@json, ",");
    END IF;
    SET @first = false;
    SET @json = CONCAT(@json, "\"mrp\"", ":", "\"", NEW.mrp, "\"");
END IF;

SET @json = CONCAT(@json, "}");

INSERT INTO oc_product_modified_log (`product_id`, `modified_field`, `date_added`,`solr_synced`) 
VALUES (NEW.product_id, @json, NOW(),1);

END;

I am using triggers and trying to summarize changes of one table into another table. I am getting an error everytime.I am not getting why it is giving me error everytime.Please suggest any solution that will work

Documentation

1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 3

来源:https://stackoverflow.com/questions/41609326/check-the-manual-that-corresponds-to-your-mysql-server-version-for-the-right-syn

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!