Select 行在使用原始查询时比较 ormlite 中的两列值
Select rows comparing two column value in ormlite while using raw query
我有以下数据库table
@DatabaseTable(tableName = "Order_Details")
public class DB_OrderDetails {
@DatabaseField(generatedId = true)
private int id;
@DatabaseField()
private int order_id_from_order_table;
@DatabaseField()
private String medicine_code;
@DatabaseField()
private String medicine_name;
@DatabaseField()
private String medicine_type;
@DatabaseField()
private int number_of_units_ordered;
@DatabaseField()
private String generic_name;
@DatabaseField()
private String manufacturer_name;
@DatabaseField()
private double ordering_cost;
... }
我正在使用 ormlite 进行本地数据库操作。我想获得
的结果
SELECT * FROM Order_Details WHERE (medicine_code='xxxx' AND manufacturer_name='yyyy')
并希望获得
中返回的结果
List<DB_OrderDetails>
任何人都可以建议我一个方法吗?
使用 Where class 的对象来构建您的查询。
List<DB_OrderDetails> list;
try {
Dao<DB_OrderDetails, String> dbOrderDetailsStringDao = dbHelper.getOrderDetailsDao();
QueryBuilder<DB_OrderDetails, String> queryBuilder = dbOrderDetailsStringDao.queryBuilder();
Where where = queryBuilder.where();
where.eq("medicine_code", "xxxx");
where.and();
where.eq("manufacturer_name", "yyyy");
PreparedQuery<DB_OrderDetails> preparedQuery = queryBuilder.prepare();
list = dbOrderDetailsStringDao.query(preparedQuery);
} catch (SQLException e) {
e.printStackTrace();
}
我有以下数据库table
@DatabaseTable(tableName = "Order_Details")
public class DB_OrderDetails {
@DatabaseField(generatedId = true)
private int id;
@DatabaseField()
private int order_id_from_order_table;
@DatabaseField()
private String medicine_code;
@DatabaseField()
private String medicine_name;
@DatabaseField()
private String medicine_type;
@DatabaseField()
private int number_of_units_ordered;
@DatabaseField()
private String generic_name;
@DatabaseField()
private String manufacturer_name;
@DatabaseField()
private double ordering_cost;
... }
我正在使用 ormlite 进行本地数据库操作。我想获得
的结果SELECT * FROM Order_Details WHERE (medicine_code='xxxx' AND manufacturer_name='yyyy')
并希望获得
中返回的结果List<DB_OrderDetails>
任何人都可以建议我一个方法吗?
使用 Where class 的对象来构建您的查询。
List<DB_OrderDetails> list;
try {
Dao<DB_OrderDetails, String> dbOrderDetailsStringDao = dbHelper.getOrderDetailsDao();
QueryBuilder<DB_OrderDetails, String> queryBuilder = dbOrderDetailsStringDao.queryBuilder();
Where where = queryBuilder.where();
where.eq("medicine_code", "xxxx");
where.and();
where.eq("manufacturer_name", "yyyy");
PreparedQuery<DB_OrderDetails> preparedQuery = queryBuilder.prepare();
list = dbOrderDetailsStringDao.query(preparedQuery);
} catch (SQLException e) {
e.printStackTrace();
}