4

This is my stored procedure:

CREATE DEFINER=`root`@`localhost` PROCEDURE `isUserValid`(IN `facebookId` VARCHAR(20), IN `userAccessToken` TEXT)
 NO SQL
 COMMENT 'check if user is valid. return true or false'
Begin
 /* declare the select resluts variables*/ 
 Declare accessToken TEXT;
 Declare expires datetime;
 /* fill the variables with saved user's access token an expires time*/
 Select Access_Token, Expires
 Into accessToken, expires
 From Users Where Facebook_Id = facebookId; 
 select expires,accessToken;
 /* If the saved access token and expires are valid return true */
 If (BINARY accessToken = userAccessToken And expires > now()) Then
 select true As isUserValid;
 Else
 select false As isUserValid;
 End If; 
End

For some reason the query:

/* fill the variables with saved user's access token an expires time*/
Select Access_Token, Expires
Into accessToken, expires
From Users Where Facebook_Id = facebookId;

returns the Expires as null all the time.

When I'm running the same query outside of the procedure, it returns a valid value for Expires.

mustaccio
28.6k24 gold badges60 silver badges77 bronze badges
asked Feb 17, 2014 at 9:05
2
  • 1
    Try using different names for the variables, not the same as the columns (accessToken is different than Access_Token but expires is the same as Expires) Commented Feb 17, 2014 at 9:54
  • yes that actually was the problem.. post it as answer and i will accept it Commented Feb 17, 2014 at 10:00

2 Answers 2

1

more correct change variable names:

CREATE DEFINER=`root`@`localhost` PROCEDURE `isUserValid`(IN `p_facebookId` VARCHAR(20), IN `p_userAccessToken` TEXT)
 NO SQL
 COMMENT 'check if user is valid. return true or false'
Begin
 /* declare the select resluts variables*/ 
 Declare v_accessToken TEXT;
 Declare v_expires datetime;
 /* fill the variables with saved user's access token an expires time*/
 Select U.Access_Token, U.Expires
 Into v_accessToken, v_expires
 From Users U Where U.Facebook_Id = p_facebookId; 
 select v_expires, v_accessToken;
 /* If the saved access token and expires are valid return true */
 If (BINARY v_accessToken = p_userAccessToken And v_expires > now()) Then
 select true As isUserValid;
 Else
 select false As isUserValid;
 End If; 
End

it help read code more easy for You and for MySQL parser as well

answered Nov 17, 2015 at 4:36
0

Actually you can alias query and solve the problem like this:

Select Users.Access_Token, Users.Expires Into accessToken, expires From Users Where Facebook_Id = facebookId;

answered Mar 20, 2015 at 8:23

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.