mirror of
https://github.com/Bayselonarrend/OpenIntegrations.git
synced 2025-03-25 21:39:21 +02:00
93 lines
4.6 KiB
Plaintext
Vendored
93 lines
4.6 KiB
Plaintext
Vendored
---
|
|
sidebar_position: 8
|
|
---
|
|
|
|
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 = "") Export`
|
|
|
|
| Parameter | CLI option | Type | Required | Description |
|
|
|-|-|-|-|-|
|
|
| Table | --table | String | ✔ | Table name |
|
|
| DataArray | --rows | Array of Structure | ✔ | An array of string data structures: Key > field, Value > field value |
|
|
| Transaction | --trn | Boolean | ✖ | True > adding records to transactions with rollback on error |
|
|
| Connection | --dbc | String, Arbitrary | ✖ | Connection or connection string |
|
|
|
|
|
|
Returns: Structure Of KeyAndValue, String - Result of query execution
|
|
|
|
<br/>
|
|
|
|
:::tip
|
|
Record data is specified as an array of structures of the following type:<br/>```json<br/>{<br/>'Field name 1': {'Type': 'Value'},<br/>'Field name 2': {'Type': 'Value'},<br/>...<br/>}`<br/>```
|
|
|
|
The list of available types is described on the initial page of the PostgreSQL library documentation
|
|
:::
|
|
<br/>
|
|
|
|
|
|
|
|
```bsl title="1C:Enterprise/OneScript code example"
|
|
Address = "93.125.42.204";
|
|
Login = "bayselonarrend";
|
|
Password = "12we...";
|
|
Base = "testbase1";
|
|
|
|
// 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()
|
|
ConnectionString = OPI_PostgreSQL.GenerateConnectionString(Address, Base, Login, Password);
|
|
|
|
Table = "testtable";
|
|
RecordsArray = New Array;
|
|
|
|
Image = "https://api.athenaeum.digital/test_data/picture.jpg";
|
|
OPI_TypeConversion.GetBinaryData(Image); // Image - Type: BinaryData
|
|
|
|
CasualStructure = New Structure("key,value", "ItsKey", 10);
|
|
CurrentDate = OPI_Tools.GetCurrentDate();
|
|
|
|
RecordStructure = New Structure;
|
|
RecordStructure.Insert("bool_field" , New Structure("BOOL" , True));
|
|
RecordStructure.Insert("oldchar_field" , New Structure("OLDCHAR" , 1)); // or "char"
|
|
RecordStructure.Insert("smallint_field" , New Structure("SMALLINT" , 5));
|
|
RecordStructure.Insert("smallserial_field", New Structure("SMALLSERIAL" , 6));
|
|
RecordStructure.Insert("int_field" , New Structure("INT" , 100));
|
|
RecordStructure.Insert("serial_field" , New Structure("SERIAL" , 100));
|
|
RecordStructure.Insert("oid_field" , New Structure("OID" , 24576));
|
|
RecordStructure.Insert("bigint_field" , New Structure("BIGINT" , 9999999));
|
|
RecordStructure.Insert("bigserial_field" , New Structure("BIGSERIAL" , 9999999));
|
|
RecordStructure.Insert("real_field" , New Structure("REAL" , 15.2));
|
|
RecordStructure.Insert("dp_field" , New Structure("DOUBLE_PRECISION" , 1.0000000000000002)); // or DOUBLE PRECISION
|
|
RecordStructure.Insert("text_field" , New Structure("TEXT" , "Some text"));
|
|
RecordStructure.Insert("varchar_field" , New Structure("VARCHAR" , "Some varchar"));
|
|
RecordStructure.Insert("charn_field" , New Structure("CHAR" , "AAA"));
|
|
RecordStructure.Insert("char_field" , New Structure("CHAR" , "A"));
|
|
RecordStructure.Insert("name_field" , New Structure("NAME" , "Vitaly"));
|
|
RecordStructure.Insert("bytea_field" , New Structure("BYTEA" , Image));
|
|
RecordStructure.Insert("ts_field" , New Structure("TIMESTAMP" , 1739207915));
|
|
RecordStructure.Insert("tswtz_field" , New Structure("TIMESTAMP_WITH_TIME_ZONE", 1739207915)); // or TIMESTAMP WITH TIME ZONE
|
|
RecordStructure.Insert("ip_field" , New Structure("INET" , "127.0.0.1"));
|
|
RecordStructure.Insert("json_field" , New Structure("JSON" , CasualStructure));
|
|
RecordStructure.Insert("jsonb_field" , New Structure("JSONB" , CasualStructure));
|
|
RecordStructure.Insert("date_field" , New Structure("DATE" , CurrentDate));
|
|
RecordStructure.Insert("time_field" , New Structure("TIME" , CurrentDate));
|
|
RecordStructure.Insert("uuid_field" , New Structure("UUID" , New UUID()));
|
|
|
|
RecordsArray.Add(RecordStructure);
|
|
|
|
Result = OPI_PostgreSQL.AddRecords(Table, RecordsArray, True, ConnectionString);
|
|
```
|
|
|
|
|
|
|
|
|
|
|