f90SQLForeignKeys (SQLForeignKeys)

 

Conformance

Version Introduced: ODBC 1.0

Standards Compliance: ODBC

 

Summary

f90SQLForeignKeys can return:

The driver returns each list as a result set on the specified statement.

 

Syntax

f90SQLForeignKeys (StatementHandle, PKCatalogName, PKSchemaName, PKTableName, FKCatalogName, FKSchemaName, FKTableName, iRet)

 

integer(SQLHSTMT_KIND),intent(in):: StatementHandle
character(len=*),intent(in):: PKCatalogName
character(len=*),intent(in):: PKSchemaName
character(len=*),intent(in):: PKTableName
character(len=*),intent(in):: FKCatalogName
character(len=*),intent(in):: FKSchemaName
character(len=*),intent(in):: FKTableName
integer(SQLRETURN_KIND),intent(out):: iRet

 

Arguments

StatementHandle [Input]

Statement handle.

PKCatalogName [Input]

Primary key table catalog name. If a driver supports catalogs for some tables but not for others, such as when the driver retrieves data from different DBMSs, an empty string ("") denotes those tables that do not have catalogs. PKCatalogName cannot contain a string search pattern.

If the SQL_ATTR_METADATA_ID statement attribute is set to SQL_TRUE, PKCatalogName is treated as an identifier, and its case is not significant. If it is SQL_FALSE, PKCatalogName is an ordinary argument; it is treated literally, and its case is significant. For more information, see "Arguments in Catalog Functions" in Chapter 10.

PKSchemaName [Input]

Primary key table schema name. If a driver supports schemas for some tables but not for others, such as when the driver retrieves data from different DBMSs, an empty string ("") denotes those tables that do not have schemas. PKSchemaName cannot contain a string search pattern.

If the SQL_ATTR_METADATA_ID statement attribute is set to SQL_TRUE, PKSchemaName is treated as an identifier, and its case is not significant. If it is SQL_FALSE, PKSchemaName is an ordinary argument; it is treated literally, and its case is significant.

PKTableName [Input]

Primary key table name. PKTableName cannot contain a string search pattern.

If the SQL_ATTR_METADATA_ID statement attribute is set to SQL_TRUE, PKTableName is treated as an identifier, and its case is not significant. If it is SQL_FALSE, PKTableName is an ordinary argument; it is treated literally, and its case is significant.

FKCatalogName [Input]

Foreign key table catalog name. If a driver supports catalogs for some tables but not for others, such as when the driver retrieves data from different DBMSs, an empty string ("") denotes those tables that do not have catalogs. FKCatalogName cannot contain a string search pattern.

If the SQL_ATTR_METADATA_ID statement attribute is set to SQL_TRUE, FKCatalogName is treated as an identifier, and its case is not significant. If it is SQL_FALSE, FKCatalogName is an ordinary argument; it is treated literally, and its case is significant.

FKSchemaName [Input]

Foreign key table schema name. If a driver supports schemas for some tables but not for others, such as when the driver retrieves data from different DBMSs, an empty string ("") denotes those tables that do not have schemas. FKSchemaName cannot contain a string search pattern.

If the SQL_ATTR_METADATA_ID statement attribute is set to SQL_TRUE, FKSchemaName is treated as an identifier, and its case is not significant. If it is SQL_FALSE, FKSchemaName is an ordinary argument; it is treated literally, and its case is significant.

FKTableName [Input]

Foreign key table name. FKTableName cannot contain a string search pattern.

If the SQL_ATTR_METADATA_ID statement attribute is set to SQL_TRUE, FKTableName is treated as an identifier, and its case is not significant. If it is SQL_FALSE, FKTableName is an ordinary argument; it is treated literally, and its case is significant.

iRet [Output]

SQL_SUCCESS, SQL_SUCCESS_WITH_INFO, SQL_STILL_EXECUTING, SQL_ERROR, or SQL_INVALID_HANDLE.

Diagnostics

When f90SQLForeignKeys returns SQL_ERROR or SQL_SUCCESS_WITH_INFO, an associated SQLSTATE value may be obtained by calling f90SQLGetDiagRec with a HandleType of SQL_HANDLE_STMT and a Handle of StatementHandle. The following table lists the SQLSTATE values commonly returned by f90SQLForeignKeys and explains each one in the context of this function; the notation "(DM)" precedes the descriptions of SQLSTATEs returned by the Driver Manager. The return code associated with each SQLSTATE value is SQL_ERROR, unless noted otherwise.

SQLSTATE Error Description
01000 General warning Driver-specific informational message.

(Function returns SQL_SUCCESS_WITH_INFO.)

08S01 Communication link failure The communication link between the driver and the data source to which the driver was connected failed before the function completed processing.
24000 Invalid cursor state A cursor was open on the StatementHandle and f90SQLFetch or f90SQLFetchScroll had been called.

This error is returned by the Driver Manager if f90SQLFetch or f90SQLFetchScroll has not returned SQL_NO_DATA, and is returned by the driver if f90SQLFetch or f90SQLFetchScroll has returned SQL_NO_DATA.

A cursor was open on the StatementHandle but f90SQLFetch or f90SQLFetchScroll had not been called.

40001 Serialization failure The transaction was rolled back due to a resource deadlock with another transaction.
40003 Statement completion unknown The associated connection failed during the execution of this function and the state of the transaction cannot be determined.
HY000 General error An error occurred for which there was no specific SQLSTATE and for which no implementation-specific SQLSTATE was defined. The error message returned by f90SQLGetDiagRec in the MessageText buffer describes the error and its cause.
HY001 Memory allocation error The driver was unable to allocate memory required to support execution or completion of the function.
HY008 Operation canceled Asynchronous processing was enabled for the StatementHandle. The function was called and, before it completed execution, f90SQLCancel was called on the StatementHandle, and then the function was called again on the StatementHandle.

The function was called and, before it completed execution, f90SQLCancel was called on the StatementHandle from a different thread in a multithread application.

HY009 Invalid use of null pointer (DM) The arguments PKTableName and FKTableName were both null pointers.

(DM) The SQL_ATTR_METADATA_ID statement attribute was set to SQL_TRUE, the FKCatalogName or PKCatalogName argument was a null pointer, and the SQL_CATALOG_NAME InfoType returns that catalog names are supported.

(DM) The SQL_ATTR_METADATA_ID statement attribute was set to SQL_TRUE, and the FKSchemaName, PKSchemaName, FKTableName, or PKTableName argument was a null pointer.

HY010 Function sequence error (DM) An asynchronously executing function (not this one) was called for the StatementHandle and was still executing when this function was called.

(DM) f90SQLExecute, f90SQLExecDirect, f90SQLBulkOperations, or f90SQLSetPos was called for the StatementHandle and returned SQL_NEED_DATA. This function was called before data was sent for all data-at-execution parameters or columns.

HY013 Memory management error The function call could not be processed because the underlying memory objects could not be accessed, possibly because of low memory conditions.
HY090 Invalid string or buffer length (DM) The value of one of the name length arguments was less than 0, but not equal to SQL_NTS.

The value of one of the name length arguments exceeded the maximum length value for the corresponding name (see "Comments").

HYC00 Optional feature not implemented A catalog name was specified and the driver or data source does not support catalogs.

A schema name was specified and the driver or data source does not support schemas.

The combination of the current settings of the SQL_ATTR_CONCURRENCY and SQL_ATTR_CURSOR_TYPE statement attributes was not supported by the driver or data source.

The SQL_ATTR_USE_BOOKMARKS statement attribute was set to SQL_UB_VARIABLE, and the SQL_ATTR_CURSOR_TYPE statement attribute was set to a cursor type for which the driver does not support bookmarks.

HYT00 Timeout expired The query timeout period expired before the data source returned the result set. The timeout period is set through f90SQLSetStmtAttr, SQL_ATTR_QUERY_TIMEOUT.
HYT01 Connection timeout expired The connection timeout period expired before the data source responded to the request. The connection timeout period is set through f90SQLSetConnectAttr, SQL_ATTR_CONNECTION_TIMEOUT.
IM001 Driver does not support this function (DM) The driver associated with the StatementHandle does not support the function.

 

Comments

For information about how the information returned by this function might be used, see "Uses of Catalog Data" in Chapter 10

If PKTableName contains a table name, f90SQLForeignKeys returns a result set containing the primary key of the specified table and all of the foreign keys that refer to it. The list of foreign keys in other tables does not include foreign keys that point to unique constraints in the specified table.

If FKTableName contains a table name, f90SQLForeignKeys returns a result set containing all of the foreign keys in the specified table that point to primary keys in others tables, and the primary keys in the other tables to which they refer. The list of foreign keys in the specified table does not contain foreign keys that refer to unique constraints in other tables.

If both PKTableName and FKTableName contain table names, f90SQLForeignKeys returns the foreign keys in the table specified in FKTableName that refer to the primary key of the table specified in PKTableName. This should be one key at most.

Note: For more information about the general use, arguments, and returned data of ODBC catalog functions, see Chapter 10.

f90SQLForeignKeys returns results as a standard result set. If the foreign keys associated with a primary key are requested, the result set is ordered by FKTABLE_CAT, FKTABLE_SCHEM, FKTABLE_NAME, and KEY_SEQ. If the primary keys associated with a foreign key are requested, the result set is ordered by PKTABLE_CAT, PKTABLE_SCHEM, PKTABLE_NAME, and KEY_SEQ. The following table lists the columns in the result set.

The lengths of CHARACTER*(*) columns are not shown in the table; the actual lengths depend on the data source. To determine the actual lengths of the PKTABLE_CAT or FKTABLE_CAT, PKTABLE_SCHEM or FKTABLE_SCHEM, PKTABLE_NAME or FKTABLE_NAME, and PKCOLUMN_NAME or FKCOLUMN_NAME columns, an application can call f90SQLGetInfo with the SQL_MAX_CATALOG_NAME_LEN, SQL_MAX_SCHEMA_NAME_LEN, SQL_MAX_TABLE_NAME_LEN, and SQL_MAX_COLUMN_NAME_LEN options.

The following columns have been renamed for ODBC 3.x. The column name changes do not affect backward compatibility because applications bind by column number.

ODBC 2.0 column ODBC 3.x column
PKTABLE_QUALIFIER PKTABLE_CAT
PKTABLE_OWNER PKTABLE_SCHEM
FKTABLE_QUALIFIER FK_TABLE_CAT
FKTABLE_OWNER FKTABLE_SCHEM

The following table lists the columns in the result set. Additional columns beyond column 14 (DEFERRABILITY) can be defined by the driver. An application should gain access to driver-specific columns by counting down from the end of the result set rather than specifying an explicit ordinal position.

Column name Column Number Data type Comments
PKTABLE_CAT
(ODBC 1.0)
1 Character*(*) Primary key table catalog name; NULL if not applicable to the data source.

If a driver supports catalogs for some tables but not for others, such as when the driver retrieves data from different DBMSs, it returns an empty string ("") for those tables that do not have catalogs.

PKTABLE_SCHEM
(ODBC 1.0)
2 Character*(*) Primary key table schema name; NULL if not applicable to the data source.

If a driver supports schemas for some tables but not for others, such as when the driver retrieves data from different DBMSs, it returns an empty string ("") for those tables that do not have schemas.

PKTABLE_NAME
(ODBC 1.0)
3 Character*(*)
not NULL
Primary key table name.
PKCOLUMN_NAME
(ODBC 1.0)
4 Character*(*)
not NULL
Primary key column name. The driver returns an empty string for a column that does not have a name.
FKTABLE_CAT
(ODBC 1.0)
5 Character*(*) Foreign key table catalog name; NULL if not applicable to the data source.

If a driver supports catalogs for some tables but not for others, such as when the driver retrieves data from different DBMSs, it returns an empty string ("") for those tables that do not have catalogs.

FKTABLE_SCHEM
(ODBC 1.0)
6 Character*(*) Foreign key table schema name; NULL if not applicable to the data source.

If a driver supports schemas for some tables but not for others, such as when the driver retrieves data from different DBMSs, it returns an empty string ("") for those tables that do not have schemas.

FKTABLE_NAME
(ODBC 1.0)
7 Character*(*)
not NULL
Foreign key table name.
FKCOLUMN_NAME
(ODBC 1.0)
8 Character*(*)
not NULL
Foreign key column name. The driver returns an empty string for a column that does not have a name.
KEY_SEQ
(ODBC 1.0)
9 SQLSMALLINT_KIND
not NULL
Column sequence number in key (starting with 1).
UPDATE_RULE
(ODBC 1.0)
10 SQLSMALLINT_KIND Action to be applied to the foreign key when the SQL operation is UPDATE. Can have one of the following values. (The referenced table is the table that has the primary key; the referencing table is the table that has the foreign key):

SQL_CASCADE: When the primary key of the referenced table is updated, the foreign key of the referencing table is also updated.

SQL_NO_ACTION: If an update of the primary key of the referenced table would cause a "dangling reference" in the referencing table (that is, rows in the referencing table would have no counterparts in the referenced table), then the update is rejected. If an update of the foreign key of the referencing table would introduce a value that does not exist as a value of the primary key of the referenced table, then the update is rejected. (This action is the same as the SQL_RESTRICT action in ODBC 2.x.)

SQL_SET_NULL: When one or more rows in the referenced table are updated such that one or more components of the primary key are changed, the components of the foreign key in the referencing table that correspond to the changed components of the primary key are set to NULL in all matching rows of the referencing table.

SQL_SET_DEFAULT: When one or more rows in the referenced table are updated such that one or more components of the primary key are changed, the components of the foreign key in the referencing table that correspond to the changed components of the primary key are set to the applicable default values in all matching rows of the referencing table.NULL if not applicable to the data source.

DELETE_RULE
(ODBC 1.0)
11 SQLSMALLINT_KIND Action to be applied to the foreign key when the SQL operation is DELETE. Can have one of the following values (The referenced table is the table that has the primary key; the referencing table is the table that has the foreign key):

SQL_CASCADE: When a row in the referenced table is deleted, all the matching rows in the referencing tables are also deleted.

SQL_NO_ACTION: If a delete of a row in the referenced table would cause a "dangling reference" in the referencing table (that is, rows in the referencing table would have no counterparts in the referenced table), then the update is rejected. (This action is the same as the SQL_RESTRICT action in ODBC 2.x.)

SQL_SET_NULL: When one or more rows in the referenced table are deleted, each component of the foreign key of the referencing table is set to NULL in all matching rows of the referencing table.

SQL_SET_DEFAULT: When one or more rows in the referenced table are deleted, each component of the foreign key of the referencing table is set to the applicable default in all matching rows of the referencing table.NULL if not applicable to the data source.

FK_NAME
(ODBC 2.0)
12 Character*(*) Foreign key name. NULL if not applicable to the data source.
PK_NAME
(ODBC 2.0)
13 Character*(*) Primary key name. NULL if not applicable to the data source.
DEFERRABILITY
(ODBC 3.0)
14 SQLSMALLINT_KIND SQL_INITIALLY_DEFERRED,SQL_INITIALLY_IMMEDIATE, SQL_NOT_DEFERRABLE

(Use of this column is not documented in the ODBC SDK)

f90SQL catalog structure f90SQL_FOREIGNKEYS_INFO_STRUCT contains fields that correspond to the columns in the previous tables. Your application can call f90SQLBindCol with an argument of type f90SQL_FOREIGNKEYS_INFO_STRUCT and conveniently bind all the columns in the table to the corresponding fields in the catalog structure in a single operation. . See Chapter 10 for more information on how to use this structure.

 

Related Subroutines

For information about See
Binding a buffer to a column in a result set f90SQLBindCol
Canceling statement processing f90SQLCancel
Fetching a single row or a block of data in a forward-only direction f90SQLFetch
Fetching a block of data or scrolling through a result set f90SQLFetchScroll
Returning the columns of a primary key f90SQLPrimaryKeys
Returning table statistics and indexes f90SQLStatistics