2012-10-05 31 views
0

雖然運行此代碼:錯誤在構建SQL語句

Problems executing Android query: SELECT * FROM `notes` WHERE `id` NOT IN 
    (MappedStatement: SELECT DISTINCT `noteId` FROM `note_states`) 

的是什麼在SQL MappedStatement任何想法:

note = noteDAO.queryForFirst(
    noteDAO.queryBuilder().where().notIn("id", 
     noteStateDAO.queryBuilder().distinct().selectColumns("noteId") 
     .prepare()) 
    .prepare()); 

...我有例外以下?

回答

1

你已經解決了你看來問題,但我想我會提供一些更多的信息。

Where.notIn(...)方法採用對象或QueryBuilder參數。通過做一個prepare(),它變成了一個MappedQuery,不幸的是它作爲Object傳遞。

正如您所提到的,如果您刪除了prepare(),它將使用QueryBuilder參數。請參閱javadocs for notIn(String, QueryBuilder)

我已經添加了更好的檢查,以防止在ORMLite版本4.43中傳遞準備好的查詢。

0

好的,自己找到的。無需prepare內subselect查詢:

note = noteDAO.queryForFirst(
    noteDAO.queryBuilder().where().notIn("id", 
     noteStateDAO.queryBuilder().distinct().selectColumns("noteId") 
     /*.prepare()*/) 
    .prepare());