Level 2 subroutine
List column names that comprise foreign keys.
call EDSForeignKeys(HSTMT_IV, PKTABLE_STRUCT, FKTABLE_STRUCT, MAXROWS_IV, NUMROWS_IV, ARR AY_STRUCT)
•HSTMT_IV An input integer value that indicates the statement handle.
•PKTABLE_STRUCT An input EDSTABLE_STRUCT structure that contains the primary key table structure.
•FKTABLE_STRUCT An input EDSTABLE_STRUCT structure that contains the foreign key table structure.
•MAXROWS_IV An input integer value that indicates the maximum number of rows in the result array.
•NUMROWS_IV An output integer value that indicates the actual number of rows in the result array.
•ARRAY_STRUCT An output array of EDSFKEY_STRUCT structures that contains foreign key information.
Description
If foreign keys exist for a specified table, EDSForeignKeys returns an ESL structure that lists the column names comprising foreign keys.
If the PKTABLE.TABLE_NAME argument is not null, EDSForeignKeys returns the table names and column names that comprise foreign keys associated with the primary key table.
If the FKTABLE.TABLE_NAME argument is not null, EDSForeignKeys returns the table names that contain the primary key associated with this foreign key.
If both PKTABLE.TABLE_NAME and FKTABLE.TABLE_NAME arguments are provided, the function returns all of the foreign keys in the foreign key table that are related to the primary key of the primary key table. (There should be only one primary key.)
The following table describes each element returned in each EDSFKEY_STRUCT structure of the array:
Element Name |
Data Type |
Comments |
PKQUALIFIER |
Varchar(128) |
Primary key table qualifier identifier;NULL if not applicable to the data source. |
PKOWNER |
Varchar(128) |
Primary key table owner identifier; NULL if not applicable to the data source. |
PKTABLENAME |
Varchar(128) not NULL |
Primary key table identifier. |
PKCOLUMNNAME |
Varchar(128) not NULL |
Primary key column identifier. |
FKQUALIFIER |
Varchar(128) |
Foreign key table qualifier identifier; NULL if not applicable to the data source. |
FKOWNER |
Varchar(128) |
Foreign key table owner identifier; NULL if not applicable to the data source. |
FKTABLENAME |
Varchar(128) not NULL |
Foreign key table identifier. |
FKCOLUMNNAME |
Varchar(128) not NULL. |
Foreign key column identifier |
KEY_SEQ |
Smallint not NULL |
Column sequence number in key (starting with 1). |
UPDATE_RULE |
Smallint |
Action to be applied to the foreign key when the SQL operation is UPDATE: EDS_CASCADE EDS_RESTRICT EDS_SET_NULL EDS_NULL if not applicable to the data source. |
DELETE_RULE |
Smallint |
Action to be applied to the foreign key when the SQL operation is DELETE: EDS_CASCADE EDS_RESTRICT EDS_SET_NULL NULL if not applicable to the data source. |
EDSForeignKeys returns results as an array of EDSFKEY_STRUCT structures.
If MAXROWS_IV=NUMROWS_IV, then there were more rows of data to fetch than there were structures in the array. To retrieve the full set of results, the user must RESIZE the array and call the function again.
Return Values
EDSForeignKeys returns EDS_SUCCESS, EDS_INVALID_HANDLE, or EDS_ERROR.
When EDSForeignKeys returns EDS_ERROR, you can obtain an associated SQLSTATE value with more specific information by calling EDSError. The following table lists each typical SQLSTATE value and explains each one in the context of the command EDSForeignKeys.
The following table lists possible SQLSTATE values:
SQL STATE |
Error |
Description |
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 |
Results were pending on the statement handle from a previous SELECT statement or a cursor associated with the statement handle had not been closed. |
IM001 |
Driver does not support this function |
The driver associated with the statement handle does not support the function. |
S1000 |
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 EDSError in the argument ERRORTEXT describes the error and its cause. |
S1001 |
Memory allocation failure |
The driver was unable to allocate the memory required to support execution or completion of the function. |
S1008 |
Operation cancelled |
Asynchronous processing was enabled for the statement handle. The function was called and before it completed execution, EDSCancel was cancelled on the statement handle. Then the function was called again on the statement handle. |
S1009 |
Invalid argument value |
The arguments PKTABLE.TABLENAME_SV and FKTABLE.TABLENAME_SV were both empty strings. |
S1010 |
Function sequence error |
An asynchronously executing function (not this one) was called for the statement handle and was still executing when this function was called. |
S1C00 |
Driver not capable |
A table qualifier or a table owner was specified and the driver or data source does not support one or both of the qualifiers. |
S1T00 |
Timeout expired |
The timeout period expired before the data source returned the result set. The timeout period is set through EDSSetStmtOption, EDS_QUERY_TIMEOUT. |
See Also
EDSPrimaryKeys retrieves names of columns that make up the primary key of a table.