---
sidebar_position: 10
description: Add rows and other functions to work with MySQL 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, MySQL]
---

import Tabs from '@theme/Tabs';
import TabItem from '@theme/TabItem';

# Add rows
 Adds new rows to the table



`Function AddRecords(Val Table, Val DataArray, Val Transaction = True, Val Connection = "", Val Tls = "") Export`

  | Parameter | CLI option | Type | Required | Description |
  |-|-|-|-|-|
  | Table | --table | String | &#x2714; | Table name |
  | DataArray | --rows | Array of Structure | &#x2714; | An array of string data structures: Key > field, Value > field value |
  | Transaction | --trn | Boolean | &#x2716; | True > adding records to transactions with rollback on error |
  | Connection | --dbc | String, Arbitrary | &#x2716; | Connection or connection string |
  | Tls | --tls | Structure Of KeyAndValue | &#x2716; | TLS settings, if necessary. See GetTlsSettings |

  
  Returns:  Map Of KeyAndValue - Result of query execution

:::tip
Record data is specified as an array of structures of the following type:<br/>`{'Field name 1': {'Type': 'Value'}, 'Field name 2': {'Type': 'Value'},...}`

The list of available types is described on the initial page of the MySQL library documentation
:::
<br/>


```bsl title="1C:Enterprise/OneScript code example"
    Address  = "127.0.0.1";
    Login    = "bayselonarrend";
    Password = "12we...";
    Base     = "testbase1";

    TLS = True;
    Port = 3306;
    ConnectionString = OPI_MySQL.GenerateConnectionString(Address, Base, Login, Password, Port);

    If TLS Then
        TLSSettings = OPI_MySQL.GetTLSSettings(True);
    Else
        TLSSettings = Undefined;
    EndIf;

    Table        = "testtable";
    RecordsArray = New Array;

    Image = "https://hut.openintegrations.dev/test_data/picture.jpg";
    OPI_TypeConversion.GetBinaryData(Image); // Image - Type: BinaryData

    CurrentDate = OPI_Tools.GetCurrentDate();

    RecordStructure = New Structure;
    RecordStructure.Insert("char_field"      , New Structure("TEXT"  , "AAAAA"));
    RecordStructure.Insert("varchar_field"   , New Structure("TEXT"  , "Some varchar"));
    RecordStructure.Insert("tinytext_field"  , New Structure("TEXT"  , "Some tiny text"));
    RecordStructure.Insert("text_field"      , New Structure("TEXT"  , "Some text"));
    RecordStructure.Insert("mediumtext_field", New Structure("TEXT"  , "Some medium text"));
    RecordStructure.Insert("longtext_field"  , New Structure("TEXT"  , "Some looooooong text"));
    RecordStructure.Insert("tinyint_field"   , New Structure("INT"   , 127));
    RecordStructure.Insert("smallint_field"  , New Structure("INT"   , -32767));
    RecordStructure.Insert("mediumint_field" , New Structure("INT"   , 8388607));
    RecordStructure.Insert("int_field"       , New Structure("INT"   , -2147483647));
    RecordStructure.Insert("uint_field"      , New Structure("UINT"  , 4294967295));
    RecordStructure.Insert("bigint_field"    , New Structure("INT"   , 9223372036854775807));
    RecordStructure.Insert("float_field"     , New Structure("FLOAT" , 100.50));
    RecordStructure.Insert("double_field"    , New Structure("FLOAT" , 100.512123));
    RecordStructure.Insert("date_field"      , New Structure("DATE"  , CurrentDate));
    RecordStructure.Insert("time_field"      , New Structure("TIME"  , CurrentDate));
    RecordStructure.Insert("datetime_field"  , New Structure("DATE"  , CurrentDate));
    RecordStructure.Insert("timestamp_field" , New Structure("DATE"  , CurrentDate));
    RecordStructure.Insert("mediumblob_field", New Structure("BYTES" , Image));
    RecordStructure.Insert("set_field"       , New Structure("TEXT"  , "one"));

    RecordsArray.Add(RecordStructure);

    // When using the connection string, a new connection is initialised,
    // which will be closed after the function is executed.
    // If several operations are performed, it is desirable to use one connection,
    // previously created by the CreateConnection function()
    Result = OPI_MySQL.AddRecords(Table, RecordsArray, True, ConnectionString, TLSSettings);
```
 

 <Tabs>
  
    <TabItem value="bash" label="Bash" default>
        ```bash
            # JSON data can also be passed as a path to a .json file
            
            oint mysql AddRecords \
             --table "testtable" \
             --rows "[{'char_field':{'TEXT':'AAAAA'},'varchar_field':{'TEXT':'Some varchar'},'tinytext_field':{'TEXT':'Some tiny text'},'text_field':{'TEXT':'Some text'},'mediumtext_field':{'TEXT':'Some medium text'},'longtext_field':{'TEXT':'Some looooooong text'},'tinyint_field':{'INT':'127'},'smallint_field':{'INT':'-32767'},'mediumint_field':{'INT':'8388607'},'int_field':{'INT':'-2147483647'},'uint_field':{'UINT':'4294967295'},'bigint_field':{'INT':'9223372036854775807'},'float_field':{'FLOAT':'100.5'},'double_field':{'FLOAT':'100.512123'},'date_field':{'DATE':'12/10/2025 19:14:41'},'time_field':{'TIME':'12/10/2025 19:14:41'},'datetime_field':{'DATE':'12/10/2025 19:14:41'},'timestamp_field':{'DATE':'12/10/2025 19:14:41'},'mediumblob_field':{'BYTES':'/tmp/seeraw4g.mts'},'set_field':{'TEXT':'one'}}]" \
             --trn true \
             --dbc "mysql://bayselonarrend:***@127.0.0.1:3306/" \
             --tls "{'use_tls':true,'accept_invalid_certs':true}"
        ```
    </TabItem>
  
    <TabItem value="bat" label="CMD/Bat" default>
        ```batch
            :: JSON data can also be passed as a path to a .json file
            
            oint mysql AddRecords ^
             --table "testtable" ^
             --rows "[{'char_field':{'TEXT':'AAAAA'},'varchar_field':{'TEXT':'Some varchar'},'tinytext_field':{'TEXT':'Some tiny text'},'text_field':{'TEXT':'Some text'},'mediumtext_field':{'TEXT':'Some medium text'},'longtext_field':{'TEXT':'Some looooooong text'},'tinyint_field':{'INT':'127'},'smallint_field':{'INT':'-32767'},'mediumint_field':{'INT':'8388607'},'int_field':{'INT':'-2147483647'},'uint_field':{'UINT':'4294967295'},'bigint_field':{'INT':'9223372036854775807'},'float_field':{'FLOAT':'100.5'},'double_field':{'FLOAT':'100.512123'},'date_field':{'DATE':'12/10/2025 19:14:41'},'time_field':{'TIME':'12/10/2025 19:14:41'},'datetime_field':{'DATE':'12/10/2025 19:14:41'},'timestamp_field':{'DATE':'12/10/2025 19:14:41'},'mediumblob_field':{'BYTES':'/tmp/seeraw4g.mts'},'set_field':{'TEXT':'one'}}]" ^
             --trn true ^
             --dbc "mysql://bayselonarrend:***@127.0.0.1:3306/" ^
             --tls "{'use_tls':true,'accept_invalid_certs':true}"
        ```
    </TabItem>
</Tabs>


```json title="Result"
{
 "commit": {
  "result": true
 },
 "result": true,
 "rows": 1,
 "errors": []
}
```
