Welcome toVigges Developer Community-Open, Learning,Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.4k views
in Technique[技术] by (71.8m points)

mysql - 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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Add this to the beginning of the Stored Procedure:

SET max_sp_recursion_depth=255;

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to Vigges Developer Community for programmer and developer-Open, Learning and Share
...