Skip to content

Commit

Permalink
fix(LocalDatabase): add SQLitePCL.Batteries.Init()
Browse files Browse the repository at this point in the history
  • Loading branch information
MingboPeng committed Mar 13, 2024
1 parent eed89fe commit 1ee6e08
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/PollinationSDK/PollinationSDK.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
<ItemGroup>
<PackageReference Include="LBT.Newtonsoft.Json" Version="12.0.3.23910" />
<PackageReference Include="LBT.RestSharp" Version="106.11.7.1" />
<PackageReference Include="Microsoft.Data.Sqlite" Version="8.0.0" />
<PackageReference Include="Microsoft.Data.Sqlite" Version="8.0.3" />
<PackageReference Include="Serilog.Sinks.File" Version="4.1.0" />
<PackageReference Include="System.ComponentModel.Annotations" Version="5.0.0" />
</ItemGroup>
Expand Down
18 changes: 13 additions & 5 deletions src/PollinationSDK/Wrapper/LocalDatabase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,10 @@ SqliteConnection CreateConnection()
SqliteConnection con;
var file = GetDatabaseFile();
var fileExist = File.Exists(file);
SQLitePCL.Batteries.Init();
con = new SqliteConnection($"Data Source={file}");
con.Open();
LogHelper.LogInfo($"ServerVersion: {con.ServerVersion}");
if (!fileExist)
InitDatabase(con);

Expand Down Expand Up @@ -89,12 +91,18 @@ public string GetDatabaseFile()

static void InitDatabase(SqliteConnection con)
{
//var con = Instance.connection;
var cmd = con.CreateCommand();
try
{
var cmd = con.CreateCommand();
var createTable = "CREATE TABLE JobTable (ProjSlug BLOB(36), JobID BLOB(36), DateTime TEXT, JobInfo BLOB)";
cmd.CommandText = createTable;
cmd.ExecuteNonQuery();
}
catch (Exception e)
{
throw LogHelper.LogReturnError(e);
}

var createTable = "CREATE TABLE JobTable (ProjSlug BLOB(36), JobID BLOB(36), DateTime TEXT, JobInfo BLOB)";
cmd.CommandText = createTable;
cmd.ExecuteNonQuery();
}


Expand Down

0 comments on commit 1ee6e08

Please sign in to comment.