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.
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:
f1..6 denotes fields1 to 6 respectively
Alternatively, instead of FieldInfo.INTEGER, FieldInfo.STRING constants, the integer values of the types (as displayed in the table) may be used.
The vectFieldInfo vector contains the fields in the order they are listed in the table. This is necessary when setting the FieldInfo data of a result set.
The vectFieldInfo vector is constructed separately for clarity purposes, however new Field info does not need to be explicitly defined in this fashion; for example vectFieldInfo.add(new FieldInfo...)); would work.
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:
rs is a record set with no field data assigned to it
vectFileInfo, a vector, is populated as in the previous step
Commented out section is similar to
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:
f1 has been allocated earlier and is a FieldInfo type
A ScriptSession method is called on the final line, which will print the constructed string if the trace level is set as debug or higher.