USE mysql;
/* ----------------------------------
Procedure structure for xp_execute
---------------------------------- */
DROP PROCEDURE IF EXISTS `xp_execute`;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` PROCEDURE `xp_execute`(vqueryddl longtext)
begin
set @ssql = vqueryddl;
prepare query from @ssql;
execute query;
end;;
DELIMITER ;
/* -------------------------------------------
-- Procedure structure for xp_routines_compare
------------------------------------------- */
DROP PROCEDURE IF EXISTS `xp_routines_compare`;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` PROCEDURE `xp_routines_compare`(v_namadatabase1 varchar(255), v_namadatabase2 varchar(255))
BEGIN
DROP VIEW IF EXISTS __db1;
SET @sql = CONCAT('
CREATE VIEW __db1 AS
select
r.`db` as nama_database,
r.`type` as tipe_routine,
r.`name` as nama_routine,
r.`param_list` as parameter_routine,
r.`body` as isi_routine,
r.`returns` as nilai_balik
from mysql.proc as r
where
r.db = "',v_namadatabase1,'"
with check option');
call xp_execute(@sql);
DROP VIEW IF EXISTS __db2;
SET @sql = CONCAT('
CREATE VIEW __db2 AS
select
r.`db` as nama_database,
r.`type` as tipe_routine,
r.`name` as nama_routine,
r.`param_list` as parameter_routine,
r.`body` as isi_routine,
r.`returns` as nilai_balik
from mysql.proc as r
where
r.db = "',v_namadatabase2,'"
with check option');
call xp_execute(@sql);
select db1.nama_routine as routine_yg_berbeda,
TRIM(CONCAT
( IF(strcmp(LCASE(REPLACE(REPLACE(db1.parameter_routine,CHAR(32),''),CHAR(13),'')
),LCASE(REPLACE(REPLACE(db2.parameter_routine,CHAR(32),''),CHAR(13),'')))
<> 0,'PARAMETER',''),' ',
IF(strcmp(LCASE(REPLACE(REPLACE(db1.isi_routine,CHAR(32),''),CHAR(13),'')),
LCASE(REPLACE(REPLACE(db2.isi_routine,CHAR(32),''),CHAR(13),''))) <> 0,'BODY',''),' ',
IF(strcmp(LCASE(REPLACE(REPLACE(db1.nilai_balik,CHAR(32),''),CHAR(13),'')),
LCASE(REPLACE(REPLACE(db2.nilai_balik,CHAR(32),''),CHAR(13),''))) <> 0,'RETURN',''),' '
)) as letak_perbedaan
from __db1 as db1 JOIN __db2 as db2
where db1.nama_routine = db2.nama_routine and
(strcmp(LCASE(REPLACE(REPLACE(db1.parameter_routine,CHAR(32),''),CHAR(13),'')),
LCASE(REPLACE(REPLACE(db2.parameter_routine,CHAR(32),''),CHAR(13),''))) <> 0
or strcmp(LCASE(REPLACE(REPLACE(db1.isi_routine,CHAR(32),''),CHAR(13),'')),
LCASE(REPLACE(REPLACE(db2.isi_routine,CHAR(32),''),CHAR(13),''))) <> 0
or strcmp(LCASE(REPLACE(REPLACE(db1.nilai_balik,CHAR(32),''),CHAR(13),'')),
LCASE(REPLACE(REPLACE(db2.nilai_balik,CHAR(32),''),CHAR(13),''))) <> 0 )
UNION ALL
select db1.nama_routine as routine_yg_berbeda, CONCAT('routines baru di db : ',v_namadatabase1) as letak_perbedaan
from __db1 as db1
where db1.nama_routine not in (select db2.nama_routine from __db2 as db2)
UNION ALL
select db2.nama_routine as routine_yg_berbeda, CONCAT('routines baru di db : ',v_namadatabase2) as letak_perbedaan
from __db2 as db2
where db2.nama_routine not in (select db1.nama_routine from __db1 as db1)
ORDER BY routine_yg_berbeda ASC;
DROP VIEW IF EXISTS __db1;
DROP VIEW IF EXISTS __db2;
END;;
DELIMITER ;
Tidak ada komentar:
Posting Komentar