Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Local and Remote Views for the same cursor.
Message
 
To
04/09/1998 09:39:28
Scott Knight
Human Resources Development Canada
St. John's, Newfoundland, Canada
General information
Forum:
Visual FoxPro
Category:
Other
Miscellaneous
Thread ID:
00133243
Message ID:
00133755
Views:
15
>Is it possible to change the CursorSource at run-time from a local view to a remote view. Both views have to same structure expect one is from VFP and the other SQL Server. To the app the to cursors function the same. If I could change the source based on a indicator I could run the same application in for local data as I do remote.
>
>Thanks in advance
>
>
>Scott k

Scott,

We have a beautifull mechanism in Codebook that does this. It is based on a writing convention: all the local views are prefixed with "lv_" and the remote ones with "rv_". We have a cDynamicView cursor class that knows which view to load based on a configuration setting.

DEFINE CLASS CDynamicViewCursor AS CCursor
*-- A dynamic view is one that can either reference
*-- local or remote data. Generic code assumes that local
*-- views are named "lv_" while remote views are
*-- named "rv_". Switching from local to remote will
*-- cause the cursor source to change, but the alias
*-- to remain the same: "v_".

*-- Defaults
NoDataOnLoad = .T.

*-- New custom properties
PROTECTED cCursorSource, ;
lUseLocalData
cCursorSource = ""
lUseLocalData = .T.

FUNCTION Init()
LOCAL lcPrefix, lcAlias
*-- Do not allow this class to be directly instantiated
IF IsAbstract(this.Class, "CDynamicViewCursor")
RETURN .F.
ENDIF

*-- Determine if the data environment to which this cursor
*-- belongs is using local or remote data.
this.lUseLocalData = this.Parent.lUseLocalData

*-- Save the alias name for later re-assignment. (Currently,
*-- the Alias property is getting set to the CursorSource
*-- property automatically as soon as you assign a value
*-- to CursorSource).
lcAlias = ""
IF !EMPTY(this.Alias)
lcAlias = this.Alias
ELSE
lcAlias = this.cCursorSource
ENDIF

lcPrefix = IIF(this.lUseLocalData, "l", "r")
this.CursorSource = lcPrefix + this.cCursorSource

*-- Reset the alias
this.Alias = lcAlias

IF !CCursor::Init()
RETURN .F.
ENDIF

ENDFUNC
ENDDEFINE

More on this on my website.

José
Previous
Reply
Map
View

Click here to load this message in the networking platform