title: Unknow column in a MySQLTrigger execution
body: <p>I have this trigger with no syntax errors working on my DB:</p>
  
  <pre><code>DROP TRIGGER IF EXISTS image_demand;
  DELIMITER //
  CREATE TRIGGER image_demand BEFORE INSERT ON demand_img
  FOR EACH ROW
  BEGIN
      DECLARE done INT DEFAULT FALSE;
      DECLARE val DATE DEFAULT NULL;
      DECLARE minValue CURSOR FOR SELECT min(date_demand) AS RES FROM demand_img;
      DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = TRUE; 
  
      OPEN minValue;
      read_loop : LOOP
          FETCH minValue INTO val;
          IF done THEN
              LEAVE read_loop;
          END IF;
      END LOOP;
      CLOSE minValue;
      IF minValue IS NOT NULL THEN
          SET NEW.date_demand = val + INTERVAL 1 HOUR;
      END IF;
  END //
  </code></pre>
  
  <p>It tries to add 1 hour from the minimum value already setted in the database, to the new register about to insert. But when I try to insert a new image_demand component with an INSERT command, it fails with this error: </p>
  
  <pre><code>18:16:40    INSERT INTO `database`.`demand_img` (USER_ID_FK, IMG_ID) VALUES (2, 'asdfasdfasdfa')    
  Error Code: 1054. Unknown column 'minValue' in 'field list' 0.000 sec
  </code></pre>
  
  <p>As you can see, <strong>minValue</strong> is a variable that comes from the Trigger, so I think the error is from it, but I can't see where is it. Maybe am I setting minValue incorrectly? </p>
  
  <p>Thank you for your help</p>
  
  <p>J.</p>