>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>