Bug #40202 Editing stored procedure / function or view can result in unintentional move
Submitted: 21 Oct 2008 11:25 Modified: 16 Apr 2009 12:28
Reporter: Serdar S. Kacar Email Updates:
Status: Duplicate Impact on me:
None 
Category:MySQL Query Browser Severity:S3 (Non-critical)
Version:1.2.12, 1.2.13 OS:Any
Assigned to: CPU Architecture:Any
Tags: Edit Function, Edit Procedure, Edit View

[21 Oct 2008 11:25] Serdar S. Kacar
Description:
Database name is missing in CREATE {View/Procedure/Function} statements that are automatically generated while editing those objects. 

If you change the database (e.g. for a brief lookup of a table metadata) and later execute the generated script, your object would be dropped from its original database and created in the new one.

Note that, in a common usage scenerio, moving object among databases is not the most frequent intention - while changing the code of the object is.

How to repeat:
In MQB, create a stored procedure object `spx` in the `test` database. Right click it and click Edit Procedure. Script will read similar to the following :

DELIMITER $$

DROP PROCEDURE IF EXISTS `test`.`spx` $$
CREATE DEFINER=`root`@`localhost` PROCEDURE `spx`()
BEGIN

END $$

DELIMITER ;

Note that database name is specified in the DROP statement but not in the CREATE statement.

Now double click `mysql` database in Schemata tab. So mysql becomes bold (i.e. in USE).

Then execute `spx` edit script.

Observe that `spx` is moved from `test` database to `mysql`.

Suggested fix:
Add database names to the CREATE statements that are generated upon Edit commands.
[21 Oct 2008 11:37] Valeriy Kravchuk
Thank you for a bug report. Verified just as described.
[7 Jan 2009 2:42] Jared S
Duplicate of http://bugs.mysql.com/bug.php?id=30465
[16 Apr 2009 12:28] Axel Schwenke
duplicate bug #30465