Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Recursion limit exceeded in non-recusrive procedure

I have a procedure which calls another procedure. They never call back to each other or call themselves, but I am getting an error response indicating that they are. The procedures are as follows:

CREATE PROCEDURE grantPermission (perm VARCHAR(30), target VARCHAR(30), id VARCHAR(8), host VARCHAR(45), passwd VARCHAR(45))
  BEGIN 
    SET @setPermissionCmd = CONCAT('GRANT ', perm, ' ON ', target, ' TO ''', id, '''@''', host, ''' IDENTIFIED BY ''', passwd, ''';');
    PREPARE setPermissionStmt FROM @setPermissionCmd;
    EXECUTE setPermissionStmt;
    DEALLOCATE PREPARE setPermissionStmt;
    FLUSH PRIVILEGES;
  END

and

CREATE PROCEDURE grantAdmin (id VARCHAR(8), host VARCHAR(45), passwd VARCHAR(45))
  BEGIN
    CALL grantPermission('EXECUTE', 'PROCEDURE createUser', id, host, passwd);
    CALL grantPermission('EXECUTE', 'PROCEDURE grantAdmin', id, host, passwd);
    CALL grantPermission('EXECUTE', 'PROCEDURE revokeAdmin', id, host, passwd);
    CALL grantPermission('INSERT,UPDATE', 'TaskType', id, host, passwd);
    CALL grantPermission('UPDATE', 'User', id, host, passwd);
    UPDATE User SET isAdmin=1 WHERE dbUser=id;
    FLUSH PRIVILEGES;
  END

When I call the second procedure, I get the following response:

MariaDB [pattsdb]> CALL grantAdmin('patts', '%', 'patts');
ERROR 1456 (HY000): Recursive limit 0 (as set by the max_sp_recursion_depth variable) was exceeded for routine grantAdmin

Why does it think my procedure is recursive? Just because the name is mentioned in the definition text?

like image 263
2mac Avatar asked Mar 17 '15 23:03

2mac


1 Answers

Add this to the beginning of the Stored Procedure:

SET max_sp_recursion_depth=255;
like image 63
Eyal Avatar answered Oct 16 '22 08:10

Eyal