从多个表ormlite中获取数据

时间:2014-12-04 13:00:41

标签: android sqlite ormlite

我需要在ORMLite中编写以下查询

SELECT * FROM T1 t1, T2 t2 where t1.id = t2.id AND t1.type='abc' AND (t1.title = 'XYZ' OR t2.description = 'xyz');

然而,到目前为止,我已经能够编写以下代码:

QueryBuilder<T1, Integer> t1QB = getT1Dao().queryBuilder();
QueryBuilder<T2, Integer> t2QB = getT2Dao().queryBuilder();
t1QB.join(t2QB);
Where<T1, Integer> where = t1QB.where();
where.eq("Type", "abc");
where.and().or(
    where.ne("title", "XYZ"),
    where.ne("description", "xyz"),
);

但是这会抛出未找到列的异常&#34; description&#34;在T1。 并且T1中还有T2对象,并且@DatabaseField注释中的autoRefresh为true。

是否有任何方法可以使用上述方法执行此操作,或者我必须编写自定义查询

1 个答案:

答案 0 :(得分:1)

对于有相同问题的人

我已通过更改查询

解决了此问题
SELECT * FROM T1 WHERE type='abc' AND (title = 'XYZ' OR id IN (SELECT id from T2 where description = 'xyz'));


QueryBuilder<T1, Integer> t1QB = getT1Dao().queryBuilder();
QueryBuilder<T2, Integer> t2QB = getT2Dao().queryBuilder();
t2QB.where().eq(id, id);

Where<T1, Integer> where = t1QB.where();
where.or(
     where.ne("title", "XYZ"),
     where.in("id", t2QB);
);
where.and().eq("Type", "abc");