2025-09-22 23:01:00 +03:00
---
sidebar_position: 5
description: Ensure table and other functions to work with SQLite in the Open Integration Package, a free open-source integration library for 1C:Enterprise 8, OneScript and CLI
keywords: [1C, 1С, 1С:Enterprise, 1С:Enterprise 8.3, API, Integration, Services, Exchange, OneScript, CLI, SQLite]
---
import Tabs from '@theme/Tabs';
import TabItem from '@theme/TabItem';
# Ensure table
Creates a new table if it does not exist or updates the composition of columns in an existing table
`Function EnsureTable(Val Table, Val ColoumnsStruct, Val Connection = "") Export`
| Parameter | CLI option | Type | Required | Description |
|-|-|-|-|-|
| Table | --table | String | ✔ | Table name |
| ColoumnsStruct | --cols | Structure Of KeyAndValue | ✔ | Column structure: Key > Name, Value > Data type |
| Connection | --db | String, Arbitrary | ✖ | Existing connection or database path |
Returns: Map Of KeyAndValue - Result of query execution
<br/>
:::tip
As a result of changing the table structure, data may be lost! It is recommended to test this method on test data beforehand
This function does not update the data type of existing columns
:::
<br/>
```bsl title="1C:Enterprise/OneScript code example"
2025-10-31 15:42:42 +03:00
Base = "C:\Users\bayse\AppData\Local\Temp\v8_2B38_2c.sqlite";
2025-09-22 23:01:00 +03:00
Table = "test";
ColoumnsStruct = New Structure;
ColoumnsStruct.Insert("id" , "INTEGER");
ColoumnsStruct.Insert("code" , "INTEGER");
ColoumnsStruct.Insert("name" , "TEXT");
ColoumnsStruct.Insert("age" , "INTEGER");
ColoumnsStruct.Insert("info" , "TEXT");
Result = OPI_SQLite.EnsureTable(Table, ColoumnsStruct, Base);
```
<Tabs>
<TabItem value="bash" label="Bash" default>
```bash
2025-10-07 19:27:04 +03:00
# JSON data can also be passed as a path to a .json file
2025-09-22 23:01:00 +03:00
oint sqlite EnsureTable \
--table "test_new" \
--cols "{'id':'INTEGER','code':'INTEGER','name':'TEXT','age':'INTEGER','info':'TEXT'}" \
2025-10-31 15:42:42 +03:00
--db "C:\Users\bayse\AppData\Local\Temp\3haxtz5d.4nv.sqlite"
2025-09-22 23:01:00 +03:00
```
</TabItem>
<TabItem value="bat" label="CMD/Bat" default>
```batch
2025-10-07 19:27:04 +03:00
:: JSON data can also be passed as a path to a .json file
2025-09-22 23:01:00 +03:00
oint sqlite EnsureTable ^
--table "test_new" ^
--cols "{'id':'INTEGER','code':'INTEGER','name':'TEXT','age':'INTEGER','info':'TEXT'}" ^
2025-10-31 15:42:42 +03:00
--db "C:\Users\bayse\AppData\Local\Temp\3haxtz5d.4nv.sqlite"
2025-09-22 23:01:00 +03:00
```
</TabItem>
</Tabs>
```json title="Result"
{
"result": true,
"commit": {
"result": true
}
}
```