Syntax error in mysql trigger

I am trying to figure out what is wrong with this trigger. I'm new to mysql triggers and stored procedures, so I'm guessing there might be something wrong with the syntax.

-- Trigger DDL Statements
DELIMITER $$

USE `SNPB`$$

DROP TRIGGER IF EXISTS getMsnps$$
CREATE TRIGGER getMsnps AFTER INSERT ON m_snps
FOR EACH ROW 
BEGIN

    DECLARE glid int(10);
    DECLARE lost int(1);
    DECLARE st int(10);
    DECLARE vto varchar(20);

    IF(EXISTS( SELECT glyc_id  FROM glyc WHERE glyc_start<=NEW.uni_pos AND glyc_end>=NEW.uni_pos AND glyc.uni_prot_ac=NEW.uni_prot_ac)) THEN
    SELECT glyc_id,glyc_start INTO glid,st  FROM glyc WHERE glyc_start<=NEW.uni_pos AND glyc_end>=NEW.uni_pos AND glyc.uni_prot_ac=NEW.uni_prot_ac;    
    SELECT all_snps.var_to INTO vto FROM all_snps,snp_map WHERE snp_map.snpb_id=NEW.snpb_id AND snp_map.ref>0 AND snp_map.all_snps_id=all_snp.all_snps_id;
    set lost=0;     
    IF NEW.uni_pos=st AND vto!='n' AND vto!='N' THEN
        set lost=1;
    END IF;
    IF NEW.uni_pos=st+1 AND (vto='p' OR vto='P') THEN
        set lost=1;
    END IF;
    IF NEW.uni_pos=st+2 AND vto!='s' AND vto!='S' AND vto!='t' AND vto!='T' THEN
        set lost=1;
    END IF;
    INSERT INTO glyc_map (glyc_id,snpb_id,loss)  VALUES (glid,NEW.snpb_id,lost);

END IF;  
END;
$$
DELIMITER ;

      

So when I insert rows into the "m_snps" table (multiple rows are inserted with one statement), I have to get some rows in the "glyc_map" table, but that never happens. I was hoping someone would tell me if the syntax is correct or not.

+3


source to share


1 answer


All your code is within IF

:

IF(EXISTS( SELECT glyc_id  FROM glyc ...
    -- rest of code, including the insert statement
END IF;

      



If the condition is false, you won't get anywhere.

0


source







All Articles