Logo

Hacker’s Guide to Visual FoxPro
An irreverent look at how Visual FoxPro really works. Tells you the inside scoop on every command, function, property, event and method of Visual FoxPro.

ISEXCLUSIVE(), ISREADONLY()

These two functions tell you what kind of access you have to a table or database.

Usage

lExclusive = ISEXCLUSIVE( [ cAlias | nWorkArea | cDatabase
                          [ , nType ] ] )
lReadOnly = ISREADONLY( [ cAlias | nWorkArea | 0 ] )

Parameter

Value

Meaning

cAlias

Character

Tell whether the specified alias was opened for exclusive access or read-only.

Omitted

If nWorkArea and cDatabase are also omitted, tell whether the table open in the current work area was opened for exclusive access or read-only.

nWorkArea

0

For ISREADONLY() only, tell whether the current database was opened read-only. (This feature was added in VFP 7.) If no database is selected, an error message is displayed.

Positive number

Tell whether the table open in the specified work area was opened for exclusive access or read-only.

Omitted

If cAlias and cDatabase are also omitted, tell whether the table open in the current work area was opened for exclusive access or read-only.

cDatabase

Character

Tell whether the specified database (DBC) was opened for exclusive access.

Omitted

If cAlias and nWorkArea are also omitted, tell whether the table open in the current work area was opened for exclusive access.

nType

1 or Omitted

Return information about a table.

2

Return information about a database.

lExclusive

.T.

The table or database was opened for exclusive access.

.F.

The table or database was opened for shared access.

lReadOnly

.T.

The table or database was opened for read-only access.

.F.

The table or database was opened for read-write access.

Before Visual FoxPro, you had to mess with SYS(2011) to figure out if a table was open for exclusive access. ISEXCLUSIVE() is much more intuitively named, and since it returns a logical, it’s easy to incorporate in code and doesn’t depend on the language you’re using.

ISREADONLY() indicates whether the specified table or database is read-only because it was opened in read-only mode or is marked as read-only at the operating system level. This function was on many developers’ “most wanted” list for a long time. It makes it easier to write black-box routines that might process either tables or cursors. (By default, cursors created by SQL-SELECT are read-only.) Prior to VFP 7, this function only accepted table aliases, not database containers, which was a shame since a DBC can be opened read-only. Fortunately, VFP 7 adds the ability to determine how a DBC was opened.

Example

SET EXCLUSIVE ON
OPEN DATABASE TasTrade NOUPDATE
USE Customer
? ISEXCLUSIVE()  && Returns .T.
USE Customer SHARED
? ISEXCLUSIVE()  && Returns .F.
SET EXCLUSIVE OFF
USE Customer
? ISEXCLUSIVE()  && Returns .F.
USE Customer EXCLUSIVE
? ISEXCLUSIVE()  && Returns .T.
? ISEXCLUSIVE("TasTrade",2)  && Returns .T.
USE Customer NOUPDATE
? ISREADONLY()            && Returns .T.
USE Customer
? ISREADONLY()            && Returns .F.
SELECT Last_Name,First_Name FROM Employee INTO CURSOR Names
? ISREADONLY()            && Returns .T.
? ISREADONLY("Employee")  && Returns .F.
? ISREADONLY(0)         && Returns .T.

See Also

Set Exclusive, SYS(2011), Use