房间找不到布尔列(存在时)

时间:2018-11-06 22:46:53

标签: android database sqlite kotlin

我正在尝试使用具有布尔值的实体构建Dao,房间一直说该列即使存在也不存在。

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()
}

使用SQL Studio使用Android Studio完成的房间发现同步列很好,但是当我尝试运行该应用程序时,会出现:

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();

该列存在,我不知道发生了什么,我什至使用布尔值作为Int,因为SQLite没有布尔值

1 个答案:

答案 0 :(得分:1)

您缺少注释FROM node:8.9.3 # Make app directory in the container. RUN MKDIR /app # Copy whole code to app directory. COPY Code/build/ /app # Copy package.json app directory. COPY package.json /app # make app directory as the working directory. WORKDIR /app # Install dependencies. RUN npm install -only=production # Expose the port EXPOSE 8080 # Start the process CMD ["npm", "start"] ...

使用Java和SQL关键字作为列名时往往会造成混淆。