Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

views

Status
Not open for further replies.

mjcmkrsr

Technical User
Nov 30, 2010
840
Hi,

I'm confused with a strange behaviour of views. I'm working with one test dataset and one real dataset. I switch from one set to the other with this code in the BEFOREOPENTABLES event of the form's dataenvironment.

Local cObjClass, cObjName, cOldDatabase, cNewDatabase, oReference
Local Array aCursors[1]


If Not (Empty(gcDrive) Or Empty(gcPath)) && two general variables from main program
= AMEMBERS(aCursors, THISFORM.Dataenvironment, 1)
For i = 1 to ALEN(aCursors,1)
If aCursors(i,2) = "Object"
cObjClass = "THISFORM.DATAENVIRONMENT." + aCursors(i,1) + ".Class"

If EVAL(cObjClass) = "Cursor"
cObjName = "THISFORM.DATAENVIRONMENT." + aCursors(i,1) + ".DATABASE"
cOldDatabase = EVAL(cObjName)
cNewDatabase = AllTrim(gcDrive) + AllTrim(gcPath) + AllTrim(Substr(cOldDatabase, RAT("\",cOldDatabase) + 1))
oReference = EVAL("THISFORM.DATAENVIRONMENT." + aCursors(i,1))
oReference.Database = cNewDatabase

Endif
Endif
EndFor

_Screen.Caption = gcCaption + " - " + gcDrive + gcPath
Endif

The views are opened with NODATAONLOAD = .T. and are REQUERYd after being opened.

When I switch from one dataset to the other, the data in the tables are correctly displayed whereas the views do not display the correct data and seem to stick to some temporary file.

Any hints are appreciated.

Mark
 
Where are the views stored? Do you have a secondary database with the views pointing to tables of a second database? Then this isn't changed by the switching of the database your code does.

Bye, Olaf.
 
Hi Olaf,
I have two distinct sets of databases, tables and views in two different folders.
Mark
 
Hm, even if the views are in both databases, the view definition contains databasename!table. If you open the form with gcDrive, gcPath set to one database and then in the same foxpro session open the form with gcDrive, gcPath setup for the other database, the fist database which I assume has the same name, only a different location, is already open and the views will reuse the currently set database.

Are you sure DBF("viewname") is the exact same file name in both forms for a certain view? Also what's cursorgetprop("Databse","viewname") for the one and the other instance of the form?

And last not least is the form set to use private datasession or not?

Many circumstances will cause, that you can only use the form once with the correct database and then need to both switch your global vars and close the form and database before calling that form really switches to the other database.

What you can try is SET DATABASE TO (cNewdatabase) to set the correct database active, this switching is really working with full paths, even if both databases have the same name.

Bye, Olaf.
 
Hi Olaf,

ad 1) seems so
ad 2) YES, absolutely
ad 3) Private DS
ad 4) I will give it a try - and keep you updated

Thanks

Mark
 
Hi Olaf,

I modified the code (see below)but it didn't help. I'm able to switch once from e.g.

gcDrive = "S:"
gcPath = "\VFPData\Realdata\"

to

gcDrive = "F:"
gcPath = "\VFPData\Testdata\"

but not back again. The "old" database seems to leave some remains somewhere.

***Code***
Local cObjClass, cObjName, cOldDatabase, cNewDatabase, oReference
Local Array aCursors[1]


If Not (Empty(gcDrive) Or Empty(gcPath)) && two general variables from main program
= AMEMBERS(aCursors, THISFORM.Dataenvironment, 1)
For i = 1 to ALEN(aCursors,1)
If aCursors(i,2) = "Object"
cObjClass = "THISFORM.DATAENVIRONMENT." + aCursors(i,1) + ".Class"

If EVAL(cObjClass) = "Cursor"
cObjName = "THISFORM.DATAENVIRONMENT." + aCursors(i,1) + ".DATABASE"
cOldDatabase = EVAL(cObjName)
cNewDatabase = AllTrim(gcDrive) + AllTrim(gcPath) + AllTrim(Substr(cOldDatabase, RAT("\",cOldDatabase) + 1))
oReference = EVAL("THISFORM.DATAENVIRONMENT." + aCursors(i,1))
oReference.Database = cNewDatabase

Endif
Endif
EndFor

Close Database
Open Database (cNewDatabase)
Set Database to (cNewDtabase)

_Screen.Caption = gcCaption + " - " + gcDrive + gcPath
Endif
***EndOfCode***

Still fiddling and googling around.

Thanks anyway

Mark
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top