BubikolRamios
08-15-2009, 02:49 AM
below proc works fine if I do: call galery_delete(1)¸from query analyser
If I do the same call from another function , function terminates with -2 coz of:
DECLARE EXIT HANDLER FOR SQLEXCEPTION return -2;
Is there perhaps a prob coz stored proc is taking data from another schema
comparing to schema in which it resides or something like that
?
DELIMITER $$
DROP PROCEDURE IF EXISTS `test`.`galery_delete` $$
CREATE DEFINER=`root`@`localhost` PROCEDURE `galery_delete`(i_id_galery INTEGER)
BEGIN
/*
brišem vse iz vseh tabel v smislu galery_1,
kjer je id_galery = c_id_galery
*/
DECLARE eof INT DEFAULT 0;
DECLARE c_tmp_str VARCHAR(400) DEFAULT '';
DECLARE cur CURSOR FOR
select table_name from information_schema.`TABLES`
where table_name like 'galery_1%';
DECLARE CONTINUE HANDLER FOR NOT FOUND SET eof = 1;
call debug_insert('galery_delete','1');
/***************************************************/
OPEN cur;
WHILE NOT eof DO
FETCH cur INTO c_tmp_str;
call debug_insert('galery_delete',c_tmp_str);
SET @r = CONCAT("DELETE FROM ",c_tmp_str, " WHERE id_galery = ", i_id_galery );
prepare stmt from @r;
execute stmt;
END WHILE;
DEALLOCATE PREPARE stmt;
CLOSE cur;
/***************************************************/
END $$
DELIMITER ;
If I do the same call from another function , function terminates with -2 coz of:
DECLARE EXIT HANDLER FOR SQLEXCEPTION return -2;
Is there perhaps a prob coz stored proc is taking data from another schema
comparing to schema in which it resides or something like that
?
DELIMITER $$
DROP PROCEDURE IF EXISTS `test`.`galery_delete` $$
CREATE DEFINER=`root`@`localhost` PROCEDURE `galery_delete`(i_id_galery INTEGER)
BEGIN
/*
brišem vse iz vseh tabel v smislu galery_1,
kjer je id_galery = c_id_galery
*/
DECLARE eof INT DEFAULT 0;
DECLARE c_tmp_str VARCHAR(400) DEFAULT '';
DECLARE cur CURSOR FOR
select table_name from information_schema.`TABLES`
where table_name like 'galery_1%';
DECLARE CONTINUE HANDLER FOR NOT FOUND SET eof = 1;
call debug_insert('galery_delete','1');
/***************************************************/
OPEN cur;
WHILE NOT eof DO
FETCH cur INTO c_tmp_str;
call debug_insert('galery_delete',c_tmp_str);
SET @r = CONCAT("DELETE FROM ",c_tmp_str, " WHERE id_galery = ", i_id_galery );
prepare stmt from @r;
execute stmt;
END WHILE;
DEALLOCATE PREPARE stmt;
CLOSE cur;
/***************************************************/
END $$
DELIMITER ;