Bug #80618 Forard Engineered DB Script for table with virtual field has syntax error
Submitted: 4 Mar 2016 15:08 Modified: 16 May 2016 23:15
Reporter: Matt Waples Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Workbench: Modeling Severity:S3 (Non-critical)
Version:6.3.6 OS:Windows (Microsoft Windows 10 Pro)
Assigned to: CPU Architecture:Any
Tags: WBBugReporter

[4 Mar 2016 15:08] Matt Waples
Description:
The SQL generated by forward engineering a table with a virtual column omits a required space:
- Expected:  "...VIRTUAL COMMENT..."
- Generated: "...VIRTUALCOMMENT..."

... This is a syntax error and so the script won't work without being manually edited every time.

Here's the SQL generated from my table (see line 12):
CREATE TABLE IF NOT EXISTS `QTM_UTF8`.`Resource` (
  `ID` BINARY(16) NOT NULL,
  `ResourceTypeID` BINARY(16) NOT NULL,
  `Name` NVARCHAR(255) NULL,
  `Description` MEDIUMTEXT NULL,
  `ScopeID` BINARY(16) NULL,
  `ResourceStateID` INT NOT NULL DEFAULT 1,
  `DateCreated` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP,
  `DateModified` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  `CreatedBy` BINARY(16) NULL,
  `ModifiedBy` BINARY(16) NULL,
  `StrID` VARCHAR(36) GENERATED ALWAYS AS (insert(insert(insert(insert(ID,9,0,'-'),14,0,'-'),19,0,'-'),24,0,'-')) VIRTUALCOMMENT 'insert(insert(insert(insert(hex(id_bin),9,0,\'-\'),14,0,\'-\'),19,0,\'-\'),24,0,\'-\')',
  PRIMARY KEY (`ID`),
  INDEX `fk_Resource_ResourceType_idx` (`ResourceTypeID` ASC),
  INDEX `fk_Resource_Resource1_idx` (`ScopeID` ASC),
  INDEX `fk_Resource_ResourceState1_idx` (`ResourceStateID` ASC),
  CONSTRAINT `fk_Resource_ResourceType`
    FOREIGN KEY (`ResourceTypeID`)
    REFERENCES `QTM_UTF8`.`ResourceType` (`ID`)
    ON DELETE NO ACTION
    ON UPDATE NO ACTION,
  CONSTRAINT `fk_Resource_Resource1`
    FOREIGN KEY (`ScopeID`)
    REFERENCES `QTM_UTF8`.`Resource` (`ID`)
    ON DELETE NO ACTION
    ON UPDATE NO ACTION,
  CONSTRAINT `fk_Resource_ResourceState1`
    FOREIGN KEY (`ResourceStateID`)
    REFERENCES `QTM_UTF8`.`ResourceState` (`ID`)
    ON DELETE NO ACTION
    ON UPDATE NO ACTION)
ENGINE = InnoDB

How to repeat:
In Workbench
1. create a table with a virtual field through the visual modeler
2. Right click on the table, copy the SQL
3. Paste in a query window
4. Try and run it!

Suggested fix:
Just need to add a space character...
[5 Mar 2016 5:44] MySQL Verification Team
Hello Matt Waples,

Thank you for the report.

Thanks,
Umesh
[5 Mar 2016 5:44] MySQL Verification Team
Sample model file to trigger the issue

Attachment: 80618.mwb (application/octet-stream, text), 6.19 KiB.

[17 Mar 2016 14:27] Mike Lischke
Bug #80764 was marked as duplicate of this bug.
[16 May 2016 23:15] Philip Olson
Posted by developer:
 
Fixed as of the upcoming MySQL Workbench 6.3.7 release, and here's the changelog entry:

The generated SQL generated by the forward engineering wizard would
incorrectly output "VIRTUALCOMMENT" instead of "VIRTUAL COMMENT".

Thank you for the bug report.