Задавайте вопросы, мы ответим
Вы не зашли.
Доброго времени суток!
Помогите пожалуйста разобраться в процедурах:
CREATE DEFINER=`root`@`%` PROCEDURE `test_tun_removal`(IN `GeoTerID` INT)
LANGUAGE SQL
NOT DETERMINISTIC
CONTAINS SQL
SQL SECURITY DEFINER
COMMENT ''
BEGIN
DECLARE done INT DEFAULT FALSE;
DECLARE CurrentVersion INT;
DECLARE CorrectVersion INT;
DECLARE BeginVersion INT;
DECLARE cur1
CURSOR FOR
SELECT Distinct(Version)
FROM geo_patch
WHERE TerID = GeoTerID AND Version >= BeginVersion;
DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = TRUE;
declare exit handler for sqlexception
begin
rollback;
resignal;
end;
CREATE Temporary TABLE `ark_tuntemp` (
`ID` INT NULL
)
COLLATE='utf8_general_ci'
ENGINE=InnoDB;
insert into ark_tuntemp ( ID ) (
SELECT ID from geo_patch
WHERE Version in ( select Version from geo_patch where Substance = 0 ) and TerID = GeoTerID
);
SET BeginVersion = ( SELECT Version from geo_patch where ID = ( SELECT ID from ark_tuntemp limit 1 ) ) - 1 ;
SET CorrectVersion = BeginVersion;
IF CorrectVersion < 2 THEN
SET CorrectVersion = 2;
END IF;
START TRANSACTION;
DELETE FROM geo_patch where ID in ( Select ID from ark_tuntemp );
open cur1;
version_loop: LOOP
FETCH cur1 into CurrentVersion;
IF done THEN
LEAVE version_loop;
END IF;
UPDATE geo_patch SET Version = CorrectVersion WHERE Version = CurrentVersion;
SET CorrectVersion = CorrectVersion + 1;
END LOOP;
close cur1;
COMMIT;
UPDATE terrain_blocks SET GeoVersion = ( select Version from geo_patch where TerID = GeoTerID order by Version desc limit 1 ) WHERE ID = GeoTerID;
drop temporary table if exists ark_tuntemp;
END
и
CREATE PROCEDURE `test_tun_removal`(IN `GeoTerID` INT)
LANGUAGE SQL
NOT DETERMINISTIC
CONTAINS SQL
SQL SECURITY DEFINER
COMMENT ''
BEGIN
CREATE Temporary TABLE `ark_tuntemp` (
`ID` INT NULL,
INDEX `ID` (`ID`)
)
COLLATE='utf8_general_ci'
ENGINE=InnoDB;
CREATE TEMPORARY TABLE `ark_geo_versions` (
`Version` INT(11) NULL DEFAULT NULL,
`NewVersion` INT(11) NULL DEFAULT NULL,
INDEX `Version` (`Version`),
UNIQUE INDEX `NewVersion` (`NewVersion`)
)
COLLATE='utf8_general_ci'
ENGINE=InnoDB;
insert into ark_tuntemp ( ID ) (
SELECT ID from geo_patch
WHERE Version in ( select Version from geo_patch where ( Substance = 0 or LevelFlags = 128 )and TerID = GeoTerID ) and TerID = GeoTerID
);
-- DELETE TUNNELS
DELETE FROM geo_patch where ID in ( Select ID from ark_tuntemp );
-- RE-INDEX
INSERT INTO ark_geo_versions ( Version ) ( SELECT Version from geo_patch where TerID = GeoTerID group by Version);
SET @n = 1;
UPDATE ark_geo_versions SET NewVersion = @n:=@n+1;
UPDATE geo_patch g
JOIN ark_geo_versions v on v.Version = g.Version
SET g.Version = v.NewVersion WHERE g.TerID = GeoTerID;
UPDATE terrain_blocks SET GeoVersion = ( select Version from geo_patch where TerID = GeoTerID order by Version desc limit 1 ) WHERE ID = GeoTerID;
drop temporary table if exists ark_tuntemp;
DROP TEMPORARY TABLE IF EXISTS ark_geo_versions;
END
В обоих случаях упорно ругается на ошибку в первой строке - /* Ошибка SQL (1064): You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'END' at line 1 */
SQL немного знаю, но тут совсем не могу понять, в чем дело и как это исправить...
Неактивен