Ticket #13 (closed defect: fixed)
Field aliases in where clause doesn't work in MSSQL
| Reported by: | cbradford | Owned by: | dhughes |
|---|---|---|---|
| Type: | defect | Priority: | highest |
| Milestone: | Component: | Reactor Samples - Reactor Blog | |
| Version: | Severity: | minor | |
| Keywords: | alias mssql | Cc: |
Description
I have a field alias defined for a particular table (BookPagesID --> ID), and when Reactor generates the SQL for loading a Record of that type (reactorFactory.createRecord("Page").load(ID=1)), it uses the alias in the where clause. This is the Reactor-generated query:
SELECT [page].[BookPagesID] AS [ID], [page].[Active] AS [Active], [page].[ProjectID] AS [ProjectID], [page].[BookPageTypeID] AS [BookPageTypeID], [page].[PageNum] AS [PageNum], [page].[BackgroundImageID] AS [BackgroundImageID], [page].[BGAlpha] AS [BGAlpha], [page].[SubLayoutCatID] AS [SubLayoutCatID], [page].[TemplateTitle] AS [TemplateTitle], [page].[TemplateImage] AS [TemplateImage] FROM [BookPages] AS [page] WHERE [page].[ID] = (param 1)
MSSQL Server returns an error (it doesn't allow aliases in where clauses):
[Macromedia][SQLServer JDBC Driver][SQLServer]Invalid column name 'ID'.
The same error occurs when running this query in Query Analyzer (substituting in the param value). Changing "WHERE [page].[ID]" to "WHERE [page].[BookPagesID]" works just fine.
For MSSQL, Reactor should use the original column name in all where clauses.

