Skip to content

Commit

Permalink
Revert "Fix Geography.point method (#853)"
Browse files Browse the repository at this point in the history
This reverts commit 123abb0.
  • Loading branch information
ulvii authored Nov 30, 2018
1 parent e6b63d5 commit b48a76e
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 57 deletions.
6 changes: 0 additions & 6 deletions src/main/java/com/microsoft/sqlserver/jdbc/DDC.java
Original file line number Diff line number Diff line change
Expand Up @@ -596,14 +596,8 @@ static final Object convertStreamToObject(BaseInputStream stream, TypeInfo typeI
if (JDBCType.GUID == jdbcType) {
return Util.readGUID(byteValue);
} else if (JDBCType.GEOMETRY == jdbcType) {
if (!typeInfo.getSSTypeName().equalsIgnoreCase(jdbcType.toString())) {
DataTypes.throwConversionError(typeInfo.getSSTypeName().toUpperCase(), jdbcType.toString());
}
return Geometry.STGeomFromWKB(byteValue);
} else if (JDBCType.GEOGRAPHY == jdbcType) {
if (!typeInfo.getSSTypeName().equalsIgnoreCase(jdbcType.toString())) {
DataTypes.throwConversionError(typeInfo.getSSTypeName().toUpperCase(), jdbcType.toString());
}
return Geography.STGeomFromWKB(byteValue);
} else {
String hexString = Util.bytesToHexString(byteValue, byteValue.length);
Expand Down
10 changes: 5 additions & 5 deletions src/main/java/com/microsoft/sqlserver/jdbc/Geography.java
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ public static Geography parse(String wkt) throws SQLServerException {
* if an exception occurs
*/
public static Geography point(double lat, double lon, int srid) throws SQLServerException {
return new Geography("POINT (" + lon + " " + lat + ")", srid);
return new Geography("POINT (" + lat + " " + lon + ")", srid);
}

/**
Expand Down Expand Up @@ -212,8 +212,8 @@ public boolean hasZ() {
* @return double value that represents the latitude.
*/
public Double getLatitude() {
if (null != internalType && internalType == InternalSpatialDatatype.POINT && yValues.length == 1) {
return yValues[0];
if (null != internalType && internalType == InternalSpatialDatatype.POINT && xValues.length == 1) {
return xValues[0];
}
return null;
}
Expand All @@ -224,8 +224,8 @@ public Double getLatitude() {
* @return double value that represents the longitude.
*/
public Double getLongitude() {
if (null != internalType && internalType == InternalSpatialDatatype.POINT && xValues.length == 1) {
return xValues[0];
if (null != internalType && internalType == InternalSpatialDatatype.POINT && yValues.length == 1) {
return yValues[0];
}
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
*/
package com.microsoft.sqlserver.jdbc.datatypes;

import static org.junit.Assert.fail;
import static org.junit.jupiter.api.Assertions.assertEquals;

import java.io.IOException;
Expand Down Expand Up @@ -813,7 +812,7 @@ public void testPoint() throws SQLException {
String geoWKT = "POINT(1 2)";

Geometry geomWKT = Geometry.point(1, 2, 0);
Geography geogWKT = Geography.point(2, 1, 4326);
Geography geogWKT = Geography.point(1, 2, 4326);

try (Connection con = (SQLServerConnection) DriverManager.getConnection(connectionString);
Statement stmt = con.createStatement()) {
Expand Down Expand Up @@ -969,8 +968,8 @@ public void testGetXGetY() throws SQLException {

x = geog.getLatitude();
y = geog.getLongitude();
assertEquals(x, 2);
assertEquals(y, 1);
assertEquals(x, 1);
assertEquals(y, 2);
}

@Test
Expand Down Expand Up @@ -1042,48 +1041,6 @@ public void testNull() throws SQLException {
}
}
}

@Test
public void testWrongtype() throws SQLException {
beforeEachSetup();

Geometry geomWKT = Geometry.point(1, 2, 0);
Geography geogWKT = Geography.point(2, 1, 4326);

try (Connection con = (SQLServerConnection) DriverManager.getConnection(connectionString);
Statement stmt = con.createStatement()) {

try (SQLServerPreparedStatement pstmt = (SQLServerPreparedStatement) con.prepareStatement(
"insert into " + AbstractSQLGenerator.escapeIdentifier(geomTableName) + " values (?)");) {
pstmt.setGeometry(1, geomWKT);
pstmt.execute();

try {
SQLServerResultSet rs = (SQLServerResultSet) stmt.executeQuery("select * from " + AbstractSQLGenerator.escapeIdentifier(geomTableName));
rs.next();
rs.getGeography(1); // should fail
fail();
} catch (SQLServerException e) {
assertEquals(e.getMessage(), "The conversion from GEOMETRY to GEOGRAPHY is unsupported.");
}
}

try (SQLServerPreparedStatement pstmt = (SQLServerPreparedStatement) con.prepareStatement(
"insert into " + AbstractSQLGenerator.escapeIdentifier(geogTableName) + " values (?)");) {
pstmt.setGeography(1, geogWKT);
pstmt.execute();

try {
SQLServerResultSet rs = (SQLServerResultSet) stmt.executeQuery("select * from " + AbstractSQLGenerator.escapeIdentifier(geogTableName));
rs.next();
rs.getGeometry(1); // should fail
fail();
} catch (SQLServerException e) {
assertEquals(e.getMessage(), "The conversion from GEOGRAPHY to GEOMETRY is unsupported.");
}
}
}
}

private void beforeEachSetup() throws SQLException {
try (Connection con = (SQLServerConnection) DriverManager.getConnection(connectionString);
Expand Down

0 comments on commit b48a76e

Please sign in to comment.