Cicode Programming Reference > Cicode Function Categories > SQL Functions > SQLFieldInfo

SQLFieldInfo

Gets information about the fields or columns selected by a SQL query. The function returns the name and width of the specified field. If you call the function within a loop, you can return the names and sizes of all the fields in the database.

When the hGeneral is the connection handle, the function returns information about the default recordset. When the hGeneral is the recordset handle, the function returns information about the recordset itself.

Keywords such as "DATE", "TIME", and "DESC" cannot be used as field names by some database systems. To use fields with these names, you need to append underscores to the names (for example, "TIME_", "DATE_", "DESC_").

This function can be called in the foreground or background.

Some combinations of database drivers and databases can return no name for certain classes of fields/columns, for example for aggregation queries such as "select SUM". In those cases such fields can be either explicitly named in the query itself, or accessed via a unified name in the format of "Field{ColumnNumber}" where {ColumnNumber} is the number of the requested field/column in the recordset.

Syntax

SQLFieldInfo(hGeneral, hField, sName, Width)

hGeneral:

The handle either to:

hField:

The field (or column) handle, indicating the position of the field in the database.

sName:

Output Parameter: A string in which the function stores the field name. The argument is returned by the function. Must be a String type variable.

Width:

Output Parameter: An integer in which the function stores the maximum number of characters in the field. The argument is returned by the function. Must be an Integer type variable.

Return Value

0 (zero) if successful, otherwise an error number is returned. (For details of the 307 error code, call the SQLErrMsg function).

Related Functions

SQLSet, SQLAppend, SQLExec, SQLGetRecordset, SQLCall, SQLGetScalar, SQLEnd, SQLNumChange, SQLNoFields, SQLNumFields, SQLFieldInfo, SQLGetField, SQLIsNullField, SQLRowCount, SQLNext, SQLPrev

Example

! Lists all fields in the Employee database
FUNCTION
ListFields()
INT hSQL;
STRING sField;
INT Count;
INT Width;
INT Index;
SQLTraceOn("C:\DATA\TRACE.LOG");
hSQL = SQLConnect("DRV=QEDBF");
SQLExec(hSQL, "SELECT * FROM C:\DATA\EMPLOYEE");
Count = SQLNoFields(hSQL);
Index = 0;
WHILE Index < Count DO
SQLFieldInfo(hSQL,Index,sField,Width);
..
END
SQLEnd(hSQL);
SQLDisconnect(hSQL);
SQLTraceOff();
END

See Also

SQL Functions

Published June 2018