API 提供了几种方法,让我们可以从ar system中取得entry,
例如常用的有:
List<Entry> | getListEntryObjects(String formName,List<String> entryIds, int[] fieldIds) Returns a list of Entry objects that match the provided criteria. |
List<Entry> | getListEntryObjects(String formName,QualifierInfo qualification, int firstRetrieve, int maxRetrieve,List<SortInfo> sortList, int[] fieldIds, boolean useLocale,OutputInteger nMatches) Returns a list of Entry objects that match the provided criteria. |
但使用这个方法的时候,会出现一个问题,即使我们将MaxRetrieve 设为Constants.AR_NO_MAX_LIST_RETRIEVE,也不能得所有的entry,那得到最大的entry size是多少?
Server Information限制了form展示的最大的entry size,也就是说,使用以上方法的时候,得到最大的entry size和这里有关.
那么,假如我要查询结果的entry size 大于server information中定义的,在不修改server information的情况下,怎么全部取出来呢?
API还提供了另一种用sql取出entry的方法:
SQLResult | getListSQL(String sqlCommand, int maxRetrieve, boolean retrieveNumMatches) Returns a list of rows from the underlying SQL database on the specified server. |
retrieveNumMatches暂时没用,设为true即可.
sql Command 就是我们平时使用的sql.
结果返回SQLResult类型,我们再看看这个类的主要方法有:
List<List<Value>> | getContents() Returns list of zero or more (accessible) rows that match the criteria defined by the sqlCommand value Each item in the list represents one matching row, each of which contains a list of the selected column values. |
String | getReturnCommand() |
int | getTotalNumberOfMatches() Returns the total number of (accessible) rows that match the SQL selection criteria. |
我们主要看getContents()方法.
返回值是List<List<Value>>,也就是说执行sqlCommand之后:
List<>里面存的是行,List<Value>存的是每一行每一格的值.
例如:
表
代码:
public static void main(String[] args) {
String sql =
"select Name,Age from Test;";
arUtil.connect();
ARServerUser server = ARUtil.getServer();
try {
SQLResult result = server.getListSQL(sql, 0, true);
for(int i = 0; i < result.getContents().size(); i++){
System.out.println(result.getContents().get(i));
for(int j=0; j < result.getContents().get(i).size(); j++){
System.out.println(result.getContents().get(i).get(j));
}
}
} catch (ARException e) {
EgisException.printError(e);
} finally{
arUtil.disConnect();
}
}
结果为:
假如SQL里面有两条select 的语句呢,List里面放的是什么值?
public static void main(String[] args) {
String sql =
"select Name,Age from Test;"
+ "select Name,Address from Test;";
arUtil.connect();
ARServerUser server = ARUtil.getServer();
try {
SQLResult result = server.getListSQL(sql, 0, true);
for(int i = 0; i < result.getContents().size(); i++){
System.out.println(result.getContents().get(i));
for(int j=0; j < result.getContents().get(i).size(); j++){
System.out.println(result.getContents().get(i).get(j));
}
}
} catch (ARException e) {
EgisException.printError(e);
} finally{
arUtil.disConnect();
}
}
没有输出Address相关的,结果依然为:
所以说:List里面存的是第一个select语句的值.
那么除了查询,我们可以放delete之类的语句吗?
当然可以,例如:
我们想查Test有多少条,并且删除Name=Jim的记录:
public static void main(String[] args) {
String sql =
"select count(*) from EGIS_CLP_Test;"
+ "delete EGIS_CLP_Test where Name='Jim'";
arUtil.connect();
ARServerUser server = ARUtil.getServer();
try {
SQLResult result = server.getListSQL(sql, 0, true);
System.out.println("Count=" + result.getContents().get(0).get(0));
} catch (ARException e) {
EgisException.printError(e);
} finally{
arUtil.disConnect();
}
}
输出为:
SQL select可见已经delete了: