| |

VerySource

 Forgot password?
 Register
Search
View: 2587|Reply: 19

Talk about how to ensure that only one user is editing a certain record when processing WEB data updates?

[Copy link]

1

Threads

4

Posts

5.00

Credits

Newbie

Rank: 1

Credits
5.00

 China

Post time: 2020-2-20 18:30:01
| Show all posts |Read mode
I did not use a timestamp, that is to judge when submitting the data, I used to add a time field to the table that needs to be uniquely updated, this field is used to record the time when the record was last updated, such as the record to be updated now The value of the time field is 2017-01-01 1:00:00, and the predefined timeout interval for the operation is 20 minutes. If the operation time does not exceed the defined timeout interval when compared with the time field in the record, then someone is considered The record, otherwise it is considered that the timeout record can be edited.
Tell me how do you do this kind of operation?
Reply

Use magic Report

0

Threads

119

Posts

67.00

Credits

Newbie

Rank: 1

Credits
67.00

 China

Post time: 2020-4-30 02:00:01
| Show all posts
It seems impossible to control on the page, but the database has a mechanism to ensure concurrency! I do not know what the landlord intends to do?
If you want to guarantee the situation you mentioned, I personally think that you can add a marker column to the database. If it is true, make sure it is editable, otherwise it is not
Reply

Use magic Report

1

Threads

4

Posts

5.00

Credits

Newbie

Rank: 1

Credits
5.00

 China

 Author| Post time: 2020-4-30 14:15:01
| Show all posts
to苹果小刀:
 There is no need to consider this problem for the addition and deletion of data, mainly to update the data, because it is necessary to ensure that only one person is editing a certain record when editing. Therefore, I use time. If you use a tag column, then the client is abnormal The record will no longer be editable.
Reply

Use magic Report

0

Threads

43

Posts

29.00

Credits

Newbie

Rank: 1

Credits
29.00

 China

Post time: 2020-5-1 21:15:01
| Show all posts
An application object can be set to record the record being edited. When any user edits a record, it is necessary to determine whether the record has an id in the application. Delete the id of the record from the application
Reply

Use magic Report

0

Threads

26

Posts

20.00

Credits

Newbie

Rank: 1

Credits
20.00

 Unknown

Post time: 2020-5-2 19:00:01
| Show all posts
You can start from the database to consider this issue, such as the use of table locks, record identification, and so on.
Reply

Use magic Report

1

Threads

11

Posts

8.00

Credits

Newbie

Rank: 1

Credits
8.00

 China

Post time: 2020-5-2 23:15:01
| Show all posts
Create an additional table to record all the edited records. When others open the edited records, they will be tested first, and if they exist, they will be prompted to lock.

It seems not very good to use the database directly ~~ I do n’t know how to control
Reply

Use magic Report

0

Threads

1

Posts

2.00

Credits

Newbie

Rank: 1

Credits
2.00

 China

Post time: 2020-5-3 09:30:01
| Show all posts
Not feasible,

The most basic approach is to use transaction processing
Reply

Use magic Report

0

Threads

1

Posts

2.00

Credits

Newbie

Rank: 1

Credits
2.00

 China

Post time: 2020-5-3 14:00:01
| Show all posts
Keep following ...
Reply

Use magic Report

0

Threads

32

Posts

22.00

Credits

Newbie

Rank: 1

Credits
22.00

 China

Post time: 2020-5-5 14:45:01
| Show all posts
This situation is bound to exist and can only be dealt with, not guaranteed.
You can only use transactions. Simply judging in the database will not work. Dirty reading and repeated reading cannot be solved.
Reply

Use magic Report

0

Threads

29

Posts

16.00

Credits

Newbie

Rank: 1

Credits
16.00

 China

Post time: 2020-5-6 09:00:01
| Show all posts
Pessimistic locking solution

-We can achieve pessimistic locking with only minor changes to the code above.

declare @CardNo varchar (20)
Begin Tran

       -Choose an unused card
        select top 1 @ CardNo = F_CardNo
        from Card with (UPDLOCK) where F_Flag = 0
        
        -Delay 50 seconds to simulate concurrent access.
        waitfor delay '000: 00: 50'

       -Register the card you just selected.

        update Card
        set F_Name = user,
            F_Time = getdate (),
            F_Flag = 1
        where F_CardNo = @ CardNo

commit
Reply

Use magic Report

You have to log in before you can reply Login | Register

Points Rules

Contact us|Archive|Mobile|CopyRight © 2008-2023|verysource.com ( 京ICP备17048824号-1 )

Quick Reply To Top Return to the list