SQLColAttribute - cSQLStatement
Returns a column attribute.
Type: Function
Return Data Type: String
Parameters
| Parameter | Type | Description |
|---|---|---|
| iCol | Integer | Column to return attribute from |
| iAttribId | Integer | Attribute id to return |
Syntax
Function SQLColAttribute Integer iCol Integer iAttribId Returns String
Call Example
Get SQLColAttribute iCol iAttribId to StringVariable
Description
The SQLColAttribute message allows the programmer to get column attributes. The following attributes are supported:
| Attribute | Description |
|---|---|
| SQLCOLATTRIB_ SIZE | The size of the column. This attribute returns the size of a column including possible decimal places. |
| SQLCOLATTRIB_ PRECISION | The precision of the column. This attribute defines the number of decimal places for columns that have decimals defined. |
| SQLCOLATTRIB_ LABEL | The label of the column in the result set. |
| SQLCOLATTRIB_ BASECOLUMNNAME | The name of the column in the base table if any. |
| SQLCOLATTRIB_ BASETABLENAME | The name of the base table if any. Some backends do not support this attribute. Others only under certain conditions. In Microsoft SQL Server, for example, the attribute is supported except when the statement has multiple result sets . |
| SQLCOLATTRIB_ SQLTYPE | The SQL type identifier of the column. |
| SQLCOLATTRIB_ NULLABLE | A Boolean indicating if the column accepts null values or not. |
| SQLCOLATTRIB_ DFTYPE | The DataFlex type of the column. This attribute will map the SQL type identifier to a DataFlex type. |
The attributes described above can be accessed through predefined constants. These constants have the SQLCOLATTRIB_ prefix. So to get the label of column 1 one would program:
Get SQLColAttribute of hstmt 1 SQLCOLATTRIB_LABEL To sLabel
For the SQL type, a number of constants have also been defined. These are: SQL_UNKNOWN_TYPE, SQL_CHAR, SQL_NUMERIC, SQL_DECIMAL, SQL_INTEGER, SQL_SMALLINT, SQL_FLOAT, SQL_REAL, SQL_DOUBLE, SQL_DATETIME, SQL_VARCHAR, SQL_TYPE_DATE, SQL_TYPE_TIME, SQL_TYPE_TIMESTAMP, SQL_DATE, SQL_INTERVAL, SQL_TIME, SQL_TIMESTAMP, SQL_LONGVARCHAR, SQL_BINARY, SQL_VARBINARY, SQL_LONGVARBINARY, SQL_BIGINT, SQL_TINYINT, SQL_BIT, SQL_GUID.
Sample
Handle hoSQLMngr
Handle hdbc hstmt
Integer iFetchResult
Integer iNumCols iCol
String sColumn sColumnName
Object oSQLHandler Is A cSQLHandleManager
Move Self To hoSQLMngr
End_Object
Open Customer
Get SQLFileConnect Of hoSQLMngr Customer.File_number To hdbc
Get SQLOpen Of hdbc To hstmt
Send SQLExecDirect Of hstmt "select * from customer"
Get SQLStmtAttribute Of hstmt SQLSTMTATTRIB_COLUMNCOUNT To iNumCols
For iCol From 1 To iNumCols
Get SQLColAttribute Of hstmt iCol SQLCOLATTRIB_LABEL To sColumnName
Show sColumnName
If (iCol < iNumCols) ;
Show ", "
Loop
Repeat
Get SQLFetch Of hstmt To iFetchResult
If (iFetchResult <> 0) Begin
For iCol From 1 To iNumCols
Get SQLColumnValue Of hstmt iCol To sColumn
Show sColumn
If (iCol < iNumCols) ;
Show ", "
Loop
Showln
End
Until (iFetchResult = 0)
Send SQLClose Of hstmt
Send SQLDisconnect Of hdbc
Return Value
Returns a column attribute.