Click or drag to resize

DbFieldInfo Function

X#
Return and optionally change information about a field.

Namespace:  XSharp.RT
Assembly:  XSharp.RT (in XSharp.RT.dll) Version: 2.19
Syntax
 FUNCTION DbFieldInfo(
	kInfoType,
	nFieldPos,
	uNewSetting
) AS USUAL CLIPPER
Request Example View Source

Parameters

kInfoType (Optional)
Type: Usual
Specifies the type of information.
The constants are described in the Remarks section below. Note, however, that not all constants are supported for all RDDs.
nFieldPos (Optional)
Type: Usual
The position of the field in the database file structure or a numeric pointer to a BLOB. Only certain kInfoType constants designed to work with BLOB fields — all noted in the Remarks section below — allow specifying the field using a pointer; all others require specifying the field by its position.
uNewSetting (Optional)
Type: Usual
If specified, this parameter is used to change the value of a setting.
The data type (and whether uNewSetting can be specified), depends on the kInfoType constant and is documented in the Remarks section below.

Return Value

Type: Usual
If uNewSetting is not specified, DBFieldInfo() returns the current setting.
If uNewSetting is specified, the previous setting is returned.
Remarks
Tip Tip
The values in the table below exist both as DEFINEs and also as members of the DbFieldInfo enum.
You can see the numeric values of the defines in the documentation of this Enum.
ConstantsDescription
DBS_NAMEReturns the name of the field.
DBS_TYPEReturns the data type of the field.
DBS_LENReturns the length of the field.
DBS_DECReturns the number of decimal places for the field.
DBS_ALIAS Returns and optionally changes an alternate name (or alias) by which a field can be referenced (by default, same as DBS_NAME).
DBS_PROPERTIESReturns the number of properties defined for a field.
DBS_BLOB_DIRECT_LEN Returns the length of data in a BLOB as an unsigned long integer, without referencing a particular memo field. For strings, the return value is the length of the string in bytes; for arrays, it is the number of elements in the first dimension; for all other data types, it returns -1. With this constant, you must specify the BLOB using a numeric pointer obtained from DBServer:BLOBDirectPut(), DBServer:BLOBDirectImport(), or DBServer:FieldInfo(DBS_BLOB_POINTER, ... />).
DBS_BLOB_DIRECT_TYPE To determine the data type of BLOB data, without reference to a particular memo field, use DBServer:FieldInfo(DBS_BLOB_DIRECT_TYPE, ...). With this constant, you must specify the BLOB using a numeric pointer obtained from DBServer:BLOBDirectPut(), DBServer:BLOBDirectImport(), or DBServer:FieldInfo(DBS_BLOB_POINTER, ...).
See DBS_BLOB_TYPE for a table of possible return values.
DBS_BLOB_LEN Returns the length of the BLOB data in a memo field as an unsigned long integer. For strings, the return value is the length of the string in bytes; for arrays, it is the number of elements in the first dimension; for all other data types, it returns -1.
Tip Tip
DBServer:FieldInfo(DBS_BLOB_LEN, ...) has a performance advantage over the Len() function.
DBS_BLOB_POINTERReturns a numeric pointer to the BLOB data associated with a memo field.
DBS_BLOB_TYPE Unlike memo fields maintained in .DBT files, BLOB files allow you to store many different types of data in memo fields. However, the standard functions for determining data types, such as ValType(), simply treat BLOB fields as regular memo fields. To determine the actual type of BLOB data stored in a memo field, use DBServer:FieldInfo(DBS_BLOB_TYPE, ...). The data type of the return value is string and can be interpreted using this table:
ReturnsMeaning
?Blank (empty/uninitialized field)
AArray
CString
DDate
EError
LLogical
NNumeric
UUndefined (NIL was stored)
DBS_USERStart of user defined DBS_ values.
Tip Tip
DBS_USER is a constant that returns the minimum value that third-party RDD developers can use for defining new properties. Values less than DBS_USER are reserved for X# development.
DBFieldInfo() retrieves information about the state of a field (column). By default, this function operates on the currently selected work area.
It can be made to operate on an unselected work area by specifying it within an aliased expression
The field information that is available is defined by the RDD. In the DBF work area model, this is limited to the information stored in the DBF file structure (that is, name, length, number of decimals, and data type) plus the field alias that can be changed at runtime. To support RDDs for other database models (such as dictionary based databases) that store more information about each field or column, the X# RDD API has been enhanced.
The DBFieldInfo() and VODBFieldInfo() functions are designed to allow for additional kInfoType values that can be defined by third-party RDD developers.
Examples
The following examples use DBFieldInfo() to retrieve field information:
X#
 1QOut(DBFieldInfo(DBS_NAME, 1))
 2// Same as FieldName(1)
 3FUNCTION DBOutStruct() AS ARRAY PASCAL
 4    LOCAL aStruct AS ARRAY
 5    LOCAL wFcount AS DWORD
 6    LOCAL i       AS DWORD
 7    aStruct := {}
 8    wFcount := FCount()
 9    FOR i := 1 UPTO wFcount
10        AAdd(aStruct, {FieldName(i), ;
11        DBFieldInfo(DBS_TYPE, i)  , ;
12        DBFieldInfo(DBS_LEN, i)   , ;
13        DBFieldInfo(DBS_DEC, i)}    )
14    NEXT
15    RETURN aStruct
The next example illustrates using the third parameter to assign an alias to a field name:
X#
1FUNCTION Start()
2    USE datebook
3    DBFieldInfo(DBS_ALIAS, FieldPos("Name"), "NewName")
4    ? Name            // Displays name field
5    ? NewName            // Also displays name field
See Also