本文整理了Java中com.j256.ormlite.stmt.Where.raw()
方法的一些代码示例,展示了Where.raw()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Where.raw()
方法的具体详情如下:
包路径:com.j256.ormlite.stmt.Where
类名称:Where
方法名:raw
[英]Add a raw statement as part of the where that can be anything that the database supports. Using more structured methods is recommended but this gives more control over the query and allows you to utilize database specific features.
[中]在where中添加一条原始语句,该语句可以是数据库支持的任何内容。建议使用更结构化的方法,但这样可以更好地控制查询,并允许您利用特定于数据库的功能。
代码示例来源:origin: TeamWalrus/Walrus
public static List<Card> filterCards(Dao<Card, ?> dao, String searchParameter) {
try {
return dao.queryBuilder()
.where()
.raw(Card.NAME_FIELD_NAME + " LIKE '%"
+ searchParameter.replaceAll("[\\\\%_]", "\\\\$0").replace("'", "''")
+ "%' ESCAPE '\\'")
.query();
} catch (SQLException e) {
throw new RuntimeException(e);
}
}
}
代码示例来源:origin: zulip/zulip-android
@Override
public Where<Message, Object> modWhere(Where<Message, Object> where)
throws SQLException {
where.raw(
Message.CONTENT_FIELD + " LIKE ? COLLATE NOCASE",
new SelectArg(Message.CONTENT_FIELD, "%"
+ DatabaseHelper.likeEscape(query) + "%"));
return where;
}
代码示例来源:origin: zulip/zulip-android
@Override
public void onDataSetChanged() {
Log.i("ZULIP_WIDGET", "onDataSetChanged() = Data reloaded");
QueryBuilder<Message, Object> queryBuilder = ZulipApp.get().getDao(Message.class).queryBuilder();
String filter;
filter = setupWhere();
if (!filter.equals("")) {
queryBuilder.where().raw(filter);
}
try {
messageList = queryBuilder.query();
} catch (SQLException e) {
ZLog.logException(e);
}
}
代码示例来源:origin: j256/ormlite-core
@Test
public void testRaw() throws Exception {
TableInfo<Foo, Integer> tableInfo = new TableInfo<Foo, Integer>(databaseType, Foo.class);
Where<Foo, Integer> where = new Where<Foo, Integer>(tableInfo, null, databaseType);
String raw = "VAL = 1";
int val = 17;
where.eq(Foo.VAL_COLUMN_NAME, val).and().raw(raw);
StringBuilder whereSb = new StringBuilder();
where.appendSql(null, whereSb, new ArrayList<ArgumentHolder>());
StringBuilder sb = new StringBuilder();
sb.append('(');
databaseType.appendEscapedEntityName(sb, Foo.VAL_COLUMN_NAME);
sb.append(" = ").append(val);
sb.append(" AND ").append(raw).append(" ) ");
assertEquals(sb.toString(), whereSb.toString());
}
代码示例来源:origin: j256/ormlite-core
@Test
public void testEscapeMethods() throws Exception {
UpdateBuilder<Foo, Integer> stmtb = new UpdateBuilder<Foo, Integer>(databaseType, baseFooTableInfo, null);
int idVal = 32524;
stmtb.updateColumnValue(Foo.ID_COLUMN_NAME, idVal);
String expression = "blah + 1";
stmtb.updateColumnExpression(Foo.VAL_COLUMN_NAME, expression);
stmtb.where().raw(stmtb.escapeColumnName(Foo.VAL_COLUMN_NAME) + " = " + stmtb.escapeValue(expression));
StringBuilder sb = new StringBuilder();
sb.append("UPDATE ");
databaseType.appendEscapedEntityName(sb, baseFooTableInfo.getTableName());
sb.append(" SET ");
databaseType.appendEscapedEntityName(sb, Foo.ID_COLUMN_NAME);
sb.append(" = ").append(idVal).append(" ,");
databaseType.appendEscapedEntityName(sb, Foo.VAL_COLUMN_NAME);
sb.append(" = ");
sb.append(expression);
sb.append(" WHERE ");
databaseType.appendEscapedEntityName(sb, Foo.VAL_COLUMN_NAME);
sb.append(" = ");
databaseType.appendEscapedWord(sb, expression);
sb.append(' ');
assertEquals(sb.toString(), stmtb.prepareStatementString());
StringBuilder whereBuilder = new StringBuilder();
stmtb.escapeColumnName(whereBuilder, Foo.VAL_COLUMN_NAME);
whereBuilder.append(" = ");
stmtb.escapeValue(whereBuilder, expression);
stmtb.where().raw(whereBuilder.toString());
}
代码示例来源:origin: j256/ormlite-core
@Test(expected = IllegalArgumentException.class)
public void testRawArgsNoColumnName() throws Exception {
Dao<Foo, String> dao = createDao(Foo.class, true);
dao.queryBuilder().where().raw("id = ?", new SelectArg(7));
}
代码示例来源:origin: com.j256.ormlite/ormlite-jdbc
@Test
public void testRaw() throws Exception {
Dao<Foo, Integer> dao = createDao(Foo.class, true);
Foo foo = new Foo();
int val = 131265312;
foo.val = val;
assertEquals(1, dao.create(foo));
StringBuilder sb = new StringBuilder();
databaseType.appendEscapedEntityName(sb, Foo.VAL_FIELD_NAME);
String fieldName = sb.toString();
QueryBuilder<Foo, Integer> qb = dao.queryBuilder();
qb.where().eq(Foo.ID_FIELD_NAME, foo.id).and().raw(fieldName + " = " + val);
assertEquals(1, dao.query(qb.prepare()).size());
qb.where().eq(Foo.ID_FIELD_NAME, foo.id).and().raw(fieldName + " != " + val);
assertEquals(0, dao.query(qb.prepare()).size());
}
代码示例来源:origin: j256/ormlite-core
@Test
public void testRawArgsColumn() throws Exception {
Dao<Foo, String> dao = createDao(Foo.class, true);
Foo foo = new Foo();
int val = 63465365;
foo.val = val;
assertEquals(1, dao.create(foo));
QueryBuilder<Foo, String> qb = dao.queryBuilder();
qb.where().raw(Foo.ID_COLUMN_NAME + " = ?", new SelectArg(Foo.ID_COLUMN_NAME, foo.id));
List<Foo> results = qb.query();
assertNotNull(results);
assertEquals(1, results.size());
assertEquals(val, results.get(0).val);
}
代码示例来源:origin: j256/ormlite-core
@Test
public void testRawArgsColumnSqlType() throws Exception {
Dao<Foo, Integer> dao = createDao(Foo.class, true);
Foo foo = new Foo();
int val = 63465365;
foo.val = val;
assertEquals(1, dao.create(foo));
QueryBuilder<Foo, Integer> qb = dao.queryBuilder();
qb.where().raw(Foo.ID_COLUMN_NAME + " = ? and " + val + " = ?", new SelectArg(SqlType.STRING, foo.id),
new SelectArg(SqlType.INTEGER, val));
List<Foo> results = qb.query();
assertNotNull(results);
assertEquals(1, results.size());
assertEquals(val, results.get(0).val);
}
代码示例来源:origin: j256/ormlite-core
@Test
public void testRawArgsColumnNoValue() throws Exception {
Dao<Foo, String> dao = createDao(Foo.class, true);
Foo foo = new Foo();
int val = 63465365;
foo.val = val;
assertEquals(1, dao.create(foo));
QueryBuilder<Foo, String> qb = dao.queryBuilder();
SelectArg arg = new SelectArg(Foo.ID_COLUMN_NAME, null);
qb.where().raw(Foo.ID_COLUMN_NAME + " = ?", arg);
arg.setValue(foo.id);
List<Foo> results = qb.query();
assertNotNull(results);
assertEquals(1, results.size());
assertEquals(val, results.get(0).val);
}
内容来源于网络,如有侵权,请联系作者删除!