0

I have a requirement wherein if a new object is found, I am adding its unique id to all the parent class inheriting this class. Eg if C:B and B:A (C extends B and B extends A), then if a new object is found for C, because of inheritance this object is also of type B and A and hence this object goes into one of the columns for A and B (childs) containing all its child instances. As such I wanted to have it as an array. To achieve this I am reading row of A and B and get the child columns, deserialize it to array and put it back to db. Now this definitely has locking issue. For instance if instance of D:C or D:B is discovered at the same time, then both of them will read same copy and last write will win erasing instance of previous write.

Is there any way to eliminate this problem by not allowing others to read it until my transaction(in this case read-->update array-->write) is complete.

Is there any recommended way to solve this issue.

Nishant
  • 407
  • 2
  • 4
  • 12

1 Answers1

0

If I understand your requirements correctly, then I think you need nest your transaction with an EXCLUSIVE lock, e.g.:

sqlite3_exec(db, "BEGIN EXCLUSIVE", 0, 0);
...
sqlite3_exec(db, "END", 0, 0);
varro
  • 2,382
  • 2
  • 16
  • 24