I am using Room Database from the new Architecture components in my project. I am adding some data through dao, but when trying to retrieve it I am not getting it. Can you please suggest me how to check whether the insert was successful or not? Below are the codes to help you understand the problem.
adding to database, I checked with debugger, this statement executed successfully.
appContext.db.rallyDAO().addVehicleListItem(vehicle)
Getting null from database on this statement after insert.
val v = appContext.db.rallyDAO().getVehicleListItem(it.vehicleID)
RoomDatabase
@Database(entities = arrayOf(Rally::class, Route::class, CheckPoints::class, Vehicles::class, VehicleListItem::class), version = 1)
abstract class TSDRoom: RoomDatabase() {
public abstract fun rallyDAO():RallyDAO
}
Inside DAO
@Insert(onConflict = OnConflictStrategy.REPLACE)
fun addVehicleListItem(vehicleListItem:VehicleListItem)
@Query("select * from vehicles_submitted where vehicle_id LIKE :vehicleID")
fun getVehicleListItem(vehicleID:String):VehicleListItem
VehicleListItem Entity
@Entity(tableName = "vehicles_submitted",
foreignKeys = arrayOf(ForeignKey(entity = Rally::class,
parentColumns = arrayOf("rally_id"),
childColumns = arrayOf("rally_id"))))
class VehicleListItem {
@PrimaryKey
@ColumnInfo(name = "vehicle_id")
@SerializedName("vehicle_id")
var vehicleID : String = ""
@ColumnInfo(name = "driver_id")
@SerializedName("driver_id")
var driverID : String = ""
@ColumnInfo(name = "vehicle_name")
@SerializedName("vehicle_name")
var vehicleName : String = ""
@ColumnInfo(name = "driver_name")
@SerializedName("driver_name")
var driverName : String = ""
@ColumnInfo(name = "driver_email")
@SerializedName("driver_email")
var driverEmail : String = ""
@ColumnInfo(name = "rally_id")
@SerializedName("rally_id")
var rallyID: String = ""
@ColumnInfo(name = "is_passed")
@SerializedName("is_passed")
var isPassed = false
@ColumnInfo(name = "passing_time")
@SerializedName("passing_time")
var passingTime:String=""
}