#65 new
alain dazzi

cannot execute a stored procedure inside migration

Reported by alain dazzi | 2012-03-07 23:46:47 UTC | in BACKLOG

I have the following stored procedure which works when executed by hand.

-- coding:utf-8 --

SQL_UP = u"""

DELIMITER $$
DROP PROCEDURE IF EXISTS DropFK $$
CREATE PROCEDURE DropFK (
IN parm_table_name VARCHAR(100),
IN parm_key_name VARCHAR(100)

) BEGIN
-- Verify the foreign key exists IF EXISTS (SELECT NULL FROM information_schema.TABLE_CONSTRAINTS WHERE CONSTRAINT_SCHEMA = DATABASE() AND CONSTRAINT_NAME = parm_key_name) THEN
-- Turn the parameters into local variables set @ParmTable = parm_table_name ;
set @ParmKey = parm_key_name ;
-- Create the full statement to execute set @StatementToExecute = concat('ALTER TABLE ',@ParmTable,' DROP FOREIGN KEY ',@ParmKey);
-- Prepare and execute the statement that was built prepare DynamicStatement from @StatementToExecute ;
execute DynamicStatement ;
-- Cleanup the prepared statement deallocate prepare DynamicStatement ;
END IF;
END $$
DELIMITER ;
"""

SQL_DOWN = u"""
"""

when I put it inside a migration and invoke db-migrate I get ...

~/Desktop/mysql/dbmigrate$ db-migrate

Starting DB migration...
- Current version is: 0 - Destination version is: 20120308020932

Starting migration up!
*** versions: ['20120228235709', '20120308003414', '20120308003950', '20120308004106', '20120308020932']

===== executing 20120228235709_tools.migration (up) ===== ===== ERROR executing /Users/alaindazzi/Desktop/mysql/dbmigrate/migrations/20120228235709_tools.migration (up) ===== [ERROR] error executing migration: (1064, "You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'DELIMITER $$ \nDROP PROCEDURE IF EXISTS DropFK $$ \nCREATE PROCEDURE DropFK ( \nIN ' at line 1")

[ERROR DETAILS] SQL command was: DELIMITER $$
DROP PROCEDURE IF EXISTS DropFK $$
CREATE PROCEDURE DropFK (
IN parm_table_name VARCHAR(100),
IN parm_key_name VARCHAR(100)

) BEGIN
-- Verify the foreign key exists IF EXISTS (SELECT NULL FROM information_schema.TABLE_CONSTRAINTS WHERE CONSTRAINT_SCHEMA = DATABASE() AND CONSTRAINT_NAME = parm_key_name) THEN
-- Turn the parameters into local variables set @ParmTable = parm_table_name

~/Desktop/mysql/dbmigrate$

Is there a workaround for this issue? display the sql show the proper code (--showsqlonly).

No comments found

Please Sign in or create a free account to add a new ticket.

With your very own profile, you can contribute to projects, track your activity, watch tickets, receive and update tickets through your email and much more.

New ticket Create new ticket

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile ยป

simple-db-migrate is a database migration tool inpired on Rails migrations. For more info check the project website: http://guilhermechapiewski.github.com/simple-db-migrate/

People watching this ticket

Pages