com.j256.ormlite.stmt.Where.between()方法的使用及代码示例

x33g5p2x  于2022-02-03 转载在 其他  
字(4.7k)|赞(0)|评价(0)|浏览(207)

本文整理了Java中com.j256.ormlite.stmt.Where.between()方法的一些代码示例,展示了Where.between()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Where.between()方法的具体详情如下:
包路径:com.j256.ormlite.stmt.Where
类名称:Where
方法名:between

Where.between介绍

[英]Add a BETWEEN clause so the column must be between the low and high parameters.
[中]添加一个BETWEEN子句,使列必须介于low和high参数之间。

代码示例

代码示例来源:origin: zulip/zulip-android

@Override
public Where<Message, Object> modWhere(Where<Message, Object> where)
    throws SQLException {
  Calendar calendar = Calendar.getInstance();
  calendar.setTime(date);
  calendar.set(Calendar.HOUR_OF_DAY, 0);
  calendar.set(Calendar.MINUTE, 0);
  calendar.set(Calendar.SECOND, 0);
  calendar.set(Calendar.MILLISECOND, 0);
  Date fromDate = calendar.getTime();
  calendar.add(Calendar.DAY_OF_MONTH, 1);
  Date toDate = calendar.getTime();
  where.between(Message.TIMESTAMP_FIELD, fromDate, toDate);
  return where;
}

代码示例来源:origin: geeksonsecurity/android-overlay-protection

cal.add(Calendar.MONTH, -1);
try {
  final long overlayCount = qb.where().between("timestamp", cal.getTimeInMillis(), System.currentTimeMillis()).countOf();
  final String overlayCountLabel = String.format(getString(R.string.detectedCount), overlayCount);

代码示例来源:origin: j256/ormlite-core

@Test
public void testBetween() throws Exception {
  Where<Foo, String> where = new Where<Foo, String>(createTableInfo(), null, databaseType);
  int low = 1;
  int high = 1;
  where.between(Foo.VAL_COLUMN_NAME, low, high);
  StringBuilder whereSb = new StringBuilder();
  where.appendSql(null, whereSb, new ArrayList<ArgumentHolder>());
  StringBuilder sb = new StringBuilder();
  databaseType.appendEscapedEntityName(sb, Foo.VAL_COLUMN_NAME);
  sb.append(" BETWEEN ").append(low);
  sb.append(" AND ").append(high);
  sb.append(' ');
  assertEquals(sb.toString(), whereSb.toString());
}

代码示例来源:origin: annmuor/jnode

break;
case "between":
  wh.between(args[i].toString(),  new SelectArg(args[i + 2]),  new SelectArg(args[i + 3]));
  i += 1;
  break;

代码示例来源:origin: j256/ormlite-core

@Test
public void testDateBetween() throws Exception {
  Dao<DateBetween, Object> dao = createDao(DateBetween.class, true);
  DateBetween dateBetween = new DateBetween();
  long now = System.currentTimeMillis();
  Date date = new Date(now);
  dateBetween.date = date;
  assertEquals(1, dao.create(dateBetween));
  QueryBuilder<DateBetween, Object> qb = dao.queryBuilder();
  qb.where().between(DateBetween.DATE_COLUMN_NAME, new Date(now - 1), new Date(now + 1));
  List<DateBetween> results = qb.query();
  assertEquals(1, results.size());
  qb.where().reset();
  qb.where().between(DateBetween.DATE_COLUMN_NAME, new Date(now), new Date(now + 1));
  results = qb.query();
  assertEquals(1, results.size());
  qb.where().reset();
  qb.where().between(DateBetween.DATE_COLUMN_NAME, new Date(now), new Date(now));
  results = qb.query();
  assertEquals(1, results.size());
}

代码示例来源:origin: com.j256.ormlite/ormlite-jdbc

@Test
public void testBetweenStrings() throws Exception {
  Dao<Foo, String> fooDao = createTestData();
  QueryBuilder<Foo, String> qb = fooDao.queryBuilder();
  String low = ID_PREFIX;
  String high = ID_PREFIX + "99999";
  qb.where().between(Foo.ID_COLUMN_NAME, low, high);
  List<Foo> results = fooDao.query(qb.prepare());
  assertEquals(2, results.size());
  assertEquals(foo1, results.get(0));
  assertEquals(foo2, results.get(1));
}

代码示例来源:origin: com.j256.ormlite/ormlite-jdbc

@Test
public void testBetween() throws Exception {
  Dao<Foo, String> fooDao = createTestData();
  QueryBuilder<Foo, String> qb = fooDao.queryBuilder();
  qb.where().between(Foo.VAL_COLUMN_NAME, LOW_VAL, HIGH_VAL);
  List<Foo> results = fooDao.query(qb.prepare());
  assertEquals(2, results.size());
  assertEquals(foo1, results.get(0));
  assertEquals(foo2, results.get(1));
  qb.where().between(Foo.VAL_COLUMN_NAME, LOW_VAL + 1, HIGH_VAL);
  results = fooDao.query(qb.prepare());
  assertEquals(1, results.size());
  assertEquals(foo2, results.get(0));
  qb.where().between(Foo.VAL_COLUMN_NAME, LOW_VAL, HIGH_VAL - 1);
  results = fooDao.query(qb.prepare());
  assertEquals(1, results.size());
  assertEquals(foo1, results.get(0));
  qb.where().between(Foo.VAL_COLUMN_NAME, LOW_VAL + 1, HIGH_VAL - 1);
  results = fooDao.query(qb.prepare());
  assertEquals(0, results.size());
}

代码示例来源:origin: com.j256.ormlite/ormlite-jdbc

@Test
public void testBetweenSelectArg() throws Exception {
  Dao<Foo, String> fooDao = createTestData();
  QueryBuilder<Foo, String> qb = fooDao.queryBuilder();
  SelectArg lowSelectArg = new SelectArg();
  qb.where().between(Foo.VAL_COLUMN_NAME, lowSelectArg, HIGH_VAL);
  lowSelectArg.setValue(LOW_VAL);
  List<Foo> results = fooDao.query(qb.prepare());
  assertEquals(2, results.size());
  assertEquals(foo1, results.get(0));
  assertEquals(foo2, results.get(1));
  SelectArg highSelectArg = new SelectArg();
  lowSelectArg.setValue(LOW_VAL + 1);
  highSelectArg.setValue(HIGH_VAL);
  qb.where().between(Foo.VAL_COLUMN_NAME, lowSelectArg, highSelectArg);
  results = fooDao.query(qb.prepare());
  assertEquals(1, results.size());
  assertEquals(foo2, results.get(0));
}

相关文章