When I run the following MySQL server stored procedure I would expect that it run forever because there is no CONTINUE HANDLER
BEGIN
DECLARE p INT(11) DEFAULT 0;
DECLARE no_more_rows BOOLEAN DEFAULT false;
DECLARE testA INT;
DECLARE iCursor CURSOR FOR SELECT test_a FROM Temp;
OPEN iCursor;
id_loop: LOOP
FETCH iCursor INTO testA;
SET p = p + 1;
INSERT INTO Temp2 (test1, test2) VALUES (testA, p);
END LOOP;
INSERT INTO Temp3 SET Finished=1;
CLOSE iCursor;
END
But it seems that the CURSOR is working perfect and wrote all the values from the Temp table to the Temp2 table (and there are also no more values of the counter p written into the table). The procedure is also not running any more when I check the running processes on the MySQL server.
But the Finished code is not written into the Temp3 table and I therefore suppose the cursor is also not closed properly.
Does anybody know what happens here?
Why is the loop not running endless?
Is it ok to implement a cursor like that (in case there is no code that should be run after the loop)?