FieldInfo Examples

Contents Hide

  

Field information may be constructed based on the table the query involves. The following table will be used to demonstrate how field information is constructed in a script.

Example 1. Constructing Field Information

Given the following table of types represented as int,

Int Value Constant
0 FieldInfo.UNKNOWN
1 FieldInfo.STRING
2 FieldInfo.BOOLEAN
3 FieldInfo.INTEGER
4 FieldInfo.DOUBLE
5 FieldInfo.DATETIME
6 FieldInfo.BASE64BINARY

Field1 of the main example may be constructed as shown below, using the FieldInfo object which has the constructor FieldInfo(string name, int type, boolean pk, boolean, size, boolean unique).

f1 = new FieldInfo("FIELD1", FieldInfo.INTEGER, true, 0, false);

The whole table in the main example may thus be represented as a vector of field data as follows:

f1 = new FieldInfo("FIELD1", FieldInfo.INTEGER, true,  0,  false);

f2 = new FieldInfo("FIELD2", FieldInfo.STRING, false, 10, true );

f3 = new FieldInfo("FIELD3", FieldInfo.STRING, false, 10, true );

f4 = new FieldInfo("FIELD4", FieldInfo.BOOLEAN, false, 0,  true );

f5 = new FieldInfo("FIELD5", FieldInfo.DOUBLE, false, 0,  true );

f6 = new FieldInfo("FIELD6", FieldInfo.DATETIME, false, 0,  true );

 

vectFieldInfo = new Vector();

vectFieldInfo.add(f1);

vectFieldInfo.add(f2);

vectFieldInfo.add(f3);

vectFieldInfo.add(f4);

vectFieldInfo.add(f5);

vectFieldInfo.add(f6);

Note:

Example 2. Assigning Field Information

Once a vector of FieldInfo has been created, it can be passed to a record set with the setFieldInfo method. Doing this will ensure the data passed between the server and script is of the same type and thus read properly.

vectFieldInfo = new Vector();

//... lines of code populating vectFieldInfo

rs.setFieldInfo(vectFieldInfo);

Note:

Example 3. Referencing Field Information

A file info object's data may be referenced by get/is methods. The following code retrieves all the information about a field and prints it out in the server log.

f1 = ...

 

str = "(";

str = str + f1.getName() + ", ";
str = str + f1.getType() + ", ";

str = str + f1.isPK() + ", ";

str = str + f1.getLength() + ", ";

str = str + f1.isNullable() + ")";

 

ScriptSession.logInfo(str);

Note: