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.

BeforeCreateOffline, AfterCreateOffline, BeforeDropOffline, AfterDropOffline

These Database Events fire when a view is taken offline with CREATEOFFLINE() or taken back online with DROPOFFLINE().

Usage

PROCEDURE DBC_BeforeCreateOffline( cViewName, cPath )

PROCEDURE DBC_AfterCreateOffline( cViewName, cPath )

PROCEDURE DBC_BeforeDropOffline( cViewName )

PROCEDURE DBC_AfterDropOffline( cViewName )

Parameter

Value

Meaning

cViewName

Character

The name of the view.

cPath

Character

The path and name for the table representing the offline view.

The template generated for the BeforeDropOffline and AfterDropOffline events by the Database Properties dialog has a second parameter, cPath. However, this parameter is never passed a value (PCOUNT() is 1 and cPath is always .F.). So, there's really no such parameter. We're pretty sure a copy and paste operation in VFP's source code was the cause of this, since we've done similar things ourselves once or twice.

As is the case with other before-and-after pairs of events, you can prevent a view from being taken offline or back online by returning .F. in the Before events, while the After events simply receive notification that something happened.

One use for BeforeDropOffline is to ensure there aren’t any changes in the offline view, since DROPOFFLINE() erases the table representing the offline view and any changes in it are lost. The example shows the code for this.

Example

* Prevent a view from being taken online if there are any
* changes. This goes in the stored procedures of the database.

PROCEDURE DBC_BeforeDropOffline(cViewName)
LOCAL lnSelect, ;
    llReturn
lnSelect = SELECT()
SELECT 0
USE (cViewName) ADMIN EXCLUSIVE
llReturn = GETNEXTMODIFIED(0, ALIAS(), .T.) = 0
USE
SELECT (lnSelect)
RETURN llReturn

* End of stored procedures.
* Test it by creating a view, taking it offline, making a
* change, and then trying to take it back online.

CREATE SQL VIEW TestView AS SELECT * FROM Customer
SET MULTILOCKS ON
CREATEOFFLINE("TestView")
USE TestView
REPLACE COMPANY WITH "New Company Name"
USE

DROPOFFLINE("TestView")
llOffline = DBGETPROP("TestView", "View", "Offline")
WAIT WINDOW 'TestView is ' + IIF(llOffline, "offline", "online")

See Also

CreateOffline(), Create SQL View, Database Events, DropOffline(), GetNextModified(), Use