SQLSpecialColumns - Get special (row identifier) columns
SQLSpecialColumns() returns unique row identifier information (primary key or unique index) for a table. For example, unique index or primary key information. The information is returned in an SQL result set, which can be retrieved using the same functions that are used to fetch a result set generated by a SELECT statement.
Syntax
SQLRETURN SQLSpecialColumns (SQLHSTMT hstmt,
SQLSMALLINT fColType,
SQLCHAR *szCatalogName,
SQLSMALLINT cbCatalogName,
SQLCHAR *szSchemaName,
SQLSMALLINT cbSchemaName,
SQLCHAR *szTableName,
SQLSMALLINT cbTableName,
SQLSMALLINT fScope,
SQLSMALLINT fNullable);
Function arguments
Data type | Argument | Use | Description |
---|---|---|---|
SQLHSTMT | hstmt | Input | Statement handle. |
SQLSMALLINT | fColType | Input | Reserved for future use to support additional
types of special columns. This data type is currently ignored. |
SQLCHAR * | szCatalogName | Input | Catalog qualifier of a three-part table name. This must be a null pointer or a zero length string. |
SQLSMALLINT | cbCatalogName | Input | Length of szCatalogName. This must be a set to 0. |
SQLCHAR * | szSchemaName | Input | Schema qualifier of the specified table. |
SQLSMALLINT | cbSchemaName | Input | Length of szSchemaName. |
SQLCHAR * | szTableName | Input | Table name. |
SQLSMALLINT | cbTableName | Input | Length of cbTableName. |
SQLSMALLINT | fScope | Input | Minimum required duration for
which the unique row identifier is valid. fScope must be
one of the following values:
|
SQLSMALLINT | fNullable | Input | This determines
whether to return
special columns that can have a NULL value. Must be one of the
following values:
|
Usage
If multiple ways exist to uniquely identify any row in a table (for example, if there are multiple unique indexes on the specified table), then DB2 for i CLI returns the best set of row identifier columns based on its internal criterion.
If there is no column set that allows any row in the table to be uniquely identified, an empty result set is returned.
Column number/name | Data type | Description |
---|---|---|
1 SCOPE | SMALLINT not NULL | Actual scope of the rowid. This contains
one of the following values:
Refer to fScope in Table 1 for a description of each value. |
2 COLUMN_NAME | VARCHAR(128) not NULL | Name of the row identifier column. |
3 DATA_TYPE | SMALLINT not NULL | SQL data type of the column. |
4 TYPE_NAME | VARCHAR(128) not NULL | Database Management System (DBMS) character string represented of the name associated with DATA_TYPE column value. |
5 COLUMN_SIZE | INTEGER | The precision of the column. NULL is returned for data types where precision is not applicable. |
6 BUFFER_LENGTH | INTEGER | The length, in bytes, of the data returned in the default C type. For CHAR data types, this is the same as the value in the LENGTH_PRECISION column. |
7 DECIMAL_DIGITS | SMALLINT | The scale of the column. NULL is returned for data types where scale is not applicable. |
8 PSEUDO_COLUMN | SMALLINT | This indicates whether
the column is a pseudo-column; DB2 for
i CLI only returns:
|
Return codes
- SQL_SUCCESS
- SQL_SUCCESS_WITH_INFO
- SQL_ERROR
- SQL_INVALID_HANDLE
Diagnostics
SQLSTATE | Description | Explanation |
---|---|---|
24000 | Cursor state that is not valid | Cursor related information is requested, but no cursor is open. |
40003 * | Statement completion unknown | The communication link between the CLI and the data source fails before the function completes processing. |
HY001 | Memory allocation failure | The driver is unable to allocate memory required to support the processing or completion of the function. |
HY009 | Argument length that is not valid | The value of one of the length arguments is less than 0, but not equal to SQL_NTS. |
HY021 | Internal descriptor that is not valid | The internal descriptor cannot be addressed or allocated, or it contains a value that is not valid. |
HYC00 | Driver not capable | The data source does not support the catalog portion (first part) of a three-part table name. |