Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using System.Data;
using System.Data.SQLite;
using Microsoft.Data.Sqlite;

namespace OSPSuite.Infrastructure.Serialization.Journal
{
Expand All @@ -12,8 +12,8 @@ public class ConnectionProvider : IConnectionProvider
{
public IDbConnection CreateConnection(string databasePath)
{
var connectionString = $"Data Source={databasePath};Version=3;New=True;Compress=True;foreign keys=True";
var cn = new SQLiteConnection(connectionString);
var connectionString = $"Data Source={databasePath}";
Copy link

Copilot AI Nov 4, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The simplified connection string removes important SQLite configuration parameters that were present in the old implementation: 'Version=3;New=True;Compress=True;foreign keys=True'. Most critically, 'foreign keys=True' enforces referential integrity constraints. Consider adding back essential parameters, particularly foreign key enforcement using: var connectionString = $\"Data Source={databasePath};Foreign Keys=True\";

Suggested change
var connectionString = $"Data Source={databasePath}";
var connectionString = $"Data Source={databasePath};Foreign Keys=True";

Copilot uses AI. Check for mistakes.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Felixmil Not sure about Version and New arguments, but ForeignKeys and Compress must be set.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, I don't see an option for compress, only the one for foreign keys.
https://learn.microsoft.com/en-us/dotnet/standard/data/sqlite/connection-strings

Regarding compress: needs to be investigated further (maybe it's always true, or can be set later via a property...)
We should create a separate issue for this.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Created #2700

var cn = new SqliteConnection(connectionString);
cn.Open();
return cn;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
<ItemGroup>
<PackageReference Include="Dapper" Version="2.1.66" />
<PackageReference Include="NHibernate" Version="5.5.2" />
<PackageReference Include="System.Data.SQLite.Core" Version="1.0.119" />
<PackageReference Include="Microsoft.Data.Sqlite" Version="8.0.0" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using System;
using System.Data.Common;
using System.Data.SQLite;
using Microsoft.Data.Sqlite;
using OSPSuite.Core.Extensions;

namespace OSPSuite.Infrastructure.Serialization.Services
Expand All @@ -10,7 +10,7 @@ public class SQLiteProjectCommandExecuter
public virtual void ExecuteCommand(string projectFile, Action<DbConnection> command )
{
string file = projectFile.ToUNCPath();
using (var sqlLite = new SQLiteConnection($"Data Source={file}"))
using (var sqlLite = new SqliteConnection($"Data Source={file}"))
{
sqlLite.Open();
command(sqlLite);
Expand All @@ -20,7 +20,7 @@ public virtual void ExecuteCommand(string projectFile, Action<DbConnection> comm
public virtual TResult ExecuteCommand<TResult>(string projectFile, Func<DbConnection, TResult> command)
{
string file = projectFile.ToUNCPath();
using (var sqlLite = new SQLiteConnection($"Data Source={file}"))
using (var sqlLite = new SqliteConnection($"Data Source={file}"))
{
sqlLite.Open();
return command(sqlLite);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
using System;
using NHibernate;
using NHibernate.Cfg;
using NHibernate.Dialect;
using NHibernate.Driver;
using NHibernate.Tool.hbm2ddl;
using Microsoft.Data.Sqlite;

namespace OSPSuite.Infrastructure.Serialization.Services
{
public class SessionFactoryProvider : ISessionFactoryProvider
{
public ISessionFactory InitalizeSessionFactoryFor(string dataSource)
{
var configuration = CreateConfiguration(dataSource);
var sessionFactory = configuration.BuildSessionFactory();
return sessionFactory;
}

public ISessionFactory OpenSessionFactoryFor(string dataSource)
{
var configuration = CreateConfiguration(dataSource);
var sessionFactory = configuration.BuildSessionFactory();
return sessionFactory;
}

public SchemaExport GetSchemaExport(string dataSource)
{
var configuration = CreateConfiguration(dataSource);
return new SchemaExport(configuration);
}

private Configuration CreateConfiguration(string dataSource)
{
var configuration = new Configuration();

// Configure database integration with Microsoft.Data.Sqlite
configuration.DataBaseIntegration(db =>
{
// Use the SQLite driver that works with Microsoft.Data.Sqlite
db.Driver<NHibernate.Driver.SQLite20Driver>();
db.Dialect<SQLiteDialect>();
db.ConnectionString = $"Data Source={dataSource}";
db.Timeout = 20;
});

// Add mapping assemblies (you may need to adjust these based on your actual mapping assemblies)
configuration.AddAssembly(typeof(SessionFactoryProvider).Assembly);

return configuration;
}
}

}

Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="OSPSuite.BDDHelper" Version="4.0.1.1" />
<PackageReference Include="System.Data.SQLite.Core" Version="1.0.119" />
<PackageReference Include="Microsoft.Data.Sqlite" Version="8.0.0" />
<PackageReference Include="SQLitePCLRaw.bundle_e_sqlite3" Version="2.1.8" GeneratePathProperty="true" />
<PackageReference Include="System.Drawing.Common" Version="9.0.2" />
</ItemGroup>

Expand All @@ -38,16 +39,11 @@
<Folder Include="Data\PKAnalysesFiles\" />
<Folder Include="Data\SensitivityAnalysisResultsFiles\" />
</ItemGroup>

<PropertyGroup>
<ContentSQLiteInteropFiles>true</ContentSQLiteInteropFiles>
<CopySQLiteInteropFiles>false</CopySQLiteInteropFiles>
<CleanSQLiteInteropFiles>false</CleanSQLiteInteropFiles>
<CollectSQLiteInteropFiles>false</CollectSQLiteInteropFiles>
<ContentSQLiteInteropFiles>true</ContentSQLiteInteropFiles>
<CopySQLiteInteropFiles>false</CopySQLiteInteropFiles>
<CleanSQLiteInteropFiles>false</CleanSQLiteInteropFiles>
<CollectSQLiteInteropFiles>false</CollectSQLiteInteropFiles>
</PropertyGroup>
<Target Name="PostBuild" AfterTargets="PostBuildEvent">
<ItemGroup>
<WindowsFiles Include="$(TargetDir)x64/SQLite.Interop.dll" />
</ItemGroup>
<Copy SourceFiles="@(WindowsFiles);" DestinationFolder="$(TargetFolder)" DestinationFiles="@(WindowsFiles-&gt;Replace('x64/SQLite.Interop.dll', 'SQLite.Interop.dll'))" />
</Target>
</Project>
22 changes: 9 additions & 13 deletions tests/OSPSuite.R.Performance/OSPSuite.R.Performance.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -50,23 +50,19 @@
<PackageReference Include="OSPSuite.FuncParser" Version="4.0.0.73" GeneratePathProperty="true" />
<PackageReference Include="OSPSuite.SimModel" Version="4.0.0.75" GeneratePathProperty="true" />
<PackageReference Include="OSPSuite.SimModelSolver_CVODES" Version="4.1.0.19" GeneratePathProperty="true" />
<PackageReference Include="System.Data.SQLite.Core" Version="1.0.119"/>
<PackageReference Include="Microsoft.Data.Sqlite" Version="8.0.0" />
<PackageReference Include="SQLitePCLRaw.bundle_e_sqlite3" Version="2.1.8" GeneratePathProperty="true" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\src\OSPSuite.Core\OSPSuite.Core.csproj" />
<ProjectReference Include="..\..\src\OSPSuite.R\OSPSuite.R.csproj" />
</ItemGroup>
<PropertyGroup>
<ContentSQLiteInteropFiles>true</ContentSQLiteInteropFiles>
<CopySQLiteInteropFiles>false</CopySQLiteInteropFiles>
<CleanSQLiteInteropFiles>false</CleanSQLiteInteropFiles>
<CollectSQLiteInteropFiles>false</CollectSQLiteInteropFiles>
</PropertyGroup>
<Target Name="PostBuild" AfterTargets="PostBuildEvent">
<ItemGroup>
<WindowsFiles Include="$(TargetDir)x64/SQLite.Interop.dll" />
</ItemGroup>
<Copy SourceFiles="@(WindowsFiles);" DestinationFolder="$(TargetFolder)" DestinationFiles="@(WindowsFiles-&gt;Replace('x64/SQLite.Interop.dll', 'SQLite.Interop.dll'))" />
</Target>

<PropertyGroup>
<ContentSQLiteInteropFiles>true</ContentSQLiteInteropFiles>
<CopySQLiteInteropFiles>false</CopySQLiteInteropFiles>
<CleanSQLiteInteropFiles>false</CleanSQLiteInteropFiles>
<CollectSQLiteInteropFiles>false</CollectSQLiteInteropFiles>
</PropertyGroup>
</Project>
21 changes: 8 additions & 13 deletions tests/OSPSuite.Starter/OSPSuite.Starter.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@
<PackageReference Include="OSPSuite.FuncParser" Version="4.0.0.73" GeneratePathProperty="true" />
<PackageReference Include="OSPSuite.SimModel" Version="4.0.0.75" GeneratePathProperty="true" />
<PackageReference Include="OSPSuite.SimModelSolver_CVODES" Version="4.1.0.19" GeneratePathProperty="true" />
<PackageReference Include="System.Data.SQLite.Core" Version="1.0.119" GeneratePathProperty="true" />
<PackageReference Include="Microsoft.Data.Sqlite" Version="8.0.0" />
<PackageReference Include="SQLitePCLRaw.bundle_e_sqlite3" Version="2.1.8" GeneratePathProperty="true" />
</ItemGroup>

<ItemGroup>
Expand All @@ -76,16 +77,10 @@
<Reference Include="System.Windows.Forms" />
</ItemGroup>

<PropertyGroup>
<ContentSQLiteInteropFiles>true</ContentSQLiteInteropFiles>
<CopySQLiteInteropFiles>false</CopySQLiteInteropFiles>
<CleanSQLiteInteropFiles>false</CleanSQLiteInteropFiles>
<CollectSQLiteInteropFiles>false</CollectSQLiteInteropFiles>
</PropertyGroup>
<Target Name="PostBuild" AfterTargets="PostBuildEvent">
<ItemGroup>
<WindowsFiles Include="$(TargetDir)x64/SQLite.Interop.dll" />
</ItemGroup>
<Copy SourceFiles="@(WindowsFiles);" DestinationFolder="$(TargetFolder)" DestinationFiles="@(WindowsFiles-&gt;Replace('x64/SQLite.Interop.dll', 'SQLite.Interop.dll'))" />
</Target>
<PropertyGroup>
<ContentSQLiteInteropFiles>true</ContentSQLiteInteropFiles>
<CopySQLiteInteropFiles>false</CopySQLiteInteropFiles>
<CleanSQLiteInteropFiles>false</CleanSQLiteInteropFiles>
<CollectSQLiteInteropFiles>false</CollectSQLiteInteropFiles>
</PropertyGroup>
</Project>