0

My Situation

I am hosting a PHP Backend for an App with MySQL Database. I am not happy with my actual hoster, so I want to switch to AWS. I have set up an ec2 instance with lamp and everythings working fine, without my MySQL procedures. I have imported this procedure with phpmyadmin import tool. The problem now is, that i have syntax error. I think the problem is the version (
mysql 5.7.19-0ubuntu0.16.04.) but I can´t figure out whats the problem?

Any help?

Old version of mysql: 5.7.17 (working fine here)

BEGIN
  DECLARE s1_len, s2_len, i, j, c, c_temp, cost INT;
  DECLARE s1_char CHAR;
  DECLARE cv0, cv1 VARBINARY(256);
  SET s1_len = CHAR_LENGTH(s1), s2_len = CHAR_LENGTH(s2), cv1 = 0x00, j = 1, i = 1, c = 0;
  IF s1 = s2 THEN
    RETURN 0;
  ELSEIF s1_len = 0 THEN
    RETURN s2_len;
  ELSEIF s2_len = 0 THEN
    RETURN s1_len;
  ELSE
    WHILE j <= s2_len DO
      SET cv1 = CONCAT(cv1, UNHEX(HEX(j))), j = j + 1;
    END WHILE;
    WHILE i <= s1_len DO
      SET s1_char = SUBSTRING(s1, i, 1), c = i, cv0 = UNHEX(HEX(i)), j = 1;
      WHILE j <= s2_len DO
        SET c = c + 1;
        IF s1_char = SUBSTRING(s2, j, 1) THEN
          SET cost = 0; ELSE SET cost = 1;
        END IF;
        SET c_temp = CONV(HEX(SUBSTRING(cv1, j, 1)), 16, 10) + cost;
        IF c > c_temp THEN SET c = c_temp; END IF;
        SET c_temp = CONV(HEX(SUBSTRING(cv1, j+1, 1)), 16, 10) + 1;
        IF c > c_temp THEN
          SET c = c_temp;
        END IF;
        SET cv0 = CONCAT(cv0, UNHEX(HEX(c))), j = j + 1;
      END WHILE;
      SET cv1 = cv0, i = i + 1;
    END WHILE;
  END IF;
  SET c = c - ABS(s1_len - s2_len);
  RETURN c;
END

The error message: In the rows 2, 3, and 4 and also syntax error because the delimiter ';'

enter image description here

Translation Error Message:

  • unregonized key (at Declare)
  • unexpected character (at s1-len)
  • .
  • .
  • .
  • unexpected key (at INT)
  • Well, it helps to post the actual error message. And posting the code as text, not as image. And formatting the code is a good idea, too. Indentation is the magic word. – fancyPants Jul 25 '17 at 09:45
  • Have you set a different delimiter with `DELIMITER $$` before the `CREATE PROCEDURE...` and ending your code with `END $$` and restoring the default delimiter again in the next line with `DELIMITER ;`? – fancyPants Jul 25 '17 at 10:01
  • No i havent set a different DELIMITER but I tried to to that and set it to $$ or ; But nothing of this worked ! It is only this code nothing else, so i wonder why it´s not working here – Burtscher_Florian Jul 25 '17 at 10:02
  • I don't know if phpmyadmin does it for you automatically (never used this crap), but you definitely should. Otherwise the first `;` ends your procedure declaration and everything after the first statement is causing a syntax error or considered a regular statement. I'd suggest you write it properly with `delimiter $$ create procedure whatever() begin end $$ delimiter ;`. Then **execute it as regular sql statement**. This way you get a proper error message indicating where exactly the error is. Your screenshot doesn't help much. – fancyPants Jul 25 '17 at 11:04
  • I tried that befor but doesn´t work! Theres a problem with the declare syntax – Burtscher_Florian Jul 25 '17 at 12:00
  • Then please post exactly what you did. – fancyPants Jul 25 '17 at 12:08

0 Answers0