MySQL Procedure Error on Creation -
creating procedure below , keeps giving out assigning values fro first select statement, doing wrong, appreciated.
error 1064 (42000): have error in sql syntax; check manual corresponds mysql server version right syntax use near ':=
m id
, vcurrentvote := vote td_voted id = pcid limit 1;
create procedure pr_update_vote (in pcid int, in pvote int, in pmid int, out pnewvote int) begin declare vmid, vvote, vcurrentvote, vnewvote int; if pvote = 1 set vvote = 1; else set vvote = -1; end if; select vmid := `mid`, vcurrentvote := vote td_voted id = pcid limit 1; if vmid <> pmid select vvotetype := vote td_votes `mid` = vmid , cid = pcid limit 1; if vvotetype not null or vvotetype <> vvote update td_votes set vote = vvote, updated = now() cid = pcid , `mid` = pmid limit 1; else insert td_votes (`mid`, cid, vote) values (pmid, pcid, vvote); end if; vnewvote = vcurrentvote + vvote; update td_voted set vote = vnewvote id = pcid limit 1; select pnewvote := vote td_voted id = pcid limit 1; end if; end
this solution worked me after debugging.
create procedure pr_update_vote (in pcid int, in pvote int, in pmid int, out pnewvote int) begin declare vmid, vvote, vcurrentvote, vnewvote int; if pvote = 1 set vvote = 1; else set vvote = -1; end if; select vmid = `mid`, vcurrentvote = vote td_voted id = pcid limit 1; if vmid <> pmid select vvotetype = vote td_votes `mid` = vmid , cid = pcid limit 1; if (vvotetype not null) or (vvotetype <> vvote) update td_votes set vote = vvote, updated = now() cid = pcid , `mid` = pmid limit 1; else insert td_votes (`mid`, cid, vote) values (pmid, pcid, vvote); end if; set vnewvote = vcurrentvote + vvote; update td_voted set vote = vnewvote id = pcid limit 1; select pnewvote = vote td_voted id = pcid limit 1; end if; end
Comments
Post a Comment