This commit is contained in:
shinya 2025-11-03 12:29:06 +01:00
commit 73eb2c93a3
6 changed files with 52 additions and 6 deletions

2
.gitignore vendored
View File

@ -1,3 +1,5 @@
*.sqlite
*.sln
## Ignore Visual Studio temporary files, build results, and
## files generated by popular Visual Studio add-ons.
##

View File

@ -1,12 +1,13 @@
using System.Data;
using Microsoft.Data.Sqlite;
namespace Database
{
public class Database
{
public static void CreateDatabaseQuery()
public static void CreateDatabaseQuery(SqliteConnection conn)
{
string createTableQuery = @"
string createTableQuery = @"
CREATE TABLE [Books] (
[ID] INTEGER PRIMARY KEY AUTOINCREMENT,
[Name] TEXT NOT NULL,
@ -21,7 +22,7 @@ namespace Database
[ID] INTEGER PRIMARY KEY AUTOINCREMENT,
[Name] TEXT,
[Surname] TEXT,
[DateOfBirth] DATE,
[DateOfBirth] DATE
);
CREATE TABLE [Publisher] (
[ID] INTEGER PRIMARY KEY AUTOINCREMENT,
@ -43,6 +44,9 @@ namespace Database
[Name] TEXT,
[Surname] TEXT
);";
var command = conn.CreateCommand();
command.CommandText = createTableQuery;
command.ExecuteNonQuery();
}
}
}

View File

@ -7,7 +7,6 @@ COPY *.csproj ./
RUN dotnet restore
RUN dotnet add package Microsoft.Data.Sqlite
RUN dotnet add package SQLitePCLRaw.lib.e_sqlite3
COPY . ./

View File

@ -8,7 +8,10 @@
</PropertyGroup>
<ItemGroup>
<PackageReference Include="SQLite" Version="3.13.0" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Data.Sqlite" Version="9.0.10" />
</ItemGroup>
</Project>

View File

@ -1 +1,39 @@

using System;
using Microsoft.Data.Sqlite;
using Database;
public class Program
{
public static void Main()
{
string db = "Database.sqlite";
string connectionString = "Data Source=" + db;
try
{
using (var connection = new SqliteConnection(connectionString))
{
connection.Open();
try
{
Database.Database.CreateDatabaseQuery(connection);
}
catch
{
Console.WriteLine("Database already exists.");
}
using (var command = connection.CreateCommand())
{
// implment stuff here idc
}
}
}
catch (SqliteException ex)
{
Console.WriteLine($"{ex.Source}: {ex.Message}");
}
}
}

View File