Error of procedure call

Asked

Viewed 22 times

0

I’m having a problem calling one procedure within a function in the SQL. When I call the function CHECK_LOGIN for SGBD, does the operation without any problem, but I need to do this operation by a code in python and this is where the error occurs.

Python excerpt

cur.execute('select CHECK_LOGIN(%s, %s)', (header['USER_INFO']['NAME'], header['USER_INFO']['KEY']))

Bet the python go through this line of code it tests the validation and returns the value -1, however, it is not done the update user, keeping the fields user_key and valid valueless.

What could be the reason for the mistake? (code was tested on two different machines and the error continued to persist)

header['USER_INFO']['NAME'] contains a user name.

header['USER_INFO']['KEY'] contains a 32 character md5.

Database

create table user(
    id integer not null auto_increment,
    name varchar(80) not null,
    login varchar(16) not null,
    user_key char(32),
    valid date,
    primary key(id)
);

create table login_info(
    id integer not null auto_increment,
    user integer not null,
    day date not null,
    key_access char(32) not null,
    primary key(id),
    foreign key(user) references user(id)
);

DELIMITER $

create procedure NEW_USER(IN uname varchar(80), IN ulogin varchar(16))
begin
    insert into user(name, login, user_key) values(uname, ulogin, '');
end$

create procedure FIRST_ACCESS(IN pid Integer, IN ukey char(32))
begin
    DECLARE valid_day date;
    set valid_day = DATE_ADD(curdate(), INTERVAL 1 MONTH);

    update user set user_key = ukey, valid = valid_day where id = pid;
end$

create function CHECK_LOGIN(ulogin varchar(16), ukey char(32)) returns Integer DETERMINISTIC
begin
    DECLARE _id integer;
    DECLARE _key char(32);
    DECLARE _date date;

    select id into _id from user where login = ulogin;
    select user_key into _key from user where id = _id;

    if _key = '' then
        call FIRST_ACCESS(_id, ukey);
        return -1;
    elseif _key = ukey then
        select valid into _date from user where id = _id;
        if _date < curdate() then
            return 1;
        end if;
        return 0;
    else
        return 2;
    end if;
    return 3;
end; $

DELIMITER ;

1 answer

0


I found the Error.

I wasn’t saving the changes because you don’t hear the confirmation using the db.commit() before finalizing the database connection.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.