Skip to content

Commit

Permalink
Merge pull request #20 from ret-Phoenix/issues_19
Browse files Browse the repository at this point in the history
Теперь метод Open всегда возвращает результат Истина/Ложь.
  • Loading branch information
ret-Phoenix authored Sep 12, 2017
2 parents 4889055 + b868529 commit 925e8dc
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 29 deletions.
37 changes: 21 additions & 16 deletions oscript-sql/DBConnector.cs
Original file line number Diff line number Diff line change
Expand Up @@ -239,17 +239,8 @@ public bool Open()
}
_connection = new SQLiteConnection(string.Format("Data Source={0};", filePath));
if (System.IO.File.Exists(DbName))
{
try
{
_connection.Open();
return true;
}
catch (Exception e)
{
Console.WriteLine(e.Message);
return false;
}
{
return OpenConnection();

}
else
Expand Down Expand Up @@ -292,7 +283,7 @@ public bool Open()
_connection.ConnectionString = _connectionString;
}

_connection.Open();
return OpenConnection();
}
else if (DbType == (new EnumDBType()).MySQL)
{
Expand All @@ -306,7 +297,7 @@ public bool Open()
_connectionString += (_port != 0 ? "port=" + _port.ToString() + ";" : "");
}
_connection = new MySqlConnection(_connectionString);
_connection.Open();
return OpenConnection();
}
else if (DbType == (new EnumDBType()).PostgreSQL)
{
Expand All @@ -320,11 +311,25 @@ public bool Open()
_connectionString += (_port != 0 ? "port=" + _port.ToString() + ";" : "");
}
_connection = new NpgsqlConnection(_connectionString);
_connection.Open();
return OpenConnection();
}
return false;
}

}

private bool OpenConnection()
{
try
{
_connection.Open();
return true;
}
catch (Exception e)
{
Console.WriteLine(e.Message);
return false;
}
}

/// <summary>
/// Закрыть соединение с БД
/// </summary>
Expand Down
16 changes: 6 additions & 10 deletions oscript-sql/oscript-sql.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -68,21 +68,18 @@
<HintPath>..\packages\MySql.Data.6.9.9\lib\net45\MySql.Data.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Newtonsoft.Json, Version=9.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<HintPath>..\packages\Newtonsoft.Json.9.0.1\lib\net45\Newtonsoft.Json.dll</HintPath>
<Private>True</Private>
<Reference Include="Newtonsoft.Json, Version=10.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<HintPath>..\packages\Newtonsoft.Json.10.0.3\lib\net45\Newtonsoft.Json.dll</HintPath>
</Reference>
<Reference Include="Npgsql, Version=3.1.9.0, Culture=neutral, PublicKeyToken=5d8b90d52f46fda7, processorArchitecture=MSIL">
<HintPath>..\packages\Npgsql.3.1.9\lib\net45\Npgsql.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="ScriptEngine, Version=1.0.15.260, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\OneScript.1.0.15\lib\net40\ScriptEngine.dll</HintPath>
<Private>True</Private>
<Reference Include="ScriptEngine, Version=1.0.17.95, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\OneScript.1.0.17\lib\net40\ScriptEngine.dll</HintPath>
</Reference>
<Reference Include="ScriptEngine.HostedScript, Version=1.0.15.260, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\OneScript.StandardLibrary.1.0.15\lib\net40\ScriptEngine.HostedScript.dll</HintPath>
<Private>True</Private>
<Reference Include="ScriptEngine.HostedScript, Version=1.0.17.95, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\OneScript.StandardLibrary.1.0.17\lib\net40\ScriptEngine.HostedScript.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.ComponentModel.DataAnnotations" />
Expand Down Expand Up @@ -110,7 +107,6 @@
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<ItemGroup>
<None Include="app.config" />
<None Include="packages.config" />
</ItemGroup>
<Import Project="..\packages\System.Data.SQLite.Core.1.0.104.0\build\net45\System.Data.SQLite.Core.targets" Condition="Exists('..\packages\System.Data.SQLite.Core.1.0.104.0\build\net45\System.Data.SQLite.Core.targets')" />
Expand Down
6 changes: 3 additions & 3 deletions oscript-sql/packages.config
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
<package id="DotNetZip" version="1.10.1" targetFramework="net45" />
<package id="EntityFramework" version="6.0.0" targetFramework="net45" />
<package id="MySql.Data" version="6.9.9" targetFramework="net45" />
<package id="Newtonsoft.Json" version="9.0.1" targetFramework="net45" />
<package id="Newtonsoft.Json" version="10.0.3" targetFramework="net45" />
<package id="Npgsql" version="3.1.9" targetFramework="net45" />
<package id="OneScript" version="1.0.15" targetFramework="net45" />
<package id="OneScript.StandardLibrary" version="1.0.15" targetFramework="net45" />
<package id="OneScript" version="1.0.17" targetFramework="net45" />
<package id="OneScript.StandardLibrary" version="1.0.17" targetFramework="net45" />
<package id="System.Data.SQLite" version="1.0.104.0" targetFramework="net45" />
<package id="System.Data.SQLite.Core" version="1.0.104.0" targetFramework="net45" />
<package id="System.Data.SQLite.EF6" version="1.0.104.0" targetFramework="net45" />
Expand Down
16 changes: 16 additions & 0 deletions tests/test-ms-sql-server.os
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
юТест = Тестирование;

СписокТестов = Новый Массив;
СписокТестов.Добавить("Тест_Должен_ПроверитьСоединение" + СуфикМетодов);
СписокТестов.Добавить("Тест_Должен_СоздатьТаблицу" + СуфикМетодов);
СписокТестов.Добавить("Тест_Должен_ДобавитьСтроки" + СуфикМетодов);
СписокТестов.Добавить("Тест_Должен_ДолженИзменитьСтроки" + СуфикМетодов);
Expand All @@ -41,6 +42,21 @@

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

Процедура Тест_Должен_ПроверитьСоединение() Экспорт
СтрокаСоединения = ПолучитьТекстИзФайла("fixtures\ms-sql-server-con-str.txt");

Соединение = Новый Соединение();
Соединение.ТипСУБД = Соединение.ТипыСУБД.MSSQLServer;
Соединение.СтрокаСоединения = СтрокаСоединения;

Результат = Соединение.Открыть();

Ожидаем.Что(Результат).Равно(Результат);

Соединение.Закрыть();

КонецПроцедуры

Процедура Тест_Должен_СоздатьТаблицу() Экспорт

СтрокаСоединения = ПолучитьТекстИзФайла("fixtures\ms-sql-server-con-str.txt");
Expand Down

0 comments on commit 925e8dc

Please sign in to comment.