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

655 Fix to return correct column type for spatial datatypes #657

Merged
merged 5 commits into from
Mar 23, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion src/main/java/com/microsoft/sqlserver/jdbc/Geography.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@

import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.util.Locale;

public class Geography extends SQLServerSpatialDatatype {

Expand Down
1 change: 0 additions & 1 deletion src/main/java/com/microsoft/sqlserver/jdbc/Geometry.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@

import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.util.Locale;

public class Geometry extends SQLServerSpatialDatatype {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down