Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 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
Original file line number Diff line number Diff line change
Expand Up @@ -1484,7 +1484,11 @@ void readPointWkt() throws SQLServerException {

while (currentWktPos < wkt.length()
&& (Character.isDigit(wkt.charAt(currentWktPos)) || wkt.charAt(currentWktPos) == '.'
|| wkt.charAt(currentWktPos) == 'E' || wkt.charAt(currentWktPos) == 'e')) {
|| wkt.charAt(currentWktPos) == 'E' || wkt.charAt(currentWktPos) == 'e'
|| ((wkt.charAt(currentWktPos) == '-' || wkt.charAt(currentWktPos) == '+')
&& currentWktPos > startPos
&& (wkt.charAt(currentWktPos - 1) == 'E'
|| wkt.charAt(currentWktPos - 1) == 'e')))) {
currentWktPos++;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2122,6 +2122,53 @@ public void testLargeCases() throws SQLException {
}
}

/**
* Tests Geography almost zero coordinates like 0.0001234. The string representation is "1.234E-4", which
* caused a bug when creating a Geography object.
*/
@Test
public void testGeographySmallCoordinates() throws SQLException {
// Test 1: Positive small latitude (original test case)
Geography g1 = Geography.point(0.0001234, 1.234, 4326);
assertEquals(0.0001234, g1.getLatitude(), 1e-10);
assertEquals(1.234, g1.getLongitude(), 1e-10);

// Test 2: Negative small latitude (tests both leading minus and exponent minus)
Geography g2 = Geography.point(-0.0001234, 1.234, 4326);
assertEquals(-0.0001234, g2.getLatitude(), 1e-10);
assertEquals(1.234, g2.getLongitude(), 1e-10);

// Test 3: Small longitude
Geography g3 = Geography.point(45.678, 0.0001234, 4326);
assertEquals(45.678, g3.getLatitude(), 1e-10);
assertEquals(0.0001234, g3.getLongitude(), 1e-10);

// Test 4: Negative small longitude
Geography g4 = Geography.point(45.678, -0.0001234, 4326);
assertEquals(45.678, g4.getLatitude(), 1e-10);
assertEquals(-0.0001234, g4.getLongitude(), 1e-10);

// Test 5: Both coordinates small
Geography g5 = Geography.point(0.0001234, 0.0005678, 4326);
assertEquals(0.0001234, g5.getLatitude(), 1e-10);
assertEquals(0.0005678, g5.getLongitude(), 1e-10);

// Test 6: Very small value (more extreme scientific notation)
Geography g6 = Geography.point(0.00000001234, 90.0, 4326);
assertEquals(0.00000001234, g6.getLatitude(), 1e-15);
assertEquals(90.0, g6.getLongitude(), 1e-10);

// Test 7: Both negative and small
Geography g7 = Geography.point(-0.0001234, -0.0005678, 4326);
assertEquals(-0.0001234, g7.getLatitude(), 1e-10);
assertEquals(-0.0005678, g7.getLongitude(), 1e-10);

// Test 8: Test with Geometry type as well (note: Geometry uses x,y not lat,lon)
Geometry geom = Geometry.point(1.234, 0.0001234, 0);
assertEquals(1.234, geom.getX(), 1e-10);
assertEquals(0.0001234, geom.getY(), 1e-10);
}

private void beforeEachSetup() throws SQLException {
try (Statement stmt = connection.createStatement()) {
TestUtils.dropTableIfExists(AbstractSQLGenerator.escapeIdentifier(geomTableName), stmt);
Expand Down
Loading