1
0
mirror of https://github.com/Bayselonarrend/OpenIntegrations.git synced 2025-11-29 22:27:42 +02:00
Files
OpenIntegrations/docs/en/md/MSSQL/Orm/Create-table.mdx

106 lines
4.5 KiB
Plaintext
Raw Normal View History

2025-07-10 08:54:42 +03:00
---
sidebar_position: 3
2025-07-10 09:02:33 +03:00
description: Create table and other functions to work with MSSQL 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, MSSQL]
2025-07-10 08:54:42 +03:00
---
import Tabs from '@theme/Tabs';
import TabItem from '@theme/TabItem';
# Create table
Creates an empty table in the database
`Function CreateTable(Val Table, Val ColoumnsStruct, Val Connection = "", Val Tls = "") 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 | --dbc | String, Arbitrary | ✖ | Connection or connection string |
| Tls | --tls | Structure Of KeyAndValue | ✖ | TLS settings, if necessary. See GetTlsSettings |
Returns: Map Of KeyAndValue - Result of query execution
<br/>
:::tip
List of available types is described on the initial page of the MSSQL library documentation
:::
<br/>
```bsl title="1C:Enterprise/OneScript code example"
Address = "127.0.0.1";
Login = "SA";
Password = "12we...";
Base = "testbase1";
TLSSettings = OPI_MSSQL.GetTlsSettings(True);
ConnectionString = OPI_MSSQL.GenerateConnectionString(Address, Base, Login, Password);
Table = "testtable";
ColoumnsStruct = New Structure;
ColoumnsStruct.Insert("tinyint_field" , "tinyint");
ColoumnsStruct.Insert("smallint_field" , "smallint");
ColoumnsStruct.Insert("int_field" , "int");
ColoumnsStruct.Insert("bigint_field" , "bigint");
ColoumnsStruct.Insert("float24_field" , "float(24)");
ColoumnsStruct.Insert("float53_field" , "float(53)");
ColoumnsStruct.Insert("bit_field" , "bit");
ColoumnsStruct.Insert("nvarchar_field" , "nvarchar(4000)");
ColoumnsStruct.Insert("varbinary_field", "varbinary(max)");
ColoumnsStruct.Insert("uid_field" , "uniqueidentifier");
ColoumnsStruct.Insert("numeric_field" , "numeric(5,3)"); // Or decimal
ColoumnsStruct.Insert("xml_field" , "xml");
ColoumnsStruct.Insert("date_field" , "date");
ColoumnsStruct.Insert("time_field" , "time");
ColoumnsStruct.Insert("dto_field" , "datetimeoffset");
ColoumnsStruct.Insert("datetime_field" , "datetime");
// 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_MSSQL.CreateTable(Table, ColoumnsStruct, ConnectionString, TLSSettings);
```
2025-07-15 23:11:07 +03:00
<Tabs>
<TabItem value="bash" label="Bash" default>
```bash
# JSON data can also be passed as a path to a .json file
oint mssql CreateTable \
--table "testtable" \
--cols "{'tinyint_field':'tinyint','smallint_field':'smallint','int_field':'int','bigint_field':'bigint','float24_field':'float(24)','float53_field':'float(53)','bit_field':'bit','nvarchar_field':'nvarchar(4000)','varbinary_field':'varbinary(max)','uid_field':'uniqueidentifier','numeric_field':'numeric(5,3)','xml_field':'xml','date_field':'date','time_field':'time','dto_field':'datetimeoffset','datetime_field':'datetime'}" \
--dbc "Server=127.0.0.1;Database=***;User Id=SA;Password=***;" \
--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 mssql CreateTable ^
--table "testtable" ^
--cols "{'tinyint_field':'tinyint','smallint_field':'smallint','int_field':'int','bigint_field':'bigint','float24_field':'float(24)','float53_field':'float(53)','bit_field':'bit','nvarchar_field':'nvarchar(4000)','varbinary_field':'varbinary(max)','uid_field':'uniqueidentifier','numeric_field':'numeric(5,3)','xml_field':'xml','date_field':'date','time_field':'time','dto_field':'datetimeoffset','datetime_field':'datetime'}" ^
--dbc "Server=127.0.0.1;Database=***;User Id=SA;Password=***;" ^
--tls "{'use_tls':true,'accept_invalid_certs':true}"
```
</TabItem>
</Tabs>
2025-07-10 08:54:42 +03:00
2025-07-14 15:21:39 +03:00
```json title="Result"
{
"result": true
}
```