AR System Java 编程 -- ARServerUser.getListSQL()

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的方法:
 SQLResultgetListSQL(String sqlCommand, int maxRetrieve, boolean retrieveNumMatches)
          Returns a list of rows from the underlying SQL database on the specified server.
这里maxRetrieve设为0,表示取出所有的.
retrieveNumMatches暂时没用,设为true即可.
sql Command 就是我们平时使用的sql.

结果返回SQLResult类型,我们再看看这个类的主要方法有:
 List<List<Value>>getContents()
          Returns list of zero or more (accessible) rows that match the criteria defined by thesqlCommand value Each item in the list represents one matching row, each of which contains a list of the selected column values.
 StringgetReturnCommand()
           
 intgetTotalNumberOfMatches()
          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了:


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值