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

[QUESTION] How differentiate max and non-max types in ResultSet #1496

Open
tormodatt opened this issue Jan 7, 2021 · 2 comments
Open

[QUESTION] How differentiate max and non-max types in ResultSet #1496

tormodatt opened this issue Jan 7, 2021 · 2 comments
Labels
Question Used when a question is asked, as opposed to an issue being raised

Comments

@tormodatt
Copy link

Question

From JDBC-spec:

    /**
     * Retrieves the designated column's SQL type.
...
     * @return SQL type from java.sql.Types
...
     */
    int getColumnType(int column) throws SQLException;

For columns of type charchar(max) I would then expect this to return -1 (java.sql.Types.LONGVARCHAR), but it returns 12 (java.sql.Types.VARCHAR). I debugged a little bit, and found that this is caused by this switch-case:

https://github.com/microsoft/mssql-jdbc/blob/master/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerResultSetMetaData.java#L138

r = -1 before that switch-case (which is what I would want).

The comment here gives a pointer to why this is done:

    // under Katmai map the max types to non max to be inline with DBMD.

https://github.com/microsoft/mssql-jdbc/blob/master/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerResultSetMetaData.java#L112

I guess DBMD is DatabaseMetaData, but still don't understand why this is done this way.

I can't find any other way to derminine whether a column in a resultset is varchar or longvarchar.

Same goes for the other max-types I guess.

I reason I ask this question is that I'm trying to do .getClob when the coloumn is varchar(max), and .getString if it's a normal varchar.

Relevant Issues and Pull Requests

I couldn't find any issues related to this.

@tormodatt tormodatt added the Question Used when a question is asked, as opposed to an issue being raised label Jan 7, 2021
@tormodatt tormodatt changed the title [QUESTION] How differantiate max and non-max types in ResultSet [QUESTION] How differentiate max and non-max types in ResultSet Jan 7, 2021
@rene-ye
Copy link
Member

rene-ye commented Jan 7, 2021

I believe the longvarchar datatype no longer exists in "newer" versions of SQL Server, it's been replaced with varchar(max).

From the documentation: "The SQL Server text and ntext types map to the JDBC LONGVARCHAR and LONGNVARCHAR type, respectively. These are deprecated types beginning in SQL Server 2005 (9.x), so you should use large value types, varchar(max) or nvarchar(max), instead."

@tormodatt
Copy link
Author

Yeah, but that is on SQL Server level, and not on JDBC level right?

According to this table, varchar(max) should map to JDBC LONGVARCHAR: https://docs.microsoft.com/en-us/sql/connect/jdbc/using-advanced-data-types?view=sql-server-ver15#remarks

@github-project-automation github-project-automation bot moved this to To be triaged in MSSQL JDBC Aug 28, 2024
@Jeffery-Wasty Jeffery-Wasty moved this from To be triaged to Backlog in MSSQL JDBC Aug 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Question Used when a question is asked, as opposed to an issue being raised
Projects
Status: Backlog
Development

No branches or pull requests

2 participants