Question

I am having an issue with making a MySql Routine.

Here is the code:

DELIMITER '$$';
CREATE PROCEDURE User.Login(IN UserName CHAR(32), IN PWord CHAR(32))
BEGIN
Select `userID`, `userType`, `userMainEmail`, `groupID`
    From `at_users`
    Where `userName` = UserName And `userPass` = PWord
    LIMIT 1
FOR UPDATE;

    Update `at_users`
    Set `lastLoginAt` = now()
    Where `userName` = UserName And `userPass` = PWord;
END$$

What it's supposed to do is a simple login task that's done just about everywhere... get a users record, then update the table with now()

What I am getting on creating this is:

#1064 - You have an error in your SQL syntax; check the manual that corresponds to your     MySQL server version for the right syntax to use near '' at line 12

Line 12 is the line right before END$$

Yes, all fields and tables exist. :)

EDIT: NEW CODE

DELIMITER //;
CREATE PROCEDURE User.Login(IN UserName CHAR(32), IN PWord CHAR(32))
BEGIN
Select `userID`, `userType`, `userMainEmail`, `groupID`
    From `at_users`
    Where `userName` = UserName And `userPass` = PWord
    LIMIT 1
FOR UPDATE;

    Update `at_users`
    Set `lastLoginAt` = now()
    Where `userName` = UserName And `userPass` = PWord;
END//
DELIMITER ;

I am trying this exact code from the command line, after logging in and selecting the proper database to USE.

After the last line 'DELIMITER ;' nothing happens and I stay at the -> line

Was it helpful?

Solution

Got it.

Here is the code I ended up having to use:

DELIMITER //
CREATE PROCEDURE UserLogin(IN UserName CHAR(32), IN PWord CHAR(32))
    BEGIN
        Select `userID`, `userType`, `userMainEmail`, `groupID`
        From `at_users`
        Where `userName` = UserName And `userPass` = PWord
        LIMIT 1
        FOR UPDATE;

        Update `at_users`
        Set `lastLoginAt` = now()
        Where `userName` = UserName And `userPass` = PWord;
    END//
DELIMITER ;
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top