Question:
There are two tables, the main table has a name
column which is the key for the child table. When I update name
, I do it like this:
// перезаписываем данные обьекта
public static void reloadObject(String oldName, String newName, String description, String date, Context context) {
ContentValues cv = new ContentValues();
ObjectDB objectDB = new ObjectDB(context);
SQLiteDatabase db = objectDB.getWritableDatabase();
cv.put(ObjectDB.objColumn.NAME, newName);
cv.put(ObjectDB.objColumn.DESCRIPTION, description);
cv.put(ObjectDB.objColumn.START_DATE, date);
db.update(ObjectDB.dbTab.OBJECT, cv, ObjectDB.objColumn.NAME + " = ?", new String[]{oldName});
db.close();
}
in the child table, this column is not updated, although the table settings indicate:
[object] TEXT REFERENCES geology_object([name]) ON DELETE RESTRICT ON UPDATE CASCADE,
If you update the name
value in the SQLite Expert Personal
program, then everything is updated correctly. I use a ready-made database and insert it into the project using Android SQLiteAssetHelper
Answer:
I found the answer to my question, maybe it will be useful to someone. I had to put in this line:
db.setForeignKeyConstraintsEnabled(true);
front
db.update(ObjectDB.dbTab.OBJECT, cv, ObjectDB.objColumn.NAME + " = ?", new String[]{oldName});
and everything worked.