Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.clipper.visual-objects > #13632

Re: Vo2Ado and multiuser environment locks

From Jamal <nospam@example.com>
Newsgroups comp.lang.clipper.visual-objects
Subject Re: Vo2Ado and multiuser environment locks
Date 2022-08-26 15:11 -0400
Organization Aioe.org NNTP Server
Message-ID <teb5sl$10id$1@gioia.aioe.org> (permalink)
References <ab8087ef-f208-435b-98bf-407ce70e7a4an@googlegroups.com> <teb1j0$15nd$1@gioia.aioe.org> <d68c452b-73b6-44ca-9c9a-f711e18018f3n@googlegroups.com>

Show all headers | View raw


May be you can use the same approach when you SELECT the row and before 
you get the authorization, then update the row.

If this does not work, try creating another table that indicates that 
you're in an update process and handle your update process accordingly.

Jamal


On 8/26/2022 2:10 PM, Sebastián BASSANO wrote:
> El Friday, August 26, 2022 a la(s) 2:57:55 PM UTC-3, Jamal escribió:
>> Try adding:
>>
>> WITH (ROWLOCK)
>>
>> to your SQL UPDATE statement.
>>
>> "UPDATE document SET authorizationCode = " + cAuthorizationCode + " WITH
>> (ROWLOCK) WHERE (id = " + NTrim(cId) + ")"
>>
>> Jamal
>> On 8/26/2022 7:58 AM, Sebastián BASSANO wrote:
>>> Hi, i have an operation that needs to authorize a document via a third party web server and then update a table on my database. The process works fine but i need to add multiuser support, means that when an user is doing that operation the other users can't. I work with Vo2Ado.
>>> Today the code (simplified, without the BEGIN SEQUENCE/RECOVER USING code block) is similar to this:
>>>
>>>
>>> // Get third party authorization code via web service
>>> cAuthorizationCode:= oWebService:GetAuthorization(...)
>>>
>>> // Update table
>>> oConnection:BeginTrans()
>>> cCommand:= "UPDATE document SET authorizationCode = " + cAuthorizationCode + " WHERE (id = " + NTrim(cId) + ")"
>>> oConnection:Execute(cCommand, @liAffectedRecords, NIL)
>>> if (liAffectedRecords > 0)
>>> oConnection:CommitTrans()
>>> ELSE
>>> oConnection:Rollback()
>>> ENDIF
>>>
>>>
>>> This code doesn't work on multiuser environment because the record lock is applied on line:
>>>
>>> oConnection:Execute(cCommand, @liAffectedRecords, NIL)
>>>
>>> and at this point two or more users could get more authorization codes because the third party web service don't receive any local information to test if the authorization code already exists. I need to lock the record before start the communication with web service.
>>> I understand that i can't lock records explicitly as with DbServer:LockCurrentRecord ¿is this correct?
>>> If i'm correct ¿what would be the correct way to achieve this?
>>>
>>> Maybe something this? I'm not convinced...
>>>
>>>
>>> oConnection:BeginTrans()
>>>
>>> // Force to lock the record updating value with the actual value
>>> cCommand:= "UPDATE document SET authorizationCode = authorizationCode + " WHERE (id = " + NTrim(cId) + ")"
>>> oConnection:Execute(cCommand, @liAffectedRecords, NIL)
>>>
>>> if (liAffectedRecords > 0)
>>> // Get third party authorization code via web service
>>> cAuthorizationCode:= oWebService:GetAuthorization(...)
>>>
>>> // Update table
>>> cCommand:= "UPDATE document SET authorizationCode = " + cAuthorizationCode + " WHERE (id = " + NTrim(cId) + ")"
>>> oConnection:Execute(cCommand, @liAffectedRecords, NIL)
>>> oConnection:CommitTrans()
>>> ELSE
>>> oConnection:Rollback()
>>> ENDIF
>>>
>>>
>>> I appreciate some help.
>>> Regards.
>>>
>>> Sebastián
> Hi Jamal, thanks for your response.
> the problem is that when a user reaches that line of code in the third party web service an authorization code has already been managed.
> 
> An example:
> 
> Time1 - User 1 open associated dialog to get authorization code on PC1
> Time2 - User 2 open associated dialog to get authorization code on PC2
> Time3 - User 1 get authorization code (before this i have to lock to avoid that other used get authorization code)
> Time4 - User 1 update authorizarion code on database
> Time5 - User 2 get authorization code
> Time6 - User 2 update authorizarion code on database
> 
> I hope my problem is better understood, English is not my native language.
> Regards.

Back to comp.lang.clipper.visual-objects | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

Vo2Ado and multiuser environment locks Sebastián BASSANO <ccyasa.sbassano@gmail.com> - 2022-08-26 04:58 -0700
  Re: Vo2Ado and multiuser environment locks Jamal <nospam@example.com> - 2022-08-26 13:57 -0400
    Re: Vo2Ado and multiuser environment locks Sebastián BASSANO <ccyasa.sbassano@gmail.com> - 2022-08-26 11:10 -0700
      Re: Vo2Ado and multiuser environment locks Jamal <nospam@example.com> - 2022-08-26 15:11 -0400
        Re: Vo2Ado and multiuser environment locks Sebastián BASSANO <ccyasa.sbassano@gmail.com> - 2022-08-26 12:16 -0700
      Re: Vo2Ado and multiuser environment locks JohnMartens <martens@tennishulp.info> - 2022-08-26 21:23 +0200
        Re: Vo2Ado and multiuser environment locks Sebastián BASSANO <ccyasa.sbassano@gmail.com> - 2022-08-26 12:41 -0700
          Re: Vo2Ado and multiuser environment locks JohnMartens <martens@tennishulp.info> - 2022-08-27 08:25 +0200
  Re: Vo2Ado and multiuser environment locks "Wolfgang Riedmann" <wriedmann@gmail.com> - 2022-08-31 09:51 +0200
    Re: Vo2Ado and multiuser environment locks Sebastián BASSANO <ccyasa.sbassano@gmail.com> - 2022-08-31 05:54 -0700

csiph-web