mirror of
https://github.com/Bayselonarrend/OpenIntegrations.git
synced 2025-01-12 04:34:10 +02:00
Main build (Jenkins)
This commit is contained in:
parent
95310d8e24
commit
d3bbf5e259
6
ci/clitesten
vendored
6
ci/clitesten
vendored
@ -1965,7 +1965,7 @@ def test_sqlite(){
|
||||
}
|
||||
|
||||
catchError(buildResult: 'FAILURE', stageResult: 'FAILURE') {
|
||||
powershell encoding: 'UTF-8', script:'./oint.exe sqlite CreateTable --table "test" --cols "test" --noex "test" --db "test" --debug --test '
|
||||
powershell encoding: 'UTF-8', script:'./oint.exe sqlite CreateTable --table "test" --cols "test" --db "test" --debug --test '
|
||||
}
|
||||
|
||||
catchError(buildResult: 'FAILURE', stageResult: 'FAILURE') {
|
||||
@ -1976,6 +1976,10 @@ def test_sqlite(){
|
||||
powershell encoding: 'UTF-8', script:'./oint.exe sqlite GetRecords --table "test" --fields "test" --filter "test" --order "test" --limit "test" --db "test" --debug --test '
|
||||
}
|
||||
|
||||
catchError(buildResult: 'FAILURE', stageResult: 'FAILURE') {
|
||||
powershell encoding: 'UTF-8', script:'./oint.exe sqlite UpdateRecords --table "test" --values "test" --filter "test" --db "test" --debug --test '
|
||||
}
|
||||
|
||||
catchError(buildResult: 'FAILURE', stageResult: 'FAILURE') {
|
||||
powershell encoding: 'UTF-8', script:'./oint.exe sqlite GetRecordsFilterStrucutre --empty "test" --debug --test '
|
||||
}
|
||||
|
6
ci/clitestru
vendored
6
ci/clitestru
vendored
@ -1965,7 +1965,7 @@ def test_sqlite(){
|
||||
}
|
||||
|
||||
catchError(buildResult: 'FAILURE', stageResult: 'FAILURE') {
|
||||
powershell encoding: 'UTF-8', script:'./oint.exe sqlite СоздатьТаблицу --table "test" --cols "test" --noex "test" --db "test" --debug --test '
|
||||
powershell encoding: 'UTF-8', script:'./oint.exe sqlite СоздатьТаблицу --table "test" --cols "test" --db "test" --debug --test '
|
||||
}
|
||||
|
||||
catchError(buildResult: 'FAILURE', stageResult: 'FAILURE') {
|
||||
@ -1976,6 +1976,10 @@ def test_sqlite(){
|
||||
powershell encoding: 'UTF-8', script:'./oint.exe sqlite ПолучитьЗаписи --table "test" --fields "test" --filter "test" --order "test" --limit "test" --db "test" --debug --test '
|
||||
}
|
||||
|
||||
catchError(buildResult: 'FAILURE', stageResult: 'FAILURE') {
|
||||
powershell encoding: 'UTF-8', script:'./oint.exe sqlite ОбновитьЗаписи --table "test" --values "test" --filter "test" --db "test" --debug --test '
|
||||
}
|
||||
|
||||
catchError(buildResult: 'FAILURE', stageResult: 'FAILURE') {
|
||||
powershell encoding: 'UTF-8', script:'./oint.exe sqlite ПолучитьСтруктуруФильтраЗаписей --empty "test" --debug --test '
|
||||
}
|
||||
|
2
docs/en/examples/SQLite/AddRecords.txt
vendored
2
docs/en/examples/SQLite/AddRecords.txt
vendored
@ -4,7 +4,7 @@
|
||||
PictureFile = GetTempFileName("png");
|
||||
Image.Write(PictureFile); // PictureFile - File to disk
|
||||
|
||||
Base = "C:\Users\Administrator\AppData\Local\Temp\v8_F86A_11.sqlite";
|
||||
Base = "C:\Users\Administrator\AppData\Local\Temp\v8_BCCE_11.sqlite";
|
||||
Table = "test";
|
||||
|
||||
DataArray = New Array;
|
||||
|
4
docs/en/examples/SQLite/CreateTable.txt
vendored
4
docs/en/examples/SQLite/CreateTable.txt
vendored
@ -1,4 +1,4 @@
|
||||
Base = "C:\Users\Administrator\AppData\Local\Temp\v8_F86A_11.sqlite";
|
||||
Base = "C:\Users\Administrator\AppData\Local\Temp\v8_BCCE_11.sqlite";
|
||||
Table = "test";
|
||||
|
||||
ColoumnsStruct = New Structure;
|
||||
@ -10,4 +10,4 @@
|
||||
ColoumnsStruct.Insert("created_at", "DATETIME");
|
||||
ColoumnsStruct.Insert("data" , "BLOB");
|
||||
|
||||
Result = OPI_SQLite.CreateTable(Table, ColoumnsStruct, , Base);
|
||||
Result = OPI_SQLite.CreateTable(Table, ColoumnsStruct, Base);
|
||||
|
2
docs/en/examples/SQLite/GetRecords.txt
vendored
2
docs/en/examples/SQLite/GetRecords.txt
vendored
@ -1,4 +1,4 @@
|
||||
Base = "C:\Users\Administrator\AppData\Local\Temp\v8_F86A_11.sqlite";
|
||||
Base = "C:\Users\Administrator\AppData\Local\Temp\v8_BCCE_11.sqlite";
|
||||
Table = "test";
|
||||
|
||||
Fields = New Array;
|
||||
|
@ -1,5 +1,5 @@
|
||||
---
|
||||
sidebar_position: 3
|
||||
sidebar_position: 4
|
||||
---
|
||||
|
||||
import Tabs from '@theme/Tabs';
|
||||
|
39
docs/en/md/SQLite/Common-methods/Is-connector.mdx
vendored
Normal file
39
docs/en/md/SQLite/Common-methods/Is-connector.mdx
vendored
Normal file
@ -0,0 +1,39 @@
|
||||
---
|
||||
sidebar_position: 3
|
||||
---
|
||||
|
||||
import Tabs from '@theme/Tabs';
|
||||
import TabItem from '@theme/TabItem';
|
||||
|
||||
# Is connector
|
||||
Checks that the value is an object of a SQLite AddIn
|
||||
|
||||
|
||||
|
||||
`Function IsConnector(Val Value) Export`
|
||||
|
||||
| Parameter | CLI option | Type | Required | Description |
|
||||
|-|-|-|-|-|
|
||||
| Value | - | Arbitrary | ✔ | Value to check |
|
||||
|
||||
|
||||
Returns: Boolean - Is connector
|
||||
|
||||
<br/>
|
||||
|
||||
|
||||
:::caution
|
||||
**NOCLI:** this method is not available in CLI version
|
||||
:::
|
||||
<br/>
|
||||
|
||||
|
||||
|
||||
```bsl title="1C:Enterprise/OneScript code example"
|
||||
|
||||
```
|
||||
|
||||
|
||||
|
||||
|
||||
|
2
docs/en/md/SQLite/Orm/Add-records.mdx
vendored
2
docs/en/md/SQLite/Orm/Add-records.mdx
vendored
@ -34,7 +34,7 @@ import TabItem from '@theme/TabItem';
|
||||
PictureFile = GetTempFileName("png");
|
||||
Image.Write(PictureFile); // PictureFile - File to disk
|
||||
|
||||
Base = "C:\Users\Administrator\AppData\Local\Temp\v8_F86A_11.sqlite";
|
||||
Base = "C:\Users\Administrator\AppData\Local\Temp\v8_BCCE_11.sqlite";
|
||||
Table = "test";
|
||||
|
||||
DataArray = New Array;
|
||||
|
7
docs/en/md/SQLite/Orm/Create-table.mdx
vendored
7
docs/en/md/SQLite/Orm/Create-table.mdx
vendored
@ -10,13 +10,12 @@ import TabItem from '@theme/TabItem';
|
||||
|
||||
|
||||
|
||||
`Function CreateTable(Val Table, Val ColoumnsStruct, Val NotExecute = False, Val Connection = "") Export`
|
||||
`Function CreateTable(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 |
|
||||
| NotExecute | --noex | Boolean | ✖ | True > Does not execute the query, but returns SQL text |
|
||||
| Connection | --db | String, Arbitrary | ✖ | Existing connection or database path |
|
||||
|
||||
|
||||
@ -28,7 +27,7 @@ import TabItem from '@theme/TabItem';
|
||||
|
||||
|
||||
```bsl title="1C:Enterprise/OneScript code example"
|
||||
Base = "C:\Users\Administrator\AppData\Local\Temp\v8_F86A_11.sqlite";
|
||||
Base = "C:\Users\Administrator\AppData\Local\Temp\v8_BCCE_11.sqlite";
|
||||
Table = "test";
|
||||
|
||||
ColoumnsStruct = New Structure;
|
||||
@ -40,7 +39,7 @@ import TabItem from '@theme/TabItem';
|
||||
ColoumnsStruct.Insert("created_at", "DATETIME");
|
||||
ColoumnsStruct.Insert("data" , "BLOB");
|
||||
|
||||
Result = OPI_SQLite.CreateTable(Table, ColoumnsStruct, , Base);
|
||||
Result = OPI_SQLite.CreateTable(Table, ColoumnsStruct, Base);
|
||||
```
|
||||
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
---
|
||||
sidebar_position: 4
|
||||
sidebar_position: 5
|
||||
---
|
||||
|
||||
import Tabs from '@theme/Tabs';
|
||||
|
2
docs/en/md/SQLite/Orm/Get-records.mdx
vendored
2
docs/en/md/SQLite/Orm/Get-records.mdx
vendored
@ -30,7 +30,7 @@ import TabItem from '@theme/TabItem';
|
||||
|
||||
|
||||
```bsl title="1C:Enterprise/OneScript code example"
|
||||
Base = "C:\Users\Administrator\AppData\Local\Temp\v8_F86A_11.sqlite";
|
||||
Base = "C:\Users\Administrator\AppData\Local\Temp\v8_BCCE_11.sqlite";
|
||||
Table = "test";
|
||||
|
||||
Fields = New Array;
|
||||
|
37
docs/en/md/SQLite/Orm/Update-records.mdx
vendored
Normal file
37
docs/en/md/SQLite/Orm/Update-records.mdx
vendored
Normal file
@ -0,0 +1,37 @@
|
||||
---
|
||||
sidebar_position: 4
|
||||
---
|
||||
|
||||
import Tabs from '@theme/Tabs';
|
||||
import TabItem from '@theme/TabItem';
|
||||
|
||||
# Update records
|
||||
Updates the value of records by selected criteria
|
||||
|
||||
|
||||
|
||||
`Function UpdateRecords(Val Table, Val ValueStructure, Val Filters = "", Val Connection = "") Export`
|
||||
|
||||
| Parameter | CLI option | Type | Required | Description |
|
||||
|-|-|-|-|-|
|
||||
| Table | --table | String | ✔ | Table name |
|
||||
| ValueStructure | --values | Structure Of KeyAndValue | ✔ | Values structure: Key > field, Value > field value |
|
||||
| Filters | --filter | Array of Structure | ✖ | Filters array. See GetRecordsFilterStrucutre |
|
||||
| Connection | --db | String, Arbitrary | ✖ | Existing connection or database path |
|
||||
|
||||
|
||||
Returns: Structure Of KeyAndValue, String - Result of query execution
|
||||
|
||||
<br/>
|
||||
|
||||
|
||||
|
||||
|
||||
```bsl title="1C:Enterprise/OneScript code example"
|
||||
|
||||
```
|
||||
|
||||
|
||||
|
||||
|
||||
|
2
docs/ru/examples/SQLite/ДобавитьЗаписи.txt
vendored
2
docs/ru/examples/SQLite/ДобавитьЗаписи.txt
vendored
@ -4,7 +4,7 @@
|
||||
ФайлКартинки = ПолучитьИмяВременногоФайла("png");
|
||||
Картинка.Записать(ФайлКартинки); // ФайлКартинки - Файл на диске
|
||||
|
||||
База = "C:\Users\Administrator\AppData\Local\Temp\v8_F86A_11.sqlite";
|
||||
База = "C:\Users\Administrator\AppData\Local\Temp\v8_BCCE_11.sqlite";
|
||||
Таблица = "test";
|
||||
|
||||
МассивДанных = Новый Массив;
|
||||
|
2
docs/ru/examples/SQLite/ПолучитьЗаписи.txt
vendored
2
docs/ru/examples/SQLite/ПолучитьЗаписи.txt
vendored
@ -1,4 +1,4 @@
|
||||
База = "C:\Users\Administrator\AppData\Local\Temp\v8_F86A_11.sqlite";
|
||||
База = "C:\Users\Administrator\AppData\Local\Temp\v8_BCCE_11.sqlite";
|
||||
Таблица = "test";
|
||||
|
||||
Поля = Новый Массив;
|
||||
|
4
docs/ru/examples/SQLite/СоздатьТаблицу.txt
vendored
4
docs/ru/examples/SQLite/СоздатьТаблицу.txt
vendored
@ -1,4 +1,4 @@
|
||||
База = "C:\Users\Administrator\AppData\Local\Temp\v8_F86A_11.sqlite";
|
||||
База = "C:\Users\Administrator\AppData\Local\Temp\v8_BCCE_11.sqlite";
|
||||
Таблица = "test";
|
||||
|
||||
СтруктураКолонок = Новый Структура;
|
||||
@ -10,4 +10,4 @@
|
||||
СтруктураКолонок.Вставить("created_at", "DATETIME");
|
||||
СтруктураКолонок.Вставить("data" , "BLOB");
|
||||
|
||||
Результат = OPI_SQLite.СоздатьТаблицу(Таблица, СтруктураКолонок, , База);
|
||||
Результат = OPI_SQLite.СоздатьТаблицу(Таблица, СтруктураКолонок, База);
|
||||
|
@ -1,5 +1,5 @@
|
||||
---
|
||||
sidebar_position: 3
|
||||
sidebar_position: 4
|
||||
---
|
||||
|
||||
import Tabs from '@theme/Tabs';
|
||||
|
39
docs/ru/md/SQLite/Common-methods/Is-connector.mdx
vendored
Normal file
39
docs/ru/md/SQLite/Common-methods/Is-connector.mdx
vendored
Normal file
@ -0,0 +1,39 @@
|
||||
---
|
||||
sidebar_position: 3
|
||||
---
|
||||
|
||||
import Tabs from '@theme/Tabs';
|
||||
import TabItem from '@theme/TabItem';
|
||||
|
||||
# Это коннектор
|
||||
Проверяет, что значение является объектом внешней компоненты SQLite
|
||||
|
||||
|
||||
|
||||
`Функция ЭтоКоннектор(Знач Значение) Экспорт`
|
||||
|
||||
| Параметр | CLI опция | Тип | Обяз. | Назначение |
|
||||
|-|-|-|-|-|
|
||||
| Значение | - | Произвольный | ✔ | Значение для проверки |
|
||||
|
||||
|
||||
Возвращаемое значение: Булево - Это коннектор
|
||||
|
||||
<br/>
|
||||
|
||||
|
||||
:::caution
|
||||
**NOCLI:** данный метод недоступен для использования в CLI версии
|
||||
:::
|
||||
<br/>
|
||||
|
||||
|
||||
|
||||
```bsl title="Пример использования для 1С:Предприятие/OneScript"
|
||||
|
||||
```
|
||||
|
||||
|
||||
|
||||
|
||||
|
2
docs/ru/md/SQLite/Orm/Add-records.mdx
vendored
2
docs/ru/md/SQLite/Orm/Add-records.mdx
vendored
@ -34,7 +34,7 @@ import TabItem from '@theme/TabItem';
|
||||
ФайлКартинки = ПолучитьИмяВременногоФайла("png");
|
||||
Картинка.Записать(ФайлКартинки); // ФайлКартинки - Файл на диске
|
||||
|
||||
База = "C:\Users\Administrator\AppData\Local\Temp\v8_F86A_11.sqlite";
|
||||
База = "C:\Users\Administrator\AppData\Local\Temp\v8_BCCE_11.sqlite";
|
||||
Таблица = "test";
|
||||
|
||||
МассивДанных = Новый Массив;
|
||||
|
7
docs/ru/md/SQLite/Orm/Create-table.mdx
vendored
7
docs/ru/md/SQLite/Orm/Create-table.mdx
vendored
@ -10,13 +10,12 @@ import TabItem from '@theme/TabItem';
|
||||
|
||||
|
||||
|
||||
`Функция СоздатьТаблицу(Знач Таблица, Знач СтруктураКолонок, Знач НеВыполнять = Ложь, Знач Соединение = "") Экспорт`
|
||||
`Функция СоздатьТаблицу(Знач Таблица, Знач СтруктураКолонок, Знач Соединение = "") Экспорт`
|
||||
|
||||
| Параметр | CLI опция | Тип | Обяз. | Назначение |
|
||||
|-|-|-|-|-|
|
||||
| Таблица | --table | Строка | ✔ | Имя таблицы |
|
||||
| СтруктураКолонок | --cols | Структура Из КлючИЗначение | ✔ | Структура колонок: Ключ > имя, Значение > Тип данных |
|
||||
| НеВыполнять | --noex | Булево | ✖ | Истина > Не выполняет запрос, а возвращает текст SQL |
|
||||
| Соединение | --db | Строка, Произвольный | ✖ | Существующее соединение или путь к базе |
|
||||
|
||||
|
||||
@ -28,7 +27,7 @@ import TabItem from '@theme/TabItem';
|
||||
|
||||
|
||||
```bsl title="Пример использования для 1С:Предприятие/OneScript"
|
||||
База = "C:\Users\Administrator\AppData\Local\Temp\v8_F86A_11.sqlite";
|
||||
База = "C:\Users\Administrator\AppData\Local\Temp\v8_BCCE_11.sqlite";
|
||||
Таблица = "test";
|
||||
|
||||
СтруктураКолонок = Новый Структура;
|
||||
@ -40,7 +39,7 @@ import TabItem from '@theme/TabItem';
|
||||
СтруктураКолонок.Вставить("created_at", "DATETIME");
|
||||
СтруктураКолонок.Вставить("data" , "BLOB");
|
||||
|
||||
Результат = OPI_SQLite.СоздатьТаблицу(Таблица, СтруктураКолонок, , База);
|
||||
Результат = OPI_SQLite.СоздатьТаблицу(Таблица, СтруктураКолонок, База);
|
||||
```
|
||||
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
---
|
||||
sidebar_position: 4
|
||||
sidebar_position: 5
|
||||
---
|
||||
|
||||
import Tabs from '@theme/Tabs';
|
||||
|
2
docs/ru/md/SQLite/Orm/Get-records.mdx
vendored
2
docs/ru/md/SQLite/Orm/Get-records.mdx
vendored
@ -30,7 +30,7 @@ import TabItem from '@theme/TabItem';
|
||||
|
||||
|
||||
```bsl title="Пример использования для 1С:Предприятие/OneScript"
|
||||
База = "C:\Users\Administrator\AppData\Local\Temp\v8_F86A_11.sqlite";
|
||||
База = "C:\Users\Administrator\AppData\Local\Temp\v8_BCCE_11.sqlite";
|
||||
Таблица = "test";
|
||||
|
||||
Поля = Новый Массив;
|
||||
|
37
docs/ru/md/SQLite/Orm/Update-records.mdx
vendored
Normal file
37
docs/ru/md/SQLite/Orm/Update-records.mdx
vendored
Normal file
@ -0,0 +1,37 @@
|
||||
---
|
||||
sidebar_position: 4
|
||||
---
|
||||
|
||||
import Tabs from '@theme/Tabs';
|
||||
import TabItem from '@theme/TabItem';
|
||||
|
||||
# Обновить записи
|
||||
Обновляет значение записей по выбранным критериям
|
||||
|
||||
|
||||
|
||||
`Функция ОбновитьЗаписи(Знач Таблица, Знач СтруктураЗначений, Знач Фильтры = "", Знач Соединение = "") Экспорт`
|
||||
|
||||
| Параметр | CLI опция | Тип | Обяз. | Назначение |
|
||||
|-|-|-|-|-|
|
||||
| Таблица | --table | Строка | ✔ | Имя таблицы |
|
||||
| СтруктураЗначений | --values | Структура Из КлючИЗначение | ✔ | Структура значений: Ключ > поле, Значение > значение поля |
|
||||
| Фильтры | --filter | Массив Из Структура | ✖ | Массив фильтров. См. ПолучитьСтруктуруФильтраЗаписей |
|
||||
| Соединение | --db | Строка, Произвольный | ✖ | Существующее соединение или путь к базе |
|
||||
|
||||
|
||||
Возвращаемое значение: Структура Из КлючИЗначение, Строка - Результат выполнения запроса
|
||||
|
||||
<br/>
|
||||
|
||||
|
||||
|
||||
|
||||
```bsl title="Пример использования для 1С:Предприятие/OneScript"
|
||||
|
||||
```
|
||||
|
||||
|
||||
|
||||
|
||||
|
12006
service/dictionaries/en.json
vendored
12006
service/dictionaries/en.json
vendored
File diff suppressed because it is too large
Load Diff
252
src/en/OInt/core/Modules/OPI_SQLite.os
vendored
252
src/en/OInt/core/Modules/OPI_SQLite.os
vendored
@ -98,6 +98,20 @@ Function CloseConnection(Val Connection) Export
|
||||
|
||||
EndFunction
|
||||
|
||||
// Is connector !NOCLI
|
||||
// Checks that the value is an object of a SQLite AddIn
|
||||
//
|
||||
// Parameters:
|
||||
// Value - Arbitrary - Value to check - value
|
||||
//
|
||||
// Returns:
|
||||
// Boolean - Is connector
|
||||
Function IsConnector(Val Value) Export
|
||||
|
||||
Return String(TypeOf(Value)) = "AddIn.OPI_SQLite.Main";
|
||||
|
||||
EndFunction
|
||||
|
||||
// Execute SQL query
|
||||
// Executes an arbitrary SQL query
|
||||
//
|
||||
@ -132,7 +146,7 @@ Function ExecuteSQLQuery(Val QueryText
|
||||
EndIf;
|
||||
|
||||
Result = Connector.Execute(QueryText, Parameters_, ForceResult);
|
||||
Result = OPI_Tools.JsonToStructure(Result, False);
|
||||
Result = OPI_Tools.JsonToStructure(Result);
|
||||
|
||||
Return Result;
|
||||
|
||||
@ -148,34 +162,13 @@ EndFunction
|
||||
// Parameters:
|
||||
// Table - String - Table name - table
|
||||
// ColoumnsStruct - Structure Of KeyAndValue - Column structure: Key > Name, Value > Data type - cols
|
||||
// NotExecute - Boolean - True > Does not execute the query, but returns SQL text - noex
|
||||
// Connection - String, Arbitrary - Existing connection or database path - db
|
||||
//
|
||||
// Returns:
|
||||
// Structure Of KeyAndValue, String - The result of the execution or SQL query text
|
||||
Function CreateTable(Val Table, Val ColoumnsStruct, Val NotExecute = False, Val Connection = "") Export
|
||||
|
||||
OPI_TypeConversion.GetBoolean(NotExecute);
|
||||
|
||||
ErrorText = "The column structure is not a valid key-value structure";
|
||||
OPI_TypeConversion.GetKeyValueCollection(ColoumnsStruct, ErrorText);
|
||||
|
||||
Scheme = OPI_SQLQueries.NewSQLScheme("CREATE");
|
||||
|
||||
OPI_SQLQueries.SetTableName(Scheme, Table);
|
||||
|
||||
For Each Coloumn In ColoumnsStruct Do
|
||||
OPI_SQLQueries.AddColoumn(Scheme, Coloumn.Key, Coloumn.Value);
|
||||
EndDo;
|
||||
|
||||
Request = OPI_SQLQueries.FormSQLText(Scheme);
|
||||
|
||||
If NotExecute Then
|
||||
Result = Request;
|
||||
Else
|
||||
Result = ExecuteSQLQuery(Request, , , Connection);
|
||||
EndIf;
|
||||
Function CreateTable(Val Table, Val ColoumnsStruct, Val Connection = "") Export
|
||||
|
||||
Result = OPI_SQLQueries.CreateTable(OPI_SQLite, Table, ColoumnsStruct, Connection);
|
||||
Return Result;
|
||||
|
||||
EndFunction
|
||||
@ -193,84 +186,8 @@ EndFunction
|
||||
// Structure Of KeyAndValue, String - Result of query execution
|
||||
Function AddRecords(Val Table, Val DataArray, Val Transaction = True, Val Connection = "") Export
|
||||
|
||||
OPI_TypeConversion.GetArray(DataArray);
|
||||
OPI_TypeConversion.GetBoolean(Transaction);
|
||||
|
||||
Connection = CreateConnection(Connection);
|
||||
|
||||
If Not IsConnector(Connection) Then
|
||||
Return Connection;
|
||||
EndIf;
|
||||
|
||||
If Transaction Then
|
||||
|
||||
Start = ExecuteSQLQuery("BEGIN TRANSACTION", , , Connection);
|
||||
|
||||
If Not Start["result"] Then
|
||||
Return Start;
|
||||
EndIf;
|
||||
|
||||
EndIf;
|
||||
|
||||
Counter = 0;
|
||||
SuccessCount = 0;
|
||||
|
||||
Error = False;
|
||||
ErrorsArray = New Array;
|
||||
CollectionError = "Invalid data";
|
||||
|
||||
ResultStrucutre = New Structure;
|
||||
|
||||
For Each Record In DataArray Do
|
||||
|
||||
If Error And Transaction Then
|
||||
|
||||
Rollback = ExecuteSQLQuery("ROLLBACK", , , Connection);
|
||||
|
||||
SuccessCount = 0;
|
||||
ResultStrucutre.Insert("rollback", Rollback);
|
||||
Break;
|
||||
|
||||
EndIf;
|
||||
|
||||
Counter = Counter + 1;
|
||||
Error = False;
|
||||
|
||||
Try
|
||||
OPI_TypeConversion.GetKeyValueCollection(Record, CollectionError);
|
||||
Except
|
||||
ErrorsArray.Add(New Structure("row,error", Counter, CollectionError));
|
||||
Error = True;
|
||||
Continue;
|
||||
EndTry;
|
||||
|
||||
Result = AddRow(Table, Record, Connection);
|
||||
|
||||
If Result["result"] Then
|
||||
|
||||
SuccessCount = SuccessCount + 1;
|
||||
|
||||
Else
|
||||
|
||||
ErrorsArray.Add(New Structure("row,error", Counter, Result["error"]));
|
||||
Error = True;
|
||||
|
||||
EndIf;
|
||||
|
||||
EndDo;
|
||||
|
||||
If Transaction And Not Error Then
|
||||
|
||||
Completion = ExecuteSQLQuery("COMMIT", , , Connection);
|
||||
ResultStrucutre.Insert("commit", Completion);
|
||||
|
||||
EndIf;
|
||||
|
||||
ResultStrucutre.Insert("result", ErrorsArray.Count() = 0);
|
||||
ResultStrucutre.Insert("rows" , SuccessCount);
|
||||
ResultStrucutre.Insert("errors", ErrorsArray);
|
||||
|
||||
Return ResultStrucutre;
|
||||
Result = OPI_SQLQueries.AddRecords(OPI_SQLite, Table, DataArray, Transaction, Connection);
|
||||
Return Result;
|
||||
|
||||
EndFunction
|
||||
|
||||
@ -294,19 +211,25 @@ Function GetRecords(Val Table
|
||||
, Val Count = ""
|
||||
, Val Connection = "") Export
|
||||
|
||||
Scheme = OPI_SQLQueries.NewSQLScheme("SELECT");
|
||||
Result = OPI_SQLQueries.GetRecords(OPI_SQLite, Table, Fields, Filters, Sort, Count, Connection);
|
||||
Return Result;
|
||||
|
||||
OPI_SQLQueries.SetTableName(Scheme, Table);
|
||||
OPI_SQLQueries.SetLimit(Scheme, Count);
|
||||
EndFunction
|
||||
|
||||
FillFields(Scheme, Fields);
|
||||
FillFilters(Scheme, Filters);
|
||||
FillSorting(Scheme, Sort);
|
||||
|
||||
Request = OPI_SQLQueries.FormSQLText(Scheme);
|
||||
|
||||
Result = ExecuteSQLQuery(Request, Scheme["values"], , Connection);
|
||||
// Update records
|
||||
// Updates the value of records by selected criteria
|
||||
//
|
||||
// Parameters:
|
||||
// Table - String - Table name - table
|
||||
// ValueStructure - Structure Of KeyAndValue - Values structure: Key > field, Value > field value - values
|
||||
// Filters - Array of Structure - Filters array. See GetRecordsFilterStrucutre - filter
|
||||
// Connection - String, Arbitrary - Existing connection or database path - db
|
||||
//
|
||||
// Returns:
|
||||
// Structure Of KeyAndValue, String - Result of query execution
|
||||
Function UpdateRecords(Val Table, Val ValueStructure, Val Filters = "", Val Connection = "") Export
|
||||
|
||||
Result = OPI_SQLQueries.UpdateRecords(OPI_SQLite, Table, ValueStructure, Filters, Connection);
|
||||
Return Result;
|
||||
|
||||
EndFunction
|
||||
@ -327,20 +250,7 @@ EndFunction
|
||||
// Structure Of KeyAndValue - Record filter element
|
||||
Function GetRecordsFilterStrucutre(Val Clear = False) Export
|
||||
|
||||
FilterStructure = New Structure;
|
||||
|
||||
FilterStructure.Insert("field", "<filtering field name>");
|
||||
FilterStructure.Insert("type" , "<comparison type>");
|
||||
FilterStructure.Insert("value", "<comparison value>");
|
||||
FilterStructure.Insert("union", "<connection with the following condition: AND, OR, etc..>");
|
||||
FilterStructure.Insert("raw" , "<true - the value will be inserted by text as it is, false - through the parameter>");
|
||||
|
||||
If Clear Then
|
||||
FilterStructure = OPI_Tools.ClearCollectionRecursively(FilterStructure);
|
||||
EndIf;
|
||||
|
||||
//@skip-check constructor-function-return-section
|
||||
Return FilterStructure;
|
||||
Return OPI_SQLQueries.GetRecordsFilterStrucutre(Clear);
|
||||
|
||||
EndFunction
|
||||
|
||||
@ -415,94 +325,4 @@ Function ProcessParameters(Val Parameters)
|
||||
|
||||
EndFunction
|
||||
|
||||
Function IsConnector(Val Value)
|
||||
|
||||
Return String(TypeOf(Value)) = "AddIn.OPI_SQLite.Main";
|
||||
|
||||
EndFunction
|
||||
|
||||
Function AddRow(Val Table, Val Record, Val Connection)
|
||||
|
||||
FieldArray = New Array;
|
||||
ValuesArray = New Array;
|
||||
|
||||
Scheme = OPI_SQLQueries.NewSQLScheme("INSERT");
|
||||
OPI_SQLQueries.SetTableName(Scheme, Table);
|
||||
|
||||
SplitDataCollection(Record, FieldArray, ValuesArray);
|
||||
|
||||
For Each Field In FieldArray Do
|
||||
OPI_SQLQueries.AddField(Scheme, Field);
|
||||
EndDo;
|
||||
|
||||
Request = OPI_SQLQueries.FormSQLText(Scheme);
|
||||
|
||||
Result = ExecuteSQLQuery(Request, ValuesArray, , Connection);
|
||||
|
||||
Return Result;
|
||||
|
||||
EndFunction
|
||||
|
||||
Procedure SplitDataCollection(Val Record, FieldArray, ValuesArray)
|
||||
|
||||
For Each Element In Record Do
|
||||
|
||||
FieldArray.Add(Element.Key);
|
||||
ValuesArray.Add(Element.Value);
|
||||
|
||||
EndDo;
|
||||
|
||||
EndProcedure
|
||||
|
||||
Procedure FillFields(Scheme, Val Fields)
|
||||
|
||||
If Not ValueIsFilled(Fields) Then
|
||||
Fields = "*";
|
||||
EndIf;
|
||||
|
||||
OPI_TypeConversion.GetArray(Fields);
|
||||
|
||||
For Each Field In Fields Do
|
||||
OPI_SQLQueries.AddField(Scheme, Field);
|
||||
EndDo;
|
||||
|
||||
EndProcedure
|
||||
|
||||
Procedure FillFilters(Scheme, Val Filters)
|
||||
|
||||
If Not ValueIsFilled(Filters) Then
|
||||
Return;
|
||||
EndIf;
|
||||
|
||||
OPI_TypeConversion.GetArray(Filters);
|
||||
|
||||
For Each Filter In Filters Do
|
||||
|
||||
OPI_SQLQueries.AddFilter(Scheme
|
||||
, Filter["field"]
|
||||
, ?(Filter.Property("type"), Filter["type"], "=")
|
||||
, Filter["value"]
|
||||
, ?(Filter.Property("union"), Filter["union"], "AND")
|
||||
, ?(Filter.Property("raw"), Filter["raw"], False));
|
||||
|
||||
EndDo;
|
||||
|
||||
EndProcedure
|
||||
|
||||
Procedure FillSorting(Val Scheme, Val Sort)
|
||||
|
||||
If Not ValueIsFilled(Sort) Then
|
||||
Return;
|
||||
EndIf;
|
||||
|
||||
OPI_TypeConversion.GetCollection(Sort);
|
||||
|
||||
For Each Element In Sort Do
|
||||
|
||||
OPI_SQLQueries.AddSorting(Scheme, Element.Key, Element.Value);
|
||||
|
||||
EndDo;
|
||||
|
||||
EndProcedure
|
||||
|
||||
#EndRegion
|
||||
|
2
src/en/OInt/lib.config
vendored
2
src/en/OInt/lib.config
vendored
@ -23,7 +23,7 @@
|
||||
<module name="OPI_YandexID" file="core/Modules/OPI_YandexID.os"/>
|
||||
<module name="OPI_YandexMarket" file="core/Modules/OPI_YandexMarket.os"/>
|
||||
<module name="OPI_YandexMetrika" file="core/Modules/OPI_YandexMetrika.os"/>
|
||||
<module name="OPI_SQLQueries" file="tools/Modules/OPI_SQLQueries.os"/>
|
||||
<module name="os" file="tools/Modules/os"/>
|
||||
<module name="OPI_Tools" file="tools/Modules/internal/Modules/OPI_Tools.os"/>
|
||||
<module name="OPI_Cryptography" file="tools/Modules/internal/Modules/OPI_Cryptography.os"/>
|
||||
<module name="OPI_TestDataRetrieval" file="tools/Modules/OPI_TestDataRetrieval.os"/>
|
||||
|
@ -16250,13 +16250,10 @@ Procedure SQLite_CreateTable(FunctionParameters)
|
||||
ColoumnsStruct.Insert("created_at", "DATETIME");
|
||||
ColoumnsStruct.Insert("data" , "BLOB");
|
||||
|
||||
Result = OPI_SQLite.CreateTable(Table, ColoumnsStruct, , Base);
|
||||
Result = OPI_SQLite.CreateTable(Table, ColoumnsStruct, Base);
|
||||
|
||||
// END
|
||||
|
||||
Text = OPI_SQLite.CreateTable(Table, ColoumnsStruct, True, Base);
|
||||
OPI_TestDataRetrieval.WriteLog(Text, "CreateTable (query)", "SQLite");
|
||||
|
||||
OPI_TestDataRetrieval.WriteLog(Result, "CreateTable", "SQLite");
|
||||
OPI_TestDataRetrieval.Check_SQLiteSuccess(Result);
|
||||
|
||||
@ -16264,7 +16261,7 @@ Procedure SQLite_CreateTable(FunctionParameters)
|
||||
ColoumnsMap.Insert("id" , "INTEGER PRIMARY KEY");
|
||||
ColoumnsMap.Insert("[An obscure column]", "TEXT");
|
||||
|
||||
Result = OPI_SQLite.CreateTable("test1", ColoumnsMap, , Base);
|
||||
Result = OPI_SQLite.CreateTable("test1", ColoumnsMap, Base);
|
||||
|
||||
OPI_TestDataRetrieval.WriteLog(Result, "CreateTable (obscure column)", "SQLite");
|
||||
OPI_TestDataRetrieval.Check_SQLiteSuccess(Result);
|
||||
|
730
src/en/OInt/tools/Modules/os
vendored
Normal file
730
src/en/OInt/tools/Modules/os
vendored
Normal file
@ -0,0 +1,730 @@
|
||||
// OneScript: ./OInt/tools/Modules/os
|
||||
|
||||
// MIT License
|
||||
|
||||
// Copyright (c) 2023 Anton Tsitavets
|
||||
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
|
||||
// https://github.com/Bayselonarrend/OpenIntegrations
|
||||
|
||||
// BSLLS:Typo-off
|
||||
// BSLLS:LatinAndCyrillicSymbolInWord-off
|
||||
// BSLLS:IncorrectLineBreak-off
|
||||
// BSLLS:NumberOfOptionalParams-off
|
||||
// BSLLS:UsingServiceTag-off
|
||||
// BSLLS:LineLength-off
|
||||
|
||||
//@skip-check module-structure-top-region
|
||||
//@skip-check module-structure-method-in-regions
|
||||
//@skip-check wrong-string-literal-content
|
||||
//@skip-check method-too-many-params
|
||||
//@skip-check constructor-function-return-section
|
||||
|
||||
// Uncomment if OneScript is executed
|
||||
#Use "./internal"
|
||||
|
||||
#Region Internal
|
||||
|
||||
Function CreateTable(Val Module, Val Table, Val ColoumnsStruct, Val Connection = "") Export
|
||||
|
||||
ErrorText = "The column structure is not a valid key-value structure";
|
||||
OPI_TypeConversion.GetKeyValueCollection(ColoumnsStruct, ErrorText);
|
||||
|
||||
Scheme = NewSQLScheme("CREATE");
|
||||
|
||||
SetTableName(Scheme, Table);
|
||||
|
||||
For Each Coloumn In ColoumnsStruct Do
|
||||
AddColoumn(Scheme, Coloumn.Key, Coloumn.Value);
|
||||
EndDo;
|
||||
|
||||
Request = FormSQLText(Scheme);
|
||||
Result = Module.ExecuteSQLQuery(Request, , , Connection);
|
||||
|
||||
Return Result;
|
||||
|
||||
EndFunction
|
||||
|
||||
Function AddRecords(Val Module
|
||||
, Val Table
|
||||
, Val DataArray
|
||||
, Val Transaction = True
|
||||
, Val Connection = "") Export
|
||||
|
||||
OPI_TypeConversion.GetArray(DataArray);
|
||||
OPI_TypeConversion.GetBoolean(Transaction);
|
||||
|
||||
Connection = Module.CreateConnection(Connection);
|
||||
|
||||
If Not Module.IsConnector(Connection) Then
|
||||
Return Connection;
|
||||
EndIf;
|
||||
|
||||
If Transaction Then
|
||||
|
||||
Start = Module.ExecuteSQLQuery("BEGIN TRANSACTION", , , Connection);
|
||||
|
||||
If Not Start["result"] Then
|
||||
Return Start;
|
||||
EndIf;
|
||||
|
||||
EndIf;
|
||||
|
||||
Counter = 0;
|
||||
SuccessCount = 0;
|
||||
|
||||
Error = False;
|
||||
ErrorsArray = New Array;
|
||||
CollectionError = "Invalid data";
|
||||
|
||||
ResultStrucutre = New Structure;
|
||||
|
||||
For Each Record In DataArray Do
|
||||
|
||||
If Error And Transaction Then
|
||||
|
||||
Rollback = Module.ExecuteSQLQuery("ROLLBACK", , , Connection);
|
||||
|
||||
SuccessCount = 0;
|
||||
ResultStrucutre.Insert("rollback", Rollback);
|
||||
Break;
|
||||
|
||||
EndIf;
|
||||
|
||||
Counter = Counter + 1;
|
||||
Error = False;
|
||||
|
||||
Try
|
||||
OPI_TypeConversion.GetKeyValueCollection(Record, CollectionError);
|
||||
Except
|
||||
ErrorsArray.Add(New Structure("row,error", Counter, CollectionError));
|
||||
Error = True;
|
||||
Continue;
|
||||
EndTry;
|
||||
|
||||
Result = AddRow(Module, Table, Record, Connection);
|
||||
|
||||
If Result["result"] Then
|
||||
|
||||
SuccessCount = SuccessCount + 1;
|
||||
|
||||
Else
|
||||
|
||||
ErrorsArray.Add(New Structure("row,error", Counter, Result["error"]));
|
||||
Error = True;
|
||||
|
||||
EndIf;
|
||||
|
||||
EndDo;
|
||||
|
||||
If Transaction And Not Error Then
|
||||
|
||||
Completion = Module.ExecuteSQLQuery("COMMIT", , , Connection);
|
||||
ResultStrucutre.Insert("commit", Completion);
|
||||
|
||||
EndIf;
|
||||
|
||||
ResultStrucutre.Insert("result", ErrorsArray.Count() = 0);
|
||||
ResultStrucutre.Insert("rows" , SuccessCount);
|
||||
ResultStrucutre.Insert("errors", ErrorsArray);
|
||||
|
||||
Return ResultStrucutre;
|
||||
|
||||
EndFunction
|
||||
|
||||
Function GetRecords(Val Module
|
||||
, Val Table
|
||||
, Val Fields = "*"
|
||||
, Val Filters = ""
|
||||
, Val Sort = ""
|
||||
, Val Count = ""
|
||||
, Val Connection = "") Export
|
||||
|
||||
Scheme = NewSQLScheme("SELECT");
|
||||
|
||||
SetTableName(Scheme, Table);
|
||||
SetSelectOptions(Scheme, Fields, Filters, Sort, Count);
|
||||
|
||||
Request = FormSQLText(Scheme);
|
||||
|
||||
Result = Module.ExecuteSQLQuery(Request, Scheme["values"], , Connection);
|
||||
|
||||
Return Result;
|
||||
|
||||
EndFunction
|
||||
|
||||
Function UpdateRecords(Val Module
|
||||
, Val Table
|
||||
, Val ValuesArray
|
||||
, Val Filters = ""
|
||||
, Val Connection = "") Export
|
||||
|
||||
Scheme = NewSQLScheme("UPDATE");
|
||||
|
||||
SetTableName(Scheme, Table);
|
||||
|
||||
Request = FormSQLText(Scheme);
|
||||
Result = Module.ExecuteSQLQuery(Request, Scheme["values"], , Connection);
|
||||
|
||||
Return Result;
|
||||
|
||||
EndFunction
|
||||
|
||||
Function GetRecordsFilterStrucutre(Val Clear = False) Export
|
||||
|
||||
FilterStructure = New Structure;
|
||||
|
||||
FilterStructure.Insert("field", "<filtering field name>");
|
||||
FilterStructure.Insert("type" , "<comparison type>");
|
||||
FilterStructure.Insert("value", "<comparison value>");
|
||||
FilterStructure.Insert("union", "<connection with the following condition: AND, OR, etc..>");
|
||||
FilterStructure.Insert("raw" , "<true - the value will be inserted by text as it is, false - through the parameter>");
|
||||
|
||||
If Clear Then
|
||||
FilterStructure = OPI_Tools.ClearCollectionRecursively(FilterStructure);
|
||||
EndIf;
|
||||
|
||||
//@skip-check constructor-function-return-section
|
||||
Return FilterStructure;
|
||||
|
||||
EndFunction
|
||||
|
||||
#EndRegion
|
||||
|
||||
#Region Private
|
||||
|
||||
#Region Scheme
|
||||
|
||||
Function EmptySchemeSelect()
|
||||
|
||||
Scheme = New Structure("type", "SELECT");
|
||||
|
||||
Scheme.Insert("table" , "");
|
||||
Scheme.Insert("filter" , New Array);
|
||||
Scheme.Insert("order" , New Array);
|
||||
Scheme.Insert("limit" , 0);
|
||||
Scheme.Insert("set" , New Array);
|
||||
Scheme.Insert("values" , New Array);
|
||||
|
||||
Return Scheme;
|
||||
|
||||
EndFunction
|
||||
|
||||
Function EmptySchemeInsert()
|
||||
|
||||
Scheme = New Structure("type", "INSERT");
|
||||
|
||||
Scheme.Insert("table", "");
|
||||
Scheme.Insert("set" , New Array);
|
||||
|
||||
Return Scheme;
|
||||
|
||||
EndFunction
|
||||
|
||||
Function EmptySchemeUpdate()
|
||||
|
||||
Scheme = New Structure("type", "UPDATE");
|
||||
|
||||
Scheme.Insert("table" , "");
|
||||
Scheme.Insert("set" , New Array);
|
||||
Scheme.Insert("filter", New Array);
|
||||
Scheme.Insert("values" , New Array);
|
||||
|
||||
Return Scheme;
|
||||
|
||||
EndFunction
|
||||
|
||||
Function EmptySchemeDelete()
|
||||
|
||||
Scheme = New Structure("type", "DELETE");
|
||||
|
||||
Scheme.Insert("table" , "");
|
||||
Scheme.Insert("filter", New Array);
|
||||
|
||||
Return Scheme;
|
||||
|
||||
EndFunction
|
||||
|
||||
Function EmptySchemeCreate()
|
||||
|
||||
Scheme = New Structure("type", "CREATE");
|
||||
|
||||
Scheme.Insert("table" , "");
|
||||
Scheme.Insert("columns", New Array);
|
||||
|
||||
Return Scheme;
|
||||
|
||||
EndFunction
|
||||
|
||||
#EndRegion
|
||||
|
||||
#Region Processors
|
||||
|
||||
Function FormTextSelect(Val Scheme)
|
||||
|
||||
CheckSchemeRequiredFields(Scheme, "table,filter,order,limit,set");
|
||||
|
||||
Table = Scheme["table"];
|
||||
Fields = Scheme["set"];
|
||||
Filters = Scheme["filter"];
|
||||
Sort = Scheme["order"];
|
||||
Count = Scheme["limit"];
|
||||
|
||||
SQLTemplate = "SELECT %1 FROM %2
|
||||
|%3";
|
||||
|
||||
OptionsBlock = ForSelectOptionsText(Filters, Sort, Count);
|
||||
|
||||
TextSQL = StrTemplate(SQLTemplate, StrConcat(Fields, ", "), Table, OptionsBlock);
|
||||
|
||||
Return TextSQL;
|
||||
|
||||
EndFunction
|
||||
|
||||
Function FormTextInsert(Val Scheme)
|
||||
|
||||
CheckSchemeRequiredFields(Scheme, "table,set");
|
||||
|
||||
Table = Scheme["table"];
|
||||
Fields = Scheme["set"];
|
||||
|
||||
SQLTemplate = "INSERT INTO %1 (%2) VALUES (%3)";
|
||||
|
||||
Parameters = New Array;
|
||||
|
||||
For N = 1 To Fields.Count() Do
|
||||
Parameters.Add("?" + OPI_Tools.NumberToString(N));
|
||||
EndDo;
|
||||
|
||||
TextSQL = StrTemplate(SQLTemplate
|
||||
, Table
|
||||
, StrConcat(Fields, ", ")
|
||||
, StrConcat(Parameters, ", "));
|
||||
|
||||
Return TextSQL;
|
||||
|
||||
EndFunction
|
||||
|
||||
Function FormTextUpdate(Val Scheme)
|
||||
|
||||
TextSQL = "";
|
||||
|
||||
Return TextSQL;
|
||||
|
||||
EndFunction
|
||||
|
||||
Function FormTextDelete(Val Scheme)
|
||||
|
||||
TextSQL = "";
|
||||
|
||||
Return TextSQL;
|
||||
|
||||
EndFunction
|
||||
|
||||
Function FormTextCreate(Val Scheme)
|
||||
|
||||
CheckSchemeRequiredFields(Scheme, "table,columns");
|
||||
|
||||
Table = Scheme["table"];
|
||||
Columns = Scheme["columns"];
|
||||
|
||||
SQLTemplate = "CREATE TABLE %1 (
|
||||
| %2
|
||||
| )";
|
||||
|
||||
ColoumTemplate = "%1 %2";
|
||||
|
||||
ColoumnsDescriptionArray = New Array;
|
||||
|
||||
For Each Coloumn In Columns Do
|
||||
For Each Element In Coloumn Do
|
||||
ColoumnsDescriptionArray.Add(StrTemplate(ColoumTemplate, Element.Key, Element.Value));
|
||||
EndDo;
|
||||
EndDo;
|
||||
|
||||
ColoumnsDescription = StrConcat(ColoumnsDescriptionArray, "," + Chars.LF);
|
||||
|
||||
TextSQL = StrTemplate(SQLTemplate, Table, ColoumnsDescription);
|
||||
|
||||
Return TextSQL;
|
||||
|
||||
EndFunction
|
||||
|
||||
#EndRegion
|
||||
|
||||
#Region Auxiliary
|
||||
|
||||
Function NewSQLScheme(Val Action)
|
||||
|
||||
OPI_TypeConversion.GetLine(Action);
|
||||
|
||||
Action = Upper(Action);
|
||||
|
||||
If Action = "SELECT" Then
|
||||
|
||||
Scheme = EmptySchemeSelect();
|
||||
|
||||
ElsIf Action = "INSERT" Then
|
||||
|
||||
Scheme = EmptySchemeInsert();
|
||||
|
||||
ElsIf Action = "UPDATE" Then
|
||||
|
||||
Scheme = EmptySchemeUpdate();
|
||||
|
||||
ElsIf Action = "DELETE" Then
|
||||
|
||||
Scheme = EmptySchemeDelete();
|
||||
|
||||
ElsIf Action = "CREATE" Then
|
||||
|
||||
Scheme = EmptySchemeCreate();
|
||||
|
||||
Else
|
||||
|
||||
Scheme = New Structure;
|
||||
|
||||
EndIf;
|
||||
|
||||
Return Scheme;
|
||||
|
||||
EndFunction
|
||||
|
||||
Function FormSQLText(Val Scheme)
|
||||
|
||||
ErrorText = "The value passed is not a valid SQL query schema";
|
||||
OPI_TypeConversion.GetKeyValueCollection(Scheme, ErrorText);
|
||||
|
||||
SchemeType = "";
|
||||
|
||||
If Not OPI_Tools.CollectionFieldExists(Scheme, "type", SchemeType) Then
|
||||
Raise ErrorText;
|
||||
EndIf;
|
||||
|
||||
SchemeType = Upper(SchemeType);
|
||||
|
||||
If SchemeType = "SELECT" Then
|
||||
|
||||
QueryText = FormTextSelect(Scheme);
|
||||
|
||||
ElsIf SchemeType = "INSERT" Then
|
||||
|
||||
QueryText = FormTextInsert(Scheme);
|
||||
|
||||
ElsIf SchemeType = "UPDATE" Then
|
||||
|
||||
QueryText = FormTextUpdate(Scheme);
|
||||
|
||||
ElsIf SchemeType = "DELETE" Then
|
||||
|
||||
QueryText = FormTextDelete(Scheme);
|
||||
|
||||
ElsIf SchemeType = "CREATE" Then
|
||||
|
||||
QueryText = FormTextCreate(Scheme);
|
||||
|
||||
Else
|
||||
|
||||
QueryText = "";
|
||||
|
||||
EndIf;
|
||||
|
||||
Return QueryText;
|
||||
|
||||
EndFunction
|
||||
|
||||
Function ForSelectOptionsText(Val Filters, Val Sort, Val Count)
|
||||
|
||||
BlockTemplate = "%1
|
||||
|%2
|
||||
|%3";
|
||||
|
||||
FilterText = FormFilterText(Filters);
|
||||
SortingText = FormSortingText(Sort);
|
||||
CountText = FormCountText(Count);
|
||||
|
||||
BlockText = StrTemplate(BlockTemplate, FilterText, SortingText, CountText);
|
||||
|
||||
Return BlockText;
|
||||
|
||||
EndFunction
|
||||
|
||||
Function FormFilterText(Val Filters)
|
||||
|
||||
If Not ValueIsFilled(Filters) Then
|
||||
Return "";
|
||||
EndIf;
|
||||
|
||||
FiltersText = "WHERE %1";
|
||||
|
||||
FiltersArray = New Array;
|
||||
|
||||
Counter = 1;
|
||||
Total = Filters.Count();
|
||||
|
||||
For Each Filter In Filters Do
|
||||
|
||||
CurrentText = "%1 %2 %3 %4";
|
||||
|
||||
Field = Filter["field"];
|
||||
Type = Filter["type"];
|
||||
Value = Filter["value"];
|
||||
Connection = Filter["union"];
|
||||
Connection = ?(ValueIsFilled(Connection), Connection, "AND");
|
||||
|
||||
If Counter = Total Then
|
||||
Connection = "";
|
||||
EndIf;
|
||||
|
||||
CurrentText = StrTemplate(CurrentText, Field, Type, Value, Connection);
|
||||
FiltersArray.Add(CurrentText);
|
||||
|
||||
Counter = Counter + 1;
|
||||
|
||||
EndDo;
|
||||
|
||||
FiltersText = StrTemplate(FiltersText, StrConcat(FiltersArray, " "));
|
||||
|
||||
Return FiltersText;
|
||||
|
||||
EndFunction
|
||||
|
||||
Function FormSortingText(Val Sort)
|
||||
|
||||
If Not ValueIsFilled(Sort) Then
|
||||
Return "";
|
||||
EndIf;
|
||||
|
||||
SortingText = "ORDER BY %1";
|
||||
|
||||
SortArray = New Array;
|
||||
|
||||
For Each Element In Sort Do
|
||||
|
||||
SortArray.Add(Element["field"] + " " + Element["type"]);
|
||||
|
||||
EndDo;
|
||||
|
||||
SortingText = StrTemplate(SortingText, StrConcat(SortArray, ", "));
|
||||
|
||||
Return SortingText;
|
||||
|
||||
EndFunction
|
||||
|
||||
Function FormCountText(Val Count)
|
||||
|
||||
If Not ValueIsFilled(Count) Then
|
||||
Return "";
|
||||
EndIf;
|
||||
|
||||
CountText = "LIMIT %1";
|
||||
CountText = StrTemplate(CountText, OPI_Tools.NumberToString(Count));
|
||||
|
||||
Return CountText;
|
||||
|
||||
EndFunction
|
||||
|
||||
Function AddRow(Val Module, Val Table, Val Record, Val Connection)
|
||||
|
||||
FieldArray = New Array;
|
||||
ValuesArray = New Array;
|
||||
|
||||
Scheme = NewSQLScheme("INSERT");
|
||||
SetTableName(Scheme, Table);
|
||||
|
||||
SplitDataCollection(Record, FieldArray, ValuesArray);
|
||||
|
||||
For Each Field In FieldArray Do
|
||||
AddField(Scheme, Field);
|
||||
EndDo;
|
||||
|
||||
Request = FormSQLText(Scheme);
|
||||
|
||||
Result = Module.ExecuteSQLQuery(Request, ValuesArray, , Connection);
|
||||
|
||||
Return Result;
|
||||
|
||||
EndFunction
|
||||
|
||||
Procedure SplitDataCollection(Val Record, FieldArray, ValuesArray)
|
||||
|
||||
For Each Element In Record Do
|
||||
|
||||
FieldArray.Add(Element.Key);
|
||||
ValuesArray.Add(Element.Value);
|
||||
|
||||
EndDo;
|
||||
|
||||
EndProcedure
|
||||
|
||||
Procedure FillFields(Scheme, Val Fields)
|
||||
|
||||
If Not ValueIsFilled(Fields) Then
|
||||
Fields = "*";
|
||||
EndIf;
|
||||
|
||||
OPI_TypeConversion.GetArray(Fields);
|
||||
|
||||
For Each Field In Fields Do
|
||||
AddField(Scheme, Field);
|
||||
EndDo;
|
||||
|
||||
EndProcedure
|
||||
|
||||
Procedure FillFilters(Scheme, Val Filters)
|
||||
|
||||
If Not ValueIsFilled(Filters) Then
|
||||
Return;
|
||||
EndIf;
|
||||
|
||||
OPI_TypeConversion.GetArray(Filters);
|
||||
|
||||
For Each Filter In Filters Do
|
||||
|
||||
AddFilter(Scheme
|
||||
, Filter["field"]
|
||||
, ?(Filter.Property("type"), Filter["type"], "=")
|
||||
, Filter["value"]
|
||||
, ?(Filter.Property("union"), Filter["union"], "AND")
|
||||
, ?(Filter.Property("raw"), Filter["raw"], False));
|
||||
|
||||
EndDo;
|
||||
|
||||
EndProcedure
|
||||
|
||||
Procedure FillSorting(Val Scheme, Val Sort)
|
||||
|
||||
If Not ValueIsFilled(Sort) Then
|
||||
Return;
|
||||
EndIf;
|
||||
|
||||
OPI_TypeConversion.GetCollection(Sort);
|
||||
|
||||
For Each Element In Sort Do
|
||||
|
||||
AddSorting(Scheme, Element.Key, Element.Value);
|
||||
|
||||
EndDo;
|
||||
|
||||
EndProcedure
|
||||
|
||||
Procedure CheckSchemeRequiredFields(Scheme, Val Fields)
|
||||
|
||||
RequiredFieldsArray = StrSplit(Fields, ",");
|
||||
AbsenteesArray = OPI_Tools.FindMissingCollectionFields(Scheme, RequiredFieldsArray);
|
||||
|
||||
If ValueIsFilled(AbsenteesArray) Then
|
||||
Raise "Required schema fields are missing: " + StrConcat(AbsenteesArray, ", ");
|
||||
EndIf;
|
||||
|
||||
EndProcedure
|
||||
|
||||
Procedure AddColoumn(Scheme, Val Name, Val Type) Export
|
||||
|
||||
OPI_TypeConversion.GetLine(Name);
|
||||
OPI_TypeConversion.GetLine(Type);
|
||||
|
||||
If Not Scheme["type"] = "CREATE" Then
|
||||
Return;
|
||||
EndIf;
|
||||
|
||||
ColoumnMap = New Map;
|
||||
ColoumnMap.Insert(Name, Type);
|
||||
|
||||
Scheme["columns"].Add(ColoumnMap);
|
||||
|
||||
EndProcedure
|
||||
|
||||
Procedure AddField(Scheme, Val Name) Export
|
||||
|
||||
OPI_TypeConversion.GetLine(Name);
|
||||
|
||||
Scheme["set"].Add(Name);
|
||||
|
||||
EndProcedure
|
||||
|
||||
Procedure AddFilter(Scheme, Val Field, Val Type, Val Value, Val Grouping, Val Raw)
|
||||
|
||||
OPI_TypeConversion.GetLine(Field);
|
||||
OPI_TypeConversion.GetLine(Type);
|
||||
OPI_TypeConversion.GetLine(Grouping);
|
||||
OPI_TypeConversion.GetBoolean(Raw);
|
||||
|
||||
MainStructure = New Structure("field,type,union"
|
||||
, Field
|
||||
, Type
|
||||
, Grouping);
|
||||
|
||||
If Raw Then
|
||||
|
||||
MainStructure.Insert("value", String(Value));
|
||||
|
||||
Else
|
||||
|
||||
Scheme["values"].Add(Value);
|
||||
|
||||
OrderNumber = Scheme["values"].Count();
|
||||
MainStructure.Insert("value", "?" + OPI_Tools.NumberToString(OrderNumber));
|
||||
|
||||
EndIf;
|
||||
|
||||
|
||||
Scheme["filter"].Add(MainStructure);
|
||||
|
||||
EndProcedure
|
||||
|
||||
Procedure AddSorting(Scheme, Val Field, Val Type)
|
||||
|
||||
OPI_TypeConversion.GetLine(Field);
|
||||
OPI_TypeConversion.GetLine(Type);
|
||||
|
||||
Scheme["order"].Add(New Structure("field,type", Field, Type));
|
||||
|
||||
EndProcedure
|
||||
|
||||
Procedure SetTableName(Scheme, Val Name)
|
||||
|
||||
OPI_TypeConversion.GetLine(Name);
|
||||
|
||||
Scheme.Insert("table", Name);
|
||||
|
||||
EndProcedure
|
||||
|
||||
Procedure SetLimit(Scheme, Val Count)
|
||||
|
||||
OPI_TypeConversion.GetNumber(Count);
|
||||
|
||||
Scheme.Insert("limit", Count);
|
||||
|
||||
EndProcedure
|
||||
|
||||
Procedure SetSelectOptions(Scheme, Val Fields, Val Filters, Val Sort, Val Count)
|
||||
|
||||
SetLimit(Scheme, Count);
|
||||
|
||||
FillFields(Scheme, Fields);
|
||||
FillFilters(Scheme, Filters);
|
||||
FillSorting(Scheme, Sort);
|
||||
|
||||
EndProcedure
|
||||
|
||||
#EndRegion
|
||||
|
||||
#EndRegion
|
@ -1,4 +1,4 @@
|
||||
// OneScript: ./OInt/tools/Modules/OPI_SQLQueries.os
|
||||
// OneScript: ./OInt/tools/Modules/os
|
||||
|
||||
// MIT License
|
||||
|
||||
@ -42,164 +42,169 @@
|
||||
|
||||
#Region Internal
|
||||
|
||||
Function NewSQLScheme(Val Action) Export
|
||||
Function CreateTable(Val Module, Val Table, Val ColoumnsStruct, Val Connection = "") Export
|
||||
|
||||
OPI_TypeConversion.GetLine(Action);
|
||||
ErrorText = "The column structure is not a valid key-value structure";
|
||||
OPI_TypeConversion.GetKeyValueCollection(ColoumnsStruct, ErrorText);
|
||||
|
||||
Action = Upper(Action);
|
||||
Scheme = NewSQLScheme("CREATE");
|
||||
|
||||
If Action = "SELECT" Then
|
||||
SetTableName(Scheme, Table);
|
||||
|
||||
Scheme = EmptySchemeSelect();
|
||||
For Each Coloumn In ColoumnsStruct Do
|
||||
AddColoumn(Scheme, Coloumn.Key, Coloumn.Value);
|
||||
EndDo;
|
||||
|
||||
ElsIf Action = "INSERT" Then
|
||||
Request = FormSQLText(Scheme);
|
||||
Result = Module.ExecuteSQLQuery(Request, , , Connection);
|
||||
|
||||
Scheme = EmptySchemeInsert();
|
||||
|
||||
ElsIf Action = "UPDATE" Then
|
||||
|
||||
Scheme = EmptySchemeUpdate();
|
||||
|
||||
ElsIf Action = "DELETE" Then
|
||||
|
||||
Scheme = EmptySchemeDelete();
|
||||
|
||||
ElsIf Action = "CREATE" Then
|
||||
|
||||
Scheme = EmptySchemeCreate();
|
||||
|
||||
Else
|
||||
|
||||
Scheme = New Structure;
|
||||
|
||||
EndIf;
|
||||
|
||||
Return Scheme;
|
||||
Return Result;
|
||||
|
||||
EndFunction
|
||||
|
||||
Function FormSQLText(Val Scheme) Export
|
||||
Function AddRecords(Val Module
|
||||
, Val Table
|
||||
, Val DataArray
|
||||
, Val Transaction = True
|
||||
, Val Connection = "") Export
|
||||
|
||||
ErrorText = "The value passed is not a valid SQL query schema";
|
||||
OPI_TypeConversion.GetKeyValueCollection(Scheme, ErrorText);
|
||||
OPI_TypeConversion.GetArray(DataArray);
|
||||
OPI_TypeConversion.GetBoolean(Transaction);
|
||||
|
||||
SchemeType = "";
|
||||
Connection = Module.CreateConnection(Connection);
|
||||
|
||||
If Not OPI_Tools.CollectionFieldExists(Scheme, "type", SchemeType) Then
|
||||
Raise ErrorText;
|
||||
If Not Module.IsConnector(Connection) Then
|
||||
Return Connection;
|
||||
EndIf;
|
||||
|
||||
SchemeType = Upper(SchemeType);
|
||||
If Transaction Then
|
||||
|
||||
If SchemeType = "SELECT" Then
|
||||
Start = Module.ExecuteSQLQuery("BEGIN TRANSACTION", , , Connection);
|
||||
|
||||
QueryText = FormTextSelect(Scheme);
|
||||
|
||||
ElsIf SchemeType = "INSERT" Then
|
||||
|
||||
QueryText = FormTextInsert(Scheme);
|
||||
|
||||
ElsIf SchemeType = "UPDATE" Then
|
||||
|
||||
QueryText = FormTextUpdate(Scheme);
|
||||
|
||||
ElsIf SchemeType = "DELETE" Then
|
||||
|
||||
QueryText = FormTextDelete(Scheme);
|
||||
|
||||
ElsIf SchemeType = "CREATE" Then
|
||||
|
||||
QueryText = FormTextCreate(Scheme);
|
||||
|
||||
Else
|
||||
|
||||
QueryText = "";
|
||||
If Not Start["result"] Then
|
||||
Return Start;
|
||||
EndIf;
|
||||
|
||||
EndIf;
|
||||
|
||||
Return QueryText;
|
||||
Counter = 0;
|
||||
SuccessCount = 0;
|
||||
|
||||
Error = False;
|
||||
ErrorsArray = New Array;
|
||||
CollectionError = "Invalid data";
|
||||
|
||||
ResultStrucutre = New Structure;
|
||||
|
||||
For Each Record In DataArray Do
|
||||
|
||||
If Error And Transaction Then
|
||||
|
||||
Rollback = Module.ExecuteSQLQuery("ROLLBACK", , , Connection);
|
||||
|
||||
SuccessCount = 0;
|
||||
ResultStrucutre.Insert("rollback", Rollback);
|
||||
Break;
|
||||
|
||||
EndIf;
|
||||
|
||||
Counter = Counter + 1;
|
||||
Error = False;
|
||||
|
||||
Try
|
||||
OPI_TypeConversion.GetKeyValueCollection(Record, CollectionError);
|
||||
Except
|
||||
ErrorsArray.Add(New Structure("row,error", Counter, CollectionError));
|
||||
Error = True;
|
||||
Continue;
|
||||
EndTry;
|
||||
|
||||
Result = AddRow(Module, Table, Record, Connection);
|
||||
|
||||
If Result["result"] Then
|
||||
|
||||
SuccessCount = SuccessCount + 1;
|
||||
|
||||
Else
|
||||
|
||||
ErrorsArray.Add(New Structure("row,error", Counter, Result["error"]));
|
||||
Error = True;
|
||||
|
||||
EndIf;
|
||||
|
||||
EndDo;
|
||||
|
||||
If Transaction And Not Error Then
|
||||
|
||||
Completion = Module.ExecuteSQLQuery("COMMIT", , , Connection);
|
||||
ResultStrucutre.Insert("commit", Completion);
|
||||
|
||||
EndIf;
|
||||
|
||||
ResultStrucutre.Insert("result", ErrorsArray.Count() = 0);
|
||||
ResultStrucutre.Insert("rows" , SuccessCount);
|
||||
ResultStrucutre.Insert("errors", ErrorsArray);
|
||||
|
||||
Return ResultStrucutre;
|
||||
|
||||
EndFunction
|
||||
|
||||
Procedure AddColoumn(Scheme, Val Name, Val Type) Export
|
||||
Function GetRecords(Val Module
|
||||
, Val Table
|
||||
, Val Fields = "*"
|
||||
, Val Filters = ""
|
||||
, Val Sort = ""
|
||||
, Val Count = ""
|
||||
, Val Connection = "") Export
|
||||
|
||||
OPI_TypeConversion.GetLine(Name);
|
||||
OPI_TypeConversion.GetLine(Type);
|
||||
Scheme = NewSQLScheme("SELECT");
|
||||
|
||||
If Not Scheme["type"] = "CREATE" Then
|
||||
Return;
|
||||
SetTableName(Scheme, Table);
|
||||
SetSelectOptions(Scheme, Fields, Filters, Sort, Count);
|
||||
|
||||
Request = FormSQLText(Scheme);
|
||||
|
||||
Result = Module.ExecuteSQLQuery(Request, Scheme["values"], , Connection);
|
||||
|
||||
Return Result;
|
||||
|
||||
EndFunction
|
||||
|
||||
Function UpdateRecords(Val Module
|
||||
, Val Table
|
||||
, Val ValuesArray
|
||||
, Val Filters = ""
|
||||
, Val Connection = "") Export
|
||||
|
||||
Scheme = NewSQLScheme("UPDATE");
|
||||
|
||||
SetTableName(Scheme, Table);
|
||||
|
||||
Request = FormSQLText(Scheme);
|
||||
Result = Module.ExecuteSQLQuery(Request, Scheme["values"], , Connection);
|
||||
|
||||
Return Result;
|
||||
|
||||
EndFunction
|
||||
|
||||
Function GetRecordsFilterStrucutre(Val Clear = False) Export
|
||||
|
||||
FilterStructure = New Structure;
|
||||
|
||||
FilterStructure.Insert("field", "<filtering field name>");
|
||||
FilterStructure.Insert("type" , "<comparison type>");
|
||||
FilterStructure.Insert("value", "<comparison value>");
|
||||
FilterStructure.Insert("union", "<connection with the following condition: AND, OR, etc..>");
|
||||
FilterStructure.Insert("raw" , "<true - the value will be inserted by text as it is, false - through the parameter>");
|
||||
|
||||
If Clear Then
|
||||
FilterStructure = OPI_Tools.ClearCollectionRecursively(FilterStructure);
|
||||
EndIf;
|
||||
|
||||
ColoumnMap = New Map;
|
||||
ColoumnMap.Insert(Name, Type);
|
||||
//@skip-check constructor-function-return-section
|
||||
Return FilterStructure;
|
||||
|
||||
Scheme["columns"].Add(ColoumnMap);
|
||||
|
||||
EndProcedure
|
||||
|
||||
Procedure AddField(Scheme, Val Name) Export
|
||||
|
||||
OPI_TypeConversion.GetLine(Name);
|
||||
|
||||
Scheme["set"].Add(Name);
|
||||
|
||||
EndProcedure
|
||||
|
||||
Procedure AddFilter(Scheme, Val Field, Val Type, Val Value, Val Grouping, Val Raw) Export
|
||||
|
||||
OPI_TypeConversion.GetLine(Field);
|
||||
OPI_TypeConversion.GetLine(Type);
|
||||
OPI_TypeConversion.GetLine(Grouping);
|
||||
OPI_TypeConversion.GetBoolean(Raw);
|
||||
|
||||
MainStructure = New Structure("field,type,union"
|
||||
, Field
|
||||
, Type
|
||||
, Grouping);
|
||||
|
||||
If Raw Then
|
||||
|
||||
MainStructure.Insert("value", String(Value));
|
||||
|
||||
Else
|
||||
|
||||
Scheme["values"].Add(Value);
|
||||
|
||||
OrderNumber = Scheme["values"].Count();
|
||||
MainStructure.Insert("value", "?" + OPI_Tools.NumberToString(OrderNumber));
|
||||
|
||||
EndIf;
|
||||
|
||||
|
||||
Scheme["filter"].Add(MainStructure);
|
||||
|
||||
EndProcedure
|
||||
|
||||
Procedure AddSorting(Scheme, Val Field, Val Type) Export
|
||||
|
||||
OPI_TypeConversion.GetLine(Field);
|
||||
OPI_TypeConversion.GetLine(Type);
|
||||
|
||||
Scheme["order"].Add(New Structure("field,type", Field, Type));
|
||||
|
||||
EndProcedure
|
||||
|
||||
|
||||
Procedure SetTableName(Scheme, Val Name) Export
|
||||
|
||||
OPI_TypeConversion.GetLine(Name);
|
||||
|
||||
Scheme.Insert("table", Name);
|
||||
|
||||
EndProcedure
|
||||
|
||||
Procedure SetLimit(Scheme, Val Count) Export
|
||||
|
||||
OPI_TypeConversion.GetNumber(Count);
|
||||
|
||||
Scheme.Insert("limit", Count);
|
||||
|
||||
EndProcedure
|
||||
EndFunction
|
||||
|
||||
#EndRegion
|
||||
|
||||
@ -237,9 +242,10 @@ Function EmptySchemeUpdate()
|
||||
|
||||
Scheme = New Structure("type", "UPDATE");
|
||||
|
||||
Scheme.Insert("table" , "");
|
||||
Scheme.Insert("set" , New Array);
|
||||
Scheme.Insert("filter", New Array);
|
||||
Scheme.Insert("table" , "");
|
||||
Scheme.Insert("set" , New Array);
|
||||
Scheme.Insert("filter" , New Array);
|
||||
Scheme.Insert("values" , New Array);
|
||||
|
||||
Return Scheme;
|
||||
|
||||
@ -363,6 +369,87 @@ EndFunction
|
||||
|
||||
#EndRegion
|
||||
|
||||
#Region Auxiliary
|
||||
|
||||
Function NewSQLScheme(Val Action)
|
||||
|
||||
OPI_TypeConversion.GetLine(Action);
|
||||
|
||||
Action = Upper(Action);
|
||||
|
||||
If Action = "SELECT" Then
|
||||
|
||||
Scheme = EmptySchemeSelect();
|
||||
|
||||
ElsIf Action = "INSERT" Then
|
||||
|
||||
Scheme = EmptySchemeInsert();
|
||||
|
||||
ElsIf Action = "UPDATE" Then
|
||||
|
||||
Scheme = EmptySchemeUpdate();
|
||||
|
||||
ElsIf Action = "DELETE" Then
|
||||
|
||||
Scheme = EmptySchemeDelete();
|
||||
|
||||
ElsIf Action = "CREATE" Then
|
||||
|
||||
Scheme = EmptySchemeCreate();
|
||||
|
||||
Else
|
||||
|
||||
Scheme = New Structure;
|
||||
|
||||
EndIf;
|
||||
|
||||
Return Scheme;
|
||||
|
||||
EndFunction
|
||||
|
||||
Function FormSQLText(Val Scheme)
|
||||
|
||||
ErrorText = "The value passed is not a valid SQL query schema";
|
||||
OPI_TypeConversion.GetKeyValueCollection(Scheme, ErrorText);
|
||||
|
||||
SchemeType = "";
|
||||
|
||||
If Not OPI_Tools.CollectionFieldExists(Scheme, "type", SchemeType) Then
|
||||
Raise ErrorText;
|
||||
EndIf;
|
||||
|
||||
SchemeType = Upper(SchemeType);
|
||||
|
||||
If SchemeType = "SELECT" Then
|
||||
|
||||
QueryText = FormTextSelect(Scheme);
|
||||
|
||||
ElsIf SchemeType = "INSERT" Then
|
||||
|
||||
QueryText = FormTextInsert(Scheme);
|
||||
|
||||
ElsIf SchemeType = "UPDATE" Then
|
||||
|
||||
QueryText = FormTextUpdate(Scheme);
|
||||
|
||||
ElsIf SchemeType = "DELETE" Then
|
||||
|
||||
QueryText = FormTextDelete(Scheme);
|
||||
|
||||
ElsIf SchemeType = "CREATE" Then
|
||||
|
||||
QueryText = FormTextCreate(Scheme);
|
||||
|
||||
Else
|
||||
|
||||
QueryText = "";
|
||||
|
||||
EndIf;
|
||||
|
||||
Return QueryText;
|
||||
|
||||
EndFunction
|
||||
|
||||
Function ForSelectOptionsText(Val Filters, Val Sort, Val Count)
|
||||
|
||||
BlockTemplate = "%1
|
||||
@ -454,6 +541,90 @@ Function FormCountText(Val Count)
|
||||
|
||||
EndFunction
|
||||
|
||||
Function AddRow(Val Module, Val Table, Val Record, Val Connection)
|
||||
|
||||
FieldArray = New Array;
|
||||
ValuesArray = New Array;
|
||||
|
||||
Scheme = NewSQLScheme("INSERT");
|
||||
SetTableName(Scheme, Table);
|
||||
|
||||
SplitDataCollection(Record, FieldArray, ValuesArray);
|
||||
|
||||
For Each Field In FieldArray Do
|
||||
AddField(Scheme, Field);
|
||||
EndDo;
|
||||
|
||||
Request = FormSQLText(Scheme);
|
||||
|
||||
Result = Module.ExecuteSQLQuery(Request, ValuesArray, , Connection);
|
||||
|
||||
Return Result;
|
||||
|
||||
EndFunction
|
||||
|
||||
Procedure SplitDataCollection(Val Record, FieldArray, ValuesArray)
|
||||
|
||||
For Each Element In Record Do
|
||||
|
||||
FieldArray.Add(Element.Key);
|
||||
ValuesArray.Add(Element.Value);
|
||||
|
||||
EndDo;
|
||||
|
||||
EndProcedure
|
||||
|
||||
Procedure FillFields(Scheme, Val Fields)
|
||||
|
||||
If Not ValueIsFilled(Fields) Then
|
||||
Fields = "*";
|
||||
EndIf;
|
||||
|
||||
OPI_TypeConversion.GetArray(Fields);
|
||||
|
||||
For Each Field In Fields Do
|
||||
AddField(Scheme, Field);
|
||||
EndDo;
|
||||
|
||||
EndProcedure
|
||||
|
||||
Procedure FillFilters(Scheme, Val Filters)
|
||||
|
||||
If Not ValueIsFilled(Filters) Then
|
||||
Return;
|
||||
EndIf;
|
||||
|
||||
OPI_TypeConversion.GetArray(Filters);
|
||||
|
||||
For Each Filter In Filters Do
|
||||
|
||||
AddFilter(Scheme
|
||||
, Filter["field"]
|
||||
, ?(Filter.Property("type"), Filter["type"], "=")
|
||||
, Filter["value"]
|
||||
, ?(Filter.Property("union"), Filter["union"], "AND")
|
||||
, ?(Filter.Property("raw"), Filter["raw"], False));
|
||||
|
||||
EndDo;
|
||||
|
||||
EndProcedure
|
||||
|
||||
Procedure FillSorting(Val Scheme, Val Sort)
|
||||
|
||||
If Not ValueIsFilled(Sort) Then
|
||||
Return;
|
||||
EndIf;
|
||||
|
||||
OPI_TypeConversion.GetCollection(Sort);
|
||||
|
||||
For Each Element In Sort Do
|
||||
|
||||
AddSorting(Scheme, Element.Key, Element.Value);
|
||||
|
||||
EndDo;
|
||||
|
||||
EndProcedure
|
||||
|
||||
Procedure CheckSchemeRequiredFields(Scheme, Val Fields)
|
||||
|
||||
RequiredFieldsArray = StrSplit(Fields, ",");
|
||||
@ -465,4 +636,95 @@ Procedure CheckSchemeRequiredFields(Scheme, Val Fields)
|
||||
|
||||
EndProcedure
|
||||
|
||||
Procedure AddColoumn(Scheme, Val Name, Val Type) Export
|
||||
|
||||
OPI_TypeConversion.GetLine(Name);
|
||||
OPI_TypeConversion.GetLine(Type);
|
||||
|
||||
If Not Scheme["type"] = "CREATE" Then
|
||||
Return;
|
||||
EndIf;
|
||||
|
||||
ColoumnMap = New Map;
|
||||
ColoumnMap.Insert(Name, Type);
|
||||
|
||||
Scheme["columns"].Add(ColoumnMap);
|
||||
|
||||
EndProcedure
|
||||
|
||||
Procedure AddField(Scheme, Val Name) Export
|
||||
|
||||
OPI_TypeConversion.GetLine(Name);
|
||||
|
||||
Scheme["set"].Add(Name);
|
||||
|
||||
EndProcedure
|
||||
|
||||
Procedure AddFilter(Scheme, Val Field, Val Type, Val Value, Val Grouping, Val Raw)
|
||||
|
||||
OPI_TypeConversion.GetLine(Field);
|
||||
OPI_TypeConversion.GetLine(Type);
|
||||
OPI_TypeConversion.GetLine(Grouping);
|
||||
OPI_TypeConversion.GetBoolean(Raw);
|
||||
|
||||
MainStructure = New Structure("field,type,union"
|
||||
, Field
|
||||
, Type
|
||||
, Grouping);
|
||||
|
||||
If Raw Then
|
||||
|
||||
MainStructure.Insert("value", String(Value));
|
||||
|
||||
Else
|
||||
|
||||
Scheme["values"].Add(Value);
|
||||
|
||||
OrderNumber = Scheme["values"].Count();
|
||||
MainStructure.Insert("value", "?" + OPI_Tools.NumberToString(OrderNumber));
|
||||
|
||||
EndIf;
|
||||
|
||||
|
||||
Scheme["filter"].Add(MainStructure);
|
||||
|
||||
EndProcedure
|
||||
|
||||
Procedure AddSorting(Scheme, Val Field, Val Type)
|
||||
|
||||
OPI_TypeConversion.GetLine(Field);
|
||||
OPI_TypeConversion.GetLine(Type);
|
||||
|
||||
Scheme["order"].Add(New Structure("field,type", Field, Type));
|
||||
|
||||
EndProcedure
|
||||
|
||||
Procedure SetTableName(Scheme, Val Name)
|
||||
|
||||
OPI_TypeConversion.GetLine(Name);
|
||||
|
||||
Scheme.Insert("table", Name);
|
||||
|
||||
EndProcedure
|
||||
|
||||
Procedure SetLimit(Scheme, Val Count)
|
||||
|
||||
OPI_TypeConversion.GetNumber(Count);
|
||||
|
||||
Scheme.Insert("limit", Count);
|
||||
|
||||
EndProcedure
|
||||
|
||||
Procedure SetSelectOptions(Scheme, Val Fields, Val Filters, Val Sort, Val Count)
|
||||
|
||||
SetLimit(Scheme, Count);
|
||||
|
||||
FillFields(Scheme, Fields);
|
||||
FillFilters(Scheme, Filters);
|
||||
FillSorting(Scheme, Sort);
|
||||
|
||||
EndProcedure
|
||||
|
||||
#EndRegion
|
||||
|
||||
#EndRegion
|
||||
|
252
src/en/OPI/src/CommonModules/OPI_SQLite/Module.bsl
vendored
252
src/en/OPI/src/CommonModules/OPI_SQLite/Module.bsl
vendored
@ -98,6 +98,20 @@ Function CloseConnection(Val Connection) Export
|
||||
|
||||
EndFunction
|
||||
|
||||
// Is connector !NOCLI
|
||||
// Checks that the value is an object of a SQLite AddIn
|
||||
//
|
||||
// Parameters:
|
||||
// Value - Arbitrary - Value to check - value
|
||||
//
|
||||
// Returns:
|
||||
// Boolean - Is connector
|
||||
Function IsConnector(Val Value) Export
|
||||
|
||||
Return String(TypeOf(Value)) = "AddIn.OPI_SQLite.Main";
|
||||
|
||||
EndFunction
|
||||
|
||||
// Execute SQL query
|
||||
// Executes an arbitrary SQL query
|
||||
//
|
||||
@ -132,7 +146,7 @@ Function ExecuteSQLQuery(Val QueryText
|
||||
EndIf;
|
||||
|
||||
Result = Connector.Execute(QueryText, Parameters_, ForceResult);
|
||||
Result = OPI_Tools.JsonToStructure(Result, False);
|
||||
Result = OPI_Tools.JsonToStructure(Result);
|
||||
|
||||
Return Result;
|
||||
|
||||
@ -148,34 +162,13 @@ EndFunction
|
||||
// Parameters:
|
||||
// Table - String - Table name - table
|
||||
// ColoumnsStruct - Structure Of KeyAndValue - Column structure: Key > Name, Value > Data type - cols
|
||||
// NotExecute - Boolean - True > Does not execute the query, but returns SQL text - noex
|
||||
// Connection - String, Arbitrary - Existing connection or database path - db
|
||||
//
|
||||
// Returns:
|
||||
// Structure Of KeyAndValue, String - The result of the execution or SQL query text
|
||||
Function CreateTable(Val Table, Val ColoumnsStruct, Val NotExecute = False, Val Connection = "") Export
|
||||
|
||||
OPI_TypeConversion.GetBoolean(NotExecute);
|
||||
|
||||
ErrorText = "The column structure is not a valid key-value structure";
|
||||
OPI_TypeConversion.GetKeyValueCollection(ColoumnsStruct, ErrorText);
|
||||
|
||||
Scheme = OPI_SQLQueries.NewSQLScheme("CREATE");
|
||||
|
||||
OPI_SQLQueries.SetTableName(Scheme, Table);
|
||||
|
||||
For Each Coloumn In ColoumnsStruct Do
|
||||
OPI_SQLQueries.AddColoumn(Scheme, Coloumn.Key, Coloumn.Value);
|
||||
EndDo;
|
||||
|
||||
Request = OPI_SQLQueries.FormSQLText(Scheme);
|
||||
|
||||
If NotExecute Then
|
||||
Result = Request;
|
||||
Else
|
||||
Result = ExecuteSQLQuery(Request, , , Connection);
|
||||
EndIf;
|
||||
Function CreateTable(Val Table, Val ColoumnsStruct, Val Connection = "") Export
|
||||
|
||||
Result = OPI_SQLQueries.CreateTable(OPI_SQLite, Table, ColoumnsStruct, Connection);
|
||||
Return Result;
|
||||
|
||||
EndFunction
|
||||
@ -193,84 +186,8 @@ EndFunction
|
||||
// Structure Of KeyAndValue, String - Result of query execution
|
||||
Function AddRecords(Val Table, Val DataArray, Val Transaction = True, Val Connection = "") Export
|
||||
|
||||
OPI_TypeConversion.GetArray(DataArray);
|
||||
OPI_TypeConversion.GetBoolean(Transaction);
|
||||
|
||||
Connection = CreateConnection(Connection);
|
||||
|
||||
If Not IsConnector(Connection) Then
|
||||
Return Connection;
|
||||
EndIf;
|
||||
|
||||
If Transaction Then
|
||||
|
||||
Start = ExecuteSQLQuery("BEGIN TRANSACTION", , , Connection);
|
||||
|
||||
If Not Start["result"] Then
|
||||
Return Start;
|
||||
EndIf;
|
||||
|
||||
EndIf;
|
||||
|
||||
Counter = 0;
|
||||
SuccessCount = 0;
|
||||
|
||||
Error = False;
|
||||
ErrorsArray = New Array;
|
||||
CollectionError = "Invalid data";
|
||||
|
||||
ResultStrucutre = New Structure;
|
||||
|
||||
For Each Record In DataArray Do
|
||||
|
||||
If Error And Transaction Then
|
||||
|
||||
Rollback = ExecuteSQLQuery("ROLLBACK", , , Connection);
|
||||
|
||||
SuccessCount = 0;
|
||||
ResultStrucutre.Insert("rollback", Rollback);
|
||||
Break;
|
||||
|
||||
EndIf;
|
||||
|
||||
Counter = Counter + 1;
|
||||
Error = False;
|
||||
|
||||
Try
|
||||
OPI_TypeConversion.GetKeyValueCollection(Record, CollectionError);
|
||||
Except
|
||||
ErrorsArray.Add(New Structure("row,error", Counter, CollectionError));
|
||||
Error = True;
|
||||
Continue;
|
||||
EndTry;
|
||||
|
||||
Result = AddRow(Table, Record, Connection);
|
||||
|
||||
If Result["result"] Then
|
||||
|
||||
SuccessCount = SuccessCount + 1;
|
||||
|
||||
Else
|
||||
|
||||
ErrorsArray.Add(New Structure("row,error", Counter, Result["error"]));
|
||||
Error = True;
|
||||
|
||||
EndIf;
|
||||
|
||||
EndDo;
|
||||
|
||||
If Transaction And Not Error Then
|
||||
|
||||
Completion = ExecuteSQLQuery("COMMIT", , , Connection);
|
||||
ResultStrucutre.Insert("commit", Completion);
|
||||
|
||||
EndIf;
|
||||
|
||||
ResultStrucutre.Insert("result", ErrorsArray.Count() = 0);
|
||||
ResultStrucutre.Insert("rows" , SuccessCount);
|
||||
ResultStrucutre.Insert("errors", ErrorsArray);
|
||||
|
||||
Return ResultStrucutre;
|
||||
Result = OPI_SQLQueries.AddRecords(OPI_SQLite, Table, DataArray, Transaction, Connection);
|
||||
Return Result;
|
||||
|
||||
EndFunction
|
||||
|
||||
@ -294,19 +211,25 @@ Function GetRecords(Val Table
|
||||
, Val Count = ""
|
||||
, Val Connection = "") Export
|
||||
|
||||
Scheme = OPI_SQLQueries.NewSQLScheme("SELECT");
|
||||
Result = OPI_SQLQueries.GetRecords(OPI_SQLite, Table, Fields, Filters, Sort, Count, Connection);
|
||||
Return Result;
|
||||
|
||||
OPI_SQLQueries.SetTableName(Scheme, Table);
|
||||
OPI_SQLQueries.SetLimit(Scheme, Count);
|
||||
EndFunction
|
||||
|
||||
FillFields(Scheme, Fields);
|
||||
FillFilters(Scheme, Filters);
|
||||
FillSorting(Scheme, Sort);
|
||||
|
||||
Request = OPI_SQLQueries.FormSQLText(Scheme);
|
||||
|
||||
Result = ExecuteSQLQuery(Request, Scheme["values"], , Connection);
|
||||
// Update records
|
||||
// Updates the value of records by selected criteria
|
||||
//
|
||||
// Parameters:
|
||||
// Table - String - Table name - table
|
||||
// ValueStructure - Structure Of KeyAndValue - Values structure: Key > field, Value > field value - values
|
||||
// Filters - Array of Structure - Filters array. See GetRecordsFilterStrucutre - filter
|
||||
// Connection - String, Arbitrary - Existing connection or database path - db
|
||||
//
|
||||
// Returns:
|
||||
// Structure Of KeyAndValue, String - Result of query execution
|
||||
Function UpdateRecords(Val Table, Val ValueStructure, Val Filters = "", Val Connection = "") Export
|
||||
|
||||
Result = OPI_SQLQueries.UpdateRecords(OPI_SQLite, Table, ValueStructure, Filters, Connection);
|
||||
Return Result;
|
||||
|
||||
EndFunction
|
||||
@ -327,20 +250,7 @@ EndFunction
|
||||
// Structure Of KeyAndValue - Record filter element
|
||||
Function GetRecordsFilterStrucutre(Val Clear = False) Export
|
||||
|
||||
FilterStructure = New Structure;
|
||||
|
||||
FilterStructure.Insert("field", "<filtering field name>");
|
||||
FilterStructure.Insert("type" , "<comparison type>");
|
||||
FilterStructure.Insert("value", "<comparison value>");
|
||||
FilterStructure.Insert("union", "<connection with the following condition: AND, OR, etc..>");
|
||||
FilterStructure.Insert("raw" , "<true - the value will be inserted by text as it is, false - through the parameter>");
|
||||
|
||||
If Clear Then
|
||||
FilterStructure = OPI_Tools.ClearCollectionRecursively(FilterStructure);
|
||||
EndIf;
|
||||
|
||||
//@skip-check constructor-function-return-section
|
||||
Return FilterStructure;
|
||||
Return OPI_SQLQueries.GetRecordsFilterStrucutre(Clear);
|
||||
|
||||
EndFunction
|
||||
|
||||
@ -415,94 +325,4 @@ Function ProcessParameters(Val Parameters)
|
||||
|
||||
EndFunction
|
||||
|
||||
Function IsConnector(Val Value)
|
||||
|
||||
Return String(TypeOf(Value)) = "AddIn.OPI_SQLite.Main";
|
||||
|
||||
EndFunction
|
||||
|
||||
Function AddRow(Val Table, Val Record, Val Connection)
|
||||
|
||||
FieldArray = New Array;
|
||||
ValuesArray = New Array;
|
||||
|
||||
Scheme = OPI_SQLQueries.NewSQLScheme("INSERT");
|
||||
OPI_SQLQueries.SetTableName(Scheme, Table);
|
||||
|
||||
SplitDataCollection(Record, FieldArray, ValuesArray);
|
||||
|
||||
For Each Field In FieldArray Do
|
||||
OPI_SQLQueries.AddField(Scheme, Field);
|
||||
EndDo;
|
||||
|
||||
Request = OPI_SQLQueries.FormSQLText(Scheme);
|
||||
|
||||
Result = ExecuteSQLQuery(Request, ValuesArray, , Connection);
|
||||
|
||||
Return Result;
|
||||
|
||||
EndFunction
|
||||
|
||||
Procedure SplitDataCollection(Val Record, FieldArray, ValuesArray)
|
||||
|
||||
For Each Element In Record Do
|
||||
|
||||
FieldArray.Add(Element.Key);
|
||||
ValuesArray.Add(Element.Value);
|
||||
|
||||
EndDo;
|
||||
|
||||
EndProcedure
|
||||
|
||||
Procedure FillFields(Scheme, Val Fields)
|
||||
|
||||
If Not ValueIsFilled(Fields) Then
|
||||
Fields = "*";
|
||||
EndIf;
|
||||
|
||||
OPI_TypeConversion.GetArray(Fields);
|
||||
|
||||
For Each Field In Fields Do
|
||||
OPI_SQLQueries.AddField(Scheme, Field);
|
||||
EndDo;
|
||||
|
||||
EndProcedure
|
||||
|
||||
Procedure FillFilters(Scheme, Val Filters)
|
||||
|
||||
If Not ValueIsFilled(Filters) Then
|
||||
Return;
|
||||
EndIf;
|
||||
|
||||
OPI_TypeConversion.GetArray(Filters);
|
||||
|
||||
For Each Filter In Filters Do
|
||||
|
||||
OPI_SQLQueries.AddFilter(Scheme
|
||||
, Filter["field"]
|
||||
, ?(Filter.Property("type"), Filter["type"], "=")
|
||||
, Filter["value"]
|
||||
, ?(Filter.Property("union"), Filter["union"], "AND")
|
||||
, ?(Filter.Property("raw"), Filter["raw"], False));
|
||||
|
||||
EndDo;
|
||||
|
||||
EndProcedure
|
||||
|
||||
Procedure FillSorting(Val Scheme, Val Sort)
|
||||
|
||||
If Not ValueIsFilled(Sort) Then
|
||||
Return;
|
||||
EndIf;
|
||||
|
||||
OPI_TypeConversion.GetCollection(Sort);
|
||||
|
||||
For Each Element In Sort Do
|
||||
|
||||
OPI_SQLQueries.AddSorting(Scheme, Element.Key, Element.Value);
|
||||
|
||||
EndDo;
|
||||
|
||||
EndProcedure
|
||||
|
||||
#EndRegion
|
||||
|
@ -16250,13 +16250,10 @@ Procedure SQLite_CreateTable(FunctionParameters)
|
||||
ColoumnsStruct.Insert("created_at", "DATETIME");
|
||||
ColoumnsStruct.Insert("data" , "BLOB");
|
||||
|
||||
Result = OPI_SQLite.CreateTable(Table, ColoumnsStruct, , Base);
|
||||
Result = OPI_SQLite.CreateTable(Table, ColoumnsStruct, Base);
|
||||
|
||||
// END
|
||||
|
||||
Text = OPI_SQLite.CreateTable(Table, ColoumnsStruct, True, Base);
|
||||
OPI_TestDataRetrieval.WriteLog(Text, "CreateTable (query)", "SQLite");
|
||||
|
||||
OPI_TestDataRetrieval.WriteLog(Result, "CreateTable", "SQLite");
|
||||
OPI_TestDataRetrieval.Check_SQLiteSuccess(Result);
|
||||
|
||||
@ -16264,7 +16261,7 @@ Procedure SQLite_CreateTable(FunctionParameters)
|
||||
ColoumnsMap.Insert("id" , "INTEGER PRIMARY KEY");
|
||||
ColoumnsMap.Insert("[An obscure column]", "TEXT");
|
||||
|
||||
Result = OPI_SQLite.CreateTable("test1", ColoumnsMap, , Base);
|
||||
Result = OPI_SQLite.CreateTable("test1", ColoumnsMap, Base);
|
||||
|
||||
OPI_TestDataRetrieval.WriteLog(Result, "CreateTable (obscure column)", "SQLite");
|
||||
OPI_TestDataRetrieval.Check_SQLiteSuccess(Result);
|
||||
|
@ -72,16 +72,6 @@
|
||||
NewLine.Область = "Orm";
|
||||
|
||||
|
||||
NewLine = CompositionTable.Add();
|
||||
NewLine.Библиотека = "sqlite";
|
||||
NewLine.Модуль = "OPI_SQLite";
|
||||
NewLine.Метод = "CreateTable";
|
||||
NewLine.МетодПоиска = "CREATETABLE";
|
||||
NewLine.Параметр = "--noex";
|
||||
NewLine.Описание = "True > Does not execute the query, but returns SQL text (optional, def. val. - No)";
|
||||
NewLine.Область = "Orm";
|
||||
|
||||
|
||||
NewLine = CompositionTable.Add();
|
||||
NewLine.Библиотека = "sqlite";
|
||||
NewLine.Модуль = "OPI_SQLite";
|
||||
@ -194,6 +184,47 @@
|
||||
NewLine.Область = "Orm";
|
||||
|
||||
|
||||
NewLine = CompositionTable.Add();
|
||||
NewLine.Библиотека = "sqlite";
|
||||
NewLine.Модуль = "OPI_SQLite";
|
||||
NewLine.Метод = "UpdateRecords";
|
||||
NewLine.МетодПоиска = "UPDATERECORDS";
|
||||
NewLine.Параметр = "--table";
|
||||
NewLine.Описание = "Table name";
|
||||
NewLine.Область = "Orm";
|
||||
NewLine.ОписаниеМетода = "Updates the value of records by selected criteria";
|
||||
|
||||
|
||||
NewLine = CompositionTable.Add();
|
||||
NewLine.Библиотека = "sqlite";
|
||||
NewLine.Модуль = "OPI_SQLite";
|
||||
NewLine.Метод = "UpdateRecords";
|
||||
NewLine.МетодПоиска = "UPDATERECORDS";
|
||||
NewLine.Параметр = "--values";
|
||||
NewLine.Описание = "Values structure: Key > field, Value > field value";
|
||||
NewLine.Область = "Orm";
|
||||
|
||||
|
||||
NewLine = CompositionTable.Add();
|
||||
NewLine.Библиотека = "sqlite";
|
||||
NewLine.Модуль = "OPI_SQLite";
|
||||
NewLine.Метод = "UpdateRecords";
|
||||
NewLine.МетодПоиска = "UPDATERECORDS";
|
||||
NewLine.Параметр = "--filter";
|
||||
NewLine.Описание = "Filters array. See GetRecordsFilterStrucutre (optional, def. val. - Empty value)";
|
||||
NewLine.Область = "Orm";
|
||||
|
||||
|
||||
NewLine = CompositionTable.Add();
|
||||
NewLine.Библиотека = "sqlite";
|
||||
NewLine.Модуль = "OPI_SQLite";
|
||||
NewLine.Метод = "UpdateRecords";
|
||||
NewLine.МетодПоиска = "UPDATERECORDS";
|
||||
NewLine.Параметр = "--db";
|
||||
NewLine.Описание = "Existing connection or database path (optional, def. val. - Empty value)";
|
||||
NewLine.Область = "Orm";
|
||||
|
||||
|
||||
NewLine = CompositionTable.Add();
|
||||
NewLine.Библиотека = "sqlite";
|
||||
NewLine.Модуль = "OPI_SQLite";
|
||||
|
14
src/ru/OInt/core/Modules/OPI_SQLite.os
vendored
14
src/ru/OInt/core/Modules/OPI_SQLite.os
vendored
@ -100,10 +100,10 @@
|
||||
|
||||
// Это коннектор !NOCLI
|
||||
// Проверяет, что значение является объектом внешней компоненты SQLite
|
||||
//
|
||||
//
|
||||
// Параметры:
|
||||
// Значение - Произвольный - Значение для проверки - value
|
||||
//
|
||||
// Значение - Произвольный - Значение для проверки - value
|
||||
//
|
||||
// Возвращаемое значение:
|
||||
// Булево - Это коннектор
|
||||
Функция ЭтоКоннектор(Знач Значение) Экспорт
|
||||
@ -188,7 +188,7 @@
|
||||
|
||||
Результат = OPI_ЗапросыSQL.ДобавитьЗаписи(OPI_SQLite, Таблица, МассивДанных, Транзакция, Соединение);
|
||||
Возврат Результат;
|
||||
|
||||
|
||||
КонецФункции
|
||||
|
||||
// Получить записи
|
||||
@ -218,7 +218,7 @@
|
||||
|
||||
// Обновить записи
|
||||
// Обновляет значение записей по выбранным критериям
|
||||
//
|
||||
//
|
||||
// Параметры:
|
||||
// Таблица - Строка - Имя таблицы - table
|
||||
// СтруктураЗначений - Структура Из КлючИЗначение - Структура значений: Ключ > поле, Значение > значение поля - values
|
||||
@ -228,10 +228,10 @@
|
||||
// Возвращаемое значение:
|
||||
// Структура Из КлючИЗначение, Строка - Результат выполнения запроса
|
||||
Функция ОбновитьЗаписи(Знач Таблица, Знач СтруктураЗначений, Знач Фильтры = "", Знач Соединение = "") Экспорт
|
||||
|
||||
|
||||
Результат = OPI_ЗапросыSQL.ОбновитьЗаписи(OPI_SQLite, Таблица, СтруктураЗначений, Фильтры, Соединение);
|
||||
Возврат Результат;
|
||||
|
||||
|
||||
КонецФункции
|
||||
|
||||
// Получить структуру фильтра записей
|
||||
|
@ -2119,9 +2119,9 @@
|
||||
КонецФункции
|
||||
|
||||
Функция ПолучитьОбщийМодуль(Знач Имя)
|
||||
|
||||
|
||||
Модуль = Вычислить(Имя);
|
||||
|
||||
|
||||
Возврат Модуль;
|
||||
КонецФункции
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
// OneScript: ./OInt/core/Modules/OPI_SQLite.os
|
||||
// OneScript: ./OInt/core/Modules/OPI_SQLite.os
|
||||
// Lib: SQLite
|
||||
// CLI: sqlite
|
||||
|
||||
@ -100,10 +100,10 @@
|
||||
|
||||
// Это коннектор !NOCLI
|
||||
// Проверяет, что значение является объектом внешней компоненты SQLite
|
||||
//
|
||||
//
|
||||
// Параметры:
|
||||
// Значение - Произвольный - Значение для проверки - value
|
||||
//
|
||||
// Значение - Произвольный - Значение для проверки - value
|
||||
//
|
||||
// Возвращаемое значение:
|
||||
// Булево - Это коннектор
|
||||
Функция ЭтоКоннектор(Знач Значение) Экспорт
|
||||
@ -188,7 +188,7 @@
|
||||
|
||||
Результат = OPI_ЗапросыSQL.ДобавитьЗаписи(OPI_SQLite, Таблица, МассивДанных, Транзакция, Соединение);
|
||||
Возврат Результат;
|
||||
|
||||
|
||||
КонецФункции
|
||||
|
||||
// Получить записи
|
||||
@ -218,7 +218,7 @@
|
||||
|
||||
// Обновить записи
|
||||
// Обновляет значение записей по выбранным критериям
|
||||
//
|
||||
//
|
||||
// Параметры:
|
||||
// Таблица - Строка - Имя таблицы - table
|
||||
// СтруктураЗначений - Структура Из КлючИЗначение - Структура значений: Ключ > поле, Значение > значение поля - values
|
||||
@ -228,10 +228,10 @@
|
||||
// Возвращаемое значение:
|
||||
// Структура Из КлючИЗначение, Строка - Результат выполнения запроса
|
||||
Функция ОбновитьЗаписи(Знач Таблица, Знач СтруктураЗначений, Знач Фильтры = "", Знач Соединение = "") Экспорт
|
||||
|
||||
|
||||
Результат = OPI_ЗапросыSQL.ОбновитьЗаписи(OPI_SQLite, Таблица, СтруктураЗначений, Фильтры, Соединение);
|
||||
Возврат Результат;
|
||||
|
||||
|
||||
КонецФункции
|
||||
|
||||
// Получить структуру фильтра записей
|
||||
|
@ -1,4 +1,4 @@
|
||||
// OneScript: ./OInt/tools/Modules/os
|
||||
// OneScript: ./OInt/tools/Modules/os
|
||||
|
||||
// MIT License
|
||||
|
||||
@ -151,13 +151,13 @@
|
||||
|
||||
Функция ПолучитьЗаписи(Знач Модуль
|
||||
, Знач Таблица
|
||||
, Знач Поля = "*"
|
||||
, Знач Фильтры = ""
|
||||
, Знач Поля = "*"
|
||||
, Знач Фильтры = ""
|
||||
, Знач Сортировка = ""
|
||||
, Знач Количество = ""
|
||||
, Знач Соединение = "") Экспорт
|
||||
|
||||
Схема = ПустаяСхемаSQL("SELECT");
|
||||
Схема = ПустаяСхемаSQL("SELECT");
|
||||
|
||||
УстановитьИмяТаблицы(Схема, Таблица);
|
||||
УстановитьНастройкиSelect(Схема, Поля, Фильтры, Сортировка, Количество);
|
||||
@ -173,18 +173,18 @@
|
||||
Функция ОбновитьЗаписи(Знач Модуль
|
||||
, Знач Таблица
|
||||
, Знач МассивЗначений
|
||||
, Знач Фильтры = ""
|
||||
, Знач Фильтры = ""
|
||||
, Знач Соединение = "") Экспорт
|
||||
|
||||
Схема = ПустаяСхемаSQL("UPDATE");
|
||||
|
||||
|
||||
Схема = ПустаяСхемаSQL("UPDATE");
|
||||
|
||||
УстановитьИмяТаблицы(Схема, Таблица);
|
||||
|
||||
|
||||
Запрос = СформироватьТекстSQL(Схема);
|
||||
Результат = Модуль.ВыполнитьЗапросSQL(Запрос, Схема["values"], , Соединение);
|
||||
|
||||
Возврат Результат;
|
||||
|
||||
|
||||
КонецФункции
|
||||
|
||||
Функция ПолучитьСтруктуруФильтраЗаписей(Знач Пустая = Ложь) Экспорт
|
||||
@ -242,9 +242,9 @@
|
||||
|
||||
Схема = Новый Структура("type", "UPDATE");
|
||||
|
||||
Схема.Вставить("table" , "");
|
||||
Схема.Вставить("set" , Новый Массив);
|
||||
Схема.Вставить("filter", Новый Массив);
|
||||
Схема.Вставить("table" , "");
|
||||
Схема.Вставить("set" , Новый Массив);
|
||||
Схема.Вставить("filter" , Новый Массив);
|
||||
Схема.Вставить("values" , Новый Массив);
|
||||
|
||||
Возврат Схема;
|
||||
@ -722,7 +722,7 @@
|
||||
ЗаполнитьПоля(Схема, Поля);
|
||||
ЗаполнитьФильтры(Схема, Фильтры);
|
||||
ЗаполнитьСортировку(Схема, Сортировка);
|
||||
|
||||
|
||||
КонецПроцедуры
|
||||
|
||||
#КонецОбласти
|
||||
|
@ -1,4 +1,4 @@
|
||||
// OneScript: ./OInt/tools/Modules/internal/Modules/OPI_Инструменты.os
|
||||
// OneScript: ./OInt/tools/Modules/internal/Modules/OPI_Инструменты.os
|
||||
|
||||
// MIT License
|
||||
|
||||
|
@ -76,16 +76,6 @@
|
||||
НоваяСтрока.Область = "Orm";
|
||||
|
||||
|
||||
НоваяСтрока = ТаблицаСостава.Добавить();
|
||||
НоваяСтрока.Библиотека = "sqlite";
|
||||
НоваяСтрока.Модуль = "OPI_SQLite";
|
||||
НоваяСтрока.Метод = "СоздатьТаблицу";
|
||||
НоваяСтрока.МетодПоиска = "СОЗДАТЬТАБЛИЦУ";
|
||||
НоваяСтрока.Параметр = "--noex";
|
||||
НоваяСтрока.Описание = "Истина > Не выполняет запрос, а возвращает текст SQL (необяз. по ум. - Нет)";
|
||||
НоваяСтрока.Область = "Orm";
|
||||
|
||||
|
||||
НоваяСтрока = ТаблицаСостава.Добавить();
|
||||
НоваяСтрока.Библиотека = "sqlite";
|
||||
НоваяСтрока.Модуль = "OPI_SQLite";
|
||||
@ -206,6 +196,51 @@
|
||||
НоваяСтрока.Область = "Orm";
|
||||
|
||||
|
||||
НоваяСтрока = ТаблицаСостава.Добавить();
|
||||
НоваяСтрока.Библиотека = "sqlite";
|
||||
НоваяСтрока.Модуль = "OPI_SQLite";
|
||||
НоваяСтрока.Метод = "ОбновитьЗаписи";
|
||||
НоваяСтрока.МетодПоиска = "ОБНОВИТЬЗАПИСИ";
|
||||
НоваяСтрока.Параметр = "--table";
|
||||
НоваяСтрока.Описание = "Имя таблицы";
|
||||
НоваяСтрока.Область = "Orm";
|
||||
НоваяСтрока.ОписаниеМетода = "Обновляет значение записей по выбранным критериям
|
||||
|
|
||||
| Пример указания параметра типа массив:
|
||||
| --param ""['Val1','Val2','Val3']""
|
||||
|";
|
||||
|
||||
|
||||
НоваяСтрока = ТаблицаСостава.Добавить();
|
||||
НоваяСтрока.Библиотека = "sqlite";
|
||||
НоваяСтрока.Модуль = "OPI_SQLite";
|
||||
НоваяСтрока.Метод = "ОбновитьЗаписи";
|
||||
НоваяСтрока.МетодПоиска = "ОБНОВИТЬЗАПИСИ";
|
||||
НоваяСтрока.Параметр = "--values";
|
||||
НоваяСтрока.Описание = "Структура значений: Ключ > поле, Значение > значение поля";
|
||||
НоваяСтрока.Область = "Orm";
|
||||
|
||||
|
||||
НоваяСтрока = ТаблицаСостава.Добавить();
|
||||
НоваяСтрока.Библиотека = "sqlite";
|
||||
НоваяСтрока.Модуль = "OPI_SQLite";
|
||||
НоваяСтрока.Метод = "ОбновитьЗаписи";
|
||||
НоваяСтрока.МетодПоиска = "ОБНОВИТЬЗАПИСИ";
|
||||
НоваяСтрока.Параметр = "--filter";
|
||||
НоваяСтрока.Описание = "Массив фильтров. См. ПолучитьСтруктуруФильтраЗаписей (необяз. по ум. - Пустое значение)";
|
||||
НоваяСтрока.Область = "Orm";
|
||||
|
||||
|
||||
НоваяСтрока = ТаблицаСостава.Добавить();
|
||||
НоваяСтрока.Библиотека = "sqlite";
|
||||
НоваяСтрока.Модуль = "OPI_SQLite";
|
||||
НоваяСтрока.Метод = "ОбновитьЗаписи";
|
||||
НоваяСтрока.МетодПоиска = "ОБНОВИТЬЗАПИСИ";
|
||||
НоваяСтрока.Параметр = "--db";
|
||||
НоваяСтрока.Описание = "Существующее соединение или путь к базе (необяз. по ум. - Пустое значение)";
|
||||
НоваяСтрока.Область = "Orm";
|
||||
|
||||
|
||||
НоваяСтрока = ТаблицаСостава.Добавить();
|
||||
НоваяСтрока.Библиотека = "sqlite";
|
||||
НоваяСтрока.Модуль = "OPI_SQLite";
|
||||
|
Loading…
Reference in New Issue
Block a user