# db

{% hint style="warning" %}
Before using this module, make sure to install `unixodbc`:

* Windows - Install `Windows SDK`
* OS X - `brew install unixodbc`
* Linux - `sudo apt-get install unixodbc unixodbc-dev` or `sudo dnf install unixODBC unixODBC-devel`
  {% endhint %}

## callProcedure

Calls a stored procedure.

\*\* Usage example:\*\*

```javascript
// calls a procedure which expects two input parameters and one output parameter.
var result = db.callProcedure('test', 3, 4, undefined);
log.info(result);
```

**Parameters:**

| Name   | Type        | Description                                                                                                                |
| ------ | ----------- | -------------------------------------------------------------------------------------------------------------------------- |
| `name` | `String`    | Name of the procedure to call.                                                                                             |
| `args` | `...Object` | `optional` Procedure arguments. If procedure produces output parameters then these need to be specified using `undefined`. |

**Returns:**

`Object` - Procedure output if any.

## executeNonQuery

Executes SQL statement.

Any results from the query are discarded.

**Parameters:**

| Name    | Type     | Description           |
| ------- | -------- | --------------------- |
| `query` | `String` | The query to execute. |

## executeQuery

Executes SQL query and returns the result set.

**Parameters:**

| Name    | Type     | Description           |
| ------- | -------- | --------------------- |
| `query` | `String` | The query to execute. |

**Returns:**

`Object` - The result set.

## getScalar

Executes SQL query and returns the first column of the first row in the result set.

**Parameters:**

| Name    | Type     | Description           |
| ------- | -------- | --------------------- |
| `query` | `String` | The query to execute. |

**Returns:**

`Object` - The first column of the first row in the result set, or null if the result set is empty.

## setConnectionString

Sets DB connection string to be used by other methods.

This method doesn't actually open the connection as it's opened/closed automatically by query methods.\
Example connection strings:\
\- `Driver={MySQL ODBC 9.0 Unicode Driver};Server=localhost;Database=myDatabase; User=myUsername;Password=myPassword;Option=3;`\
\- `Driver={Oracle in instantclient_11_2};dbq=127.0.0.1:1521/XE;uid=myUsername; pwd=myPassword;`

**Parameters:**

| Name         | Type     | Description             |
| ------------ | -------- | ----------------------- |
| `connString` | `String` | ODBC connection string. |


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.oxygenhq.org/download-installation-start/modules/module-db.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
