> For the complete documentation index, see [llms.txt](https://inscada.gitbook.io/ins/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://inscada.gitbook.io/ins/en-1/programing/apis/database-functions.md).

# Database Functions

Database functions are used to retrieve or write data from the database via script/expression in the inSCADA platform.

## Write Data To The Log

#### ins.writeLog(String type, String source, String activity, String msg)

Used to write information or warning messages to the database log table.

String type: The type of message to write. (info, warning, error ..)

String source: The source of the message to be written. The message can be a description of an object or a module. (Device 01, Communication Channel 1, Pump 1 ..)

String activity: The description of the activity to which the message is to be written. (Read Data From PLC ..)

Return Value: Does not return any value.

#### Syntax

```javascript
var ins.writeLog("info","UNIT 01","Starting Sequence","Water Cooling System is Ready");
```

## Fetching Data From The Log <a href="#fetching-data-from-the-log" id="fetching-data-from-the-log"></a>

#### ins.getLoggedVariableValueStats(String\[] variableNames, Date startDate, Date endDate) <a href="#ins-getloggedvariablevaluestats-string-variablenames-date-startdate-date-enddate" id="ins-getloggedvariablevaluestats-string-variablenames-date-startdate-date-enddate"></a>

Returns the min, max, first, last, avg, counter, total, integral values in the requested time range from the table in which the variable values in the database are saved.

String \[] variableNames: String array where variable names are stored.

startDate: The start time of the data to be fetched from the database.

endDate: The end time of the data to be fetched from the database.

Return Value: Returns a JSON object that contains the variable and its values.

#### Syntax

```javascript
var aaaa
```

## Fetching Daily Data From The Log

#### ins.getLoggedDailyVariableValueStats(String\[] variableNames, Date startDate, Date endDate)

Returns min, max, first, last, avg, counter, total, integral values in the requested daily time interval from the table where the variable values in the database are saved.

String \[] variableNames: String array where variable names are stored.

startDate: The start time of the data to be fetched from the database.

endDate: The end time of the data to be fetched from the database.

Return Value: Returns a JSON object that contains the variable and its values.

#### Syntax

```javascript
var aaaa
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## 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, and the optional `goal` query parameter:

```
GET https://inscada.gitbook.io/ins/en-1/programing/apis/database-functions.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
