e_msg_c_as_register_req-注册存储过程

TOP:BEGIN
#Routine body goes here... IF EXISTS
(
SELECT * FROM `global_account`
WHERE `plantform_id` = in_plantform_id
AND `plantform_sub_id` = in_plantform_sub_id
AND `account` = in_account
) THEN
SELECT -1 AS RET;
LEAVE TOP;
END IF; INSERT INTO `global_account` SET
`plantform_id` = in_plantform_id,
`plantform_sub_id` = in_plantform_sub_id,
`account` = in_account,
`password` = in_password,
`register_time` = NOW()
; SELECT 0 AS RET, LAST_INSERT_ID() AS user_id; END

将这个存储过程解释一下

IF EXISTS()其实看select能不能有数据,如果有数据就是true否则就是false
 LEAVE TOP;就是从存储过程返回,这个TOP是自己加上去的,默认是没有的
SELECT 0 AS RET, LAST_INSERT_ID() AS user_id;结果集,RET就是返回结果,一般MySQL0是表示成功,LAST_INSERT_ID()表示上一条insert插入的id,将这两个值作为存储过程的返回值。
BEGIN
#Routine body goes here...
DECLARE var_user_id INT DEFAULT NULL;
DECLARE var_password VARCHAR(255) DEFAULT ""; SELECT `user_id`, `password` INTO var_user_id, var_password FROM `global_account`
WHERE `plantform_id` = in_plantform_id
AND `plantform_sub_id` = in_plantform_sub_id
AND `account` = in_account
#AND `password` = in_password
; IF ISNULL(var_user_id) THEN #没有这个用户时
INSERT INTO `global_account`
SET `plantform_id` = in_plantform_id,
`plantform_sub_id` = in_plantform_sub_id,
`account` = in_account,
`password` = in_password,
`register_time` = NOW()
; SELECT 0 AS RET, LAST_INSERT_ID() AS user_id;
ELSE
IF var_password = in_password THEN
SELECT 0 AS RET, var_user_id AS user_id;
ELSE
SELECT -1 AS RET;
END IF;
END IF; END

 
 
上一篇:Purfer Sequence


下一篇:nginx+django+uwsgi