Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Impacting Structure of one table on another
Message
De
21/02/2001 15:20:04
 
 
Information générale
Forum:
Visual FoxPro
Catégorie:
Base de données, Tables, Vues, Index et syntaxe SQL
Divers
Thread ID:
00478057
Message ID:
00478123
Vues:
24
Thanks Nadya!

At first glance that code looks just what I need:)

I will study it in work tomorrow.

Please send me the whole thing, my email is

markyoung@ntlworld.com

Many Thanks




>Hi Mark,
>
>I have a procedure called CloneBldMstr. It creates a new empty database, creates 2 tables (with all long field names, rules, etc.) and then append records from the file. This is an extract from this program, hopefuly, it will give you idea. If you want the whole program text, just e-mail me, I'll send the program to you.
>
>
>
>if !dbused(lcBldMstrDBC)
>     open database (lcBldMstrDBC)
>endif
>set database to (lcBldMstrDBC)
>local lcTempSpFile
>lcTemSpFile=addbs(gcTempPath)+'sp'+sys(2015)
>copy procedure to (lcTempSpFile) && Save stored procedure
>*--- Open Base Bldmstr table which has all the field & table validations in it.
>=opentable(lcBldMstrDBF,'WorkFile') && Open Base BldMstr table
>select WorkFile
>*--- Create a table that holds the structure with validations that we want to create.
>ltBldMstr=addbs(gcTempPath)+'b'+sys(2015)
>copy structure extended to (ltBldMstr)
>use     in WorkFile      && Close bldmstr!bldmstr
>=opentable(lcVallogDBF,'ValLog') && Open Base ValLog table
>select ValLog
>ltValLog=addbs(gcTempPath)+'v'+sys(2015)
>copy structure extended  to (ltValLog)
>use in ValLog && Close bldmstr!ValLog
>
>*--- Create the new database.
>if dbused(lcNewBldMstr) && Database is in use, close it first
>     set database to (lcNewBldMstr)
>     close database
>endif
>if !empty(lcSetDB)
>     set database to (lcSetDB)
>endif
>local lcOldError, lnError
>lcOldError=on('error')
>lnError=0
>on error lnError=error()
>create database (lcNewBldMstr)
>if !empty(lcOldError)
>     on error &lcOldError && Restore previous Error Handler
>endif
>
>**** Error cases
>if lnError>0
>     select (lnOldArea)
>     if lcOldSafety='ON'
>          set safety on && Restore Safety settings
>     endif
>     if lnError=3 && File is in Use
>          =messagebox(lcNewBldMstr+' database could not be created!',48,'Warning')
>     else && Another problem occurs
>          local lnRows
>          lnRows=aerror[laErrors]
>          if lnRows>0
>               =messagebox('Error # '+transform(laErrors[1])+ ;
>                    ' "'+laErrors[2]+'" occurs...',48,'Warning')
>          endif
>     endif
>     oJC.CurAppStat='I' && Failed
>     return .f.
>endif
>***************************************
>*--- Update the table_name field value in this extended structure so when added to dbc it has the correct name.
>*---- First open extended table in same work space.
>if !dbused(lcNewBldMstr) && Database is not in use
>     open database (lcNewBldMstr)
>endif
>set database to (lcNewBldMstr)
>append procedures from (lcTempSpFile) && Add stored procedure
>=opentable(ltBldMstr,'ltBldMstr')
>select ltBldMstr
>locate
>replace table_name with (lcNewBldMstrName+'_B') in ltBldMstr
>use     in select('ltBldMstr')     && Close the table
>
>*--- Update the table_name field value in this extended structure so when added to dbc it has the correct name.
>*---- First open extended table in same work space.
>=opentable(ltValLog,'ltValLog')
>select ltValLog
>locate
>replace table_name with (lcNewBldMstrName+'_V') in ltValLog
>use     in select('ltValLog')     && Close the table
>
>*--- Create the new table based and add to the dbc.
>wait window nowait "Wait while creating "+lcNewBldMstr+'_B'+".DBF ..."  && NSL 4/5/2000 added message
>select 0
>create (lcNewBldMstr+'_B') database (lcNewBldMstrName) from (ltBldMstr)
>flush && To save modifications on the disk
>
>wait window nowait "Wait while creating "+lcNewBldMstr+'_V'+".DBF ..."  && NSL 4/5/2000 added message
>select 0
>create  (lcNewBldMstr+'_V') database (lcNewBldMstrName) from (ltValLog) && This table would be opened exclusively
>*--- Create necessary index(s).
>=GenerateIndexes('VALLOG',lcNewBldMstrName+'_V')
>flush
>
>>When I am developing I normally have several test areas with data in them and testers using them to test various aspects of my systems.
>>
>>Changes in my development tables will normally have to be made to all my test tables.
>>
>>In my 2.6 days I wrote a function called ImpStruc that Impacted the Structure of one table on another for me.
>>It worked as follows.
>>
>>1. Get source and target information
>>2. Rename the target table
>>3. Use COPY STRUCTURE WITH CDX to create a new structure
>>4. Append the data in from the old (renamed) table.
>>
>>
>>Now I can not use the function because COPY STRU will convert my primary keys to candidate keys.
>>
>>I would also have to remove the Target table from its DBC in order to carry out this operation and would lose various settings I have made at the DBC level.
>>
>>Does anyone have some code that has the same functionality as my good old IMPSTRUC function.
>>
>>I have searched through the files section to no avail. Although I have looked at one of Erik Moore's progs that generates the code for recreating the table.
>>It looks like this could do it with a bit of additional work.
>>
>>I want to avoid that work However:)
>>
>>All help no matter how trivial gratefully received.
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform