我动态创建一个字符串,以便EXECUTE
执行此操作。它引发了一个例外 - 为什么?
如你所见,我在尝试执行之前返回了我的字符串。当我在MySQL客户端而不是CALL procedure ()
中运行此结果时,它可以完美地运行。
如果我尝试返回PREPARE
d字符串,则无法获得结果。似乎PREPARE
有点打破我的字符串。
例外
错误代码:1064您的SQL语法出错;检查与MySQL服务器版本对应的手册,以便在'SELECT movie_name,@ ClearLOGO:= IF((SELECT COUNT(image_id)FROM movie_images WHE'第1行附近)使用正确的语法
最重要的sql
SET set_part = CONCAT(set_part, '; ');
SET having_part = CONCAT(having_part, ' ORDER BY completeness ASC');
SET completeness_part = CONCAT(completeness_part, ') AS completeness');
SET complete_select = CONCAT('',set_part, select_part, completeness_part, ' FROM movie_items ',having_part);
SET @exec = complete_select;
SELECT @exec;
PREPARE _exec FROM @exec;
EXECUTE _exec;
结果(未格式化,精确复制)
SET @ClearLOGOs=0, @ClearART=0, @cdART=0, @Movie_Backgrounds=0, @Movie_Banner=0, @HD_Movie_Logos=0, @Movie_Thumbs=0, @HD_ClearART=0, @Movie_Poster=0; SELECT movie_name, @ClearLOGOs:=IF((SELECT COUNT(image_id) FROM movie_images WHERE image_active = 'y' AND image_type = '10' AND image_movie_tmdb_id = movie_tmdb_id) > 0, 0, 1) AS ClearLOGOs, @ClearART:=IF((SELECT COUNT(image_id) FROM movie_images WHERE image_active = 'y' AND image_type = '11' AND image_movie_tmdb_id = movie_tmdb_id) > 0, 0, 1) AS ClearART, @cdART:=IF((SELECT COUNT(image_id) FROM movie_images WHERE image_active = 'y' AND image_type = '12' AND image_movie_tmdb_id = movie_tmdb_id) > 0, 0, 1) AS cdART, @Movie_Backgrounds:=IF((SELECT COUNT(image_id) FROM movie_images WHERE image_active = 'y' AND image_type = '16' AND image_movie_tmdb_id = movie_tmdb_id) > 0, 0, 1) AS Movie_Backgrounds, @Movie_Banner:=IF((SELECT COUNT(image_id) FROM movie_images WHERE image_active = 'y' AND image_type = '19' AND image_movie_tmdb_id = movie_tmdb_id) > 0, 0, 1) AS Movie_Banner, @HD_Movie_Logos:=IF((SELECT COUNT(image_id) FROM movie_images WHERE image_active = 'y' AND image_type = '23' AND image_movie_tmdb_id = movie_tmdb_id) > 0, 0, 1) AS HD_Movie_Logos, @Movie_Thumbs:=IF((SELECT COUNT(image_id) FROM movie_images WHERE image_active = 'y' AND image_type = '24' AND image_movie_tmdb_id = movie_tmdb_id) > 0, 0, 1) AS Movie_Thumbs, @HD_ClearART:=IF((SELECT COUNT(image_id) FROM movie_images WHERE image_active = 'y' AND image_type = '26' AND image_movie_tmdb_id = movie_tmdb_id) > 0, 0, 1) AS HD_ClearART, @Movie_Poster:=IF((SELECT COUNT(image_id) FROM movie_images WHERE image_active = 'y' AND image_type = '29' AND image_movie_tmdb_id = movie_tmdb_id) > 0, 0, 1) AS Movie_Poster,(@ClearLOGOs + @ClearART + @cdART + @Movie_Backgrounds + @Movie_Banner + @HD_Movie_Logos + @Movie_Thumbs + @HD_ClearART + @Movie_Poster) AS completeness FROM movie_items HAVING ClearLOGOs > 0 OR ClearART > 0 OR cdART > 0 OR Movie_Backgrounds > 0 OR Movie_Banner > 0 OR HD_Movie_Logos > 0 OR Movie_Thumbs > 0 OR HD_ClearART > 0 OR Movie_Poster > 0 ORDER BY completeness ASC
答案 0 :(得分:0)
您不能在预准备语句中使用多个查询。
预处理语句的SQL语法不支持多语句(即,单个字符串中的多个语句由“;”字符分隔)。
http://dev.mysql.com/doc/refman/5.0/en/sql-syntax-prepared-statements.html