2010-10-01 27 views
0

J'essaie de comprendre pourquoi ce qui suit échoue et je ne suis pas capable de le voir. Le phpMyAdmin sur notre serveur de développement a généré ceci exactement, mais quand j'essaye de l'importer - je cours dans une erreur bizarre d'analyse (?).Impossible d'importer la fonction MYSQL - ERREUR 1064 (42000)

mysql> DELIMITER $$ 
mysql> 
mysql> -- 
mysql> -- Functions 
mysql> -- 
mysql> DROP FUNCTION IF EXISTS `get_class_nextsession`$$ 
Query OK, 0 rows affected, 1 warning (0.00 sec) 

mysql> CREATE DEFINER=`myusername`@`localhost` FUNCTION `get_class_nextsession`(class_id INT) RETURNS datetime 
    ->  READS SQL DATA 
    -> BEGIN 
    -> DECLARE nextsession,startdate,runningdate,enddate DATETIME; 
    -> SET nextsession= '-'; 
    -> SELECT MIN(CS.start_datetime) INTO startdate FROM site_class_schedule AS CS INNER JOIN site_class AS C ON (C.id=CS.class_id) WHERE CS.class_id=class_id Group by C.id Limit 0,1; 
    -> IF startdate >= NOW() THEN 
    -> RETURN startdate; 
    -> ELSE 
    -> SELECT CS.start_datetime INTO runningdate FROM site_class_schedule AS CS INNER JOIN site_class AS C ON (C.id=CS.class_id) WHERE CS.class_id=class_id and (NOW() between start_datetime and end_datetime) Limit 0,1; 
    -> IF runningdate IS NOT NULL THEN 
    -> RETURN runningdate; 
    -> ELSE 
    -> SELECT MAX(CS.end_datetime) INTO enddate FROM site_class_schedule AS CS INNER JOIN site_class AS C ON (C.id=CS.class_id) WHERE CS.class_id=class_id Group by C.id Limit 0,1; 
    -> IF enddate < NOW() THEN 
    -> RETURN enddate; 
    -> ELSEIF enddate >= NOW() THEN 
    -> SELECT MIN(CS.start_datetime) INTO startdate FROM site_class_schedule AS CS INNER JOIN site_class AS C ON (C.id=CS.class_id) WHERE CS.class_id=class_id and CS.start_datetime > NOW() Group by C.id Limit 0,1; 
    -> 
Display all 1866 possibilities? (y or n) 
    -> startdate; 
    -> 
Display all 1866 possibilities? (y or n) 
    -> D IF; 
    -> END IF; 
    -> END IF; 
    -> RETURN nextsession; 
    -> END$$ 
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '; 
D IF; 
END IF; 
END IF; 
RETURN nextsession; 
END' at line 19 
mysql> 
mysql> 

Progress Update 1

Cette TRAVAILLEES

mysql> DELIMITER $$ 
mysql> 
mysql> DROP FUNCTION IF EXISTS `get_class_nextsession`$$ 
Query OK, 0 rows affected, 1 warning (0.00 sec) 

mysql> CREATE DEFINER=`myusername`@`localhost` FUNCTION `get_class_nextsession`(class_id INT) RETURNS datetime 
    ->  READS SQL DATA 
    -> BEGIN 
    -> RETURN nextsession; 
    -> END$$ 
Query OK, 0 rows affected (0.00 sec) 

Ce TRAVAILLEES

mysql> 
mysql> DROP FUNCTION IF EXISTS `get_class_nextsession`$$ 
Query OK, 0 rows affected (0.00 sec) 

mysql> 
mysql> CREATE DEFINER=`myusername`@`localhost` FUNCTION `get_class_nextsession`(class_id INT) RETURNS datetime 
    ->  READS SQL DATA 
    -> BEGIN 
    -> DECLARE nextsession,startdate,runningdate,enddate DATETIME; 
    -> RETURN nextsession; 
    -> END$$ 
Query OK, 0 rows affected (0.00 sec) 

Cela n'a pas marché - Remarquez comment je suis en train de simplifier la requête/déclarations dans les bases.

mysql> DROP FUNCTION IF EXISTS `get_class_nextsession`$$ 
Query OK, 0 rows affected, 1 warning (0.01 sec) 

mysql> CREATE DEFINER=`myusername`@`localhost` FUNCTION `get_class_nextsession`(class_id INT) RETURNS datetime 
    ->  READS SQL DATA 
    -> BEGIN 
    -> DECLARE nextsession,startdate,runningdate,enddate DATETIME; 
    -> SET nextsession= '-'; 
    -> SELECT MIN(start_datetime) INTO startdate FROM site_class_schedule; 
    -> IF startdate >= NOW() THEN 
    -> RETURN startdate; 
    -> ELSE 
    -> END IF; 
    -> RETURN nextsession; 
    -> END$$ 
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'END IF; 
RETURN nextsession; 
END' at line 10 

Répondre

2

Ah ah!

Certainement une erreur «inhabituelle» où «rien» était faux! Les problèmes auxquels je faisais face étaient dus à des onglets excessifs générés ou placés dans la création originale de FUNCTION! Les deux ts \ consécutifs cassaient le flux d'entrée de données sur l'invite de mysql et ayant mysql demande

Display all 1866 possibilities? (y or n) 

De plus, quand j'étais coller copie ici, je suis coller le résultat final de mon interaction avec le MYSQL invite de commande, pas ce que j'avais réellement placé «dans» là!

DROP FUNCTION IF EXISTS `get_class_nextsession`$$ 
CREATE DEFINER=`myusername`@`localhost` FUNCTION `get_class_nextsession`(class_id INT) RETURNS datetime 
    READS SQL DATA 
BEGIN 
DECLARE nextsession,startdate,runningdate,enddate DATETIME; 
SET nextsession= '-'; 
SELECT MIN(CS.start_datetime) INTO startdate FROM site_class_schedule AS CS INNER JOIN site_class AS C ON (C.id=CS.class_id) WHERE CS.class_id=class_id Group by C.id Limit 0,1; 
IF startdate >= NOW() THEN 
RETURN startdate; 
ELSE  
SELECT CS.start_datetime INTO runningdate FROM site_class_schedule AS CS INNER JOIN site_class AS C ON (C.id=CS.class_id) WHERE CS.class_id=class_id and (NOW() between start_datetime and end_datetime) Limit 0,1; 
IF runningdate IS NOT NULL THEN 
RETURN runningdate; 
ELSE 
SELECT MAX(CS.end_datetime) INTO enddate FROM site_class_schedule AS CS INNER JOIN site_class AS C ON (C.id=CS.class_id) WHERE CS.class_id=class_id Group by C.id Limit 0,1; 
IF enddate < NOW() THEN 
    RETURN enddate; 
ELSEIF enddate >= NOW() THEN 
SELECT MIN(CS.start_datetime) INTO startdate FROM site_class_schedule AS CS INNER JOIN site_class AS C ON (C.id=CS.class_id) WHERE CS.class_id=class_id and CS.start_datetime > NOW() Group by C.id Limit 0,1; 
      RETURN startdate; ****ISSUE WITH MORE THAN 2 TABS**** 
     END IF; ****ISSUE WITH MORE THAN 2 TABS**** 
    END IF; 
END IF; 
RETURN nextsession; 
END$$