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 = "", 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 | ✖ | Existing connection or database path |
Tls | --tls | Structure Of KeyAndValue | ✖ | TLS settings, if necessary. See GetTlsSettings |
Returns: Map Of KeyAndValue - Result of query execution
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
1C:Enterprise/OneScript code example
Address = "127.0.0.1";
Login = "bayselonarrend";
Password = "12we...";
Base = "testbase1";
Table = "testtable";
ConnectionString = OPI_MySQL.GenerateConnectionString(Address, Base, Login, Password);
ColoumnsStruct = New Structure;
ColoumnsStruct.Insert("smallint_field" , "SMALLINT");
ColoumnsStruct.Insert("double_field" , "DOUBLE");
ColoumnsStruct.Insert("bigint_field" , "BIGINT");
ColoumnsStruct.Insert("custom_field" , "TEXT");
Result = OPI_MySQL.EnsureTable(Table, ColoumnsStruct, ConnectionString);
- Bash
- CMD/Bat
# JSON data can also be passed as a path to a .json file
oint mysql EnsureTable \
--table "testtable" \
--cols "{'smallint_field':'SMALLINT','double_field':'DOUBLE','bigint_field':'BIGINT','custom_field':'TEXT'}" \
--dbc "mysql://bayselonarrend:***@127.0.0.1:3306/" \
--tls "{'use_tls':true,'accept_invalid_certs':true}"
:: JSON data can also be passed as a path to a .json file
oint mysql EnsureTable ^
--table "testtable" ^
--cols "{'smallint_field':'SMALLINT','double_field':'DOUBLE','bigint_field':'BIGINT','custom_field':'TEXT'}" ^
--dbc "mysql://bayselonarrend:***@127.0.0.1:3306/" ^
--tls "{'use_tls':true,'accept_invalid_certs':true}"
Result
{
"result": true,
"commit": {
"result": true
}
}