Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Begin Transaction x LOCK/UNLOCK
Message
De
30/03/2006 12:27:07
 
 
À
30/03/2006 12:13:57
Information générale
Forum:
Visual FoxPro
Catégorie:
Base de données, Tables, Vues, Index et syntaxe SQL
Versions des environnements
Visual FoxPro:
VFP 6 SP5
OS:
Windows 2000 SP4
Network:
Windows 2000 Server
Database:
Visual FoxPro
Divers
Thread ID:
01109212
Message ID:
01109241
Vues:
23
>Hello Terry
>>Fred
>>
>>1) How can you assume that the LOCK() has been successful? Someone else may have locked it.
>>
>>Better iS:
>>
>>If LOCK('mytable')
>> insert into mytable ...
>> Unlock
>>EndIf
>>
>
>I already use an IF command to verify if the table is locked, this rotine is OK.

Well the examples you provided do not suggest that. If LOCK() alone sees if file locked and, if not, locks it for you.

>
>
>
>>2) Is it necessary to lock the whole table anyway? I believe that Lock only locks the file header when inserting anyway. Do you want to prevent all other users update access to the already existing data while you're adding new?
>>
>>3) your codse suggests that you only want to insert 1 record anyway. Xactions are used mainly to ensure ALL critical updates succeed or none. Surely here TableUpdate() for buffered data will suffice to decide on success or failure of the insert?
>
>I wonder that BEGIN/END TRANSACTION do the same thing as LOCK/UNLOCK, so I don't need BEGIN a transaction and LOCK the file at the same time. Just Begining a transaction is my file safe to insert data under network?

Suppose you want to add, update or delete many records, and suppose these records have related data that need to be added, updated or deleted, and all were dependant on each other (say parent/child), then you would noyt want to have added, say, a child and the computer breaks down before its parent is added, leaving an orphan. That's the kind of scenario where you need xactions.

For the addition of just one record, I don't see the need, it's pointless.
Also, xactions don't lock the table per se - rather they "lock in" your changes - the part of the table that you're changing.

If, say, you have a loop of INSERT commands, and you want to ensure all rec's are inserted, then xactions are appropriate.

>
>I have many users inserting data at the same file.

Again, I don't see how locking the whole table will help, especially if there are several frustrated users all wanting to insert at the same time.

RLOCK() is usually preferable, as it only locks the current record. But this is no good here either, as you can't lock a record that is yet to be inserted.

>
>>
>>HTH
>>
>>Terry
>>
>>>Hello *.*
>>>
>>>look at these scenarios:
>>>
>>>1) I´m using free tables under a network, when I insert data I do it:
>>>
>>>
>>>select mytable
>>>   lock('mytable')
>>>insert into mytable ...
>>>unlock
>>>
>>>It´s all right.
>>>
>>>2) I´m using DBF Tables in to DBC container, so I do it:
>>>
>>>BEGIN TRANSACTION
>>>  SELECT MYTABLE
>>>  LOCK('MYTABLE')
>>>    INSERT INTO MYTABLE ...
>>>  UNLOCK
>>>END TRANSACTION
>>>
>>>
>>>The question is: Is it really necessary LOCK the table when I use BEGIN/END TRANSACTION ?
>>>
>>>Thanks in advance.
- Whoever said that women are the weaker sex never tried to wrest the bedclothes off one in the middle of the night
- Worry is the interest you pay, in advance, for a loan that you may never need to take out.
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform