I have a stored function in MySQL:
CREATE FUNCTION `login_count`(o INT, start_date DATE, end_date DATE) RETURNS INT
READS SQL DATA
BEGIN
DECLARE total_count INT;
SELECT COUNT(*) INTO total_count FROM logins as l WHERE `order_id` = o && modified BETWEEN start_date AND end_date;
RETURN total_count;
END
Pretty simple, it takes an identifier, a start date and an end date and returns the number of logins for this date range. Whenever I run it, I get back 0. If I did not delete the date section of the where clause. Then it returns the actual number. OR, if I just manually put the dates in the stored function, this works ... So this is not a problem with dates, but only when I give dates through a list of parameters does not like it.
Any thoughts on what might lead to this? The fact that I can just manually put dates in a stored function and it works really scares me. It doesn’t look like a lot is going on here that can go bad, so I’m kind of lost to try further.
In addition, there is a way to debug stored functions / procedures. I just get 0 back, but is there a way to debug this to try to figure out what could happen?
source
share