﻿---
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 | &#x2714; | Table name |
  | ColoumnsStruct | --cols | Structure Of KeyAndValue | &#x2714; | Column structure: Key > Name, Value > Data type |
  | Connection | --db | String, Arbitrary | &#x2716; | 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"
    Base = "C:\Users\Administrator\AppData\Local\Temp\v8_6002_332.sqlite";

    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);
```
 




