MySQL Forums
Forum List  »  Stored Procedures

Stored Procedure Insert executing twice??????
Posted by: Jimmy Warren
Date: July 19, 2015 07:32PM

Hi, I am having a problem with a stored procedure running twice and I only call it once. The fallowing is the stored procedure and the store procedure that it calls during execution:

*****************************************************************************
CREATE DEFINER=`vpsmetal`@`%` PROCEDURE `spInitialZoneCreation`()
BEGIN

DECLARE var_hostname varchar(75);
DECLARE var_admin_email varchar(75);
DECLARE var_ns1 varchar(75);
DECLARE var_ns1_ip varchar(75);
DECLARE var_ns2 varchar(75);
DECLARE var_ns2_ip varchar(75);
DECLARE var_mail varchar(75);
DECLARE var_mail_ip varchar(75);
DECLARE var_mysql varchar(75);
DECLARE var_mysql_ip varchar(75);
DECLARE var_www varchar(75);
DECLARE var_www_ip varchar(75);
DECLARE int_zone_id INT(11);

SELECT server_name INTO var_ns1 FROM zone_servers WHERE host = 'ns1';
SELECT server_name INTO var_ns2 FROM zone_servers WHERE host = 'ns2';
SELECT server_name INTO var_mail FROM zone_servers WHERE host = 'mail';
SELECT server_name INTO var_mysql FROM zone_servers WHERE host = 'mysql';
SELECT server_name INTO var_www FROM zone_servers WHERE host = 'www';
SELECT server_ip INTO var_ns1_ip FROM zone_servers WHERE host = 'ns1';
SELECT server_ip INTO var_ns2_ip FROM zone_servers WHERE host = 'ns2';
SELECT server_ip INTO var_mail_ip FROM zone_servers WHERE host = 'mail';
SELECT server_ip INTO var_mysql_ip FROM zone_servers WHERE host = 'mysql';
SELECT server_ip INTO var_www_ip FROM zone_servers WHERE host = 'www';

SET var_hostname = SUBSTRING_INDEX(var_ns1, '.', -2);
SET var_admin_email = 'admin.' + var_hostname;

INSERT INTO zones (hostname, soa, admin_email)
VALUES (var_hostname, var_ns1, var_admin_email);

SELECT LAST_INSERT_ID() INTO int_zone_id;

CALL MetalCPanel.spInsertZoneRecord(int_zone_id, 'NS', 0, var_hostname, var_ns1);
CALL MetalCPanel.spInsertZoneRecord(int_zone_id, 'NS', 0, var_hostname, var_ns2);
CALL MetalCPanel.spInsertZoneRecord(int_zone_id, 'A', 0, var_hostname, var_ns1_ip);
CALL MetalCPanel.spInsertZoneRecord(int_zone_id, 'A', 0, var_hostname, var_ns2_ip);

SET var_hostname = SUBSTRING_INDEX(var_www, '.', -2);
SET var_admin_email = 'admin.' + var_hostname;

INSERT INTO zones (hostname, soa, admin_email)
VALUES (var_hostname, var_ns1, var_admin_email);

SELECT LAST_INSERT_ID() INTO int_zone_id;

CALL MetalCPanel.spInsertZoneRecord(int_zone_id, 'NS', 0, var_hostname, var_ns1);
CALL MetalCPanel.spInsertZoneRecord(int_zone_id, 'NS', 0, var_hostname, var_ns2);
CALL MetalCPanel.spInsertZoneRecord(int_zone_id, 'MX', 10, var_hostname, var_mail);
CALL MetalCPanel.spInsertZoneRecord(int_zone_id, 'A', 0, 'mail', var_mail_ip);
CALL MetalCPanel.spInsertZoneRecord(int_zone_id, 'A', 0, 'pop', var_mail_ip);
CALL MetalCPanel.spInsertZoneRecord(int_zone_id, 'A', 0, 'smtp', var_mail_ip);
CALL MetalCPanel.spInsertZoneRecord(int_zone_id, 'A', 0, 'mysql', var_mysql_ip);
CALL MetalCPanel.spInsertZoneRecord(int_zone_id, 'A', 0, 'www', var_www_ip);

END
*************************************************************************
CREATE DEFINER=`vpsmetal`@`%` PROCEDURE `spInsertZoneRecord`(
IN int_zone_id INT(11),
IN var_record_type varchar(25),
IN int_mail_priority INT(11),
IN var_hostname varchar(75),
IN var_hostname_ip varchar(75)
)
BEGIN

IF int_mail_priority = 0 THEN SET int_mail_priority = NULL; END IF;

INSERT INTO zone_records (zone_id, record_type, mail_priority, hostname, hostname_ip)
VALUES (int_zone_id, var_record_type, int_mail_priority, var_hostname, var_hostname_ip);

END
*************************************************************************

Options: ReplyQuote


Subject
Views
Written By
Posted
Stored Procedure Insert executing twice??????
3435
July 19, 2015 07:32PM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.