dbTalk Databases Forums  

VFP, SQL: Locking

comp.databases.xbase.fox comp.databases.xbase.fox


Discuss VFP, SQL: Locking in the comp.databases.xbase.fox forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Gene Wirchenko
 
Posts: n/a

Default VFP, SQL: Locking - 09-20-2005 , 06:59 PM






How do I lock tables so that a series of SQL statements will get
current and consistent data (that is, no updates while the series is
executing)? I am having to bolt on multi-user use to my app when
single-user was a basic spec.

Sincerely,

Gene Wirchenko


Reply With Quote
  #2  
Old   
Eugene Vtial
 
Posts: n/a

Default Re: VFP, SQL: Locking - 09-20-2005 , 09:16 PM






Gene Wirchenko wrote:
Quote:
How do I lock tables so that a series of SQL statements will get
current and consistent data (that is, no updates while the series is
executing)? I am having to bolt on multi-user use to my app when
single-user was a basic spec.

Sincerely,

Gene Wirchenko


Are you using VFP data on the backend or client server?
If client server, what server is on the backend?


Reply With Quote
  #3  
Old   
Fred Taylor
 
Posts: n/a

Default Re: VFP, SQL: Locking - 09-20-2005 , 09:20 PM



If these are VFP tables, your tables need to be part of a DBC and then you
can use transactions.

BEGIN TRANSACTION

UPDATE yourtable SET field1='some value' WHERE keyid=x

UPDATE othertable SET field1 = 'other vlaue' WHERE kyid=x

END TRANSACTION

You can use the ROLLBACK command to cancel the transaction.

VFP9 can do transactions on free tables, see ISTRANSACTABLE() and
MAKETRANSACTABLE() functions

For backend tables, you'll need to use SQLEXEC to start/end it's transaction
capabilities.
--
Fred
Microsoft Visual FoxPro MVP


"Gene Wirchenko" <genew (AT) ucantrade (DOT) com.NOTHERE> wrote

Quote:
How do I lock tables so that a series of SQL statements will get
current and consistent data (that is, no updates while the series is
executing)? I am having to bolt on multi-user use to my app when
single-user was a basic spec.

Sincerely,

Gene Wirchenko




Reply With Quote
  #4  
Old   
Dan Freeman
 
Posts: n/a

Default Re: VFP, SQL: Locking - 09-21-2005 , 11:36 AM



This *could* be a really bad idea, depending on how long "the series" takes.
Just wanted to get that little warning out of the way first. It's one of
those "always there" things that always needs to be mentioned. <s>

You might be surprised how multi-user friendly VFP is without your having to
do a thing. Implicit locking handles a lot more than you might think.

However, for your "series" you could always explicitly FLOCK() the tables
involved. That will keep updates/inserts out for the duration. Of course,
back to the first paragraph, your update/insert routines have to be written
to handle situations where they might happen during your "series".

Dan



Gene Wirchenko wrote:
Quote:
How do I lock tables so that a series of SQL statements will get
current and consistent data (that is, no updates while the series is
executing)? I am having to bolt on multi-user use to my app when
single-user was a basic spec.

Sincerely,

Gene Wirchenko



Reply With Quote
  #5  
Old   
Gene Wirchenko
 
Posts: n/a

Default Re: VFP, SQL: Locking - 09-21-2005 , 11:58 AM



On Tue, 20 Sep 2005 22:16:42 -0400, Eugene Vtial <news (AT) microsoft (DOT) com>
wrote:

Quote:
Gene Wirchenko wrote:
How do I lock tables so that a series of SQL statements will get
current and consistent data (that is, no updates while the series is
executing)? I am having to bolt on multi-user use to my app when
single-user was a basic spec.

Are you using VFP data on the backend or client server?
No, I am not.

Quote:
If client server, what server is on the backend?
Sincerely,

Gene Wirchenko


Reply With Quote
  #6  
Old   
Gene Wirchenko
 
Posts: n/a

Default Re: VFP, SQL: Locking - 09-21-2005 , 03:29 PM



[reordered to chronological for readability]

On Wed, 21 Sep 2005 16:36:54 GMT, "Dan Freeman" <spam (AT) microsoft (DOT) com>
wrote:

Quote:
Gene Wirchenko wrote:
How do I lock tables so that a series of SQL statements will get
current and consistent data (that is, no updates while the series is
executing)? I am having to bolt on multi-user use to my app when
single-user was a basic spec.

This *could* be a really bad idea, depending on how long "the series" takes.
Just wanted to get that little warning out of the way first. It's one of
those "always there" things that always needs to be mentioned. <s
The series is short, but longer than one. I do not want
incorrect results due to something changing between one SQL statement
and the next.

Quote:
You might be surprised how multi-user friendly VFP is without your having to
do a thing. Implicit locking handles a lot more than you might think.
But does it handle in between two SQL statements?

Not everything can be done in ONE SQL statement.

Quote:
However, for your "series" you could always explicitly FLOCK() the tables
involved. That will keep updates/inserts out for the duration. Of course,
back to the first paragraph, your update/insert routines have to be written
to handle situations where they might happen during your "series".
Sincerely,

Gene Wirchenko



Reply With Quote
  #7  
Old   
Eugene Vtial
 
Posts: n/a

Default Re: VFP, SQL: Locking - 09-21-2005 , 09:11 PM



Gene Wirchenko wrote:
Quote:
On Tue, 20 Sep 2005 22:16:42 -0400, Eugene Vtial <news (AT) microsoft (DOT) com
wrote:


Gene Wirchenko wrote:

How do I lock tables so that a series of SQL statements will get
current and consistent data (that is, no updates while the series is
executing)? I am having to bolt on multi-user use to my app when
single-user was a basic spec.


Are you using VFP data on the backend or client server?


No, I am not.


Ok, I will assume using VFP tables and not sure what version of VFP you
are using.


Can't you just FLOCK() the table before doing your query ?

USE SomeTable1 IN 0
USE SomeTable2 IN 0
FLOCK("SomeTable1")
FLOCK("SomeTable2")

SELECT * FROM SomeTable1 WHERE something = .t.

* do some processing that may take some time

SELECT * FROM SomeTable1 ;
LEFT JOIN SomeTable2 ON SomeTable2.Field1 == SomeTable1.Field1 WHERE
somethingnew = .t.


UNLOCK IN "SomeTable1"
UNLOCK IN "SomeTable2"

USE IN SELECT("SomeTable1")
USE IN SELECT("SomeTable2")


Reply With Quote
  #8  
Old   
Bernhard Sander
 
Posts: n/a

Default Re: VFP, SQL: Locking - 09-22-2005 , 06:20 AM



Hi Gene

Quote:
You might be surprised how multi-user friendly VFP is without your having to
do a thing. Implicit locking handles a lot more than you might think.


But does it handle in between two SQL statements?

Not everything can be done in ONE SQL statement.
I think, if you can't use transactions, then the only reliable method is using
pure native Foxpro code, without SQL statements. Then I would first SEEK or
LOCATE FOR the necessary records in all necessary tables, rlock() all these
records (maybe SET MULTILOCKS ON is necessary), do all updates and after this
unlock all the involved tables.

Regards
Bernhard Sander


Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.