DROP PROCEDURE IF EXISTS `get_user_products`;
DELIMITER ;;
CREATE PROCEDURE `get_user_products` (
    IN p_session_id CHAR(64)
)
proc:BEGIN
    IF (SELECT COUNT(session_id) FROM sessions WHERE session_id = LOWER(p_session_id)) = 0 OR p_session_id IS NULL THEN
        SIGNAL SQLSTATE '45000' SET MESSAGE_TEXT = 'get_user_products: No user logged in';
        LEAVE proc;
    END IF;
    SELECT user_id INTO @user_id FROM sessions WHERE session_id = LOWER(p_session_id);
    SELECT *, 'get_user_products' AS 'proc' FROM products WHERE user_id = @user_id AND archived = false;
END ;;
DELIMITER ;
