empire-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Shaun Forbes (JIRA)" <empire-db-...@incubator.apache.org>
Subject [jira] [Commented] (EMPIREDB-209) Using a reserved word as a column alias in a select statement.
Date Sun, 24 Aug 2014 03:10:10 GMT

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

Shaun Forbes commented on EMPIREDB-209:

Hey Rainer,

I believe the database metadata method getIdentifierQuoteString() is the method to call to
determine what character to use to quote the alias name (I've never seen anything but ' used
myself, so I'm not 100% sure if this is the correct method).
The driver.appendElementName() uses the identifiers required to quote the column name itself,
so for example in SQL Server
  select order as order from ...
should be 
  select [order] as 'order' from ...
  select [order] as [order] from ...
as I believe your suggestion would generate.

The reason I added the method to the DBDatabaseDriver class rather than the DBAliasExpr class
is because I try to grab the identifier quote value once during the attachDatabase method,
and store it as a variable in the DBDriverClass, then the DBAliasExpr is delegating to the
DBDatabaseDriver class to handle the DB specific logic (i.e. should the alias be quoted) of
adding the alias to the SQL.
I guess it would be just as valid (possible more so, since it'd keep the alias specific logic
in the alias class) to move the decision to the DBAliasExpr class and just have the driver
provide the information required for the alias class to make the decision.
The value for the quote identifier could also be setup as a new SQL phrase I guess, but I
don't know if this is how it's done for values that the database can provide itself, via the
metadata, compared to values that you have to hard code in the db specific driver.
This is why I didn't bother including my code in the initial report, since I'd figured you
guys would have a better understanding of where it should be done as I haven't been using
empire-db for long.


PS. BTW, I believe that at least the SQL Server driver also need to be updated to include
'order' as a reserved word.

> 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

View raw message