0

このストアド プロシージャでは、準備済みステートメントを使用して 2 つのクエリを実行しています。手順は次のとおりです。

SET @uid    = puserid;
SET @rangee = plimit * 50;
SET @post = 'post';

PREPARE STMT FROM 
'
SELECT  notifications.postid,victims.victimid,friends.friendsname,notificationrecievers.status 

FROM friends,victims,notifications,notificationrecievers

WHERE victims.postid=notifications.postid 

AND notificationrecievers.notificationid=notifications.notid

AND notificationrecievers.recieverid=?

AND notifications.type=? 

AND friends.friendsid=victims.victimid

AND notificationrecievers.notificationid <=
(
   SELECT MAX(notid) FROM
   (
      SELECT n.notid FROM user u,notifications n,notificationrecievers nr WHERE
      nr.recieverid=? AND u.userid=n.senderid AND nr.notificationid=n.notid ORDER BY n.notid DESC
      LIMIT 50 OFFSET ?
   )a
)
AND notificationrecievers.notificationid >=
(
   SELECT MIN(notid) FROM
   (
      SELECT n.notid FROM user u,notifications n,notificationrecievers nr WHERE
      nr.recieverid=? AND u.userid=n.senderid AND nr.notificationid=n.notid ORDER BY n.notid DESC
      LIMIT 50 OFFSET ?
   )b
)
ORDER BY notifications.postid DESC;

UPDATE notificationrecievers 

SET notificationrecievers.status=1 

WHERE notificationrecievers.status=0
AND   notificationrecievers.recieverid=? 

AND

notificationrecievers.notificationid <=
(
     SELECT MAX(notid) FROM
     (
      SELECT n.notid FROM user u,notifications n,notificationrecievers nr WHERE
      nr.recieverid=? AND u.userid=n.senderid AND nr.notificationid=n.notid ORDER BY n.notid DESC
      LIMIT 50 OFFSET ?
     )e
)   

AND

notificationrecievers.notificationid >=
(
     SELECT min(notid) FROM
     (
      SELECT n.notid FROM user u,notifications n,notificationrecievers nr WHERE
      nr.recieverid=? AND u.userid=n.senderid AND nr.notificationid=n.notid ORDER BY n.notid DESC
      LIMIT 50 OFFSET ?
     )g
);

';
EXECUTE STMT USING @uid,@post,@uid,@rangee,@uid,@rangee,@uid,@uid,@rangee,@uid,@rangee;

プロシージャでこのクエリを実行すると、構文エラーが発生します。しかし、代わりにハードコードされた値を指定して直接使用すると、?正常に動作します。なぜこれが起こっているのですか? puseridそしてplimit、このプロシージャに渡すパラメータです。

これはエラーです:

Code: 1064
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 ';

UPDATE 
notificationrecievers 
SET notificationrecievers.st' at line 25
4

0 に答える 0