android-room

Room database - Foreign Key Constraint Failed Error code 787

走远了吗. 提交于 2020-04-17 22:53:07
问题 I am getting the above problem, and am unable to solve even while looking at other similar questions and their solutions, as well as the sqlite document on foreign keys. I understand that a foreign key must exist in the parent table first before it can be created in the child table. However, even though that was done first the problem is still there. This is how my program flows until the point where it crashes: MainActivity -> Create Trip -> Shows up as a RecyclerView -> Click on it to enter

Passing in a string to use as part of a Room query

房东的猫 提交于 2020-04-17 22:50:26
问题 Why does this not work in Room?: val dataSourceFactory = database.gameDao.getGames("Game.platforms LIKE '%XONE%'") @Query("SELECT * FROM Game WHERE :likeClause") fun getGames(likeClause: String): DataSource.Factory<Int, Game> But this does?: @Query("SELECT * FROM Game WHERE Game.platforms LIKE '%XONE%'") fun getGames(): DataSource.Factory<Int, Game> Is there any way to pass in a string that can stand in as part of the query? EDIT: I know this isn't the correct way to form a single LIKE clause

Passing in a string to use as part of a Room query

笑着哭i 提交于 2020-04-17 22:42:50
问题 Why does this not work in Room?: val dataSourceFactory = database.gameDao.getGames("Game.platforms LIKE '%XONE%'") @Query("SELECT * FROM Game WHERE :likeClause") fun getGames(likeClause: String): DataSource.Factory<Int, Game> But this does?: @Query("SELECT * FROM Game WHERE Game.platforms LIKE '%XONE%'") fun getGames(): DataSource.Factory<Int, Game> Is there any way to pass in a string that can stand in as part of the query? EDIT: I know this isn't the correct way to form a single LIKE clause

Insert on Room DB does not trigger Observer on Activity

与世无争的帅哥 提交于 2020-04-17 22:14:54
问题 In my activity i have an Observer that observes this query @Query("""Select *, (Select account_id from accounts where account_id = from_account_id) as contact_account_id, (Select first_name from accounts where account_id = from_account_id) as contact_first_name, (Select last_name from accounts where account_id = from_account_id) as contact_last_name from messages inner join messageQueue on messages.client_message_id = messagequeue.client_message_id where ((msg_type = 1 and body <> "") or msg

Insert on Room DB does not trigger Observer on Activity

丶灬走出姿态 提交于 2020-04-17 22:14:22
问题 In my activity i have an Observer that observes this query @Query("""Select *, (Select account_id from accounts where account_id = from_account_id) as contact_account_id, (Select first_name from accounts where account_id = from_account_id) as contact_first_name, (Select last_name from accounts where account_id = from_account_id) as contact_last_name from messages inner join messageQueue on messages.client_message_id = messagequeue.client_message_id where ((msg_type = 1 and body <> "") or msg

Insert on Room DB does not trigger Observer on Activity

我的未来我决定 提交于 2020-04-17 22:14:01
问题 In my activity i have an Observer that observes this query @Query("""Select *, (Select account_id from accounts where account_id = from_account_id) as contact_account_id, (Select first_name from accounts where account_id = from_account_id) as contact_first_name, (Select last_name from accounts where account_id = from_account_id) as contact_last_name from messages inner join messageQueue on messages.client_message_id = messagequeue.client_message_id where ((msg_type = 1 and body <> "") or msg

Cannot create an instance of class com.example.architectureexample.NoteViewModel

风格不统一 提交于 2020-04-17 18:45:57
问题 every time i run my app it shows this error in the title and i have searched for the problem some said make the ViewModel constructor public and mine is public other said Either: Remove the Context context and LifecycleOwner lifecycleOwner constructor parameters from your HomeViewModel, or Create a ViewModelProvider.Factory that can build your HomeViewModel instances, and use that factory with ViewModelProviders.of() and i have made the two solutions and still get the same error MainActivity

Cannot create an instance of class com.example.architectureexample.NoteViewModel

大城市里の小女人 提交于 2020-04-17 18:45:23
问题 every time i run my app it shows this error in the title and i have searched for the problem some said make the ViewModel constructor public and mine is public other said Either: Remove the Context context and LifecycleOwner lifecycleOwner constructor parameters from your HomeViewModel, or Create a ViewModelProvider.Factory that can build your HomeViewModel instances, and use that factory with ViewModelProviders.of() and i have made the two solutions and still get the same error MainActivity

Android Room Dao: Order By CASE not working

江枫思渺然 提交于 2020-04-16 02:58:06
问题 I have a Room database using Dao to process queries etc. I am using static (non live data) function to retrieve results via the query, all works well when I manual hard code the Order By values and column as below, however when passing params to the Dao to do the sorting, the Order By reverts back to default (order by id column) and does not retrieve results based on the passed sort param Hard coded Dao example works, results sorted by ASC or DESC @Query("SELECT * FROM cameras WHERE suburb

Android Room + Window Functions

无人久伴 提交于 2020-04-14 07:38:14
问题 I try to use a Window Functions in a Room Query. The parser is complaining about my query. I simply try to add a "ROW_NUMBER() OVER (ORDER BY column)" expression in my select statement. Without this expression, the query is running correctly. Parser error: extraneous input '(' expecting {<EOF>, ';', ',', K_ALTER, K_ANALYZE, K_ATTACH, K_BEGIN, K_COMMIT, K_CREATE, K_DELETE, K_DETACH, K_DROP, K_END, K_EXCEPT, K_EXPLAIN, K_FROM, K_GROUP, K_INSERT, K_INTERSECT, K_LIMIT, K_ORDER, K_PRAGMA, K