CREATE DEFINER PROCEDURE `updaterole_20171127`()
begin
DROP TEMPORARY TABLE IF EXISTS tmppassword;
create temporary table if not exists tmppassword
(
tabname varchar(50),
PhonePassword text
);
BEGIN
declare v_gameid int(11);
declare done INT(3) DEFAULT 0;
declare v_name1 varchar(100);
DECLARE rs CURSOR FOR select table_name from information_schema.tables
where table_schema='zzzjh' and table_name like 'Player%' order by table_name;
DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = 1 ;
OPEN rs;
REPEAT
FETCH rs INTO v_name1;
IF done = 0 THEN
set @sql11="DELETE from tmppassword";
PREPARE stmt FROM @sql11;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;
set @sql1=concat(' insert into tmppassword(tabname,PhonePassword) select ''',v_name1,''',PhonePassword from ',v_name1,' where Nick like ''游客%'' and Phone is NOT NULL and Gold=0 ',
'and RegisterSP=''guanfang'' group by PhonePassword having count(1)>=5');
PREPARE stmt FROM @sql1;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;
set @sql12=concat('update ',v_name1,' set Gold=0,Score=0,PhonePassword=''96E79218805EB72C92A589DD5A330119''
where PhonePassword in(select PhonePassword from tmppassword) and Nick like ''游客%'' and Phone is NOT NULL and Gold=0
and RegisterSP=''guanfang''');
PREPARE stmt FROM @sql12;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;
set @sql13=concat('update ',v_name1,' set Gold=0,Score=0,PhonePassword=''96E79218805EB72C92A589DD5A330119''
where (RegisterMachine=''XXEmulator'' or NowMachine=''XXEmulator'')
and Phone is not null');
PREPARE stmt FROM @sql13;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;
END IF;
UNTIL done END REPEAT;
CLOSE rs;
END;
end