-- ----------------------------
-- Triggers structure for table productmatchresults
-- ----------------------------
DROP TRIGGER IF EXISTS `sync$productmatchresults_i`;
delimiter ;;
CREATE DEFINER = `root`@`%` TRIGGER `sync$productmatchresults_i` AFTER INSERT ON `productmatchresults` FOR EACH ROW begin
	  declare v_table_name varchar(64) default 'productmatchresults';
    declare v_method_type varchar(6) default 'insert';
    declare v_data_key text;
    declare v_data text;
    declare v_priority int default 1;

    set v_data_key=concat('{"pr_id": ', new.pr_id, '}');
    select concat(
      concat('{'),
      -- varchar
      concat('"pr_brandcn": ', case when new.pr_brandcn is null then 'null' else concat('"', replace(new.pr_brandcn, '"', '\\"'), '"') end),
      concat(',"pr_branden": ', case when new.pr_branden is null then 'null' else concat('"', replace(new.pr_branden, '"', '\\"'), '"') end),
      concat(',"pr_cmpcode": ', case when new.pr_cmpcode is null then 'null' else concat('"', replace(new.pr_cmpcode, '"', '\\"'), '"') end),
      concat(',"pr_uuid": ', case when new.pr_uuid is null then 'null' else concat('"', replace(new.pr_uuid, '"', '\\"'), '"') end),
      concat(',"pr_encapsulation": ', case when new.pr_encapsulation is null then 'null' else concat('"', replace(new.pr_encapsulation, '"', '\\"'), '"') end),
      concat(',"pr_kindcn": ', case when new.pr_kindcn is null then 'null' else concat('"', replace(new.pr_kindcn, '"', '\\"'), '"') end),
      concat(',"pr_kinden": ', case when new.pr_kinden is null then 'null' else concat('"', replace(new.pr_kinden, '"', '\\"'), '"') end),
      concat(',"pr_pbranduuid": ', case when new.pr_pbranduuid is null then 'null' else concat('"', replace(new.pr_pbranduuid, '"', '\\"'), '"') end),
      concat(',"pr_uuid": ', case when new.pr_uuid is null then 'null' else concat('"', replace(new.pr_uuid, '"', '\\"'), '"') end),
      -- bit(1), smallint(6), int(11), bigint(20), double
      concat(',"pr_brid": ', case when new.pr_brid is null then 'null' else new.pr_brid end),
      concat(',"pr_cmpid": ', case when new.pr_cmpid is null then 'null' else new.pr_cmpid end),
      concat(',"pr_enuu": ', case when new.pr_enuu is null then 'null' else new.pr_enuu end),
      concat(',"pr_kindid": ', case when new.pr_kindid is null then 'null' else new.pr_kindid end),
      concat(',"pr_number": ', case when new.pr_number is null then 'null' else new.pr_number end),
      concat(',"pr_prid": ', case when new.pr_prid is null then 'null' else new.pr_prid end),
      -- datetime
      -- text
      -- json
      concat('}')
    ) into v_data;
    call sync$enqueue_message(v_table_name, v_method_type, v_data_key, v_data, v_priority);
end
;;
delimiter ;

-- ----------------------------
-- Triggers structure for table productmatchresults
-- ----------------------------
DROP TRIGGER IF EXISTS `sync$productmatchresults_u`;
delimiter ;;
CREATE DEFINER = `root`@`%` TRIGGER `sync$productmatchresults_u` AFTER UPDATE ON `productmatchresults` FOR EACH ROW begin
	declare v_table_name varchar(64) default 'productmatchresults';
    declare v_method_type varchar(6) default 'update';
    declare v_data_key text;
    declare v_data text;
    declare v_priority int default 1;

    set v_data_key=concat('{"pr_id": ', old.pr_id, '}');
    select concat(
      concat('{'),
      -- varchar
      concat('"pr_brandcn": ', case when new.pr_brandcn is null then 'null' else concat('"', replace(new.pr_brandcn, '"', '\\"'), '"') end),
      concat(',"pr_branden": ', case when new.pr_branden is null then 'null' else concat('"', replace(new.pr_branden, '"', '\\"'), '"') end),
      concat(',"pr_cmpcode": ', case when new.pr_cmpcode is null then 'null' else concat('"', replace(new.pr_cmpcode, '"', '\\"'), '"') end),
      concat(',"pr_uuid": ', case when new.pr_uuid is null then 'null' else concat('"', replace(new.pr_uuid, '"', '\\"'), '"') end),
      concat(',"pr_encapsulation": ', case when new.pr_encapsulation is null then 'null' else concat('"', replace(new.pr_encapsulation, '"', '\\"'), '"') end),
      concat(',"pr_kindcn": ', case when new.pr_kindcn is null then 'null' else concat('"', replace(new.pr_kindcn, '"', '\\"'), '"') end),
      concat(',"pr_kinden": ', case when new.pr_kinden is null then 'null' else concat('"', replace(new.pr_kinden, '"', '\\"'), '"') end),
      concat(',"pr_pbranduuid": ', case when new.pr_pbranduuid is null then 'null' else concat('"', replace(new.pr_pbranduuid, '"', '\\"'), '"') end),
      concat(',"pr_uuid": ', case when new.pr_uuid is null then 'null' else concat('"', replace(new.pr_uuid, '"', '\\"'), '"') end),
      -- bit(1), smallint(6), int(11), bigint(20), double
      concat(',"pr_brid": ', case when new.pr_brid is null then 'null' else new.pr_brid end),
      concat(',"pr_cmpid": ', case when new.pr_cmpid is null then 'null' else new.pr_cmpid end),
      concat(',"pr_enuu": ', case when new.pr_enuu is null then 'null' else new.pr_enuu end),
      concat(',"pr_kindid": ', case when new.pr_kindid is null then 'null' else new.pr_kindid end),
      concat(',"pr_number": ', case when new.pr_number is null then 'null' else new.pr_number end),
      concat(',"pr_prid": ', case when new.pr_prid is null then 'null' else new.pr_prid end),
      -- datetime
      -- text
      -- json
      concat('}')
    ) into v_data;
    call sync$enqueue_message(v_table_name, v_method_type, v_data_key, v_data, v_priority);
end
;;
delimiter ;

-- ----------------------------
-- Triggers structure for table productmatchresults
-- ----------------------------
DROP TRIGGER IF EXISTS `sync$productmatchresults_d`;
delimiter ;;
CREATE DEFINER = `root`@`%` TRIGGER `sync$productmatchresults_d` AFTER DELETE ON `productmatchresults` FOR EACH ROW begin
	declare v_table_name varchar(64) default 'productmatchresults';
    declare v_method_type varchar(6) default 'delete';
    declare v_data_key text;
    declare v_data text;
    declare v_priority int default 1;

    set v_data_key=concat('{"pr_id": ', old.pr_id, '}');
    call sync$enqueue_message(v_table_name, v_method_type, v_data_key, v_data, v_priority);
end
;;
delimiter ;