Search in sources :

Example 86 with DatabaseMetaData

use of java.sql.DatabaseMetaData in project calcite-avatica by apache.

the class MetaResultSetTest method testGetImportedKeys.

@Test
public void testGetImportedKeys() throws SQLException {
    DatabaseMetaData metadata = getDatabaseMetadata();
    try (ResultSet rs = metadata.getImportedKeys(null, null, null)) {
        ResultSetMetaData rsMeta = rs.getMetaData();
        assertEquals(14, rsMeta.getColumnCount());
        assertColumn(rsMeta, 1, "PKTABLE_CAT", Types.VARCHAR, DatabaseMetaData.columnNullable);
        assertColumn(rsMeta, 2, "PKTABLE_SCHEM", Types.VARCHAR, DatabaseMetaData.columnNullable);
        assertColumn(rsMeta, 3, "PKTABLE_NAME", Types.VARCHAR, DatabaseMetaData.columnNoNulls);
        assertColumn(rsMeta, 4, "PKCOLUMN_NAME", Types.VARCHAR, DatabaseMetaData.columnNoNulls);
        assertColumn(rsMeta, 5, "FKTABLE_CAT", Types.VARCHAR, DatabaseMetaData.columnNullable);
        assertColumn(rsMeta, 6, "FKTABLE_SCHEM", Types.VARCHAR, DatabaseMetaData.columnNullable);
        assertColumn(rsMeta, 7, "FKTABLE_NAME", Types.VARCHAR, DatabaseMetaData.columnNoNulls);
        assertColumn(rsMeta, 8, "FKCOLUMN_NAME", Types.VARCHAR, DatabaseMetaData.columnNoNulls);
        assertColumn(rsMeta, 9, "KEY_SEQ", Types.SMALLINT, DatabaseMetaData.columnNoNulls);
        assertColumn(rsMeta, 10, "UPDATE_RULE", Types.SMALLINT, DatabaseMetaData.columnNoNulls);
        assertColumn(rsMeta, 11, "DELETE_RULE", Types.SMALLINT, DatabaseMetaData.columnNoNulls);
        assertColumn(rsMeta, 12, "FK_NAME", Types.VARCHAR, DatabaseMetaData.columnNullable);
        assertColumn(rsMeta, 13, "PK_NAME", Types.VARCHAR, DatabaseMetaData.columnNullable);
        assertColumn(rsMeta, 14, "DEFERABILITY", Types.SMALLINT, DatabaseMetaData.columnNoNulls);
    }
}
Also used : ResultSetMetaData(java.sql.ResultSetMetaData) ResultSet(java.sql.ResultSet) DatabaseMetaData(java.sql.DatabaseMetaData) Test(org.junit.Test)

Example 87 with DatabaseMetaData

use of java.sql.DatabaseMetaData in project calcite-avatica by apache.

the class MetaResultSetTest method testGetPrimaryKeys.

@Test
public void testGetPrimaryKeys() throws SQLException {
    DatabaseMetaData metadata = getDatabaseMetadata();
    try (ResultSet rs = metadata.getPrimaryKeys(null, null, null)) {
        ResultSetMetaData rsMeta = rs.getMetaData();
        assertEquals(6, rsMeta.getColumnCount());
        assertColumn(rsMeta, 1, "TABLE_CAT", Types.VARCHAR, DatabaseMetaData.columnNullable);
        assertColumn(rsMeta, 2, "TABLE_SCHEM", Types.VARCHAR, DatabaseMetaData.columnNullable);
        assertColumn(rsMeta, 3, "TABLE_NAME", Types.VARCHAR, DatabaseMetaData.columnNoNulls);
        assertColumn(rsMeta, 4, "COLUMN_NAME", Types.VARCHAR, DatabaseMetaData.columnNoNulls);
        assertColumn(rsMeta, 5, "KEY_SEQ", Types.SMALLINT, DatabaseMetaData.columnNoNulls);
        assertColumn(rsMeta, 6, "PK_NAME", Types.VARCHAR, DatabaseMetaData.columnNullable);
    }
}
Also used : ResultSetMetaData(java.sql.ResultSetMetaData) ResultSet(java.sql.ResultSet) DatabaseMetaData(java.sql.DatabaseMetaData) Test(org.junit.Test)

Example 88 with DatabaseMetaData

use of java.sql.DatabaseMetaData in project calcite-avatica by apache.

the class MetaResultSetTest method testGetCatalogs.

@Test
public void testGetCatalogs() throws SQLException {
    DatabaseMetaData metadata = getDatabaseMetadata();
    try (ResultSet rs = metadata.getCatalogs()) {
        ResultSetMetaData rsMeta = rs.getMetaData();
        assertEquals(1, rsMeta.getColumnCount());
        assertColumn(rsMeta, 1, "TABLE_CAT", Types.VARCHAR, DatabaseMetaData.columnNoNulls);
    }
}
Also used : ResultSetMetaData(java.sql.ResultSetMetaData) ResultSet(java.sql.ResultSet) DatabaseMetaData(java.sql.DatabaseMetaData) Test(org.junit.Test)

Example 89 with DatabaseMetaData

use of java.sql.DatabaseMetaData in project calcite-avatica by apache.

the class MetaResultSetTest method testGetCrossReference.

@Test
public void testGetCrossReference() throws SQLException {
    DatabaseMetaData metadata = getDatabaseMetadata();
    try (ResultSet rs = metadata.getCrossReference(null, null, null, null, null, null)) {
        ResultSetMetaData rsMeta = rs.getMetaData();
        assertEquals(14, rsMeta.getColumnCount());
        assertColumn(rsMeta, 1, "PKTABLE_CAT", Types.VARCHAR, DatabaseMetaData.columnNullable);
        assertColumn(rsMeta, 2, "PKTABLE_SCHEM", Types.VARCHAR, DatabaseMetaData.columnNullable);
        assertColumn(rsMeta, 3, "PKTABLE_NAME", Types.VARCHAR, DatabaseMetaData.columnNoNulls);
        assertColumn(rsMeta, 4, "PKCOLUMN_NAME", Types.VARCHAR, DatabaseMetaData.columnNoNulls);
        assertColumn(rsMeta, 5, "FKTABLE_CAT", Types.VARCHAR, DatabaseMetaData.columnNullable);
        assertColumn(rsMeta, 6, "FKTABLE_SCHEM", Types.VARCHAR, DatabaseMetaData.columnNullable);
        assertColumn(rsMeta, 7, "FKTABLE_NAME", Types.VARCHAR, DatabaseMetaData.columnNoNulls);
        assertColumn(rsMeta, 8, "FKCOLUMN_NAME", Types.VARCHAR, DatabaseMetaData.columnNoNulls);
        assertColumn(rsMeta, 9, "KEY_SEQ", Types.SMALLINT, DatabaseMetaData.columnNoNulls);
        assertColumn(rsMeta, 10, "UPDATE_RULE", Types.SMALLINT, DatabaseMetaData.columnNoNulls);
        assertColumn(rsMeta, 11, "DELETE_RULE", Types.SMALLINT, DatabaseMetaData.columnNoNulls);
        assertColumn(rsMeta, 12, "FK_NAME", Types.VARCHAR, DatabaseMetaData.columnNullable);
        assertColumn(rsMeta, 13, "PK_NAME", Types.VARCHAR, DatabaseMetaData.columnNullable);
        assertColumn(rsMeta, 14, "DEFERABILITY", Types.SMALLINT, DatabaseMetaData.columnNoNulls);
    }
}
Also used : ResultSetMetaData(java.sql.ResultSetMetaData) ResultSet(java.sql.ResultSet) DatabaseMetaData(java.sql.DatabaseMetaData) Test(org.junit.Test)

Example 90 with DatabaseMetaData

use of java.sql.DatabaseMetaData in project phoenix by apache.

the class QueryDatabaseMetaDataIT method testTableMetadataScan.

@Test
public void testTableMetadataScan() throws SQLException {
    long ts = nextTimestamp();
    ensureTableCreated(getUrl(), ATABLE_NAME, ATABLE_NAME, ts);
    ensureTableCreated(getUrl(), STABLE_NAME, STABLE_NAME, ts);
    ensureTableCreated(getUrl(), CUSTOM_ENTITY_DATA_FULL_NAME, CUSTOM_ENTITY_DATA_FULL_NAME, ts);
    Properties props = new Properties();
    props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB, Long.toString(ts + 5));
    Connection conn = DriverManager.getConnection(getUrl(), props);
    DatabaseMetaData dbmd = conn.getMetaData();
    String aTableName = StringUtil.escapeLike(TestUtil.ATABLE_NAME);
    String aSchemaName = TestUtil.ATABLE_SCHEMA_NAME;
    ResultSet rs = dbmd.getTables(null, aSchemaName, aTableName, null);
    assertTrue(rs.next());
    assertEquals(rs.getString("TABLE_NAME"), aTableName);
    assertEquals(PTableType.TABLE.toString(), rs.getString("TABLE_TYPE"));
    assertEquals(rs.getString(3), aTableName);
    assertEquals(PTableType.TABLE.toString(), rs.getString(4));
    assertFalse(rs.next());
    rs = dbmd.getTables(null, null, null, null);
    assertTrue(rs.next());
    assertEquals(rs.getString("TABLE_SCHEM"), SYSTEM_CATALOG_SCHEMA);
    assertEquals(rs.getString("TABLE_NAME"), SYSTEM_CATALOG_TABLE);
    assertEquals(PTableType.SYSTEM.toString(), rs.getString("TABLE_TYPE"));
    assertTrue(rs.next());
    assertEquals(rs.getString("TABLE_SCHEM"), SYSTEM_CATALOG_SCHEMA);
    assertEquals(rs.getString("TABLE_NAME"), SYSTEM_FUNCTION_TABLE);
    assertEquals(PTableType.SYSTEM.toString(), rs.getString("TABLE_TYPE"));
    assertTrue(rs.next());
    assertEquals(rs.getString("TABLE_SCHEM"), SYSTEM_CATALOG_SCHEMA);
    assertEquals(rs.getString("TABLE_NAME"), TYPE_SEQUENCE);
    assertEquals(PTableType.SYSTEM.toString(), rs.getString("TABLE_TYPE"));
    assertTrue(rs.next());
    assertEquals(rs.getString("TABLE_SCHEM"), SYSTEM_CATALOG_SCHEMA);
    assertEquals(rs.getString("TABLE_NAME"), PhoenixDatabaseMetaData.SYSTEM_STATS_TABLE);
    assertEquals(PTableType.SYSTEM.toString(), rs.getString("TABLE_TYPE"));
    assertTrue(rs.next());
    assertEquals(rs.getString("TABLE_SCHEM"), null);
    assertEquals(rs.getString("TABLE_NAME"), ATABLE_NAME);
    assertEquals(PTableType.TABLE.toString(), rs.getString("TABLE_TYPE"));
    assertTrue(rs.next());
    assertEquals(rs.getString("TABLE_SCHEM"), null);
    assertEquals(rs.getString("TABLE_NAME"), STABLE_NAME);
    assertEquals(PTableType.TABLE.toString(), rs.getString("TABLE_TYPE"));
    assertTrue(rs.next());
    assertEquals(CUSTOM_ENTITY_DATA_SCHEMA_NAME, rs.getString("TABLE_SCHEM"));
    assertEquals(CUSTOM_ENTITY_DATA_NAME, rs.getString("TABLE_NAME"));
    assertEquals(PTableType.TABLE.toString(), rs.getString("TABLE_TYPE"));
    assertEquals("false", rs.getString(PhoenixDatabaseMetaData.TRANSACTIONAL));
    assertEquals(Boolean.FALSE, rs.getBoolean(PhoenixDatabaseMetaData.IS_NAMESPACE_MAPPED));
    rs = dbmd.getTables(null, CUSTOM_ENTITY_DATA_SCHEMA_NAME, CUSTOM_ENTITY_DATA_NAME, null);
    assertTrue(rs.next());
    try {
        rs.getString("RANDOM_COLUMN_NAME");
        fail();
    } catch (ColumnNotFoundException e) {
    // expected
    }
    assertEquals(rs.getString("TABLE_SCHEM"), CUSTOM_ENTITY_DATA_SCHEMA_NAME);
    assertEquals(rs.getString("TABLE_NAME"), CUSTOM_ENTITY_DATA_NAME);
    assertEquals(PTableType.TABLE.toString(), rs.getString("TABLE_TYPE"));
    assertFalse(rs.next());
    rs = dbmd.getTables(null, "", "_TABLE", new String[] { PTableType.TABLE.toString() });
    assertTrue(rs.next());
    assertEquals(rs.getString("TABLE_SCHEM"), null);
    assertEquals(rs.getString("TABLE_NAME"), ATABLE_NAME);
    assertEquals(PTableType.TABLE.toString(), rs.getString("TABLE_TYPE"));
    assertTrue(rs.next());
    assertEquals(rs.getString("TABLE_SCHEM"), null);
    assertEquals(rs.getString("TABLE_NAME"), STABLE_NAME);
    assertEquals(PTableType.TABLE.toString(), rs.getString("TABLE_TYPE"));
    assertFalse(rs.next());
}
Also used : ColumnNotFoundException(org.apache.phoenix.schema.ColumnNotFoundException) Connection(java.sql.Connection) PhoenixConnection(org.apache.phoenix.jdbc.PhoenixConnection) ResultSet(java.sql.ResultSet) Properties(java.util.Properties) PhoenixDatabaseMetaData(org.apache.phoenix.jdbc.PhoenixDatabaseMetaData) DatabaseMetaData(java.sql.DatabaseMetaData) Test(org.junit.Test)

Aggregations

DatabaseMetaData (java.sql.DatabaseMetaData)360 ResultSet (java.sql.ResultSet)215 Connection (java.sql.Connection)169 SQLException (java.sql.SQLException)154 Test (org.junit.Test)87 Statement (java.sql.Statement)49 ResultSetMetaData (java.sql.ResultSetMetaData)42 ArrayList (java.util.ArrayList)40 PreparedStatement (java.sql.PreparedStatement)38 IOException (java.io.IOException)26 Properties (java.util.Properties)25 HashSet (java.util.HashSet)16 PhoenixDatabaseMetaData (org.apache.phoenix.jdbc.PhoenixDatabaseMetaData)16 HashMap (java.util.HashMap)15 PhoenixConnection (org.apache.phoenix.jdbc.PhoenixConnection)15 PrintWriter (java.io.PrintWriter)10 Savepoint (java.sql.Savepoint)10 List (java.util.List)10 Map (java.util.Map)9 DataSource (javax.sql.DataSource)9