# ExecuteQuery

Required Frends version: 5.5+

Required .NET version: 6.0

Compatible Agents: Crossplatform

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

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

| Name                              | Description                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   |
| --------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| 🗝ConnectionString : `String`     | <p>String that contains the necessary data to connect to the database.</p><p><br>Default: <code>-</code><br>Example: <code>account=testaccount-123;user=user;role=ACCOUNTADMIN;db=SHOP;schema=PUBLIC; authenticator=SNOWFLAKE\_JWT;private\_key\_file=C:/snow/rsa\_key.p8;private\_key\_pwd=MyStrongPassphrase</code></p>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                     |
| CommandType : `CommandTypes`      | <p>Specifies how a command string is interpreted.</p><p>ExecuteNonQuery: Executes an SQL statement, and returns the number of rows affected.</p><p>ExecuteReader: Executes the query, and returns an object that can iterate over the entire result set.</p><p>ExecuteScalar: Executes the query, and returns the first column of the first row in the result set returned by the query. Additional columns or rows are ignored.</p><p>Possible values:</p><ul><li><code>ExecuteNonQuery</code>:</li></ul><p>Specifies how a command string is interpreted.</p><p>ExecuteNonQuery: Executes an SQL statement, and returns the number of rows affected.</p><p>ExecuteReader: Executes the query, and returns an object that can iterate over the entire result set.</p><p>ExecuteScalar: Executes the query, and returns the first column of the first row in the result set returned by the query. Additional columns or rows are ignored.</p><ul><li><code>ExecuteReader</code>:</li></ul><p>Specifies how a command string is interpreted.</p><p>ExecuteNonQuery: Executes an SQL statement, and returns the number of rows affected.</p><p>ExecuteReader: Executes the query, and returns an object that can iterate over the entire result set.</p><p>ExecuteScalar: Executes the query, and returns the first column of the first row in the result set returned by the query. Additional columns or rows are ignored.</p><ul><li><code>ExecuteScalar</code>:</li></ul><p>Specifies how a command string is interpreted.</p><p>ExecuteNonQuery: Executes an SQL statement, and returns the number of rows affected.</p><p>ExecuteReader: Executes the query, and returns an object that can iterate over the entire result set.</p><p>ExecuteScalar: Executes the query, and returns the first column of the first row in the result set returned by the query. Additional columns or rows are ignored.</p><p><br>Default: <code>-</code><br>Example: <code>-</code></p> |
| CommandText : `String`            | <p>text command to run against the data source.</p><p><br>Default: <code>-</code><br>Example: <code>SELECT \* FROM mytable</code></p>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                         |
| PrivateKeyFilePath : `String`     | <p>Full file path to the private key (.p8) used for Snowflake key pair authentication.</p><p><br>Default: <code>-</code><br>Example: <code>C:\keys\rsa\_key.p8</code></p>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                     |
| 🗝PrivateKeyPassphrase : `String` | <p>Optional passphrase for the private key file, if the key was generated with encryption.</p><p>Leave empty if the key file is unencrypted.</p><p><br>Default: <code>-</code><br>Example: <code>MySuperSecret123</code></p>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  |
| {% endtab %}                      |                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               |

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

| Name                              | Description                                                                                                                                                                                                                                                                                                                                                                                      |
| --------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| ThrowExceptionOnError : `Boolean` | <p>Gets or sets a value indicating whether an error should stop the Task and throw an exception.</p><p>If set to true, an exception will be thrown when an error occurs. If set to false, Task will try to continue and the error message will be added into Result.ErrorMessage and Result.Success will be set to false.</p><p><br>Default: <code>True</code><br>Example: <code>true</code></p> |
| TimeOut : `Int32`                 | <p>Gets or sets the wait time (in seconds) before terminating the attempt to execute a command and generating an error.</p><p><br>Default: <code>30</code><br>Example: <code>30</code></p>                                                                                                                                                                                                       |
| {% endtab %}                      |                                                                                                                                                                                                                                                                                                                                                                                                  |

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

| Name                      | Description                                                                                                                                                                                                                                                             |
| ------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| Success : `Boolean`       | <p>Gets a value indicating whether the Task was executed successfully.<br>Example: <code>true</code></p>                                                                                                                                                                |
| RecordsAffected : `Int32` | <p>Records affected. Some statements will return -1.<br>Example: <code>100</code></p>                                                                                                                                                                                   |
| ErrorMessage : `Object`   | <p>Error message. This value is generated when an exception occurs and Options.ThrowErrorOnFailure = false.<br>Example: <code>Table 'NOTABLE' does not exist or not authorized...</code></p>                                                                            |
| Data : `Object`           | <p>Procedure's result as JToken.<br>Example: <code>Examples using SELECT query Input.ExecuteType = ExecuteReader: \[{"NAME": "Jane","AGE": 94},{"NAME": "Eve","AGE": 53}], Input.ExecuteType = NonQuery: null, Input.ExecuteType = Scalar: {"Value": "Jane"}</code></p> |
| {% endtab %}              |                                                                                                                                                                                                                                                                         |

{% tab title="Changelog" %}

## Changelog

### \[2.0.0] - 2025-09-03

#### Changed

* \[Breaking] Result now returns a dynamic JToken instead of DataTable when using ExecuteReader mode.
* Added support for CancellationToken, thus enabling query cancellation.

### \[1.2.0] - 2025-09-03

#### Added

* Added support for Snowflake key pair authentication: Input.PrivateKeyFilePath: full path to the .p8 private key file. Input.PrivateKeyPassphrase: optional passphrase for encrypted private keys.

### \[1.1.0] - 2025-02-12

#### Changed

* Update: Snowflake.Data 2.1.5 -> 4.3.0 MSTest.TestAdapter 3.8.0 -> 3.8.3 MSTest.TestFramework 3.8.0 -> 3.8.3

### \[1.0.0] - 2024-01-08

#### Added

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