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 | ✔ | Table name |
ColoumnsStruct | --cols | Structure Of KeyAndValue | ✔ | Column structure: Key > Name, Value > Data type |
Connection | --db | String, Arbitrary | ✖ | Existing connection or database path |
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
Base = "C:\Users\Administrator\AppData\Local\Temp\v8_B4C9_162.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);
- Bash
- CMD/Bat
# JSON data can also be passed as a path to a .json file
oint sqlite EnsureTable \
--table "test_new" \
--cols "{'id':'INTEGER','code':'INTEGER','name':'TEXT','age':'INTEGER','info':'TEXT'}" \
--db "C:\Users\Administrator\AppData\Local\Temp\0rltbbruj1o.sqlite"
:: JSON data can also be passed as a path to a .json file
oint sqlite EnsureTable ^
--table "test_new" ^
--cols "{'id':'INTEGER','code':'INTEGER','name':'TEXT','age':'INTEGER','info':'TEXT'}" ^
--db "C:\Users\Administrator\AppData\Local\Temp\0rltbbruj1o.sqlite"
Result
{
"result": true,
"commit": {
"result": true
}
}