Purpose
Retrieves information about columns in a result set. You can call this function from the MapBasic window in MapInfo Pro.
Syntax
Server_ColumnInfo( StatementNumber, ColumnNo, Attr )
StatementNumber is an integer value that identifies information about an SQL statement.
ColumnNo is the number of the column in the table, starting at 1 with the leftmost column.
Attr is a code indicating which aspect of the column to return.
Return Value
The return value is conditional based on the value of the attribute passed (Attr).
Description
The Server_ColumnInfo function returns information about the current fetched column in the result set of a remote data source described by a remotely executed Select statement. The StatementNumber parameter specifies the particular statement handle associated with that connection. The ColumnNo parameter indicates the desired column (the columns are numbered from the left starting at 1). Attr selects the kind of information that will be returned.
The following table contains the attributes returned to the Attr parameter. These types are defined in MAPBASIC.DEF.
Attr value | ID | Server_ColumnInfo() returns: |
---|---|---|
SRV_COL_INFO_NAME | 1 | String result, the name identifying the column. |
SRV_COL_INFO_TYPE | 2 | Integer result, a code indicating the column type:
See Server Fetch for how MapInfo Pro interprets data types. |
SRV_COL_INFO_WIDTH | 3 | Integer result, indicating maximum number of characters in a column of type SRV_COL_TYPE_CHAR (1) or SRV_COL_TYPE_FIXED_LEN_STRING (16).
When using ODBC the null terminator is not counted. The value returned is the same as the server database table column width. |
SRV_COL_INFO_PRECISION | 4 | Integer result, indicating the total number of digits for a SRV_COL_TYPE_DECIMAL (2) column, or -1 for any other column type. |
SRV_COL_INFO_SCALE | 5 | Integer result, indicating the number of digits to the right of the decimal for a SRV_COL_TYPE_DECIMAL (2) column, or -1 for any other column type. |
SRV_COL_INFO_VALUE | 6 | Result type varies. Returns the actual data value from the column of the current row. Long character column values greater than 32,766 will be truncated. Binary column values are returned as a double length string of hexadecimal characters. |
SRV_COL_INFO_STATUS | 7 | Integer result, indicating the status of the column value:
|
SRV_COL_INFO_ALIAS | 8 | Column alias returned if an alias was used for the column in the query. |
Example
Dim hdbc, Stmt As Integer
Dim Col As Integer
hdbc = Server_Connect("ODBC", "DLG=1")
Stmt = Server_Execute(hdbc, "Select * from emp")
Server Stmt Fetch NEXT
For Col = 1 To Server_NumCols(Stmt)
Print Server_ColumnInfo(Stmt, Col, SRV_COL_INFO_NAME) +
" = " +
Server_ColumnInfo(Stmt, Col, SRV_COL_INFO_VALUE)
Next
See Also:
Server Bind Column statement, Server Fetch statement, Server_NumCols() function