Skip to content
Advertisement

Lost connection to MySQL server during query error when I try to use function

I am trying to make a function which checks if any date between say Date-range A and B lies between the Date-range C and D. Whenever I try running the function MySQL Workbench always throws an Error Code:2013 Lost connection to MySQL Server during query. I am assuming this error is arising due to the loop running forever (please correct me If I’m thinking about it completely wrong).

Table Code :

Value Insertion Code :

Function :

Calling/Driver Code:

Note: The driver code might throw an error code 1175: safe update, it can be disabled using SET SQL_SAFE_UPDATES=0 before the driver code. If someone could also explain why it throws the error that’ll be great.

DB-Fiddle: https://www.db-fiddle.com/f/4Bof1gdHRnkSYJwVZekRJ9/1

EDIT:

Advertisement

Answer

Your code creates an endless loop (LeaveStart < LeaveEnd is always true).

Also, take a look at the code if you need the loop at all. As it currently stands, you do not need it as the value of the DET will be determined from the last loop round. All other rounds mean nothing.

You could simply do:

User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement