|
Posted by Jerry Stuckle on 05/20/06 03:54
Rik wrote:
> Jerry Stuckle wrote:
>
>>rich wrote:
>>
>>>I am building an app using php and postgresql. My questionis this.
>>>How do you handle people wanting to make parallel changes to a
>>>record.
>>>Since in web apps you are doing a select, bring over a record then
>>>updating it, there is no lock on that record while you are making the
>>>changes in your browser window. Does transactions handle that? Do
>>>you
>>>make your selection and update all part of the same transaction?
>>>This
>>>whole scenario has me stumped.
>>>
>>
>>Keep the original values. Before updating, read the record in again
>>and compare the values to the old ones. If they don't match, put the
>>window back up with the new values and tell the user.
>>
>>You can also be a little more creative. Check the columns which are
>>being updated. If they haven't changed (but perhaps others have), go
>>ahead and allow the update to the changed columns. However, if one
>>or more columns have been changed, send a message back to the user
>>with the new values from the database.
>>
>>A lot of hassle, I know. However, you wouldn't want to lock the row
>>anyway. What happens if someone displays the record then closes his
>>browser? Now you have a locked recored which you can't unlock (until
>>perhaps some timeout value expires).
>
>
> And still, it's possible to check if the values are the same, someone
> immediatlly thereafter changes the values, and only then your script has
> reached the point of updating the values. So it's by no way fullproof. It
> would have to happen in a very small timeframe though, and it't not very
> likely to happen. Yet, given enough time and transactions, someday it might.
>
> Then again, I haven't heard of a slim workable solution witthout that
> weakness either.
>
> Grtz,
Sure you can guarantee it.
$result = mysql_query("UPDATE myTable SET col1='$col1' AND col2='$col2']
"WHERE col1='$oldcol1' AND col2='$oldcol2'");
if (mysql_affected_rows != 1)
echo "Data has changed!<br>";
If either col1 or col2 has been changed the update will fail and
mysql_affected_rows() will return zero.
--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================
Navigation:
[Reply to this message]
|