Q. I have a table in an InterBase database that I want to insert into an external file that includes new lines. How do I get the new lines into the external file?
A. What a new line is varies on your platform. For UNIX it is a single line feed. For Windows it is a carrage return line feed combination. This example will create new lines for Windows.
If you have Delphi or C++ Builder the simplest way to create a text file is to use the BatchMove component. Here are simple step by step directions. These steps assume the BDE is installed.
- Place a TDatabase on your form and connect it to your database. Enter a value for the Database Name property.
- Create a TTable or TQuery. Set the Database Name property to the Database Name propert of your TDatabase. Set either the SQL property of a TTable or the SQL Property of a TQuery to extract your source data.
- Create another TTable. Set the Database Name property to the directory you want the text file to be created (example: c:). Set the TableType to be ttASCII. Set the TableName property to be name of the file you want to be created.
- Create a TBatchMove component. Set the Source property to Table1 or Query1. Set the Destination property to Table1 if your source is a TQuery or Table2 if your source is a TTable. Set the Mode property to batCopy. Right click on the BatchMove component and select Execute or execute the Execute method of BatchMove component in your Delphi or C++ Application.
If you have Delphi or C++ Builder you can also use a straight INSERT statement doing the following:
Query.SQL.ADD('INSERT INTO DEST SELECT Field1,Field2,"' + #13#10 + '" FROM Source');
In this example #13#10 is equivilent to a Carrage Return and a Line Feed. It assumes Dest is a foreign file table specification you have already created.
Finally, the Developer Guide manual included with InterBase 6 includes steps to fill a foreign text file using InterBase express. If you use a SELECT statement similar to the SELECT statement embeded in the INSERT statement about that includes #13#10 InterBase Express can create a foreign file with new lines in it.