Share this page

# lr_db_executeSQLStatement

Submits an SQL statement to a database.

    int  lr_db_executeSQLStatement("StepName=<step_name>", "ConnectionName=<connection_name>", "SQLStatement=<statement>", ["DatasetName=<dataset_name>",] LAST );

Alphabetical Listing - C Language Utility Functions

## Arguments

Name | Comments
--- | ---
StepName | The name of the step, as it appears in the test tree. Any text can be used.
ConnectionName | The logical name for the connection specified in lr_db_connect.
SQLStatement | The SQL statement, such as SELECT, INSERT, DELETE, and UPDATE. The syntax is database-dependent. SQLStatement can be parameterized.
DatasetName | Logical name for the resulting dataset from the SQL query, by which you can refer to the dataset in subsequent steps. For use only when SQLStatement is a SELECT statement.
LAST | This delimiter marks the end of the argument list.

The lr_db_executeSQLStatement submits an SQL statement to a database.

This function is supported only under the Windows operating system.

When SQLStatement is a SELECT statement, DatasetName points to the resulting dataset. In this context, the term dataset is used to describe tables of data (formatted as rows and columns). The data in the dataset can be manipulated by subsequent steps in the script.

When SQLStatement is either DELETE, INSERT, or UPDATE, a warning is issued.

After calling this function, the row is undefined. In this case, make sure to set Row to `next` or `1` if calling lr_db_getValue after this function.

## Return Values

On failure, this function returns LR_FAIL. On success, this function returns the number of records in the dataset. The number of records does not include header rows produced in the output.

## Parameterization

All string arguments (char type) can be parameterized using standard parameterization.

## Example

In the following example, lr_db_executeSQLStatement submits a query to a database. The dataset is pointed to by MyDataset and the number of rows in the dataset is saved to the NumRows variable.

Copy code

        int NumRows=0;
         NumRows = lr_db_executeSQLStatement("StepName=PerformQuery",
            "ConnectionName=db1",
            "SQLStatement=SELECT dbo.Customer.CustID, dbo.Customer.FirstName, dbo.Customer.LastName FROM dbo.Customer",
            "DatasetName=MyDataset",
            LAST );
        lr_output_message("The query returned %d rows.", NumRows);

Tips to improve your search results... VuGen Function Reference Version 26.1-26.3 Function Reference 26.1-26.3 All View Local Help Center View Online Help Center Version: