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

Rainer Döbele commented on EMPIREDB-209:
----------------------------------------

You are right, that quoting of an alias for reserved keywords has not yet been 
implemented.
However I am not sure, whether we need to create a new method in 
DBDatabaseDriver.
Wouldn't the following change to DBAliasExpr do the job:

    public void addSQL(StringBuilder buf, long context)
    { // Append alias
        if((context & CTX_ALIAS)!=0)
        {   // Add the column expression
            expr.addSQL(buf, context);
            // Rename
            DBDatabaseDriver driver = getDatabase().getDriver();
            String asExpr = 
driver.getSQLPhrase(DBDatabaseDriver.SQL_RENAME_COLUMN);
            if (asExpr!=null)
            {
                buf.append(asExpr);
                driver.appendElementName(buf, alias);
            }
        } 
        else
        {
            expr.addSQL(buf, context);
        }
    }

If I missed something then you may create a patch file and append it to this 
issue. I will then have a closer look at it.
If my suggestion works, please let me know and I will submit the change.

Regards
Rainer


> Using a reserved word as a column alias in a select statement.
> --------------------------------------------------------------
>
>                 Key: EMPIREDB-209
>                 URL: https://issues.apache.org/jira/browse/EMPIREDB-209
>             Project: Empire-DB
>          Issue Type: New Feature
>          Components: Core
>    Affects Versions: empire-db-2.4.2
>            Reporter: Shaun Forbes
>            Priority: Minor
>              Labels: newbie
>
> I believe it's possible in sql to use a reserved word as an alias in a select 
> statement if it's correctly quoted (it is for the databases I've tested 
> anyway).
> Checking for and quoting reserved word aliases does not currently appear to 
> be implemented.
> To overcome this limitation I've added an method to the DBDatabaseDriver 
> class to add the alias and perform any required quoting and altered the 
> DBAliasExpr class to delegate the adding of the alias to the DBDatabaseDriver 
> class.
> The character I'm using for quoting is determined from the 
> getIdentifierQuoteString() method of the database connection metadata class, 
> and I've used the detectQuoteName(String name) method in DBDatabaseDriver to 
> determine if the alias needs to be quoted.
> Patches available if required.



--
This message was sent by Atlassian JIRA
(v6.2#6252)

Reply via email to