Subject Re: [firebird-support] How to import text file data into Firebird table ?
Author Jason Dodson
Heck, here is my five minutes of effort... and this includes
finding/downloading/installing the OLEDB provider, so I could write it
in a script (meaning if you run windows, you can run this).

First, the OLEDB provider for Interbase/Firebird:

http://www.zstyle.dp.ua/files/ibfree5.zip

Next, the VBScript to "Get 'er done":

_________________________________________________

Dim DBConn
Dim Cmd
Dim FSO
Dim InputFile
Dim InputLine
Dim LineElements

'Init the DB connection
Set DBConn = New ADODB.Connection
DBConn.Open "Provider=ZStyle IBOLE Provider;Data
Source=ServrIPGoesHere:PathToDBGoesHere;User
ID=SomeUserName;Password=SomePassword;role=SomeRole;"

Set Cmd = New ADODB.Command
Set Cmd.ActiveConnection = DBConn

'Init the file system objects for reading
Set FSO = CreateObject("Scripting.FileSystemObject")
Set InputFile = FSO.OpenTextFile("test.txt",1)

'Buzz past the header (edit as appropriate)
InputLine = InputFile.Readline
InputLine = InputFile.Readline
InputLine = InputFile.Readline

'Loop through the rest of the lines in the file
Do Until InputFile.AtEndOfStream
InputLine = objTextFile.Readline
LineElements = split(strComputer, chr(9))
Cmd.CommandText = "Insert Into SomeTable (Col1, Col2, Col3) Values (" &
"""" LineElements(1) & """" & ", " & """" LineElements(2) & """" & ", "
& """" LineElements(3) & """" & ");"
Cmd.Execute

'If the file is huge, we want to erase the array each time we are done
with it, else the mem usage will build until the end of script
Erase LineElements
Loop

'Cleanup
Set Cmd = Nothing

DBConn.Close
Set DBConn = Nothing

MsgBox "Complete!"

_________________________________________________



mario1fb wrote:
> The structure of the text (ASCII) file is as follows:
> The initial row length (number characters in each row) varies, e.g.
>
> zzz yyyy Initial Title row xxxx zzzz Title Row
> xxx zzz Header row ... More text
> ...
> ssxxccvvv zzz ... more rows like those above
> ...
> here starts the actual text content that I want to import into table:
>
> COL1 COL2 COL3
>
> D1234 12.46 1.234
> D3214 11.45 0.122
> Z5533 -10.22 -3.456
> ...
> etc.
>
> I want to end up with a Firebird table having three columns with the
> actual data extracted from the regular text columns (the initial file
> header info to be discarded).
> I have tried to parse the above data following the "Inserting Data
> from an External File" example from Delphi-InterBase.PDF manual (pp.
> 96-99), but this only works with regular (fixed) text data columns. My
> example produces incorrect and unpredictable output due to the
> variable length of the inital rows in the external text file.
>
> Any ideas how to insert the above text data (starting from COL1, COL2,
> etc.) into the Firebird/Interbase database table ?
> Many thanks.
> Mario
>
>
>
>
>
>
>
> ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
>
> Visit http://firebird.sourceforge.net and click the Resources item
> on the main (top) menu. Try Knowledgebase and FAQ links !
>
> Also search the knowledgebases at http://www.ibphoenix.com
>
> ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
>
> Yahoo! Groups Links
>
>
>
>
>
>
>
>