-
-
Save loaded02/2d6fdca6e1654e51bbde6bac19a902bc to your computer and use it in GitHub Desktop.
Using DBApp to change FPT file header
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Function CopyCustomDB(dbName as string) as void | |
LOCAL _db as bDBServer | |
LOCAL _aStruData as ARRAY | |
LOCAL oFSSource as usual | |
LOCAL oFSSourceFpt as usual | |
LOCAL oIni as IniFile | |
oIni := IniFile { "ads_sync.ini" } | |
/* | |
open the file | |
get its structure (DBStruct()) | |
close the file | |
*/ | |
System.Console.WriteLine("=====") | |
_db := bDBServer{oIni:GetPath("System", "SourcePath") + dbName} | |
_aStruData := _db:DbStruct | |
_db:Close() | |
/* | |
set the memoblock size to 64 | |
create a new file with DbCreate() using the structure you read | |
use an Append from to append the data from the existing file into the new file | |
close the new file | |
*/ | |
RDDINFO(_SET_MEMOBLOCKSIZE, 64) | |
DBCREATE(oIni:GetPath("System", "SourcePath") + dbName + "_RDD64", _aStruData) | |
DBUSEAREA(true,, oIni:GetPath("System", "SourcePath") + dbName + "_RDD64",,false) | |
System.Console.WriteLine("Appending: " + (string)oIni:GetPath("System", "SourcePath") + dbName) | |
DbApp(oIni:GetPath("System", "SourcePath") + dbName) | |
System.Console.WriteLine("Closing DB") | |
DBCLOSEALL() | |
System.Console.WriteLine("Done Closing DB") | |
/* | |
delete or move the old file to another folder | |
rename the new file so it gets the same name as the old one | |
open that file | |
reindex | |
*/ | |
System.Console.WriteLine("Erasing and Renaming Files") | |
IF .NOT. FErase(oIni:GetPath("System", "SourcePath") + dbName + ".DBF") | |
System.Console.WriteLine("Erasing failed") | |
ENDIF | |
IF .NOT. FErase(oIni:GetPath("System", "SourcePath") + dbName + ".FPT") | |
System.Console.WriteLine("Erasing failed") | |
ENDIF | |
oFSSource := FileSpec{oIni:GetPath("System", "SourcePath") + dbName + "_RDD64.DBF"} | |
oFSSource:Rename(dbName + ".DBF") | |
oFSSourceFpt := FileSpec{oIni:GetPath("System", "SourcePath") + dbName + "_RDD64.FPT"} | |
oFSSourceFpt:Rename(dbName + ".FPT") | |
DBUSEAREA(true,, oIni:GetPath("System", "SourcePath") + dbName,,false) | |
System.Console.WriteLine("Reindexing DB") | |
IF !DbReindex() | |
System.Console.WriteLine("Reindexing failed") | |
ENDIF | |
System.Console.WriteLine("Closing DB") | |
DBCLOSEALL() | |
System.Console.WriteLine("Done Closing DB") | |
System.Console.WriteLine("=====") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment