How to use TSL Function to Work with a Database - WinRunner

WinRunner provides several TSL functions (db_ ) that enable you to work with databases.

You can use the Function Generator to insert the database functions in your test script, or you can manually program statements that use these functions.

Checking Data in a Database

You use the db_check function to create a standard database checkpoint with ODBC (Microsoft Query) and Data Junction. For information on this function, see “Creating a Default Check on a Database” and
“Creating a Custom Check on a Database”For information on parameterizing db_check statements, see “Parameterizing Standard Database Checkpoints”

Checking Runtime Data in Your Application Against the Data in a Database

You use the db_record_check function to create a runtime database record checkpoint with ODBC (Microsoft Query) and Data Junction.

TSL Functions for Working with ODBC (Microsoft Query)

When you work with ODBC (Microsoft Query), you must perform the following steps in the following order:

  1. Connect to the database.
  2. Execute a query and create a result set based an SQL statement. (This step is optional. You must perform this step only if you do not create and execute a query using Microsoft Query.)
  3. Retrieve information from the database.
  4. Disconnect from the database.
    The TSL functions for performing these steps are described below:

Connecting to a Database

The db_connect function creates a new database session and establishes a connection to an ODBC database. This function has the following syntax:

db_connect ( session_name, connection_string );

The session_name is the logical name of the database session. The connection_string is the connection parameters to the ODBC database.

  • Executing a Query and Creating a Result Set Based on an SQL Statement

The db_execute_query function executes the query based on the SQL statement and creates a record set. This function has the following syntax:

db_execute_query ( session_name, SQL, record_number );

The session_name is the logical name of the database session. The SQL is the SQL statement. The record_number is an out parameter returning the number of records in the result set.

  • Retrieving Information from the Database

Returning the Value of a Single Field in the Database

The db_get_field_value function returns the value of a single field in the database. This function has the following syntax:

db_get_field_value ( session_name, row_index, column );

The session_name is the logical name of the database session. The row_index is the numeric index of the row. (The first row is always numbered “0”.) The column is the name of the field in the column or the numeric index of the column within the database. (The first column is always numbered “0”.)

Returning the Content and Number of Column Headers

The db_get_headers function returns the number of column headers in a query and the content of the column headers, concatenated and delimited by tabs. This function has the following syntax:

db_get_headers ( session_name, header_count, header_content );

The session_name is the logical name of the database session. The header_count is the number of column headers in the query. The header_content is the column headers, concatenated and delimited by tabs.

Returning the Row Content

The db_get_row function returns the content of the row, concatenated and delimited by tabs. This function has the following syntax:

db_get_row ( session_name, row_index, row_content );

The session_name is the logical name of the database session. The row_index is the numeric index of the row. (The first row is always numbered “0”.) The row_content is the row content as a concatenation of the fields values, delimited by tabs.

Writing the Record Set into a Text File

The db_write_records function writes the record set into a text file delimited by tabs. This function has the following syntax:

db_write_records ( session_name, output_file [ , headers [ , record_limit ] ] );

The session_name is the logical name of the database session. The output_file is the name of the text file in which the record set is written. The headers are an optional Boolean parameter that will include or exclude the column headers from the record set written into the text file. The record_limit is the maximum number of records in the record set to be written into the text file. A value of NO_LIMIT (the default value) indicates there is no maximum limit to the number of records in the record set.

Returning the Last Error Message of the Last Operation

The db_get_last_error function returns the last error message of the last ODBC or Data Junction operation. This function has the following syntax:

db_get_last_error ( session_name, error );

The session_name is the logical name of the database session. The error is the error message.

  • Disconnecting from a Database

The db_disconnect function disconnects WinRunner from the database and ends the database session. This function has the following syntax:

db_disconnect ( session_name );

The session_name is the logical name of the database session.

TSL Functions for Working with Data Junction

You can use the following two functions when working with Data Junction.

Running a Data Junction Export File

The db_dj_convert function runs a Data Junction export file (.djs file). This function has the following syntax:

db_dj_convert ( djs_file [ , output_file [ , headers [ , record_limit ] ] ] );

The djs_file is the Data Junction export file. The output_file is an optional parameter to override the name of the target file. The headers are an optional Boolean parameter that will include or exclude the column headers from the Data Junction export file. The record_limit is the maximum number of records that will be converted.

Returning the Last Error Message of the Last Operation

The db_get_last_error function returns the last error message of the last ODBC or Data Junction operation. This function has the following syntax:

db_get_last_error ( session_name, error );

The session_name is ignored when working with Data Junction. The error is the error message.


All rights reserved © 2018 Wisdom IT Services India Pvt. Ltd DMCA.com Protection Status

WinRunner Topics