zoukankan      html  css  js  c++  java
  • 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
    
    
    
     
     
  • 相关阅读:
    eclipse 添加.gitignore
    HTTP method POST is not supported by this URL
    Nodejs 如何解决每次向后台发起请求时判断用户是否处于登录状态?
    Servlet 全局验证是否登录
    会员管理系统的设计和开发(1)
    C程序模拟实现银行家算法
    XPath Helper:chrome爬虫网页解析工具 Chrome插件
    scrapy爬虫出现Forbidden by robots.txt
    廖雪峰
    Nodejs中export的作用
  • 原文地址:https://www.cnblogs.com/zzyoucan/p/5137174.html
Copyright © 2011-2022 走看看