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 ## Ignore Visual Studio temporary files, build results, and
## files generated by popular Visual Studio add-ons. ## files generated by popular Visual Studio add-ons.
## ##

View File

@ -1,12 +1,13 @@
using System.Data; using System.Data;
using Microsoft.Data.Sqlite;
namespace Database namespace Database
{ {
public class Database public class Database
{ {
public static void CreateDatabaseQuery() public static void CreateDatabaseQuery(SqliteConnection conn)
{ {
string createTableQuery = @" string createTableQuery = @"
CREATE TABLE [Books] ( CREATE TABLE [Books] (
[ID] INTEGER PRIMARY KEY AUTOINCREMENT, [ID] INTEGER PRIMARY KEY AUTOINCREMENT,
[Name] TEXT NOT NULL, [Name] TEXT NOT NULL,
@ -21,7 +22,7 @@ namespace Database
[ID] INTEGER PRIMARY KEY AUTOINCREMENT, [ID] INTEGER PRIMARY KEY AUTOINCREMENT,
[Name] TEXT, [Name] TEXT,
[Surname] TEXT, [Surname] TEXT,
[DateOfBirth] DATE, [DateOfBirth] DATE
); );
CREATE TABLE [Publisher] ( CREATE TABLE [Publisher] (
[ID] INTEGER PRIMARY KEY AUTOINCREMENT, [ID] INTEGER PRIMARY KEY AUTOINCREMENT,
@ -43,6 +44,9 @@ namespace Database
[Name] TEXT, [Name] TEXT,
[Surname] 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 restore
RUN dotnet add package Microsoft.Data.Sqlite RUN dotnet add package Microsoft.Data.Sqlite
RUN dotnet add package SQLitePCLRaw.lib.e_sqlite3
COPY . ./ COPY . ./

View File

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