[ 
https://issues.apache.org/jira/browse/EMPIREDB-250?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15707938#comment-15707938
 ] 

jan commented on EMPIREDB-250:
------------------------------

DBDDLGenerator.createView uses cmd.addSQL to add the SELECT of a command to the 
view definition. DBCommandExpr.addSQL adds the parentheses (wich are always 
optional for view declaration IMO).

My solution is to override createView in MySQLDDLGenerator, copy the code from 
DBDDLGenerator but change one thing:

 if (cmd instanceof DBCombinedCmd)
{
        sql.append(cmd.getSelect());
} else
{
        cmd.addSQL( sql, DBExpr.CTX_DEFAULT);
}

A better solution would be appreciated, but it works for now.

(added in commit 6e14aae470353760099bec6c9e6ce6fc9ba4a52c)

> DBDDLGenerator generates wrong SQL for Views with DBCombinedCmd
> ---------------------------------------------------------------
>
>                 Key: EMPIREDB-250
>                 URL: https://issues.apache.org/jira/browse/EMPIREDB-250
>             Project: Empire-DB
>          Issue Type: Bug
>          Components: Core
>    Affects Versions: empire-db-2.4.5
>            Reporter: jan
>            Assignee: jan
>            Priority: Critical
>             Fix For: empire-db-2.4.6
>
>
> When you declare a view like
> @Override
> public DBCommandExpr createCommand() {
>       
>       TTable1 T1 = db.T_ONE;
>       TTable2 T2 = db.T_TWO;
>       DBCommand c1 = db.createCommand();
>       c1.select(T1.ID);
>       DBCommand c2 = db.createCommand();
>       c2.select(T2.ID);
>       return t1.union(t2);
>       
> }
> which results in
> CREATE VIEW v1 (ID)
> AS
> ((SELECT t3.ID
> FROM TABLE1 t3)
> UNION
> (SELECT t4.ID
> FROM TABLE2 t4));
> if you run this command on MySQL (or MariaDB) you get ERROR 1064, because its 
> not valid. 
> Whyever MySQL/MariaDB does not like the double (( )). Running that statement 
> without creating the view works.



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Reply via email to