Page #62

OpenData, CloseData, Activate, Deactivate, ModifyData

These database events fire when a database is opened, closed, made the current database, made non-current, or displayed in the Database Designer, respectively.

Usage

PROCEDURE DBC_OpenData( cDatabaseName, lExclusive, lNoUpdate,                         lValidate )   PROCEDURE DBC_CloseData( cDatabaseName, lAll )   PROCEDURE DBC_Activate( cDatabaseName )   PROCEDURE DBC_Deactivate( cDatabaseName )   PROCEDURE DBC_ModifyData( cDatabaseName, lNoWait, lNoEdit )

Parameter

Value

Meaning

cDatabaseName

Character

The name of the database being opened, closed, modified, activated, or deactivated.

lExclusive

.T.

The database is being opened exclusively, either because the EXCLUSIVE clause was used or because SET EXCLUSIVE is set to ON.

.F.

The database is being opened for shared access.

lNoUpdate

Logical

Indicates whether the NOUPDATE clause was specified.

lValidate

Logical

Indicates whether the VALIDATE clause was used.

lAll

Logical

Indicates whether the ALL clause was specified in the CLOSE DATABASES command.

lNoWait

Logical

Indicates whether the NOWAIT clause was specified.

lNoEdit

Logical

Indicates whether the NOEDIT clause was used.


Just because lNoUpdate is .F. doesn't mean the database is updateable; it may be marked as read-only at the operating system level. Use ISREADONLY(0) (added in VFP 7) to determine if the database can be updated.


OpenData fires before a database is opened. After it fires, if another database was current, Deactivate fires for that database (since it won't be the current database anymore). Activate for the newly opened database then fires (since that database becomes the current one). Only after Activate is done does DBC() return the name of the newly opened database.

If OpenData returns .F., a "file access is denied" error is triggered and the database can't be opened. Of course, be sure that you do this only under certain circumstances (for example, if the current user isn't authorized to access the database), or you'll be somewhat hosed because you won't be able to reopen the database even to turn that feature off! (You're only "somewhat" hosed because you can always USE the DBC to open it as a table, modify the code directly in the Code memo of the StoredProceduresSource record, close it, and then use COMPILE DATABASE to compile the changes. Of course, that's also the reason you can't depend on database events to give you rock-solid security.)

CloseData fires before a database is closed; return .F. to prevent the database from being closed. Deactivate also fires (after CloseData), since the database is no longer the current one.

Activate fires when the database becomes the current one via such means as SET DATABASE, after OPEN DATABASE completes, clicking on an open Database Designer window, and so on. If another database is current, Deactivate fires for that database first. Return .F. from this event to prevent the database from becoming the current one.

Deactivate fires when the database is made non-current, such as when SET DATABASE is used to select another or no database, when the database is closed, and so forth. Return .F. to prevent this from happening (this also prevents the database from being closed).

ModifyData fires when MODIFY DATABASE is used; return .F. to prevent the Database Designer from appearing.

Example

* This goes in the stored procedures of a database.   PROCEDURE DBC_OpenData(cDatabaseName, lExclusive, lNoupdate, ;     lValidate) WAIT WINDOW PROGRAM() + CHR(13) + ;     'cDatabaseName: ' + cDatabaseName + CHR(13) + ;     'lExclusive: ' + TRANSFORM(lExclusive) + CHR(13) + ;     'lNoUpdate: ' + TRANSFORM(lNoUpdate) + CHR(13) + ;     'lValidate: ' + TRANSFORM(lValidate) + CHR(13) + ;     'DBC(): ' + DBC()   PROCEDURE DBC_CloseData(cDatabaseName, lAll) WAIT WINDOW PROGRAM() + CHR(13) + ;     'cDatabaseName: ' + cDatabaseName + CHR(13) + ;     'lAll: ' + TRANSFORM(lAll)   PROCEDURE DBC_Activate(cDatabaseName) WAIT WINDOW PROGRAM() + CHR(13) + ;     'cDatabaseName: ' + cDatabaseName + CHR(13) + ;     'DBC(): ' + DBC()   PROCEDURE DBC_Deactivate(cDatabaseName) WAIT WINDOW PROGRAM() + CHR(13) + ;     'cDatabaseName: ' + cDatabaseName + CHR(13) + ;     'DBC(): ' + DBC()   PROCEDURE DBC_ModifyData(cDatabaseName, lNoWait, lNoEdit) WAIT WINDOW PROGRAM() + CHR(13) + ;     'cDatabaseName: ' + cDatabaseName + CHR(13) + ;     'lNoWait: ' + TRANSFORM(lNoWait) + CHR(13) + ;     'lNoEdit: ' + TRANSFORM(lNoEdit)   * End of stored procedures.     * Open a database, change what's current, modify it,  * then close it.   OPEN DATABASE TestData SET DATABASE TO SET DATABASE TO TestData MODIFY DATABASE CLOSE DATABASE

See Also

Close All, Close Databases, Compile Database, Database Events, DBC(), IsReadOnly(), Modify Database, Open Database, Set Database, Set Exclusive, Validate Database


View Updates

Copyright © 2002 by Tamar E. Granor, Ted Roche, Doug Hennig, and Della Martin. All Rights Reserved.



Hacker's Guide to Visual FoxPro 7. 0
Hackers Guide to Visual FoxPro 7.0
ISBN: 1930919220
EAN: 2147483647
Year: 2001
Pages: 899

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net