在ORMLite中查询这个的最佳方法是什么?
SELECT JOB.TASK_JOB,
JOB.NAME_JOB,
JOB_SETTINGS.DAY1,
JOB_SETTINGS.DAY2,
JOB_SETTINGS.DAY3,
JOB_SETTINGS.DAY4,
JOB_SETTINGS.DAY5,
JOB_SETTINGS.DAY6,
JOB_SETTINGS.DAY7,
JOB_SETTINGS.HOURSPERWEEK,
JOB_SETTINGS.PAYPERHOUR,
JOB_SETTINGS.VARIABLEHOURS,
WORKINGDAY.DATE_WD,
WORKINGDAY.H_BREAK,
WORKINGDAY.H_REAL,
WORKINGDAY.H_IN,
WORKINGDAY.H_OUT
FROM JOB, JOB_SETTINGS,WORKINGDAY
WHERE JOB.ID_JOB = JOB_SETTINGS.ID_JOB
AND JOB_SETTINGS.ID_JOB = WORKINGDAY.ID_JOB
AND JOB.ID_JOB = 2
我为每个表都有一个类(标准ORMLite),但我不了解如何构建此查询...
感谢!!!
修改
我写了这段代码,但实际上我无法继续,因为我对OrmLite语法感到困惑......
DbHelperJob queryDao = new DbHelperJob(getActivity());
QueryBuilder<Job, String> qJob = queryDao.getJobDao().queryBuilder();
qJob.selectColumns("NAME_JOB", "TASK_JOB");
QueryBuilder<JobSettings, String> qJobSett = queryDao.getJobSettDao().queryBuilder();
qJobSett.selectColumns("DAY1", "DAY2", "DAY3", "DAY4", "DAY5", "DAY6", "DAY7", "HOURSPERWEEK", "PAYPERHOUR", "VARIABLEHOURS");
QueryBuilder<WorkingDay, String> qWD = queryDao.getWDDao().queryBuilder();
qWD.selectColumns("DATE_WD", "H_BREAK", "H_REAL", "H_IN", "H_OUT");
答案 0 :(得分:0)
Android查询有参数:
使用它。
答案 1 :(得分:0)
这与ORMLite无关,但是在SQLiteQueryBuilder中有一个非常方便的查询工具。你可以这样做:
private static final String COLS = new String[] {
JOB.TASK_JOB,
JOB.NAME_JOB,
JOB_SETTINGS.DAY1,
JOB_SETTINGS.DAY2,
JOB_SETTINGS.DAY3,
JOB_SETTINGS.DAY4,
JOB_SETTINGS.DAY5,
JOB_SETTINGS.DAY6,
JOB_SETTINGS.DAY7,
JOB_SETTINGS.HOURSPERWEEK,
JOB_SETTINGS.PAYPERHOUR,
JOB_SETTINGS.VARIABLEHOURS,
WORKINGDAY.DATE_WD,
WORKINGDAY.H_BREAK,
WORKINGDAY.H_REAL,
WORKINGDAY.H_IN,
WORKINGDAY.H_OUT
}
private static String SEL =
"JOB.ID_JOB = JOB_SETTINGS.ID_JOB"
+ "AND JOB_SETTINGS.ID_JOB = WORKINGDAY.ID_JOB"
+ "AND JOB.ID_JOB = 2"
private static String TABLES = "JOB, JOB_SETTINGS, WORKINGDAY""
// in the query method...
db.execSQL(
SQLiteQueryBuilder.buildQueryString(
false, TABLES, COLS, SEL, null, null, null, null);
答案 2 :(得分:0)
你可以使用你的Dao的queryRaw()方法。例如
GenericRawResults<String[]> rawResults = queryDao.queryRaw("SELECT JOB.TASK_JOB,
JOB.NAME_JOB,
JOB_SETTINGS.DAY1,
JOB_SETTINGS.DAY2,
JOB_SETTINGS.DAY3,
JOB_SETTINGS.DAY4,
JOB_SETTINGS.DAY5,
JOB_SETTINGS.DAY6,
JOB_SETTINGS.DAY7,
JOB_SETTINGS.HOURSPERWEEK,
JOB_SETTINGS.PAYPERHOUR,
JOB_SETTINGS.VARIABLEHOURS,
WORKINGDAY.DATE_WD,
WORKINGDAY.H_BREAK,
WORKINGDAY.H_REAL,
WORKINGDAY.H_IN,
WORKINGDAY.H_OUT
FROM JOB, JOB_SETTINGS,WORKINGDAY
WHERE JOB.ID_JOB = JOB_SETTINGS.ID_JOB
AND JOB_SETTINGS.ID_JOB = WORKINGDAY.ID_JOB
AND JOB.ID_JOB = 2")
在此处阅读更多内容enter link description here