Shahriar Zaman
Shahriar Zaman

Reputation: 938

Failed to create table with @Query in Room database

My @Dao interface is:

@Dao
public interface TaskDao {
    @Insert
    void insert(Task task);

    @Update
    void update(Task task);

    @Delete
    void delete(Task task);

    @Query("DELETE FROM task_table")
    void deleteAllTasks();

    @Query("SELECT * FROM task_table")
    LiveData<List<Task>> getAllMainTasks();
}

Using this query every thing works fine and just as wanted. Here is the table screenshot: enter image description here

Changing the last two lines to below lines causing problem:

    @Query("SELECT * FROM task_table WHERE creator_ID = NULL ORDER BY task_ID ASC")
    LiveData<List<Task>> getAllMainTasks();

But when I use this, no entry in this table is created!

Upvotes: 0

Views: 114

Answers (1)

sergiy tykhonov
sergiy tykhonov

Reputation: 5113

Try to replace your null-condition:

@Query("SELECT * FROM task_table WHERE creator_ID = NULL ORDER BY task_ID ASC")

to

@Query("SELECT * FROM task_table WHERE creator_ID is NULL ORDER BY task_ID ASC")

Upvotes: 1

Related Questions