Specification: | DB2 CLI 2.1 | ODBC 1.0 |
|
SQLColumns() returns a list of columns in the specified tables. 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 query.
Syntax
SQLRETURN SQLColumns ( SQLHSTMT StatementHandle, /* hstmt */ SQLCHAR FAR *CatalogName, /* szCatalogName */ SQLSMALLINT NameLength1, /* cbCatalogName */ SQLCHAR FAR *SchemaName, /* szSchemaName */ SQLSMALLINT NameLength2, /* cbSchemaName */ SQLCHAR FAR *TableName, /* szTableName */ SQLSMALLINT NameLength3, /* cbTableName */ SQLCHAR FAR *ColumnName, /* szColumnName */ SQLSMALLINT NameLength4); /* cbColumnName */
Function arguments
Table 92. SQLColumns arguments
Data type | Argument | Use | Description |
---|---|---|---|
SQLHSTMT | StatementHandle | Input | Statement handle. |
SQLCHAR | CatalogName | Input | Buffer that may contain a pattern-value to qualify the result
set. Catalog is the first part of a 3 part table name.
This argument is ignored by DB2 Everyplace. |
SQLSMALLINT | NameLength1 | Input | Length of CatalogName.
This argument is ignored by DB2 Everyplace. |
SQLCHAR | SchemaName | Input | Buffer that may contain a pattern-value to qualify the result
set by schema name.
This argument is ignored by DB2 Everyplace. |
SQLSMALLINT | NameLength2 | Input | Length of SchemaName.
This argument is ignored by DB2 Everyplace. |
SQLCHAR | TableName | Input | Buffer that may contain a pattern-value to qualify the result set by table name. |
SQLSMALLINT | NameLength3 | Input | Length of TableName. |
SQLCHAR | ColumnName | Input | Buffer that may contain a pattern-value to qualify the result set by column name. |
SQLSMALLINT | NameLength4 | Input | Length of ColumnName. |
Usage
This function is called to retrieve information about the columns of either a table or a set of tables. A typical application may wish to call this function after a call to SQLTables() to determine the columns of a table. The application should use the character strings returned in the TABLE_NAME of the SQLTables() result set as input to this function.
SQLColumns() returns a standard result set, ordered by TABLE_NAME, and ORDINAL_POSITION. *** lists the columns in the result set.
The TableName, and ColumnName arguments accept search patterns.
This function does not return information on the columns in a result set. SQLDescribeCol() or SQLColAttribute() should be used instead.
Calls to SQLColumns() should be used sparingly, because in many cases they map to a complex and thus expensive query against the system catalog. The results should be saved rather than repeating calls.
The VARCHAR columns of the catalog functions result set have been declared with a maximum length attribute of 128 to be consistent with SQL92 limits. Since DB2 names are less than 128, the application can choose to always set aside 128 characters (plus the null-terminator) for the output buffer, or alternatively, call SQLGetInfo() with the SQL_MAX_TABLE_NAME_LEN, and SQL_MAX_COLUMN_NAME_LEN to determine respectively the actual lengths of the TABLE_NAME, and COLUMN_NAME columns supported by the connected DBMS.
Although new columns may be added and the names of the existing columns changed in future releases, the position of the current columns will not change.
Columns Returned By SQLColumns
If the DATA_TYPE column value denotes a character or binary string, then this column contains the maximum length in characters for the column.
For DATE, TIME, or TIMESTAMP data types, this is the total number of characters required to display the value when converted to character.
For numeric data types, this is the total number of digits allowed in the column.
See also, Data type attributes.
Either 10 or NULL.
If DATA_TYPE is an exact numeric data type, this column contains the value 10 and the COLUMN_SIZE contains the number of decimal digits allowed for the column.
For numeric data types, the DBMS returns a NUM_PREC_RADIX of 10.
NULL is returned for data types where radix is not applicable.
SQL_NO_NULLS if the column does not accept NULL values.
SQL_NULLABLE if the column accepts NULL values.
The column's default value. If the default value is a numeric literal, then this column contains the character representation of the numeric literal with no enclosing single quotes. If the default value is a character string, then this column is that string enclosed in single quotes. If the default value a pseudo-literal, such as for DATE, TIME, and TIMESTAMP columns, then this column contains the keyword of the pseudo-literal (e.g. CURRENT DATE) with no enclosing quotes.
If NULL was specified as the default value, then this column returns the word NULL, not enclosed in quotes. If no default value was specified, then this column is NULL.
Contains the string 'NO' if the column is known to be not nullable; and 'YES' otherwise.
This result set is identical to the X/Open CLI Columns() result set specification, which is an extended version of the SQLColumns() result set specified in ODBC V2. The ODBC SQLColumns() result set includes every column in the same position.
Note: This result set is identical to the X/Open CLI Columns() result set specification, which is an extended version of the SQLColumns() result set specified in ODBC V2. The ODBC SQLColumns() result set includes every column in the same position.
Return codes
Diagnostics
Table 93. SQLColumns SQLSTATEs
SQLSTATE | Description | Explanation |
---|---|---|
24000 | Invalid cursor state. | A cursor was already opened on the statement handle. |
40003 08S01 | Communication link failure. | The communication link between the application and data source failed before the function completed. |
HY001 | Memory allocation failure. | DB2 CLI is unable to allocate memory required to support execution or completion of the function. |
HY014 | No more handles. | DB2 CLI was unable to allocate a handle due to internal resources. |
HY090 | Invalid string or buffer length. | The value of one of the name length arguments was less than 0, but not equal SQL_NTS. |
Restrictions
None.
Related reference