# ExecuteQuery

Required Frends version: 5.7+

Required .NET version: 8.0

Compatible Agents: Unknown

Source code: <https://github.com/FrendsPlatform/Frends.ODBC>

{% tabs %}
{% tab title="Parameter: Input" %}

| Name                                   | Description                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                             |
| -------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| 🗝ConnectionString : `String`          | <p>Connection string.</p><p><br>Default: <code>-</code><br>Example: <code>Driver={driver};Server=127.0.0.1,1433; Database=UnitTests;DSN=ODBC\_testDB;Uid=sa;Pwd=yourStrong!Password;</code></p>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                         |
| Query : `String`                       | <p>Query to be executed in string format.</p><p><br>Default: <code>-</code><br>Example: <code>SELECT \* FROM MyTable WHERE ID = ?, INSERT INTO MyTable (id, first\_name, last\_name) VALUES (?, ?, ?),</code></p>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       |
| ParametersInOrder : `QueryParameter[]` | <p>Parameters for the database query.</p><p><br>Default: <code>-</code><br>Example: <code>\[ { Value = "1" }, { Value = "Foo" } { Value = "Bar" } ]</code></p>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          |
| ExecuteType : `ExecuteTypes`           | <p>Specifies how a command string is interpreted.</p><p>Auto: ExecuteReader for SELECT-query and NonQuery for UPDATE, INSERT, or DELETE statements.</p><p>ExecuteReader: Use this operation to execute any arbitrary SQL statements in SQL Server if you want the result set to be returned.</p><p>NonQuery: Use this operation to execute any arbitrary SQL statements in SQL Server if you do not want any result set to be returned. You can use this operation to create database objects or change data in a database by executing UPDATE, INSERT, or DELETE statements. The return value of this operation is of Int32 data type, and For the UPDATE, INSERT, and DELETE statements, the return value is the number of rows affected by the SQL statement. For all other types of statements, the return value is -1.</p><p>Scalar: Use this operation to execute any arbitrary SQL statements in SQL Server to return a single value. This operation returns the value only in the first column of the first row in the result set returned by the SQL statement.</p><p>Possible values:</p><ul><li><code>Auto</code>:</li></ul><p>Specifies how a command string is interpreted.</p><p>Auto: ExecuteReader for SELECT-query and NonQuery for UPDATE, INSERT, or DELETE statements.</p><p>ExecuteReader: Use this operation to execute any arbitrary SQL statements in SQL Server if you want the result set to be returned.</p><p>NonQuery: Use this operation to execute any arbitrary SQL statements in SQL Server if you do not want any result set to be returned. You can use this operation to create database objects or change data in a database by executing UPDATE, INSERT, or DELETE statements. The return value of this operation is of Int32 data type, and For the UPDATE, INSERT, and DELETE statements, the return value is the number of rows affected by the SQL statement. For all other types of statements, the return value is -1.</p><p>Scalar: Use this operation to execute any arbitrary SQL statements in SQL Server to return a single value. This operation returns the value only in the first column of the first row in the result set returned by the SQL statement.</p><ul><li><code>NonQuery</code>:</li></ul><p>Specifies how a command string is interpreted.</p><p>Auto: ExecuteReader for SELECT-query and NonQuery for UPDATE, INSERT, or DELETE statements.</p><p>ExecuteReader: Use this operation to execute any arbitrary SQL statements in SQL Server if you want the result set to be returned.</p><p>NonQuery: Use this operation to execute any arbitrary SQL statements in SQL Server if you do not want any result set to be returned. You can use this operation to create database objects or change data in a database by executing UPDATE, INSERT, or DELETE statements. The return value of this operation is of Int32 data type, and For the UPDATE, INSERT, and DELETE statements, the return value is the number of rows affected by the SQL statement. For all other types of statements, the return value is -1.</p><p>Scalar: Use this operation to execute any arbitrary SQL statements in SQL Server to return a single value. This operation returns the value only in the first column of the first row in the result set returned by the SQL statement.</p><ul><li><code>Scalar</code>:</li></ul><p>Specifies how a command string is interpreted.</p><p>Auto: ExecuteReader for SELECT-query and NonQuery for UPDATE, INSERT, or DELETE statements.</p><p>ExecuteReader: Use this operation to execute any arbitrary SQL statements in SQL Server if you want the result set to be returned.</p><p>NonQuery: Use this operation to execute any arbitrary SQL statements in SQL Server if you do not want any result set to be returned. You can use this operation to create database objects or change data in a database by executing UPDATE, INSERT, or DELETE statements. The return value of this operation is of Int32 data type, and For the UPDATE, INSERT, and DELETE statements, the return value is the number of rows affected by the SQL statement. For all other types of statements, the return value is -1.</p><p>Scalar: Use this operation to execute any arbitrary SQL statements in SQL Server to return a single value. This operation returns the value only in the first column of the first row in the result set returned by the SQL statement.</p><ul><li><code>ExecuteReader</code>:</li></ul><p>Specifies how a command string is interpreted.</p><p>Auto: ExecuteReader for SELECT-query and NonQuery for UPDATE, INSERT, or DELETE statements.</p><p>ExecuteReader: Use this operation to execute any arbitrary SQL statements in SQL Server if you want the result set to be returned.</p><p>NonQuery: Use this operation to execute any arbitrary SQL statements in SQL Server if you do not want any result set to be returned. You can use this operation to create database objects or change data in a database by executing UPDATE, INSERT, or DELETE statements. The return value of this operation is of Int32 data type, and For the UPDATE, INSERT, and DELETE statements, the return value is the number of rows affected by the SQL statement. For all other types of statements, the return value is -1.</p><p>Scalar: Use this operation to execute any arbitrary SQL statements in SQL Server to return a single value. This operation returns the value only in the first column of the first row in the result set returned by the SQL statement.</p><p><br>Default: <code>3</code><br>Example: <code>ExecuteType.ExecuteReader</code></p> |
| {% endtab %}                           |                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                         |

{% tab title="Parameter: Options" %}

| Name                            | Description                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 |
| ------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| ThrowErrorOnFailure : `Boolean` | <p>(true) Throw an exception or (false) stop the Task and return result object containing Result.Success = false and Result.ErrorMessage = 'exception message'.</p><p><br>Default: <code>True</code><br>Example: <code>true</code></p>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      |
| CommandTimeoutSeconds : `Int32` | <p>Number of seconds for the operation to complete before it times out.</p><p><br>Default: <code>60</code><br>Example: <code>60</code></p>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  |
| OutputMode : `OutputMode`       | <p>Output mode. Default is JToken.</p><p>DataReader is valid only for ExecuteReader queries.</p><p>For JToken output, the data is returned in Data property as a dynamic JToken type.</p><p>For DataReader output, the data is returned in DataReader property as OdbcDataReader type.</p><p>If using DataReader, remember to dispose task result at end of scope.</p><p>Possible values:</p><ul><li><code>JToken</code>:</li></ul><p>Output mode. Default is JToken.</p><p>DataReader is valid only for ExecuteReader queries.</p><p>For JToken output, the data is returned in Data property as a dynamic JToken type.</p><p>For DataReader output, the data is returned in DataReader property as OdbcDataReader type.</p><p>If using DataReader, remember to dispose task result at end of scope.</p><ul><li><code>DataReader</code>:</li></ul><p>Output mode. Default is JToken.</p><p>DataReader is valid only for ExecuteReader queries.</p><p>For JToken output, the data is returned in Data property as a dynamic JToken type.</p><p>For DataReader output, the data is returned in DataReader property as OdbcDataReader type.</p><p>If using DataReader, remember to dispose task result at end of scope.</p><p><br>Default: <code>-</code><br>Example: <code>JToken</code></p> |
| {% endtab %}                    |                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                             |

{% tab title="Result: Result" %}

| Name                             | Description                                                                                                                                                                                                                                                                          |
| -------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| Success : `Boolean`              | <p>Operation complete without errors.<br>Example: <code>true</code></p>                                                                                                                                                                                                              |
| RecordsAffected : `Int32`        | <p>Records affected. Some statements will return -1. See documentation of Input.ExecuteType for more information.<br>Example: <code>100</code></p>                                                                                                                                   |
| ErrorMessage : `String`          | <p>Error message. This value is generated when an exception occurs and Options.ThrowErrorOnFailure = false.<br>Example: <code>Error occured...</code></p>                                                                                                                            |
| Data : `Object`                  | <p>Query result as JToken.<br>Example: <code>Input.ExecuteType = ExecuteReader: \[{"ID": "1","FIRST\_NAME": "Saija","LAST\_NAME": "Saijalainen","START\_DATE": ""}], Input.ExecuteType = NonQuery: {{ "AffectedRows": -1 }}, Input.ExecuteType = Scalar: {{ "Value": 1 }}</code></p> |
| DataReader : `DataReaderWrapper` | <p>Gets the DataReaderWrapper instance when OutputMode is set to DataReader.<br>Example: <code>DataReaderWrapper object</code></p>                                                                                                                                                   |
| {% endtab %}                     |                                                                                                                                                                                                                                                                                      |

{% tab title="Changelog" %}

## Changelog

### \[3.0.0] - 2026-02-18

#### Added

* Added DataReaderWrapper class to encapsulate OdbcDataReader and avoid assembly reference issues when using DataReader output mode.
* Result now implements IAsyncDisposable and exposes a DisposeAsync method for async resource cleanup.

#### Changed

* \[Breaking change] Updated target framework from net6.0 to net8.0.

### \[2.1.0] - 2025-03-25

#### Changed

* Update packages: System.Data.Odbc 7.0.0 -> 9.0.3 coverlet.collector 3.1.2 -> 6.0.4 Microsoft.NET.Test.Sdk 17.1.0 -> 17.13.0 MSTest.TestAdapter 2.2.8 -> 3.8.3 MSTest.TestFramework 2.2.8 -> 3.8.3

### \[2.0.0] - 2024-09-13

#### Added

* Breaking change - Support for returning data as a DataReader
  * The task now has an option field `OutputType`

#### Security

* Updated Newtonsoft.Json to 13.0.3

### \[1.0.0] - 2023-05-24

#### Added

* Initial implementation
  {% endtab %}
  {% endtabs %}
