Subject | Re: How to import text file data into Firebird table ? |
---|---|
Author | Adam |
Post date | 2005-07-08T01:20:30Z |
--- In firebird-support@yahoogroups.com, "mario1fb" <mario1fb@y...>
wrote:
You probably don't need to reinvent the wheel, unless the import file
is too big to fit in memory.
procedure TForm1.Button1Click(Sender: TObject);
const
cFileName = 'c:\path\to\filename.txt';
cRecordsToRemove = 3;
var
s : TStringList;
procedure LoadFile;
begin
s.LoadFromFile(cFileName);
end;
procedure RemoveHeaderRecords;
var
i : Integer;
begin
for i := 0 to cRecordsToRemove-1 do
begin
s.Delete(0);
end;
end;
procedure SaveFile;
begin
s.SaveToFile(cFileName);
end;
begin
s := TStringList.Create;
try
LoadFile;
RemoveHeaderRecords;
SaveFile;
finally
s.Free;
end;
end;
wrote:
> Thank you Jason - your suggestions and sample code are mostappreciated.
> Unfortunately, I am not familiar with writing VBScripts and have noprovider.
> tools to write it.
> My preference is to keep the whole development code in Delphi and
> avoid using additional external applications, such as OLEDB
>long
> The data parsing method described in the Delphi-InterBase.PDF manual
> ("Inserting Data from an External File") works perfectly well, as
> as all data rows have identical lengths.irregular
> I am now considering writing a code to eliminate the initial
> title rows from the external text file (using simple ReadLn /WriteLn
> Delphi functions) and then use the built-in Interbase method toMario,
> directly parse the remaining regular data rows into the temporary
> Interbase table, as per Delphi-InterBase.PDF manual example.
>
> Would you have any other, better suggestions ?
>
> Kind regards,
> Mario
You probably don't need to reinvent the wheel, unless the import file
is too big to fit in memory.
procedure TForm1.Button1Click(Sender: TObject);
const
cFileName = 'c:\path\to\filename.txt';
cRecordsToRemove = 3;
var
s : TStringList;
procedure LoadFile;
begin
s.LoadFromFile(cFileName);
end;
procedure RemoveHeaderRecords;
var
i : Integer;
begin
for i := 0 to cRecordsToRemove-1 do
begin
s.Delete(0);
end;
end;
procedure SaveFile;
begin
s.SaveToFile(cFileName);
end;
begin
s := TStringList.Create;
try
LoadFile;
RemoveHeaderRecords;
SaveFile;
finally
s.Free;
end;
end;