1、通过代码把一个pg数据源中所有数据集的宽文本类型的字段修改为文本类型,未能成功,代码如下:
public void changeFieldTypeWtext2Text(Datasource datasource){
Datasets datasets = datasource.getDatasets();
try {
for(int i=0; i<datasets.getCount(); i++){
Dataset dataset = datasets.get(i);
DatasetVector datasetVector = (DatasetVector) dataset;
String datasetVectorName = datasetVector.getName();
FieldInfos fieldInfos = datasetVector.getFieldInfos();
for (int j=0; j<fieldInfos.getCount(); j++){
FieldInfo fieldInfoOld = fieldInfos.get(j);
if (fieldInfoOld.getType() == FieldType.WTEXT){
String name = fieldInfoOld.getName();
FieldType type = fieldInfoOld.getType();
int length = fieldInfoOld.getMaxLength();
String caption = fieldInfoOld.getCaption();
String defaultValue = fieldInfoOld.getDefaultValue();
fieldInfoOld.setType(FieldType.TEXT);
int index = fieldInfos.indexOf(name);
FieldInfo fieldInfoNew = new FieldInfo();
fieldInfoNew.setName(name);
fieldInfoNew.setType(FieldType.TEXT);
fieldInfoNew.setMaxLength(length);
fieldInfoNew.setCaption(caption);
fieldInfoNew.setDefaultValue(defaultValue);
boolean isModofy = fieldInfos.modify(name, fieldInfoNew);
if (isModofy == false){
String message = "False";
}
}
}
Application.getActiveApplication().getOutput().output(String.format("%s处理完成.", datasetVectorName));
}
Application.getActiveApplication().getOutput().output("字段类型修改处理完成。");
}catch (Exception ex){
String message = ex.getMessage();
}
}