DbFieldInfo Function | |
Return and optionally change information about a field.
Namespace:
XSharp.RT
Assembly:
XSharp.RT (in XSharp.RT.dll) Version: 2.21
Syntax FUNCTION DbFieldInfo(
kInfoType,
nFieldPos,
uNewSetting
) AS USUAL CLIPPER
[ClipperCallingConventionAttribute(new string[] { ... })]
public static Usual DbFieldInfo(
Usual kInfoType = default,
Usual nFieldPos = default,
Usual uNewSetting = default
)
Request Example
View SourceParameters
- kInfoType (Optional)
- Type: Usual
Specifies the type of information.
The constants are described in the Constants section below. Note, however, that not all constants are supported for all RDDs.
See the remarks section for a list of the constants that are supported.
- 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 Constants 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 Constants 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
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
Constants | Description |
---|
DBS_ALIAS |
Returns and optionally changes an alternate name (or alias) by which a field can be referenced
(by default, same as DBS_NAME). Using the uNewSetting argument, you can
specify a string that you can subsequently use to access the indicated 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 BLOBDirectPut(), BLOBDirectImport(), or
FieldInfo(DBS_BLOB_POINTER, .../>).
|
DBS_BLOB_DIRECT_TYPE |
To determine the data type of BLOB data, without reference to a particular memo field, use DBS_BLOB_DIRECT_TYPE.
With this constant, you must specify the BLOB using a numeric pointer obtained from BLOBDirectPut(),
BLOBDirectImport(), or 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 |
---|
Using DBS_BLOB_LEN has a performance advantage over retrieving the value and using the Len() function. |
|
DBS_BLOB_POINTER | Returns 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 DBS_BLOB_TYPE.
The data type of the return value is string and can be interpreted using this table:
Returns | Meaning |
---|
? | Blank (empty/uninitialized field) | A | Array | C | String | D | Date | E | Error | L | Logical | N | Numeric | U | Undefined (NIL was stored) |
|
DBS_DEC | Returns the number of decimal places for the field. |
DBS_LEN | Returns the length of the field. |
DBS_NAME | Returns the name of the field. |
DBS_PROPERTIES | Returns the number of properties defined for a field. |
DBS_TYPE | Returns the data type of the field. |
DBS_USER | Start of user defined values. |
Tip |
---|
DBS_USER is a constant that returns the minimum value that third-party RDD developers can use for customizations.
Values less than DBS_USER are reserved for X# development.
|
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:
1QOut(DBFieldInfo(DBS_NAME, 1))
2
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:
1FUNCTION Start()
2 USE datebook
3 DBFieldInfo(DBS_ALIAS, FieldPos("Name"), "NewName")
4 ? Name
5 ? NewName
See Also