最近没怎么写博客,写个会给大家带来方便的东西,好不好大家评判了。
看看maximo7的api介绍,上面写着:
Performs a number of formatting operations on Sql Strings. Currently, this includes bind values from an Mbo to a SQL statement. eg. Convert a statement like 'WHERE X=:assetnum to 'WHERE X='11430''. Converts strings to db-specific SQL Strings
说白了,就是按照maximo的方式解析sql语句。这个类其实很有用,比如我们定义sql语句时,可以按照定义关系时那样定义需要去匹配的字段,举个例子:
SqlFormat sqf = new SqlFormat("wonum in (select wonum from woancestor where ancestor=:1 and siteid =:2) and siteid=:2 and istask=0");
sqf.setObject(1, "WORKORDER", "WONUM", wo.getString("wonum"));
sqf.setObject(2, "WORKORDER", "SITEID", wo.getString("siteid"));
MboSetRemote workorderSet = wo.getMboSet("$workorder", "WORKORDER", sqf.format());
有个特殊情况,如果我们需要去匹配的字段,如果我们不知道他的格式时,怎么去处理呢。我们到底应该调用getString(),getInt()还是getDate()呢。
举个小例子,不能完全借鉴:
int type = mainMbo.getMboValueData(attr).getTypeAsInt();
switch (type) {
case 3:
case 4:
case 5:
return mainMbo.getDate(attr).toString();
case 8:
return String.valueOf(mainMbo.getFloat(attr));
case 9:
case 10:
case 11:
return String.valueOf(mainMbo.getDouble(attr));
case 6:
case 7:
case 12:
return String.valueOf(mainMbo.getInt(attr));
default:
return mainMbo.getString(attr);
}