diff --git a/src/main/java/com/microsoft/sqlserver/jdbc/Geography.java b/src/main/java/com/microsoft/sqlserver/jdbc/Geography.java index 7c9fcaf8a..0790a0691 100644 --- a/src/main/java/com/microsoft/sqlserver/jdbc/Geography.java +++ b/src/main/java/com/microsoft/sqlserver/jdbc/Geography.java @@ -10,7 +10,6 @@ import java.nio.ByteBuffer; import java.nio.ByteOrder; -import java.util.Locale; public class Geography extends SQLServerSpatialDatatype { diff --git a/src/main/java/com/microsoft/sqlserver/jdbc/Geometry.java b/src/main/java/com/microsoft/sqlserver/jdbc/Geometry.java index 5966d5fe9..90f4427a5 100644 --- a/src/main/java/com/microsoft/sqlserver/jdbc/Geometry.java +++ b/src/main/java/com/microsoft/sqlserver/jdbc/Geometry.java @@ -10,7 +10,6 @@ import java.nio.ByteBuffer; import java.nio.ByteOrder; -import java.util.Locale; public class Geometry extends SQLServerSpatialDatatype { diff --git a/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerResultSetMetaData.java b/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerResultSetMetaData.java index 93de065ee..66e801a23 100644 --- a/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerResultSetMetaData.java +++ b/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerResultSetMetaData.java @@ -121,14 +121,21 @@ public int getColumnType(int column) throws SQLServerException { } JDBCType jdbcType = typeInfo.getSSType().getJDBCType(); + SSType sqlType = typeInfo.getSSType(); // in bulkcopy for instance, we need to return the real jdbc type which is sql variant and not the default Char one. - if ( SSType.SQL_VARIANT == typeInfo.getSSType()){ + if ( SSType.SQL_VARIANT == sqlType){ jdbcType = JDBCType.SQL_VARIANT; } + if (SSType.UDT == sqlType) { + if (typeInfo.getSSTypeName().equalsIgnoreCase(SSType.GEOMETRY.name())) { + jdbcType = JDBCType.GEOMETRY; + } + if (typeInfo.getSSTypeName().equalsIgnoreCase(SSType.GEOGRAPHY.name())) { + jdbcType = JDBCType.GEOGRAPHY; + } + } int r = jdbcType.asJavaSqlType(); if (con.isKatmaiOrLater()) { - SSType sqlType = typeInfo.getSSType(); - switch (sqlType) { case VARCHARMAX: r = SSType.VARCHAR.getJDBCType().asJavaSqlType(); diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/datatypes/SQLServerSpatialDatatypeTest.java b/src/test/java/com/microsoft/sqlserver/jdbc/datatypes/SQLServerSpatialDatatypeTest.java index 28bd072db..71c2b68e3 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/datatypes/SQLServerSpatialDatatypeTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/datatypes/SQLServerSpatialDatatypeTest.java @@ -11,6 +11,8 @@ import java.io.IOException; import java.sql.DriverManager; +import java.sql.ParameterMetaData; +import java.sql.ResultSetMetaData; import java.sql.SQLException; import java.sql.Statement; import java.util.ArrayList; @@ -817,6 +819,43 @@ public void testSTAsBinary() throws SQLException { assertEquals(geomWKB, geomWKB2); assertEquals(geogWKB, geogWKB2); } + + public void testCheckGeomMetaData() throws SQLException { + beforeEachSetup(); + + pstmt = (SQLServerPreparedStatement) connection.prepareStatement("INSERT INTO " + geomTableName +" (c1) VALUES (?)"); + ParameterMetaData paramMetaData = pstmt.getParameterMetaData(); + Geometry g = Geometry.STGeomFromText("POINT (1 2 3 4)", 0); + pstmt.setGeometry(1, g); + pstmt.execute(); + + int sqlType = paramMetaData.getParameterType(1); + String sqlTypeName = paramMetaData.getParameterTypeName(1); + assertEquals(sqlType, -157); + assertEquals(sqlTypeName, "geometry"); + SQLServerResultSet rs = (SQLServerResultSet) stmt.executeQuery("select * from " + geomTableName); + ResultSetMetaData rsmd = rs.getMetaData(); + assertEquals(rsmd.getColumnType(1), -157); + } + + @Test + public void testCheckGeogMetaData() throws SQLException { + beforeEachSetup(); + + pstmt = (SQLServerPreparedStatement) connection.prepareStatement("INSERT INTO " + geogTableName +" (c1) VALUES (?)"); + ParameterMetaData paramMetaData = pstmt.getParameterMetaData(); + Geography g = Geography.STGeomFromText("POINT (1 2 3 4)", 4326); + pstmt.setGeography(1, g); + pstmt.execute(); + + int sqlType = paramMetaData.getParameterType(1); + String sqlTypeName = paramMetaData.getParameterTypeName(1); + assertEquals(sqlType, -158); + assertEquals(sqlTypeName, "geography"); + SQLServerResultSet rs = (SQLServerResultSet) stmt.executeQuery("select * from " + geogTableName); + ResultSetMetaData rsmd = rs.getMetaData(); + assertEquals(rsmd.getColumnType(1), -158); + } private void beforeEachSetup() throws SQLException { Utils.dropTableIfExists(geomTableName, stmt);