Created
September 17, 2015 20:40
-
-
Save rashfael/fef018a57d51cc66a7d5 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
DELIMITER $$ | |
CREATE PROCEDURE create_user(username TEXT, passwordhash TEXT) | |
BEGIN | |
DECLARE temp TEXT; | |
SELECT user FROM mysql.user WHERE user = username INTO temp; | |
IF temp = username THEN | |
SIGNAL SQLSTATE '45002' SET MESSAGE_TEXT = 'username already exists'; | |
ELSE | |
SET @s = CONCAT('CREATE USER \'', username, '\'@localhost IDENTIFIED BY PASSWORD \''+passwordhash+'\''); | |
PREPARE stmt_create FROM @s; | |
EXECUTE stmt_create; | |
DEALLOCATE PREPARE stmt_create; | |
FLUSH PRIVILEGES; | |
END IF; | |
END $$ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment