Started the work for SQLI

This commit is contained in:
2023-05-16 15:11:28 +02:00
parent 39e9dbb7d6
commit 511f5d98e4
4 changed files with 86 additions and 2 deletions

View File

@@ -1 +0,0 @@


View File

@@ -22,6 +22,10 @@ namespace Test_Merge
public List<string> Drivers;
public List<Zone> MainZones;
private SqliteStorage _storage;
public SqliteStorage Storage { get => _storage; private set => _storage = value; }
public Reader(string configFile, Bitmap image, bool loadOCR = true)
{
MainZones = Load(image, configFile, ref Drivers, loadOCR);
@@ -214,6 +218,8 @@ namespace Test_Merge
string result = "";
List<DriverData> mainResults = new List<DriverData>();
Storage = new SqliteStorage();
//Decode
for (int mainZoneId = 0; mainZoneId < mainZones.Count; mainZoneId++)
{

View File

@@ -0,0 +1,79 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data.SQLite;
using System.IO;
namespace Test_Merge
{
public class SqliteStorage
{
private const string DATABASE_FOLDER = "./Data";
private const string DATABASE_FILE = "/database.sqlite";
private const string CONNECTION_STRING = "Data Source=" + DATABASE_FOLDER + DATABASE_FILE + ";Version=3;";
public SqliteStorage()
{
Load();
}
private void Load()
{
if (!Directory.Exists(DATABASE_FOLDER))
Directory.CreateDirectory(DATABASE_FOLDER);
if (!File.Exists(DATABASE_FOLDER + DATABASE_FILE))
{
SQLiteConnection.CreateFile(DATABASE_FOLDER + DATABASE_FILE);
}
else
{
//We are not using the existing DataBase
File.Delete(DATABASE_FOLDER+DATABASE_FILE);
}
using (var connection = new SQLiteConnection(CONNECTION_STRING))
{
connection.Open();
//Create the drivers table
string createDriversTableQuery = @"CREATE TABLE IF NOT EXISTS Drivers
(ID INTEGER PRIMARY KEY AUTOINCREMENT,
Name VARCHAR NOT NULL);";
using (var command = new SQLiteCommand(createDriversTableQuery, connection))
{
command.ExecuteNonQuery();
}
//Create the drivers table
string createPitstopTableQuery = @"CREATE TABLE Pitstops
(Lap INTEGER NOT NULL,
DriverID INTEGER NOT NULL,
Tyre VARCHAR,
PRIMARY KEY (Lap,DriverID));";
using (var command = new SQLiteCommand(createDriversTableQuery, connection))
{
command.ExecuteNonQuery();
}
//Create the stats
string createStatsTableQuery = @"CREATE TABLE IF NOT EXISTS Stats
(Lap INTEGER NOT NULL,
DriverID INTEGER NOT NULL,
Tyre VARCHAR NOT NULL,
LapTime INTEGER NOT NULL,
Sector1 INTEGER NOT NULL,
Sector2 INTEGER NOT NULL,
Sector3 INTEGER NOT NULL,
GapToLeader INTEGER NOT NULL,
Position INTEGER NOT NULL,
PRIMARY KEY (Lap, DriverID));";
using (var command = new SQLiteCommand(createStatsTableQuery, connection))
{
command.ExecuteNonQuery();
}
}
}
}
}

View File

@@ -129,6 +129,7 @@
<Compile Include="Settings.Designer.cs">
<DependentUpon>Settings.cs</DependentUpon>
</Compile>
<Compile Include="SqliteStorage.cs" />
<Compile Include="Window.cs" />
<Compile Include="Zone.cs" />
<EmbeddedResource Include="Form1.resx">
@@ -146,7 +147,6 @@
<EmbeddedResource Include="Settings.resx">
<DependentUpon>Settings.cs</DependentUpon>
</EmbeddedResource>
<None Include="Data\database.sqlite" />
<None Include="packages.config" />
<None Include="Properties\Settings.settings">
<Generator>SettingsSingleFileGenerator</Generator>