Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Multiuser file access
Message
De
07/12/2013 04:10:52
 
 
À
06/12/2013 10:09:10
Information générale
Forum:
Visual FoxPro
Catégorie:
Codage, syntaxe et commandes
Versions des environnements
Visual FoxPro:
VFP 9 SP2
OS:
Windows 7
Network:
Windows 2008 Server
Database:
Visual FoxPro
Application:
Web
Divers
Thread ID:
01589362
Message ID:
01589514
Vues:
53
>>>Hi All:
>>>
>>>Every time I run a transaction, my program either APPENDs BLANK to a log table, or updates an existing record in the log table.
>>>
>>>What is the best resource to consult with regard to doing this in a multiuser environment?
>>>
>>>Thanks,
>>>
>>>Yossi
>>
>>Don't use Append Blank, use Insert Into instead, this is especially important in a multiuser environment. And in general you should never update a record in a log table, you should only add new records.
>
>Are you saying that with INSERT INTO, I don't need flock()?
>I guess that 'Log file' is inaccurate. It's a list of emails that have a lSent field. If the previous attempt was unsuccessful and it is successful now, I want to update the lSent to .t.
>
>
>PROCEDURE UpdateEmailLog(tcText, tcCustno, tcDisposition)
>
>LOCAL lnSelect, llUpdated
>
>lnSelect = SELECT()
>
>SELECT emails
>
>llUpdated = .F.
>
>DO WHILE !llUpdated
>
>	IF FLOCK()
>		APPEND BLANK
>		REPLACE em_body WITH tcText, ;
>			em_datetim WITH DATETIME(), ;
>			em_custno WITH tcCustno, ;
>			em_disptn WITH tcDisposition
>
>		UNLOCK
>		llUpdated = .t.
>	ENDIF
>
>ENDDO
>
>
>SELECT (lnSelect)
>
>RETURN
>
This will show you a much better code. Append Blank followed by Replace is bad, you should never use it again! Instead use Insert as I told you earlier.
Function UpdateEmailLog(tcText, tcCustno, tcDisposition)
   Local llSuccess As Boolean, ;
      lnSelect As Number, ;
      lnX As Number
   m.lnSelect = Select()
   m.llSuccess = .F.
   For m.lnX = 1 To 10
      Try
         Insert Into emails (em_body, em_datetim) Values m.tcText, Datetime()
         m.llSuccess = .T.
         Exit
      Catch
      Endtry
   Endfor
   Select(m.lnSelect)
Return m.llSuccess
Note that this is a function, not a procedure. The advantage is that you can check the return value, if it's .F. something went wrong. I also specified a maximum number of tries, to avoid that the system hangs if something fails.

One last note about using flock(). I checked all the programs I have created over the last 25 years, and I never use flock! The only place I use the sibling, rlock(), is in my procedure to calculate the next number which has to be in sequence, for instance an invoice number.
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform