Room can't find boolean column when it exists

3841 views android
1

I've trying to build a Dao using an entity that has a boolean value, room keeps saying that the column doesn't exists even when it exists.

Device.kt

@Entity(tableName = "device_table")
data class Device(
    @Expose
    @SerializedName("name")
    var name: String,
    @Expose
    @SerializedName("strength")
    var strength: Int,
    @Expose
    @ColumnInfo(name = "pk")
    @SerializedName("address")
    @PrimaryKey(autoGenerate = false)
    var address: String,
    @Expose
    @ColumnInfo(name = "created_at")
    @SerializedName("created_at")
    var createdAt: String,
    var synchronized: Boolean
) {
    constructor() : this("", 0, "", "", true)
}

DeviceDao.kt

@Dao
interface DeviceDao {
    /**
     * Inserts a device into the database, if it already exists
     * the device gets updated with the device data.
     */
    @Insert(onConflict = OnConflictStrategy.REPLACE)
    fun insertOrUpdate(device: Device)

    /**
     * Retrieves all the bluetooth devices from the
     * local database ordered by their creation date.
     */
    @Query("SELECT * FROM device_table ORDER BY created_at ASC")
    fun read(): LiveData<List<Device>>

    @Query("SELECT * FROM device_table WHERE synchronized = 0 ORDER BY created_at ASC")
    fun readUnSync(): List<Device>

    /**
     * Nukes the device_table, deletes everything.
     */
    @Query("DELETE FROM device_table")
    fun deleteAll()
}

Room using SQL completion using Android Studio finds the synchronized column just fine, but when I try to run the app, this appears:

There is a problem with the query: [SQLITE_ERROR] SQL error or missing database (no such column: synchronized)

public abstract java.util.List<me.alfredobejarano.bluethootmanager.data.Device> readUnSync();

The column exists, I don't know whats happening, Im even using the boolean value as an Int because SQLite doesn't have Boolean values

answered question

1 Answer

0

you are missing annotation @ColumnInfo(name = "synchronized") ...

while using Java & SQL keywords as column names tends to be confusing.

posted this

Have an answer?

JD

Please login first before posting an answer.