分类: Mysql/postgreSQL
2007-12-26 14:43:28
DELIMITER
$$
DROP PROCEDURE IF EXISTS `mysql`.`sp_grant_privileges_on_routine`$$
CREATE DEFINER=`root`@`localhost`
PROCEDURE `sp_grant_privileges_on_routine`(
IN f_db
varchar(255), IN
f_username varchar(255),IN f_host
varchar(255),
IN
f_privileges varchar(255))
BEGIN
declare i int default
0;
-- Get the total of the
procedure.
set @stmt = concat('select count(1)
from mysql.proc where db = ''',f_db,''' into
@cnt');
prepare s1 from @stmt;
execute s1;
deallocate prepare s1;
set @stmt = '';
while i < @cnt do
-- Grant privilege one by one.
set @stmt = concat('select `name` from mysql.proc where db = ''',f_db,''' and type = 2 limit ',i,',1 into @name');
prepare s1 from @stmt;
execute s1;
deallocate prepare s1;
set @stmt = '';
set @stmt = concat('insert into mysql.procs_priv values (''',f_host,''',''',f_db,''',''',f_username,''',''',@name,''',2,''',user(),''',''',f_privileges,''',''',now(),''')');
prepare s1 from @stmt;
execute s1;
deallocate prepare s1;
set @stmt = '';
set
i = i +
1;
end while;
flush
privileges;
END$$
DELIMITER ;