Using Text File Driver (ODBC) with RPG2SQL
From Support
Contents |
Why Use the Text File Driver?
Much information is stored in delimited or fixed-length text files, such as CSV (comma-separated variable) or tab-delimited files. Usually these can be handled using Excel functions. But sometimes the data is not consistent from row to row, or Excel is too "helpful" and interprets data as dates or times when they should be plain text. E.g., 10:09 will be treated as a time by Excel, 89:09 will not.
The MS Text File Driver (ODBC) driver can be used to process this kind of information. This article shows one way to use it. It also presents some of the difficulties with using the Text File Driver.
Necessary Things
In order to use the Text File Driver with a file, there has to be an information file in the same directory as the text file. The name is always schema.ini. This file can be created manually by using any text editor, by using the ODBC wizard, or programmatically. We will use the ODBC wizard to start out, then make some additional edits as needed.
Creating a DSN for Text Files
In XP, at least, go to Start->Settings->Control Panel->Administrative Tools->Data Sources (ODBC) or Start->Settings->->Administrative Tools->Data Sources (ODBC). Then follow the steps presented in the following windows:
The RPG2SQL connection string
Rtn = SQL_DBOpenConn(SQL_Socket : 'DSN=NameAddr;');
There are other options that can be used in the connection string—see Setting Options Programmatically for the Text File Driver
The RPG2SQL SELECT Statement
Rtn = SQL_RunSQLSel(SQL_Socket: 'SELECT * FROM nameaddr.csv');
| | It seems that, when you use a default directory, you should not qualify the file name. |
Now you can continue with the rest of your RPG2SQL code, as for any other SQL resource.














![Delete everything except the [nameaddr.csv] entry; change the data types--in this case, everything is character with appropriate lengths; then save schema.ini](/wiki/images/5/50/Tfd15.jpg)
