Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

wrong column names [JDBC356] #398

Closed
firebird-automations opened this issue Jun 3, 2014 · 5 comments
Closed

wrong column names [JDBC356] #398

firebird-automations opened this issue Jun 3, 2014 · 5 comments

Comments

@firebird-automations
Copy link

Submitted by: Roland Keitel (rolli71)

Is related to JDBC162
Duplicates JDBC260

I have a SQL statement with alias names for columns and aggregated columns with alias name.
This is my statement:
select p.personalnr
, p.eintritt1 as eintritt
, p.austritt1 as austritt
, st.jahr, st.monat, http://st.kw
, (st.t1 + st.t2 + st.t3 + st.t4 + st.t5) as wert5
from stunden st
, personal p
where p.personalnr = st.personalnr
and st.jahr = 2014
and st.monat = 3
and (st.t1 + st.t2 + st.t3 + st.t4 + st.t5) is not null

If I get the metadata from JDBC, I get wrong column names.
This is my LOG from my own class:
ar[0]=PERSONALNR; Type:integer; Len:11; {DatabaseType=INTEGER}
ar[1]=EINTRITT1; Type:date; Len:19; {DatabaseType=TIMESTAMP}
ar[2]=AUSTRITT1; Type:date; Len:19; {DatabaseType=TIMESTAMP}
ar[3]=JAHR; Type:integer; Len:6; {DatabaseType=SMALLINT}
ar[4]=MONAT; Type:integer; Len:6; {DatabaseType=SMALLINT}
ar[5]=KW; Type:integer; Len:11; {DatabaseType=INTEGER}
ar[6]=; Type:double; Len:17; {DatabaseType=DOUBLE PRECISION}

The columns 1 and 2 (EINTRITT, AUSTRITT) is wrong and column 6 dont have a name.

Normaly the column names should be:
ar[0]=PERSONALNR
ar[1]=EINTRITT <-- without 1 at the end
ar[2]=AUSTRITT <-- without 1 at the end
ar[3]=JAHR
ar[4]=MONAT
ar[5]=KW
ar[6]=WERT5

I have the same problem if I using BIRT for reporting.

If I use the old JDBC driver jaybird-full-2.1.1 I get the right column names.
At this time I can use the old driver but if anyone update the driver nothing works.

@firebird-automations
Copy link
Author

Commented by: @mrotteveel

This is an intentional change with the ResultSetMetaData that was introduced in Jaybird 2.2.0 to be compliant with the JDBC specification. See the releasenotes: http://www.firebirdsql.org/file/documentation/drivers_documentation/java/2.2.5/release_notes.html#__RefHeading__3644_1575618738 and http://www.firebirdsql.org/file/documentation/drivers_documentation/java/2.2.5/release_notes.html#__RefHeading__3722_2133805793

"FBResultSetMetaData#⁠getcolumnName(int) will now return the original column name (if available) for compliance with the JDBC specification, getColumnLabel(int) will still return the alias (or the column name if no alias is defined). See Compatibility with com.sun.rowset.* for potential problems when using the reference implementation of CachedRowSet.
Jaybird 2.2.1 introduced the connection property columnLabelForName which will revert to the old behavior when set to true. Be aware that the old behavior is not JDBCcompliant."

Historically JDBC wasn't entirely clear on the distinction between name and label, but it has since been clarified.. getColumnName is supposed to return the original column name (if any), if you want the alias then you need to use getColumnLabel (the label is also what you should use when retrieving values from the ResultSet by name).

If you want the old behavior (which is not JDBCcompliant), then you can specify the connection property columnLabelForName=true. I'd strongly advise to fix your code instead of relying on the old and incorrect behavior, and only use the columnLabelForName property if you depend on third-party tools or applications that need the old behavior.

@firebird-automations
Copy link
Author

Modified by: @mrotteveel

Link: This issue is related to JDBC162 [ JDBC162 ]

@firebird-automations
Copy link
Author

Modified by: @mrotteveel

Link: This issue duplicates JDBC260 [ JDBC260 ]

@firebird-automations
Copy link
Author

Commented by: @mrotteveel

Closing as "won't fix" as the behavior is intended, and a workaround is available (see JDBC260)

@firebird-automations
Copy link
Author

Modified by: @mrotteveel

status: Open [ 1 ] => Closed [ 6 ]

resolution: Won't Fix [ 2 ]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants