Bug #63807 | WB creates incorrect create query when a if using view | ||
---|---|---|---|
Submitted: | 20 Dec 2011 12:05 | Modified: | 6 Jul 2012 5:05 |
Reporter: | Javier Domingo | Email Updates: | |
Status: | Closed | Impact on me: | |
Category: | MySQL Workbench: Modeling | Severity: | S3 (Non-critical) |
Version: | 5.2.36, 5.2.37 | OS: | Any |
Assigned to: | CPU Architecture: | Any |
[20 Dec 2011 12:05]
Javier Domingo
[20 Dec 2011 13:23]
Valeriy Kravchuk
What exact server version, 5.x.y, are you trying to synchronize with? Please, upload simple .mwb file that demonstrates the problem.
[22 Dec 2011 11:57]
Javier Domingo
The idea was that if you use in the select, something that cant be used for creating a table, it will fail the sync. Just because WB creates and drops a table with the view's fields, and then creates the view. Create a model with: CREATE TABLE trying_crash (id INT, active BIT(1)); And then a view that makes some data manipulation between the table and the view CREATE VIEW vi_try AS SELECT trying_crash.id, IF(trying_crash.active,'active','unactive') FROM trying_crash; And when you try to sync it, it will tell you it failed because cant be created a table like this: CREATE TABLE vi_try ( trying_crash.id INT, IF(trying_crash.active,'active','unactive') INT); WB makes a table before creating a view to avoid errors, but doesn't have into account that the syntax for the CREATE TABLE can not be correct although it is for a view.
[27 Dec 2011 12:34]
Valeriy Kravchuk
OK, this is what can happen: Executing SQL script in server ERROR: Error 1059: Identifier name 'if(c1, 'active, very active', 'inactive, very very very inactive')' is too long -- ----------------------------------------------------- -- Placeholder table for view `mydb2`.`view1` -- ----------------------------------------------------- CREATE TABLE IF NOT EXISTS `mydb2`.`view1` (`idtable1` INT, `if(c1, 'active, very active', 'inactive, very very very inactive')` INT) SQL script execution finished: statements: 6 succeeded, 1 failed So, the problem in CREATE TABLE generated may be related to column name used (when it is just long enough expression). Workbench, indeed, should detect this before sending to server and suggest to define alias for columns like this.
[6 Jul 2012 5:05]
Philip Olson
This is fixed as of 5.2.41, and here's the changelog entry: If a view contains a row that is too long to be represented as a table column, it will now be substituted with an alias column in a placeholder table, similar to how 'mysqldump' behaves. Before it could generate invalid SQL, and fail to synchronize the model.