-- ----------------------------
-- Triggers structure for table product$storestaus
-- ----------------------------
DROP TRIGGER IF EXISTS `sync$product_storestaus_i`;
delimiter ;;
CREATE DEFINER = `root`@`%` TRIGGER `sync$product_storestaus_i` AFTER INSERT ON `product$storestaus` FOR EACH ROW begin
	  declare v_table_name varchar(64) default 'product$storestaus';
    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
      -- bit(1), smallint(6), int(11), bigint(20), double
      concat('"pr_enuu": ', case when new.pr_enuu is null then 'null' else new.pr_enuu end),
      concat(',"pr_status": ', case when new.pr_status is null then 'null' else new.pr_status end),
      concat(',"pr_useruu": ', case when new.pr_useruu is null then 'null' else new.pr_useruu end),
      -- datetime
      concat(',"pr_date": ', case when new.pr_date is null then 'null' else concat('"', replace(new.pr_date, '"', '\\"'), '"') end),
      -- 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 product$storestaus
-- ----------------------------
DROP TRIGGER IF EXISTS `sync$product_storestaus_u`;
delimiter ;;
CREATE DEFINER = `root`@`%` TRIGGER `sync$product_storestaus_u` AFTER UPDATE ON `product$storestaus` FOR EACH ROW begin
	declare v_table_name varchar(64) default 'product$storestaus';
    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
      -- bit(1), smallint(6), int(11), bigint(20), double
      concat('"pr_enuu": ', case when new.pr_enuu is null then 'null' else new.pr_enuu end),
      concat(',"pr_status": ', case when new.pr_status is null then 'null' else new.pr_status end),
      concat(',"pr_useruu": ', case when new.pr_useruu is null then 'null' else new.pr_useruu end),
      -- datetime
      concat(',"pr_date": ', case when new.pr_date is null then 'null' else concat('"', replace(new.pr_date, '"', '\\"'), '"') end),
      -- 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 product$storestaus
-- ----------------------------
DROP TRIGGER IF EXISTS `sync$product_storestaus_d`;
delimiter ;;
CREATE DEFINER = `root`@`%` TRIGGER `sync$product_storestaus_d` AFTER DELETE ON `product$storestaus` FOR EACH ROW begin
	declare v_table_name varchar(64) default 'product$storestaus';
    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 ;