Skip to content

Commit

Permalink
feat: Show all catalogs. [metadata]
Browse files Browse the repository at this point in the history
Closes #461.

Signed-off-by: Michael Simons <[email protected]>
  • Loading branch information
michael-simons committed Jan 9, 2025
1 parent 34bbb15 commit d6b2183
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1211,6 +1211,18 @@ void primaryKeysWithMoreThanOneColumn() throws SQLException, IOException {
assertThat(primaryKeys.next()).isFalse();
}

@Test
void getCatalogsShouldWork() throws SQLException {

var catalogs = new ArrayList<String>();
try (var rs = this.connection.getMetaData().getCatalogs()) {
while (rs.next()) {
catalogs.add(rs.getString("TABLE_CAT"));
}
}
assertThat(catalogs).containsExactly("neo4j", "system");
}

record IndexInfo(String tableName, boolean nonUnique, String indexName, int type, int ordinalPosition,
String columnName, String ascOrDesc) {
IndexInfo(ResultSet resultset) throws SQLException {
Expand Down
12 changes: 2 additions & 10 deletions neo4j-jdbc/src/main/java/org/neo4j/jdbc/DatabaseMetadataImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -492,7 +492,7 @@ public String getProcedureTerm() {

@Override
public String getCatalogTerm() {
return "catalog";
return "database";
}

@Override
Expand Down Expand Up @@ -830,18 +830,10 @@ public ResultSet getTables(String catalog, String schemaPattern, String tableNam
return doQueryForResultSet(request);
}

/***
* Returns an empty Result set as there cannot be Catalogs in neo4j.
* @return all catalogs
*/
@Override
public ResultSet getCatalogs() throws SQLException {
var keys = new ArrayList<String>();
keys.add("TABLE_CAT");

var response = createRunResponseForStaticKeys(keys);
var pull = staticPullResponseFor(keys, List.<Value[]>of(new Value[] { Values.value(getSingleCatalog()) }));
return new ResultSetImpl(new LocalStatementImpl(), new ThrowingTransactionImpl(), response, pull, -1, -1, -1);
return doQueryForResultSet(getRequest("getCatalogs"));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -215,3 +215,5 @@ RETURN toInteger(value)
getPrimaryKeys=SHOW CONSTRAINTS YIELD name, labelsOrTypes, properties \
WHERE ANY (v IN labelsOrTypes WHERE v = $name) \
RETURN *

getCatalogs=SHOW DATABASES YIELD name AS TABLE_CAT ORDER BY TABLE_CAT
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,20 @@ void getAllTablesShouldErrorIfYouPassCatalog() throws SQLException {
"Catalog 'NotNull' is not available in this Neo4j instance, please leave blank or specify the current database name");
}

@Test
void getCatalogTermShouldWork() throws SQLException {

var connection = newConnection();
assertThat(connection.getMetaData().getCatalogTerm()).isEqualTo("database");
}

@Test
void getCatalogSeparatorShouldWork() throws SQLException {

var connection = newConnection();
assertThat(connection.getMetaData().getCatalogSeparator()).isEqualTo(".");
}

private Connection newConnection() throws SQLException {
var url = "jdbc:neo4j://host";

Expand Down

0 comments on commit d6b2183

Please sign in to comment.