DROP PROCEDURE IF EXISTS RegisterUser;
	
	DELIMITER //

	CREATE PROCEDURE RegisterUser (uname varchar(60), mail varchar(60), passhash text)
	BEGIN
		SELECT COUNT(*) INTO @usernameCount
		FROM user
		Where username = uname AND email = mail;

		IF @usernameCount > 0 THEN
			SELECT NULL as user_id, "Username already exists" AS  'Error';
		ELSE
			INSERT INTO user (username, email, password) VALUES (uname, mail, passhash);
			SELECT last_insert_id() AS user_id, NULL as 'Error';
		END IF;
	END;

	//

	DELIMITER;
