Table of contents
    No headers

    Lets you run a query on multiple catalogs

    DELIMITER $$
    
    DROP PROCEDURE IF EXISTS `mysql`.`batchexec`$$
    
    CREATE PROCEDURE `mysql`.`batchexec`()
    BEGIN
    	DECLARE catalog varchar(255);
    	DECLARE done INT DEFAULT 0;
    	DECLARE curs CURSOR FOR select db from mysql.proc where `name` = "page_get_pagesbyids" limit 100;
    	DECLARE CONTINUE HANDLER FOR SQLSTATE '02000' SET done = 1;
    	open curs;
    
    	repeat
    		fetch curs into catalog;
    
    	 	if not done then 
    		begin	
    			SET @sql = CONCAT(
    			 "select count(*) from `", catalog, "`.pages into @pagecount"
    			);
    
    			PREPARE STMT FROM @sql;
    			EXECUTE STMT; 
    
    
    			set @sql = CONCAT(
    			 "select count(*) from `", catalog, "`.users into @usercount"
    			);
    			PREPARE STMT FROM @sql;
    			EXECUTE STMT; 
    
    	
    			select catalog, @pagecount, @usercount;
    		end; 
    		end if;
    
    	until done end repeat;
    	close curs;
    END$$
    
    DELIMITER ;
    
    Tag page
    You must login to post a comment.

    Copyright © 2011 MindTouch, Inc. Powered by