Skip to content

Commit

Permalink
Prepend jdbc: to DatabaseMetaData.getURL result
Browse files Browse the repository at this point in the history
Fixed the PrestoDatabaseMetaData implementation of the getURL method to
include the jdbc: prefix in the resulting URL. A JDBC URL always starts with jdbc:.

Added an unit and a product test to verify that the database connection URL starts with the expected jdbc: prefix.
  • Loading branch information
misterjpapa authored and tdcmeehan committed Aug 7, 2024
1 parent fb100f3 commit 6e4896d
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
public class PrestoDatabaseMetaData
implements DatabaseMetaData
{
private static final String JDBC_URL_START = "jdbc:";
private static final String SEARCH_STRING_ESCAPE = "\\";

private final PrestoConnection connection;
Expand Down Expand Up @@ -60,7 +61,7 @@ public boolean allTablesAreSelectable()
public String getURL()
throws SQLException
{
return connection.getURI().toString();
return JDBC_URL_START + connection.getURI().toString();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,14 @@ public void testGetClientInfoProperties()
}
}

@Test
public void testGetUrl()
throws Exception
{
DatabaseMetaData metaData = connection.getMetaData();
assertEquals(metaData.getURL(), "jdbc:presto://" + server.getAddress());
}

private static void assertColumnSpec(ResultSet rs, int dataType, Long precision, Long numPrecRadix, String typeName)
throws SQLException
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,17 @@ public void testDeallocate()
}
}

@Test(groups = JDBC)
@Requires(ImmutableNationTable.class)
public void testMetaDataGetURL()
throws SQLException
{
DatabaseMetaData metaData = metaData();
String url = metaData.getURL();
assertThat(url).startsWith("jdbc:presto://");
assertThat(url).isEqualTo(prestoJdbcURL);
}

private QueryResult queryResult(Statement statement, String query)
throws SQLException
{
Expand Down

0 comments on commit 6e4896d

Please sign in to comment.