Skip to content

SQLColumnInfo - cBaseSQLExecutor

Returns the column information for the result set

Type: Function
Return Data Type: tSQLColumnInfo[]

Syntax

Function SQLColumnInfo Returns tSQLColumnInfo[]

Call Example

Get SQLColumnInfo to tSQLColumnInfo[]Variable

Description

SQLColumnInfo returns the column information for the result set into a array of tSQLColumnInfo structs.

Types reported are based on the data types returned by ODBC and might be slightly different than the actual data type in the table structure in the backend.

If you want to put the results into a grid, the column information, for example, can be used to initialize your grid columns. Always call SQLColumnInfo after a SQLExecute or SQLExecDirect.

Example

This query will result in a aColumnsInfo array with 3 elements holding the information for the columns Name, City and Zip.

String[][] aResults
tSQLColumnInfo[] aSQLColumnsInfo

// Fetch results into aResults
Get SQLExecDirect of ghoSQLExecutor @SQL"SELECT
    Name,  
    City,
    Zip
    FROM Customer" to aResults

// Test for errors
If (not(Err)) Begin
    // Get the columns info
    Get SQLColumnInfo of ghoSQLExecutor to aSQLColumnsInfo

    // Process results here..
End

Multiple Result Set SQLColumnInfo Example

A SQLExecutor query can return multiple result sets. To retrieve the column info for all result sets the tSQLColumnInfo must be defined as a 2 dimensional array.

Procedure TestSQLMultiResults
    String[][][] aResults
    tSQLColumnInfo[][] aSQLColumnsInfo

    String sSQLQuery

    Move @SQL"""
    SELECT * FROM Vendor   
    SELECT * FROM Customer 
    """ to sSQLQuery

    Get SQLExecDirect of ghoSqlExecutor sSQLQuery to aResults
    Get SQLColumnInfo of ghoSQLExecutor to aSQLColumnsInfo        

    Showln (SFormat("Query returned %1 result sets",(SizeOfArray(aResults)) ))
    Showln (SFormat("SQLColumnInfo returned %1 result sets",(SizeOfArray(aSQLColumnsInfo)) ))

    Integer iIx
    For iIx from 0 to ((SizeOfArray(aSQLColumnsInfo)) - 1)
        Showln (SFormat("Result set %1 has %2 columns",iIx,(SizeOfArray(aSQLColumnsInfo[iIx])) ))
    Loop
End_Procedure

Return Value

Column information for the result set