Я пытался обновить один столбец, в котором хранится тип данных double, но он не прошел без ошибок, и я понятия не имею, что я делаю неправильно
Я пытался использовать как rawquery, так и обновление с использованием ContentValues, но оба не работают, я знаю, что это связано с РЕАЛЬНЫМ типом данных в sqlite, но я понятия не имею, как заставить его работать
мой стол
private static final String SQL_CREATE_TABLE_WOUND
= "CREATE TABLE "
+ WOUND_TABLE_NAME + "("
//+ WOUND_ID + " TEXT,"
+ WOUND_POSITION + " INT,"
+ WOUND_SIZE + " DOUBLE,"
+ WOUND_OWNER + " TEXT,"
+ WOUND_PHOTO + " TEXT,"
+ WOUND_THUMBNAIL + " TEXT,"
+ WOUND_TREATED + " INT DEFAULT 0,"
+ WOUND_NUMBER + " INT,"
+ WOUND_DATE + " INT,"
+" FOREIGN KEY ("+WOUND_OWNER+") REFERENCES "+PATIENT_TABLE_NAME+"("+PATIENT_ID+"),"
+" FOREIGN KEY ("+WOUND_POSITION+") REFERENCES "+WOUND_POSITION_TABLE_NAME+"("+POSITION_NUMBER+"),"
+" PRIMARY KEY ("+ WOUND_OWNER +", "+ WOUND_POSITION +", "+ WOUND_NUMBER +", "+ WOUND_DATE +")"
+ ")";
это моя функция обновления
public boolean setWoundSizeValue(String ownerID,String position,String number,long date,Double value){
boolean setSuccess = false;
/*approach 2
ContentValues cv = new ContentValues();
cv.put(WOUND_SIZE,value);*/
SQLiteDatabase db = this.getWritableDatabase();
/*approach 1, didn't work
try{
String strSQL = "UPDATE "+WOUND_TABLE_NAME+" SET "+WOUND_SIZE+" = "+value+" WHERE "+WOUND_OWNER+" = "+ownerID+" AND "
+ WOUND_POSITION+" = "+position+ " AND "+ WOUND_NUMBER +" = "+ number +" AND "+WOUND_DATE +" = "+date;
Cursor c = db.rawQuery(strSQL,null);
if(c!=null){
if(c.moveToFirst()){
setSuccess = true;
}
c.close();
}
}catch (Exception e){
}*/
/*approach 2 didn't work
long result = db.update(WOUND_TABLE_NAME,cv,WOUND_OWNER+"=? AND "+ WOUND_POSITION+"=? AND "+ WOUND_NUMBER +"=? AND "+WOUND_DATE+"=?"
,new String[]{ownerID,position,number,String.valueOf(date)});
if(result>0){
setSuccess = true;
}*/
return setSuccess;
}
и здесь я вызываю функцию обновления
public class SetWoundSizeActivity extends AppCompatActivity {
private EditText setWoundSize;
private Button saveButton;
private String owner;
private String position;
private String woundNum;
private String timer;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_set_wound_size);
getSupportActionBar().setTitle("Set Wound Size");
Intent intent = getIntent();
owner = intent.getStringExtra("owner");
position = intent.getStringExtra("position");
woundNum = intent.getStringExtra("woundNum");
timer = intent.getStringExtra("timer");
setWoundSize = findViewById(R.id.wound_size);
saveButton = findViewById(R.id.wound_size_button);
saveButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
DatabaseHelper helper = new DatabaseHelper(SetWoundSizeActivity.this);
SQLiteDatabase db = helper.getWritableDatabase();
final double woundSize = Double.valueOf(setWoundSize.getText().toString());
Toast.makeText(SetWoundSizeActivity.this,"size is"+woundSize,Toast.LENGTH_LONG).show();
//String ownerID,String position,String number,long date,float value
boolean result;
result = helper.setWoundSizeValue(owner,position,woundNum,Long.valueOf(timer),woundSize);
if(result){
Toast.makeText(SetWoundSizeActivity.this,"size inserted",Toast.LENGTH_LONG).show();
}else{Toast.makeText(SetWoundSizeActivity.this,"size not inserted",Toast.LENGTH_LONG).show();}
finish();
}
});
}
}
ошибки нет, но результат, подтверждающий, где я его называю, всегда ложен