Skip to content

Commit f13e36d

Browse files
authored
Merge pull request #34 from ret-Phoenix/dev
Переработал определение статуса соединения.
2 parents 7690391 + dcfca9d commit f13e36d

File tree

4 files changed

+122
-33
lines changed

4 files changed

+122
-33
lines changed

docs/Соединение.md

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,23 @@
5757
### Открыто / IsOpen
5858
Доступ: Чтение
5959

60+
Тип значения: Булево
61+
62+
Статус соединения с БД: Открыто - Истина, Закрыто - Ложь.
63+
64+
### Состояние / State
65+
Доступ: Чтение
66+
6067
Тип значения: ConnectionState
6168

62-
Статус соединения с БД
69+
Состояние соединения:
70+
71+
- Closed - Закрыто.
72+
- Open - Открыто.
73+
- Connecting - Соединяется с источником.
74+
- Executing - Выполняет команду
75+
- Fetching - Получает данные
76+
- Broken - Соединение оборвано.
6377

6478
### ПоследнееСообщениеОбОшибке / LastErrorMessage
6579
Доступ: Чтение

oscript-sql/DBConnector.cs

Lines changed: 39 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,7 @@ public DBConnector()
4343
_password = "";
4444
_connectionString = "";
4545
_lastErrorMessage = "";
46-
47-
46+
_connection = null;
4847
}
4948

5049
public override string ToString()
@@ -180,13 +179,48 @@ public string Password
180179
/// <summary>
181180
/// Статус соединения с БД
182181
/// </summary>
183-
/// <value>ConnectionState</value>
182+
/// <value>Булево</value>
184183
[ContextProperty("Открыто", "IsOpen")]
185-
public string IsOpen
184+
public bool IsOpen
186185
{
187186
get
188187
{
189-
return Connection.State.ToString();
188+
if ((_connection == null))
189+
{
190+
return false;
191+
}
192+
193+
switch (_connection.State)
194+
{
195+
case ConnectionState.Broken: return false;
196+
case ConnectionState.Closed: return false;
197+
case ConnectionState.Connecting: return false;
198+
default: return true;
199+
}
200+
201+
}
202+
}
203+
204+
/// <summary>
205+
/// Состояние соединения:
206+
///
207+
/// - Closed - Закрыто.
208+
/// - Open - Открыто.
209+
/// - Connecting - Соединяется с источником.
210+
/// - Executing - Выполняет команду
211+
/// - Fetching - Получает данные
212+
/// - Broken - Соединение оборвано.
213+
/// </summary>
214+
[ContextProperty("Состояние", "State")]
215+
public string State
216+
{
217+
get
218+
{
219+
if ((_connection == null))
220+
{
221+
return "Closed";
222+
}
223+
return _connection.State.ToString();
190224
}
191225
}
192226

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,27 @@
1-
using System.Reflection;
2-
using System.Runtime.CompilerServices;
3-
4-
// Information about this assembly is defined by the following attributes.
5-
// Change them to the values specific to your project.
6-
7-
[assembly: AssemblyTitle("oscript-sql")]
8-
[assembly: AssemblyDescription("")]
9-
[assembly: AssemblyConfiguration("")]
10-
[assembly: AssemblyCompany("")]
11-
[assembly: AssemblyProduct("")]
12-
[assembly: AssemblyCopyright("ret-Phoenix")]
13-
[assembly: AssemblyTrademark("")]
14-
[assembly: AssemblyCulture("")]
15-
16-
// The assembly version has the format "{Major}.{Minor}.{Build}.{Revision}".
17-
// The form "{Major}.{Minor}.*" will automatically update the build and revision,
18-
// and "{Major}.{Minor}.{Build}.*" will update just the revision.
19-
20-
[assembly: AssemblyVersion("1.0.*")]
21-
22-
// The following attributes are used to specify the signing key for the assembly,
23-
// if desired. See the Mono documentation for more information about signing.
24-
25-
//[assembly: AssemblyDelaySign(false)]
26-
//[assembly: AssemblyKeyFile("")]
27-
1+
using System.Reflection;
2+
using System.Runtime.CompilerServices;
3+
4+
// Information about this assembly is defined by the following attributes.
5+
// Change them to the values specific to your project.
6+
7+
[assembly: AssemblyTitle("oscript-sql")]
8+
[assembly: AssemblyDescription("")]
9+
[assembly: AssemblyConfiguration("")]
10+
[assembly: AssemblyCompany("")]
11+
[assembly: AssemblyProduct("")]
12+
[assembly: AssemblyCopyright("ret-Phoenix")]
13+
[assembly: AssemblyTrademark("")]
14+
[assembly: AssemblyCulture("")]
15+
16+
// The assembly version has the format "{Major}.{Minor}.{Build}.{Revision}".
17+
// The form "{Major}.{Minor}.*" will automatically update the build and revision,
18+
// and "{Major}.{Minor}.{Build}.*" will update just the revision.
19+
20+
[assembly: AssemblyVersion("1.1.0.0")]
21+
22+
// The following attributes are used to specify the signing key for the assembly,
23+
// if desired. See the Mono documentation for more information about signing.
24+
25+
//[assembly: AssemblyDelaySign(false)]
26+
//[assembly: AssemblyKeyFile("")]
27+

tests/test-sqlite.os

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@
1212
юТест = Тестирование;
1313

1414
СписокТестов = Новый Массив;
15+
СписокТестов.Добавить("Тест_Должен_ПроверитьСоединениеОткрыто");
16+
СписокТестов.Добавить("Тест_Должен_ПроверитьСоединениеЗакрыто");
17+
СписокТестов.Добавить("Тест_Должен_ВернутьСтатусОткрыто");
18+
СписокТестов.Добавить("Тест_Должен_ВернутьСтатусЗакрыто");
1519
СписокТестов.Добавить("Тест_Должен_СоздатьБД");
1620
СписокТестов.Добавить("Тест_Должен_СоздатьТаблицу");
1721
СписокТестов.Добавить("Тест_Должен_ДобавитьСтроки");
@@ -26,6 +30,43 @@
2630

2731
КонецФункции
2832

33+
Процедура Тест_Должен_ПроверитьСоединениеОткрыто() Экспорт
34+
Соединение = Новый Соединение();
35+
Соединение.ТипСУБД = Соединение.ТипыСУБД.sqlite;
36+
Соединение.ИмяБазы = ":memory:";
37+
Соединение.Открыть();
38+
Ожидаем.Что(Соединение.Открыто).ЭтоИстина();
39+
Соединение.Закрыть();
40+
КонецПроцедуры
41+
42+
Процедура Тест_Должен_ПроверитьСоединениеЗакрыто() Экспорт
43+
Соединение = Новый Соединение();
44+
Соединение.ТипСУБД = Соединение.ТипыСУБД.sqlite;
45+
Соединение.ИмяБазы = ":memory:";
46+
Соединение.Открыть();
47+
Соединение.Закрыть();
48+
Ожидаем.Что(Соединение.Открыто).ЭтоЛожь();
49+
КонецПроцедуры
50+
51+
Процедура Тест_Должен_ВернутьСтатусОткрыто() Экспорт
52+
Соединение = Новый Соединение();
53+
Соединение.ТипСУБД = Соединение.ТипыСУБД.sqlite;
54+
Соединение.ИмяБазы = ":memory:";
55+
Соединение.Открыть();
56+
Ожидаем.Что(Соединение.Состояние).Равно("Open");
57+
Соединение.Закрыть();
58+
КонецПроцедуры
59+
60+
Процедура Тест_Должен_ВернутьСтатусЗакрыто() Экспорт
61+
Соединение = Новый Соединение();
62+
Соединение.ТипСУБД = Соединение.ТипыСУБД.sqlite;
63+
Соединение.ИмяБазы = ":memory:";
64+
Соединение.Открыть();
65+
Соединение.Закрыть();
66+
Ожидаем.Что(Соединение.Состояние).Равно("Closed");
67+
КонецПроцедуры
68+
69+
2970
Процедура Тест_Должен_СоздатьБД() Экспорт
3071

3172
ФайлБД = Новый Файл("fixtures\test.sqlite");

0 commit comments

Comments
 (0)