雪花JDBC数据库元数据不返回getimportedkeys

发布于 2025-01-28 13:31:57 字数 4598 浏览 2 评论 0原文

我有Java代码从JDBC连接中提取元数据。电话之一是提取导入的键。数据库具有RI创建的,但已禁用。 有没有办法提取残疾的导入键?

<!-- https://mvnrepository.com/artifact/net.snowflake/snowflake-jdbc -->
<dependency>
    <groupId>net.snowflake</groupId>
    <artifactId>snowflake-jdbc</artifactId>
    <version>3.13.18</version>
</dependency>
keys = metadata.getImportedKeys(tableCatalog, tableSchema, tableName);

while (keys.next()) {
    importedTag(docBuff, keys, columnMap);
}
keys.close();
    /**
     *
     * @param docBuff
     * @param foreignKeys
     * @param columnMap
     * @throws SQLException
     */
    private void importedTag(StringBuilder docBuff, ResultSet foreignKeys, Map<String, Map<String, String>> columnMap) throws SQLException {
        /*
            PKTABLE_CAT String => primary key table catalog being imported (may be null)
            PKTABLE_SCHEM String => primary key table schema being imported (may be null)
            PKTABLE_NAME String => primary key table name being imported
            PKCOLUMN_NAME String => primary key column name being imported
            FKTABLE_CAT String => foreign key table catalog (may be null)
            FKTABLE_SCHEM String => foreign key table schema (may be null)
            FKTABLE_NAME String => foreign key table name
            FKCOLUMN_NAME String => foreign key column name
            KEY_SEQ short => sequence number within a foreign key( a value of 1 represents the first column of the foreign key, a value of 2 would represent the second column within the foreign key).
            UPDATE_RULE short => What happens to a foreign key when the primary key is updated:
                importedNoAction - do not allow update of primary key if it has been imported
                importedKeyCascade - change imported key to agree with primary key update
                importedKeySetNull - change imported key to NULL if its primary key has been updated
                importedKeySetDefault - change imported key to default values if its primary key has been updated
                importedKeyRestrict - same as importedKeyNoAction (for ODBC 2.x compatibility)
            DELETE_RULE short => What happens to the foreign key when primary is deleted.
                importedKeyNoAction - do not allow delete of primary key if it has been imported
                importedKeyCascade - delete rows that import a deleted key
                importedKeySetNull - change imported key to NULL if its primary key has been deleted
                importedKeyRestrict - same as importedKeyNoAction (for ODBC 2.x compatibility)
                importedKeySetDefault - change imported key to default if its primary key has been deleted
            FK_NAME String => foreign key name (may be null)
            PK_NAME String => primary key name (may be null)
            DEFERRABILITY short => can the evaluation of foreign key constraints be deferred until commit
                importedKeyInitiallyDeferred - see SQL92 for definition
                importedKeyInitiallyImmediate - see SQL92 for definition
                importedKeyNotDeferrable - see SQL92 for definition


         */
        String primaryCatalog = null;
        String primaryModel = null;
        String primaryTable = null;
        String primaryColumn = null;
        String foreignCatalog = null;
        String foreignModel = null;
        String foreignTable = null;
        String foreignColumn = null;
        String columnType = null;
        short keySequence = 0;

        primaryCatalog = foreignKeys.getString("PKTABLE_CAT");
        primaryModel = foreignKeys.getString("PKTABLE_SCHEM");
        primaryTable = foreignKeys.getString("PKTABLE_NAME");
        primaryColumn = foreignKeys.getString("PKCOLUMN_NAME");

        foreignCatalog = foreignKeys.getString("FKTABLE_CAT");
        foreignModel = foreignKeys.getString("FKTABLE_SCHEM");
        foreignTable = foreignKeys.getString("FKTABLE_NAME");
        foreignColumn = foreignKeys.getString("FKCOLUMN_NAME");

        columnType = columnMap.get(foreignColumn).get(TYPE_NAME);


        keySequence = foreignKeys.getShort(KEY_SEQ);

        foreignTag(docBuff, primaryCatalog, primaryModel, primaryTable, primaryColumn, foreignCatalog, foreignModel, foreignTable, foreignColumn, keySequence, columnType);
    }

I have Java code that extracts metadata from a JDBC connection. One of the calls is to extract the imported keys. The database has the RI created, but is disabled. Is there a way to extract the disabled imported keys?

<!-- https://mvnrepository.com/artifact/net.snowflake/snowflake-jdbc -->
<dependency>
    <groupId>net.snowflake</groupId>
    <artifactId>snowflake-jdbc</artifactId>
    <version>3.13.18</version>
</dependency>
keys = metadata.getImportedKeys(tableCatalog, tableSchema, tableName);

while (keys.next()) {
    importedTag(docBuff, keys, columnMap);
}
keys.close();
    /**
     *
     * @param docBuff
     * @param foreignKeys
     * @param columnMap
     * @throws SQLException
     */
    private void importedTag(StringBuilder docBuff, ResultSet foreignKeys, Map<String, Map<String, String>> columnMap) throws SQLException {
        /*
            PKTABLE_CAT String => primary key table catalog being imported (may be null)
            PKTABLE_SCHEM String => primary key table schema being imported (may be null)
            PKTABLE_NAME String => primary key table name being imported
            PKCOLUMN_NAME String => primary key column name being imported
            FKTABLE_CAT String => foreign key table catalog (may be null)
            FKTABLE_SCHEM String => foreign key table schema (may be null)
            FKTABLE_NAME String => foreign key table name
            FKCOLUMN_NAME String => foreign key column name
            KEY_SEQ short => sequence number within a foreign key( a value of 1 represents the first column of the foreign key, a value of 2 would represent the second column within the foreign key).
            UPDATE_RULE short => What happens to a foreign key when the primary key is updated:
                importedNoAction - do not allow update of primary key if it has been imported
                importedKeyCascade - change imported key to agree with primary key update
                importedKeySetNull - change imported key to NULL if its primary key has been updated
                importedKeySetDefault - change imported key to default values if its primary key has been updated
                importedKeyRestrict - same as importedKeyNoAction (for ODBC 2.x compatibility)
            DELETE_RULE short => What happens to the foreign key when primary is deleted.
                importedKeyNoAction - do not allow delete of primary key if it has been imported
                importedKeyCascade - delete rows that import a deleted key
                importedKeySetNull - change imported key to NULL if its primary key has been deleted
                importedKeyRestrict - same as importedKeyNoAction (for ODBC 2.x compatibility)
                importedKeySetDefault - change imported key to default if its primary key has been deleted
            FK_NAME String => foreign key name (may be null)
            PK_NAME String => primary key name (may be null)
            DEFERRABILITY short => can the evaluation of foreign key constraints be deferred until commit
                importedKeyInitiallyDeferred - see SQL92 for definition
                importedKeyInitiallyImmediate - see SQL92 for definition
                importedKeyNotDeferrable - see SQL92 for definition


         */
        String primaryCatalog = null;
        String primaryModel = null;
        String primaryTable = null;
        String primaryColumn = null;
        String foreignCatalog = null;
        String foreignModel = null;
        String foreignTable = null;
        String foreignColumn = null;
        String columnType = null;
        short keySequence = 0;

        primaryCatalog = foreignKeys.getString("PKTABLE_CAT");
        primaryModel = foreignKeys.getString("PKTABLE_SCHEM");
        primaryTable = foreignKeys.getString("PKTABLE_NAME");
        primaryColumn = foreignKeys.getString("PKCOLUMN_NAME");

        foreignCatalog = foreignKeys.getString("FKTABLE_CAT");
        foreignModel = foreignKeys.getString("FKTABLE_SCHEM");
        foreignTable = foreignKeys.getString("FKTABLE_NAME");
        foreignColumn = foreignKeys.getString("FKCOLUMN_NAME");

        columnType = columnMap.get(foreignColumn).get(TYPE_NAME);


        keySequence = foreignKeys.getShort(KEY_SEQ);

        foreignTag(docBuff, primaryCatalog, primaryModel, primaryTable, primaryColumn, foreignCatalog, foreignModel, foreignTable, foreignColumn, keySequence, columnType);
    }

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文