Subject Re: How to import text file data into Firebird table ?
Author Adam
--- In firebird-support@yahoogroups.com, "mario1fb" <mario1fb@y...>
wrote:
> Thank you Jason - your suggestions and sample code are most
appreciated.
> Unfortunately, I am not familiar with writing VBScripts and have no
> tools to write it.
> My preference is to keep the whole development code in Delphi and
> avoid using additional external applications, such as OLEDB
provider.
>
> The data parsing method described in the Delphi-InterBase.PDF manual
> ("Inserting Data from an External File") works perfectly well, as
long
> as all data rows have identical lengths.
> I am now considering writing a code to eliminate the initial
irregular
> title rows from the external text file (using simple ReadLn /
WriteLn
> Delphi functions) and then use the built-in Interbase method to
> 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

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;