Search code examples
androidkotlinandroid-room

autocomplete for room query stopped working?


After opening my room dao I noticed that the autocomplete for Query annotation does not work at all. Not only that, but it also does not check any SQL queries I try to enter for errors and spelling mistakes:

Proof

( I purposefully used "FRR" instead of "FROM" to show that the error correction does not work )

I've already tried to invalidate caches and restarting android studio, but that changed nothing. Any ideas?

(also, just for the sake of it: The autocomplete works for standard kotlin code, just not inside that query string)


Solution

  • If you compile, then the error will be detected and will be available in the build log.

    e.g.

    E:\AndroidStudioApps\SO72784799KotlinRoomJSON11\app\build\tmp\kapt3\stubs\debug\a\a\so72784799kotlinroomjson1_1\AllDao.java:35: error: extraneous input 'FRR' expecting {<EOF>, ';', K_ALTER, K_ANALYZE, K_ATTACH, K_BEGIN, K_COMMIT, K_CREATE, K_DELETE, K_DETACH, K_DROP, K_END, K_EXPLAIN, K_INSERT, K_PRAGMA, K_REINDEX, K_RELEASE, K_REPLACE, K_ROLLBACK, K_SAVEPOINT, K_SELECT, K_UPDATE, K_VACUUM, K_VALUES, K_WITH, UNEXPECTED_CHAR}
        public abstract java.util.List<a.a.so72784799kotlinroomjson1_1.AddedPhotoEntity> getSomething();
    
    • The above used an existing project with a function in an @Dao annotated interface based upon

    :-

    @Query("SELECT * FRR AddedPhotoEntity")
    fun getSomething(): List<AddedPhotoEntity>
    

    Although at one time SQL was checked/auto completed for Room annotations, this hasn't been the case for some time now. Frequently compiling and checking the build log, is (IMHO) a must.