android - Ternary operator in select statement -


i trying execute query has ternary operator inside select statement:

select id,         memory_id,         case           when word_to =? word_from           else word_to         end    translations   word_to =?         or word_from =?  

how can build such query using querybuilder object? tried:

public list<translation> findmeanings(long wordid) {      try {         dao<translation, long> translations = getdao(translation.class);         querybuilder<translation, long> querybuilder = translations.querybuilder();         string id = long.tostring(wordid);          querybuilder.selectraw(dbcolumns.id, dbcolumns.memory_id, "case when word_to="+id+" word_from else word_to end");         querybuilder.where().eq(dbcolumns.word_to, id).or().eq(dbcolumns.word_from, id);          return querybuilder.query();     } catch (sqlexception e) {         logger.error("db", e.getmessage(), e);     }     return new arraylist<translation>(); } 

but getting exception:

could not compile select_raw statement since caller expecting select statement. check querybuilder methods.

translation class:

@databasetable(tablename = databasetables.table_translations) public class translation extends baseentity {      @databasefield(foreign = true, foreigncolumnname = dbcolumns.id, columnname = dbcolumns.word_to)     private word wordto;     @databasefield(foreign = true, foreigncolumnname = dbcolumns.id)     private memory memory;     //... 

where baseentity is:

public class baseentity {      @databasefield(generatedid = true, unique = true)     protected long id;      //.... 

could not compile select_raw statement since caller expecting select statement. check querybuilder methods.

as call qb.selectraw(...) need use qb.queryraw(...) instead of query(). mentioned in javadocs selectraw(...):

add raw columns or aggregate functions (count, max, ...) query. this turn query suitable dao.queryraw(string, string...) type of statement. can called multiple times add more columns select.

typically selectraw(...) used sort of aggregation function count() or max() , therefore not compatible entity type returned query().


Comments

Popular posts from this blog

google api - Incomplete response from Gmail API threads.list -

Installing Android SQLite Asset Helper -

Qt Creator - Searching files with Locator including folder -