Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Change database
Message
De
26/07/2002 11:34:16
 
 
À
25/07/2002 19:28:03
Information générale
Forum:
Visual FoxPro
Catégorie:
Base de données, Tables, Vues, Index et syntaxe SQL
Titre:
Divers
Thread ID:
00682829
Message ID:
00683019
Vues:
31
Hi Rob.

>I have the database location at ..\gen002\sas.dbc
>This database is the default database, and I have set it
>up so that this is the one thatthat is always opened on the
>initial screen.
>
>Now I have been asked to change the set-up program so that
>the User can see the older version of the data, which is
>in a different folder:
>..\gen001\sasdbc

One thing you'll have to do is change the Database property of every cursor object in your forms. Here's how I do that. Put the following code into the BeforeOpenTables method of the DataEnvironment:
local laObjects[1], ;
  lnObjects, ;
  lcDirectory, ;
  lcCommon, ;
  lnI, ;
  loObject, ;
  lcDatabase, ;
  lcTable

* Get a list of the members, and get the data directory
* from the global gcDataDir variable.

lnObjects   = amembers(laObjects, This, 2)
lcDirectory = gcDataDir

* Look at each member object, but only process cursors.

for lnI = 1 to lnObjects
  loObject = evaluate('This.' + laObjects[lnI])
  if upper(loObject.BaseClass) = 'CURSOR'
    lcDatabase = loObject.Database

* If this is a free table, adjust the CursorSource property.

    if empty(lcDatabase)
      lcTable = loObject.CursorSource
      loObject.CursorSource = lcDirectory + ;
        substr(lcTable, rat('\', lcTable) + 1)

* This cursor is part of a database, so change the database property.

    else
      loObject.Database = lcDirectory + ;
        substr(lcDatabase, rat('\', lcDatabase) + 1)
    endif empty(lcDatabase)
  endif upper(loObject.BaseClass) = 'CURSOR'
next lnI
Then, when the user selects the desired database, set a global variable called gcDataDir to the directory where the database exists (not including the database name). You can also do this by storing the directory in a property of a global object, such as an application object you may be using.

>OPEN DATABASE ..\gen001\sas.dbc
>and then
>SET DATABASE etc etc

You don't need the SET DATABASE command here -- OPEN DATABASE both opens the database and makes it the current one.

Doug
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform