开发者

Mysql syntax help

开发者 https://www.devze.com 2022-12-13 11:22 出处:网络
I have problems writing a SP in MySQL. From what I can read on the net the following should work, but it does not. I use Mysql v. 5.1.开发者_JAVA百科35

I have problems writing a SP in MySQL. From what I can read on the net the following should work, but it does not. I use Mysql v. 5.1.开发者_JAVA百科35

CREATE DEFINER=`My_Username`@`%` PROCEDURE `ChangePassword`(IN SPusername VARCHAR(100),
    IN SPoldPassword VARCHAR(100),
    IN SPnewPassword VARCHAR(100))
BEGIN
IF EXISTS(SELECT Password_Hash 
                FROM Customer
                WHERE SPusername = Email 
                AND  SPoldPassword = Password_Hashed)
THEN
UPDATE Customer
SET Password_Hashed = SPnewPassword
END IF;
END;


I think it's because the procedure name should not be in ''s.

In the first line, try this:

CREATE DEFINER='My_Username'@'%' PROCEDURE ChangePassword(IN SPusername VARCHAR(100),

Ohh ... and remember to also look at astander's answer regarding your WHERE clause in the UPDATE statement. Without extending the WHERE clause all passwords would be set to the same thing ... every time! He is advise is good! (Although the SQL statement would work) :-)

Regards
     Sigersted

PS: The complete query (with delimiter and astander's advice):

DELIMITER //
CREATE DEFINER='My_Username'@'%' PROCEDURE ChangePassword(
    IN SPusername VARCHAR(100),
    IN SPoldPassword VARCHAR(100),
    IN SPnewPassword VARCHAR(100))
BEGIN
IF EXISTS(SELECT Password_Hash 
          FROM Customer
          WHERE SPusername = Email 
          AND  SPoldPassword = Password_Hashed)
THEN
  UPDATE Customer
  SET Password_Hashed = SPnewPassword
  WHERE SPusername = Email 
  AND  SPoldPassword = Password_Hashed;
END IF;
END//
DELIMITER ;


It would seem that you might be missing the WHERE statement from the IF EXISTS check in the UPDATE statement.

Change it to

UPDATE Customer
SET Password_Hashed = SPnewPassword
WHERE SPusername = Email
AND  SPoldPassword = Password_Hashed
0

精彩评论

暂无评论...
验证码 换一张
取 消