Bug #58117 Forward Engineered SQL create DELIMITER and USE statements on the same line
Submitted: 10 Nov 2010 16:06 Modified: 7 Mar 2011 16:40
Reporter: Andrew Bywater Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Workbench: Modeling Severity:S3 (Non-critical)
Version:5.2.29, 5.2.30, 5.2.31 OS:Windows (Windows 7 (x64))
Assigned to: Alexander Musienko CPU Architecture:Any

[10 Nov 2010 16:06] Andrew Bywater
Description:
I have a model which has two different schemas each containg stored procedures and tables. When I forward engineer the model, the tables in the second schema are not created.

I tracked this down to the SQL script:

$$

DELIMITER ;USE `Schema2` ;

Placing the USE on a new line and running the script then, solves the problem.

How to repeat:
To reproduce:

Create a new model with two schemas, "schema1" and "schema2"
Add a table to each schema and then add a stored procedure to each schema.

Forward engineer the SQL.

Here is the created SQL.

SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0;
SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0;
SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='TRADITIONAL';

CREATE SCHEMA IF NOT EXISTS `schema1` DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci ;
CREATE SCHEMA IF NOT EXISTS `schema2` DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci ;
USE `schema1` ;

-- -----------------------------------------------------
-- Table `schema1`.`table1`
-- -----------------------------------------------------
CREATE  TABLE IF NOT EXISTS `schema1`.`table1` (
)
ENGINE = InnoDB;

-- -----------------------------------------------------
-- procedure routine1
-- -----------------------------------------------------

DELIMITER $$
USE `schema1`$$
CREATE PROCEDURE `schema1`.`routine1` ()
BEGIN

END
$$

DELIMITER ;USE `schema2` ;

-- -----------------------------------------------------
-- Table `schema2`.`table1`
-- -----------------------------------------------------
CREATE  TABLE IF NOT EXISTS `schema2`.`table1` (
)
ENGINE = InnoDB;

-- -----------------------------------------------------
--  routine1
-- -----------------------------------------------------

DELIMITER $$
USE `schema2`$$
CREATE PROCEDURE `schema2`.`routine1` ()
BEGIN

END$$

DELIMITER ;

SET SQL_MODE=@OLD_SQL_MODE;
SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS;
SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS;
[23 Nov 2010 15:18] MySQL Verification Team
Thank you for the bug report.
[13 Dec 2010 19:45] Valeriy Kravchuk
Bug #58894 was marked as a duplicate of this one.
[3 Mar 2011 13:39] Johannes Taxacher
fix confirmed in repository
[7 Mar 2011 16:40] Tony Bedford
An entry has been added to the 5.2.32 changelog: 

        Forward engineering a model containing two schema resulted in a 
        generated script that contained incorrect SQL: 

DELIMITER ;USE `Schema2` ;      	

        The <literal>DELIMITER</literal> and <literal>USE</literal> 
        statements should not have appeared on the same line.