Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Check for Exclusive Open?
Message
From
13/01/2003 23:51:08
 
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Miscellaneous
Thread ID:
00741115
Message ID:
00741287
Views:
26
Nadya, The original post was as follows

"What is the best way to check to see if a table can be open exclusively before opening it exclusively and getting an error?

In this case I want to do an ocassional PACK if there are no other users using the database, but of course use summary excl produces an error if other users are using the db.

Thanks!
Marvin Masson"


The above message did not indicate that Marvin wanted to know if anyone else has the table open exclusively, but how to avoid an error on pack or other commands which require the table to _be_ opened exclusively

Try this - Create a table test.dbf
*!* the following line is somewhere else in your code 
use test.dbf alias test1 shared in 0
*!* not readily apparent that I or someone else has the table exclusive or otherwise

llOpenError = .f.
m.lcOldError = on("error")
on error llOpenError = .t.
use test.dbf alias test exclusive in 0 again
on error &lcOldError
if !llOpenError
	* we opened the file exclusively
	*!* but is it really?
	messagebox("VFP did not throw an error -llOpenError assumes test is open exclusively")
	select test
        *!* Pack generates error table not open exclusively
	pack
else
	* could not exclusively open file
	messagebox("VFP threw an error - Did not get test.dbf exclusively")

endif
if used("test") and isexclusive("test")
	*!* this line only executes when test.dbf can be opened exclusively 
        select test
        *!* Pack table is successful
	pack
else
	*!* did not get table exclusively, I don't care why
	messagebox("Did not get test.dbf exclusively")
endif
Admittedly, issuing "use test.dbf exclusive in 0 again" is a stretch and not a wise thing to do if you really want to open a table exclusively, but it can happen and VFP will not throw an error.

Elmer

>Your check would make sense after we attempted to open the table. Did we really open it exclusive? This check, however, would not let us know, if the table is opened exclusive somewhere or not...
>
>So, I would probably put this check afterwards as a precaution...
>
>>
>>>>Nadya,
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform