Let's be Mono friendly

This is a massive overhaul that replaces System.Data.SQLite with Mono.Data.Sqlite. This should make it more compatible with Linux and Mac and has no known downsides for Windows.
This commit is contained in:
Matt Nadareski
2016-04-20 17:02:15 -07:00
parent ac575438a1
commit 39b66ed8a1
154 changed files with 79824 additions and 212766 deletions

View File

@@ -1,26 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<configSections>
<section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
<!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
</configSections>
<entityFramework>
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework">
<parameters>
<parameter value="v12.0" />
</parameters>
</defaultConnectionFactory>
<providers>
<provider invariantName="System.Data.SQLite.EF6" type="System.Data.SQLite.EF6.SQLiteProviderServices, System.Data.SQLite.EF6" />
<provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
</providers>
</entityFramework>
<system.data>
<DbProviderFactories>
<remove invariant="System.Data.SQLite.EF6" />
<add name="SQLite Data Provider (Entity Framework 6)" invariant="System.Data.SQLite.EF6" description=".NET Framework Data Provider for SQLite (Entity Framework 6)" type="System.Data.SQLite.EF6.SQLiteProviderFactory, System.Data.SQLite.EF6" />
<remove invariant="System.Data.SQLite" />
<add name="SQLite Data Provider" invariant="System.Data.SQLite" description=".NET Framework Data Provider for SQLite" type="System.Data.SQLite.SQLiteFactory, System.Data.SQLite" />
</DbProviderFactories>
</system.data>
</configuration>

View File

@@ -1,5 +1,5 @@
using System;
using System.Data.SQLite;
using Mono.Data.Sqlite;
using System.IO;
namespace SabreTools.Helper
@@ -19,14 +19,14 @@ namespace SabreTools.Helper
// Make sure the file exists
if (!File.Exists(db))
{
SQLiteConnection.CreateFile(db);
SqliteConnection.CreateFile(db);
}
//Get "type" from the filename
string type = Path.GetFileNameWithoutExtension(db);
// Connect to the file
SQLiteConnection dbc = new SQLiteConnection(connectionString);
SqliteConnection dbc = new SqliteConnection(connectionString);
dbc.Open();
// Make sure the database has the correct schema
@@ -43,7 +43,7 @@ CREATE TABLE IF NOT EXISTS checksums (
'sha1' TEXT NOT NULL,
PRIMARY KEY (file, size, crc, md5, sha1)
)";
SQLiteCommand slc = new SQLiteCommand(query, dbc);
SqliteCommand slc = new SqliteCommand(query, dbc);
slc.ExecuteNonQuery();
query = @"
@@ -54,7 +54,7 @@ CREATE TABLE IF NOT EXISTS files (
'type' TEXT NOT NULL DEFAULT 'rom',
'lastupdated' TEXT NOT NULL
)";
slc = new SQLiteCommand(query, dbc);
slc = new SqliteCommand(query, dbc);
slc.ExecuteNonQuery();
query = @"
@@ -65,7 +65,7 @@ CREATE TABLE IF NOT EXISTS games (
'parent' INTEGER NOT NULL DEFAULT '0',
'source' INTEGER NOT NULL DEFAULT '0'
)";
slc = new SQLiteCommand(query, dbc);
slc = new SqliteCommand(query, dbc);
slc.ExecuteNonQuery();
query = @"
@@ -73,7 +73,7 @@ CREATE TABLE IF NOT EXISTS parent (
'id' INTEGER PRIMARY KEY NOT NULL,
'name' TEXT NOT NULL
)";
slc = new SQLiteCommand(query, dbc);
slc = new SqliteCommand(query, dbc);
slc.ExecuteNonQuery();
query = @"
@@ -82,7 +82,7 @@ CREATE TABLE IF NOT EXISTS sources (
'name' TEXT NOT NULL UNIQUE,
'url' TEXT NOT NULL
)";
slc = new SQLiteCommand(query, dbc);
slc = new SqliteCommand(query, dbc);
slc.ExecuteNonQuery();
query = @"
@@ -91,7 +91,7 @@ CREATE TABLE IF NOT EXISTS systems (
'manufacturer' TEXT NOT NULL,
'system' TEXT NOT NULL
)";
slc = new SQLiteCommand(query, dbc);
slc = new SqliteCommand(query, dbc);
slc.ExecuteNonQuery();
}
else if (type == "Headerer")
@@ -103,7 +103,7 @@ CREATE TABLE IF NOT EXISTS data (
'type' TEXT NOT NULL,
PRIMARY KEY (sha1, header, type)
)";
SQLiteCommand slc = new SQLiteCommand(query, dbc);
SqliteCommand slc = new SqliteCommand(query, dbc);
slc.ExecuteNonQuery();
}
}
@@ -128,18 +128,18 @@ CREATE TABLE IF NOT EXISTS data (
public static bool AddSource(string name, string url, string connectionString)
{
string query = "SELECT id, name, url FROM sources WHERE name='" + name + "'";
using (SQLiteConnection dbc = new SQLiteConnection(connectionString))
using (SqliteConnection dbc = new SqliteConnection(connectionString))
{
dbc.Open();
using (SQLiteCommand slc = new SQLiteCommand(query, dbc))
using (SqliteCommand slc = new SqliteCommand(query, dbc))
{
using (SQLiteDataReader sldr = slc.ExecuteReader())
using (SqliteDataReader sldr = slc.ExecuteReader())
{
// If nothing is found, add the source
if (!sldr.HasRows)
{
string squery = "INSERT INTO sources (name, url) VALUES ('" + name + "', '" + url + "')";
using (SQLiteCommand sslc = new SQLiteCommand(squery, dbc))
using (SqliteCommand sslc = new SqliteCommand(squery, dbc))
{
return sslc.ExecuteNonQuery() >= 1;
}
@@ -151,7 +151,7 @@ CREATE TABLE IF NOT EXISTS data (
if (url != sldr.GetString(2))
{
string squery = "UPDATE sources SET url='" + url + "' WHERE id=" + sldr.GetInt32(0);
using (SQLiteCommand sslc = new SQLiteCommand(squery, dbc))
using (SqliteCommand sslc = new SqliteCommand(squery, dbc))
{
return sslc.ExecuteNonQuery() >= 1;
}
@@ -173,10 +173,10 @@ CREATE TABLE IF NOT EXISTS data (
public static bool RemoveSource(int id, string connectionString)
{
string query = "DELETE FROM sources WHERE id=" + id;
using (SQLiteConnection dbc = new SQLiteConnection(connectionString))
using (SqliteConnection dbc = new SqliteConnection(connectionString))
{
dbc.Open();
using (SQLiteCommand slc = new SQLiteCommand(query, dbc))
using (SqliteCommand slc = new SqliteCommand(query, dbc))
{
return slc.ExecuteNonQuery() >= 1;
}
@@ -193,18 +193,18 @@ CREATE TABLE IF NOT EXISTS data (
public static bool AddSystem(string manufacturer, string system, string connectionString)
{
string query = "SELECT id, manufacturer, system FROM systems WHERE manufacturer='" + manufacturer + "' AND system='" + system + "'";
using (SQLiteConnection dbc = new SQLiteConnection(connectionString))
using (SqliteConnection dbc = new SqliteConnection(connectionString))
{
dbc.Open();
using (SQLiteCommand slc = new SQLiteCommand(query, dbc))
using (SqliteCommand slc = new SqliteCommand(query, dbc))
{
using (SQLiteDataReader sldr = slc.ExecuteReader())
using (SqliteDataReader sldr = slc.ExecuteReader())
{
// If nothing is found, add the system
if (!sldr.HasRows)
{
string squery = "INSERT INTO systems (manufacturer, system) VALUES ('" + manufacturer + "', '" + system + "')";
using (SQLiteCommand sslc = new SQLiteCommand(squery, dbc))
using (SqliteCommand sslc = new SqliteCommand(squery, dbc))
{
return sslc.ExecuteNonQuery() >= 1;
}
@@ -224,10 +224,10 @@ CREATE TABLE IF NOT EXISTS data (
public static bool RemoveSystem(int id, string connectionString)
{
string query = "DELETE FROM systems WHERE id=" + id;
using (SQLiteConnection dbc = new SQLiteConnection(connectionString))
using (SqliteConnection dbc = new SqliteConnection(connectionString))
{
dbc.Open();
using (SQLiteCommand slc = new SQLiteCommand(query, dbc))
using (SqliteCommand slc = new SqliteCommand(query, dbc))
{
return slc.ExecuteNonQuery() >= 1;
}

View File

@@ -40,6 +40,10 @@
<HintPath>..\packages\EntityFramework.6.1.3\lib\net45\EntityFramework.SqlServer.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Mono.Data.Sqlite, Version=2.0.0.0, Culture=neutral, PublicKeyToken=0738eb9f132ed756, processorArchitecture=MSIL">
<HintPath>..\packages\Mono.Data.Sqlite.Portable.1.0.3.5\lib\net4\Mono.Data.Sqlite.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="SharpCompress, Version=0.11.6.0, Culture=neutral, PublicKeyToken=beaf6f427e128133, processorArchitecture=MSIL">
<HintPath>..\packages\sharpcompress.0.11.6\lib\net40\SharpCompress.dll</HintPath>
<Private>True</Private>
@@ -47,16 +51,13 @@
<Reference Include="System" />
<Reference Include="System.ComponentModel.DataAnnotations" />
<Reference Include="System.Core" />
<Reference Include="System.Data.SQLite, Version=1.0.99.0, Culture=neutral, PublicKeyToken=db937bc2d44ff139, processorArchitecture=MSIL">
<HintPath>..\packages\System.Data.SQLite.Core.1.0.99.0\lib\net451\System.Data.SQLite.dll</HintPath>
<Reference Include="System.Data.Portable, Version=4.0.0.0, Culture=neutral, PublicKeyToken=59e704a76bc4613a, processorArchitecture=MSIL">
<HintPath>..\packages\Mono.Data.Sqlite.Portable.1.0.3.5\lib\net4\System.Data.Portable.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="System.Data.SQLite.EF6, Version=1.0.99.0, Culture=neutral, PublicKeyToken=db937bc2d44ff139, processorArchitecture=MSIL">
<HintPath>..\packages\System.Data.SQLite.EF6.1.0.99.0\lib\net451\System.Data.SQLite.EF6.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="System.Data.SQLite.Linq, Version=1.0.99.0, Culture=neutral, PublicKeyToken=db937bc2d44ff139, processorArchitecture=MSIL">
<HintPath>..\packages\System.Data.SQLite.Linq.1.0.99.0\lib\net451\System.Data.SQLite.Linq.dll</HintPath>
<Reference Include="System.Transactions" />
<Reference Include="System.Transactions.Portable, Version=4.0.0.0, Culture=neutral, PublicKeyToken=59e704a76bc4613a, processorArchitecture=MSIL">
<HintPath>..\packages\Mono.Data.Sqlite.Portable.1.0.3.5\lib\net4\System.Transactions.Portable.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="System.Web" />
@@ -82,7 +83,6 @@
<Compile Include="Build.cs" />
</ItemGroup>
<ItemGroup>
<None Include="App.config" />
<None Include="DATabase.sqlite">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
@@ -134,14 +134,15 @@
<Content Include="Skippers\snes.xml">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
<Content Include="sqlite3.dll">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<Import Project="..\packages\System.Data.SQLite.Core.1.0.99.0\build\net451\System.Data.SQLite.Core.targets" Condition="Exists('..\packages\System.Data.SQLite.Core.1.0.99.0\build\net451\System.Data.SQLite.Core.targets')" />
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
<PropertyGroup>
<ErrorText>This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
</PropertyGroup>
<Error Condition="!Exists('..\packages\System.Data.SQLite.Core.1.0.99.0\build\net451\System.Data.SQLite.Core.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\System.Data.SQLite.Core.1.0.99.0\build\net451\System.Data.SQLite.Core.targets'))" />
<Import Project="..\packages\Mono.Data.Sqlite.Portable.1.0.3.5\tools\Mono.Data.Sqlite.Portable.targets" Condition="Exists('..\packages\Mono.Data.Sqlite.Portable.1.0.3.5\tools\Mono.Data.Sqlite.Portable.targets')" />
<Target Name="EnsureMonoDataSqlitePortableImported" BeforeTargets="BeforeBuild" Condition="'$(MonoDataSqlitePortableImported)' == ''">
<Error Condition="!Exists('..\packages\Mono.Data.Sqlite.Portable.1.0.3.5\tools\Mono.Data.Sqlite.Portable.targets')" Text="This project references NuGet package(s) that are missing on this computer. Enable NuGet Package Restore to download them." />
<Error Condition="Exists('..\packages\Mono.Data.Sqlite.Portable.1.0.3.5\tools\Mono.Data.Sqlite.Portable.targets')" Text="The build restored NuGet packages. Build the project again to include these packages in the build." />
</Target>
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.

View File

@@ -1,9 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="EntityFramework" version="6.1.3" targetFramework="net452" />
<package id="Mono.Data.Sqlite.Portable" version="1.0.3.5" targetFramework="net452" />
<package id="sharpcompress" version="0.11.6" targetFramework="net452" />
<package id="System.Data.SQLite" version="1.0.99.0" targetFramework="net452" />
<package id="System.Data.SQLite.Core" version="1.0.99.0" targetFramework="net452" />
<package id="System.Data.SQLite.EF6" version="1.0.99.0" targetFramework="net452" />
<package id="System.Data.SQLite.Linq" version="1.0.99.0" targetFramework="net452" />
</packages>

BIN
SabreHelper/sqlite3.dll Normal file

Binary file not shown.