Reputation:
When I try to run updateAlarmTriggered Query with two String parameters I get the following error:
Logcat output
E/SQLiteLog: (1299) abort at 33 in [UPDATE alarmTable SET triggered = 1 AND triggerTime = ? WHERE date = ?]: NOT NULL constraint failed: alarmTable.triggered
android.database.sqlite.SQLiteConstraintException: NOT NULL constraint failed: alarmTable.triggered (code 1299)
Here are my Dao and Entity classes:
AlarmDao.java
@Query("UPDATE alarmTable SET triggered = 1 AND triggerTime = :triggerTime WHERE date = :alarmDate")
void updateAlarmTriggered(String alarmDate, String triggerTime);
AlarmEntity.java
@PrimaryKey
@NonNull
private String date;
@NonNull
private int triggered;
@Nullable
private String triggerTime;
@NonNull
public String getDate() {return date; }
public void setDate(@NonNull String date) {this.date = date; }
@NonNull
public int getTriggered() {return triggered; }
public void setTriggered(@NonNull int triggered) { this.triggered =triggered; }
I initalize the new entities with:
@Insert
void insertAlarm(AlarmEntity alarmEntity);
And the alarmEntity object I:
AlarmEntity newAlarm = new AlarmEntity();
newAlarm.setDate(time.substring(4,20) + time.substring(30,34));
newAlarm.setTriggered(0);
newAlarm.setDeleted(0);
I can't figure out the reason why NOT NULL constraint is failed on alarmTable.triggered, because that's what I'm setting it to 1 at the updateQuery.
Upvotes: 2
Views: 155
Reputation: 1143
To update multiple columns use a comma ,
to separate columns. like following
@Query("UPDATE alarmTable SET triggered = 1, triggerTime = :triggerTime WHERE date = :alarmDate")
void updateAlarmTriggered(String alarmDate, String triggerTime);
Upvotes: 1