FileCSVLoad Function

Action

Reads a file in CSV format (comma-separated format) into memory. After the file has been read, the whole file is accessible without further I/O. The file is read into shared memory only once at a client machine, even if it is read by multiple virtual users. Usually you will use this function only once in your script for each file you load for example, in a start up transaction that initializes your simulation.

If the file name includes a directory name, the file is opened in the specified directory. Otherwise, Silk Performer searches for the file in the directory where the test script is located, in the data directory, in the results directory and in the project directory.

If you are going to use remote agents for the load test, you should store your data files in the Data directory or in the directory where the test script is located. Note that in any case you have to add the data files to your load-testing project.
注: The values for sSeparator and sDelimiter may not be equal. The sSeparator parameter is used to separate data cells, while the sDelimiter parameter is used to encapsulate a data cell if the value used for the separator is used as data itself. If these parameters are set to the same value, the parser will fail.

Include file

Kernel.bdh

Syntax

FileCSVLoad( out hFile      : number,
             in  sFileName  : string,
             in  sSeparator : string optional,
             in  sDelimiter : string optional ): boolean;

Return value

  • true if successful

  • false otherwise

Parameter Description
hFile Variable receiving the file handle used to access the file
sFileName Specifies the path and file name of the file to read. If you specify a file name without path information, Silk Performer searches for the file in the user data directory specified in the Directories tab of the System Settings - Workbench dialog.
sSeparator Specifies the separator of the columns you want to use (optional). Usually the separator for CSV-formatted files is the comma (",").
sDelimiter Specifies the delimiter you want to use for identifying a separator/delimiter sign within a data field (optional). By default the delimiter is the double quotes sign (").

Sample columns

Name Nickname Address City
John Smith John ““The Tester”” “Fast Lane, 1432” Test City

Since double quotes are the delimiter, the double quotes in the Nickname need to be preceded by the delimiter itself (in this case the delimiter has the same functionality as for example a backslash has in BDL code).

The address field includes a comma, which is usually the separator. To prevent FileCSVLoad from using this comma as a separator, the value of John Smith’s address must be encompassed by the delimiter (“…”).

Example

var
  hFile, r: number;
dcltrans
  transaction TInit
  begin
    ...
     FileCSVLoad(hFile, "login.csv", ",", "\"");
  end TInit; 

  transaction TMain
  begin
    r := FileGetNextRow(hFile);
...
  end TMain;