Having problems with your account or logging in?
A lot of changes are happening in the community right now. Some may affect you. READ MORE HERE

Using a DSN connection to read a csv file in SilkTest Classic

Using a DSN connection to read a csv file in SilkTest Classic

There are some occasions where it is necessary to read data from a csv file rather than from a spreadsheet or a database. The sequence of actions is similar to a spreadsheet or database but there are enough differences for it not to be obvious.


The first thing you will need to do is to create a DSN. This must be done as as System DSN and not a User DSN. In addition, there are two possible drivers for csv and text files - use the Microsoft Access Text driver in preference to using the Microsoft Text Driver. Configure the new DSN and use Select Directory to select the folder that the csv file resides in:


In the following code note that the connection string does not include the name of the file, unlike a connection string to a spreadsheet. The command to be executed includes the name of the csv file to be read; please note that unlike an SQL query you do not need to surround the select string with quotes.

[ ] STRING sConnectString="DSN=CSVDriver;DBQ=c:\csvdir"
[ ] STRING sCSV                    //Command string
[ ] HANDLE hDB                    //The handle of the database
[ ] HANDLE hSQL                    //The handle of the current table
[ ]
[-] testcase getCSVData() appstate none
    [ ]
    [ ] LIST OF ANYTYPE laData    //List to store the returned data
    [ ]
    [ ] //Connect to the database
    [ ] hDB=DB_Connect(sConnectString)
    [ ]
    [ ] //Create the command to be executed
    [ ]  sCSV="SELECT * FROM Read_Test.csv"
    [ ]
    [ ] //Get the handle of the current table and execute the SQL statement
    [ ] hSQL=DB_ExecuteSQL(hDB,sCSV)
    [ ]
    [-] while DB_FetchNext(hSQL,laData)
        [ ] //Print each return to the results file
        [ ] Print(laData)
    [ ] DB_FinishSQL(hSQL)
    [ ] DB_Disconnect(hDB)

[ ] Script db_connect.t - Passed
[ ] Machine: (local)
[ ] Started: 07:39:16PM on 04-Oct-2013
[ ] Elapsed: 0:00:01
[ ] Passed:  1 test (100%)
[ ] Failed:  0 tests (0%)
[ ] Totals:  1 test, 0 errors, 0 warnings
[ ]
[-] Testcase getCSVData - Passed
    [ ] {One, Alpha}
    [ ] {Two, Beta}
    [ ] {Three, Gamma}
    [ ] {Four, Delta}
    [ ] {Five, Epsilon}
    [ ] {Six, Theta}

DISCLAIMER:

Some content on Community Tips & Information pages is not officially supported by Micro Focus. Please refer to our Terms of Use for more detail.
Top Contributors
Version history
Revision #:
1 of 1
Last update:
‎2013-10-24 23:00
Updated by:
 
The opinions expressed above are the personal opinions of the authors, not of Micro Focus. By using this site, you accept the Terms of Use and Rules of Participation. Certain versions of content ("Material") accessible here may contain branding from Hewlett-Packard Company (now HP Inc.) and Hewlett Packard Enterprise Company. As of September 1, 2017, the Material is now offered by Micro Focus, a separately owned and operated company. Any reference to the HP and Hewlett Packard Enterprise/HPE marks is historical in nature, and the HP and Hewlett Packard Enterprise/HPE marks are the property of their respective owners.