Urkman
(Stefan Sturm)
May 19, 2014, 10:46am
1
Hello,
I need to handle concurrent access to a table.
So I would like to load a specific row and lock it using "select for update".
Then I make changes to this Model and then I write it back using the save() function and so release the lock…
What is the best way to handle this using ActiveRecords?
Thanks,
Urkman
CeBe
May 19, 2014, 10:55am
2
which DBMS are you using? In general you should use transactions for this. But you have to use isolation level setting of your dbms to ensure your transaction gets a read lock on the table.
CeBe
May 19, 2014, 10:56am
3
There currently is no native support in Yii yet but we consider to add it soon. https://github.com/yiisoft/yii2/issues/3220
Urkman
(Stefan Sturm)
May 19, 2014, 11:23am
4
Thanks for your answer
I’m using PostgresSQL in Version 9.3
CeBe
May 19, 2014, 11:42am
5
Urkman
(Stefan Sturm)
May 19, 2014, 8:16pm
6
Hi,
I don’t need a read lock. It is fine, when other scripts read from the table at the same time…
I only need a write lock, so no other script should be able to start a new transaction on this row…
Greetings,
Urkman