﻿# SQLOP\_GET\_COLDEFS

__

**xcall SQL, SQLOP\_GET\_COLDEFS, cmdhdr, columninfox**

This operation retrieves an array of column information structures describing the previous query. It is optional, but in cases where the query does not list specific columns (e.g. SELECT \*), it is the only way you can find out the structure of the information retrieved. 

**Parameters**

_cmdhdr_ (ST\_SQL\_CMDHDR), \[in/out\]

The fields of interest to this opcode in the _cmdhdr_ structure (defined in [SQL.DEF](https://bitbucket.org/microsabio/exlib/src/master/909060/sql.def)) are listed below.

| **Field** | **Dir** | **Notes** |
|------|------|------|
| handle | in | handle to connection (returned from SQLOP\_INIT\_CONN) |
| dbmsconid | in | [DBMS Connector ID](dbmsconnectorid.md) |
| opflags | n/a |  |
| cmdarg1,2 | n/a |  |
| rc | out | return code (0 = ok, see SQLERR\_xxx) |
| rcext | out | extended error code |
| info1 | out | \# of columns in result set (if _rc_ = 0) |
| info2 | n/a |  |
| sqlstate | out | ANSI standard SQL state code |
| reshdl | in | Result set handle.  |
| psthdl | n/a |  |




_columninfox _\[array of ST\_SQL\_FIELD structures, out\]

Should be mapped as follows:

map1 columninfox

map2 flddef(MAX\_SQL\_FIELD),ST\_SQL\_FIELD 

The MAX\_SQL\_FIELD definition (maximum number of fields to consider in a query result set) is up to you; SQL.SBR infers this from the overall size of the columninfox parameter. (See Notes for information on allocating a dynamic array here.)

The SQ\_SQL\_FIELD structure is defined in SQL.DEF and contains the following members:

| **ST\_SQL\_FIELD**  <br>**member** | **Type** | **Notes** |
|------|------|------|
| name | s,32 | field name (or alias) |
| org’name | s,32 | original field name (no alias) |
| table | s,32 | table name (unless calculated) |
| org’table | s,32 | original table name (no alias) |
| db | s,32 | name of database |
| catalog | s,12 | name of catalog (always ‘def’ for MySQL 5.x) |
| dflt | s,32 | default value of field |
| length | b,4 | width of field (display width) |
| max’length | b,4 | max width of actual field data for current result set. ODBC does not appear to support this, so max’length will be equal to length. See FETCH\_MAXLENS flag for [SQLOP\_FETCH\_GRID](sqlop_fetch_grid.md). |
| flags | b,4 | bit flags describing field – see [SQL Field Types and Flags](sqlfieldtypesandflags.md)in the appendix |
| type | b,4 | field type – see [SQL Field Types and Flags](sqlfieldtypesandflags.md)in the appendix |
| decimals | b,2 | number of decimals for numeric fields |
| charsetnr | b,2 | character set/collation ID |




**Notes**

If you're not sure of the maximum number of fields, you can use a dynamic (DIMX) array to retrieve the column information, as follows: First, get the number of columns returned from SQLOP\_QUERY or SQLOP\_GET\_INFO / SQLINFO\_FIELDCOUNT calls, and use it to DIMX or REDIMX an array of the necessary number of elements, each equal in size to the size of the SQ\_SQL\_FIELD structure, e.g.

map1 flddef,ST\_SQL\_FIELD    \! a structure for one field def

dimx flddef(columns),x,sizeof(flddef) \! Array for all flddefs

Then, create a dynamic overlay on top of the array just allocated:

map1 columninfox,x,@0   \! Define an overlay variable

columninfox = @flddef() \! And overlay it on the array

…

The dynamic overlay variable can now be passed to the SQLOP\_GET\_COLDEFS, just like the static _columninfox_ in the standard syntax example. And just as in the standard case, on return the individual field definitions can be accessed directly within the flddef() array.