Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
a097bb2
Migrate from System.Data.SQLite to Microsoft.Data.Sqlite
Nov 4, 2025
ff903db
Fix SnapshotRunner SQLite driver compatibility and error handling
Nov 4, 2025
53df268
Update R dependency artifact creation to handle Microsoft.Data.Sqlite…
Nov 4, 2025
14b72ef
Merge upstream/V13 into Microsoft.Data.Sqlite branch
Nov 4, 2025
0d10da8
Remove leftover SQLite interop properties from System.Data.SQLite mig…
Nov 4, 2025
96085ca
Merge latest upstream/V13 into Microsoft.Data.Sqlite branch
Nov 4, 2025
ed84383
Disable foreign keys in Microsoft.Data.Sqlite connection string
Nov 4, 2025
8d97412
Fix duplicate error logging in SnapshotRunner
Nov 5, 2025
14b5b43
Use Count property instead of Count() LINQ extension
Nov 5, 2025
cdee9bb
Merge upstream/V13 into Microsoft.Data.Sqlite branch
Nov 5, 2025
8ee2c98
Revert "Use Count property instead of Count() LINQ extension"
Nov 5, 2025
5451bbf
Revert SnapshotRunner changes - out of scope for SQLite migration
Nov 5, 2025
bb7e503
Aligns with how other native DLLs are handled
Nov 5, 2025
b9838de
Update to use NHibernate.Extensions.SQLite and new core
rwmcintosh Nov 5, 2025
7c09e93
create a custom data adapter
rwmcintosh Nov 6, 2025
82dcde5
add project schema dump as source
rwmcintosh Nov 7, 2025
5dfc52c
do not automatically update schema from nhibernate
rwmcintosh Nov 7, 2025
29be0d9
remove constructor init of factory
rwmcintosh Nov 8, 2025
e07b263
foreign keys enabled
rwmcintosh Nov 9, 2025
e03ced1
enable foreign keys
rwmcintosh Nov 9, 2025
6d3e50d
update core
rwmcintosh Nov 10, 2025
3a2dc3a
pr feedback
rwmcintosh Nov 10, 2025
e787068
undo
rwmcintosh Nov 10, 2025
8e87fc9
the default connection did not enforce foreign keys
rwmcintosh Nov 10, 2025
545c2b3
update core
rwmcintosh Nov 10, 2025
1955361
remove postbuild and unused references
rwmcintosh Nov 10, 2025
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
11 changes: 10 additions & 1 deletion .github/workflows/build-nightly_12.2.yml
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,16 @@ jobs:
run: |
pushd .
cd src\PKSimRDependencyResolution\bin\Debug\${{env.TARGET_FRAMEWORK}}
7z.exe a pk-sim-r-dependencies.zip -x@"excludedFiles.txt" * -xr!runtimes
@("win-x64", "linux-x64", "osx-arm64") | ForEach-Object {
$nativePath = "runtimes\$_\native"
if (Test-Path $nativePath) {
Copy-Item "$nativePath\*sqlite*" -Destination "." -Force -ErrorAction SilentlyContinue
}
}
if (Test-Path "runtimes") {
Remove-Item -Recurse -Force "runtimes"
}
7z.exe a pk-sim-r-dependencies.zip -x@"excludedFiles.txt" *
popd

- name: Sign PKSim setup with CodeSignTool
Expand Down
2 changes: 1 addition & 1 deletion src/PKSim.BatchTool/PKSim.BatchTool.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@
<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" />
</ItemGroup>

<ItemGroup>
Expand Down
32 changes: 24 additions & 8 deletions src/PKSim.CLI.Core/Services/SnapshotRunner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -101,21 +101,37 @@ private async Task startSnapshotRun(IReadOnlyList<FileMap> fileMaps, Func<FileMa
private async Task createProjectFromSnapshotFile(FileMap file, bool runSimulations)
{
_logger.AddInfo($"Starting project export for '{file.SnapshotFile}'");
var project = await _snapshotTask.LoadProjectFromSnapshotFileAsync(file.SnapshotFile, runSimulations);
if (project == null)
return;

_logger.AddDebug($"Snapshot loaded successfully from '{file.SnapshotFile}'");
_workspace.Project = project;
try
{
_workspacePersistor.SaveSession(_workspace, file.ProjectFile);
var project = await _snapshotTask.LoadProjectFromSnapshotFileAsync(file.SnapshotFile, runSimulations);
if (project == null)
{
_logger.AddError($"Failed to load project from snapshot file '{file.SnapshotFile}'. The snapshot may be corrupted or incompatible.");
return;
}

_logger.AddDebug($"Snapshot loaded successfully from '{file.SnapshotFile}'");
_workspace.Project = project;
try
{
_workspacePersistor.SaveSession(_workspace, file.ProjectFile);
_logger.AddInfo($"Project saved to '{file.ProjectFile}'");
}
catch (Exception ex)
{
_logger.AddError($"Failed to save project to '{file.ProjectFile}': {ex.Message}");
throw;
}
}
catch (Exception ex)
{
_logger.AddError($"Error processing snapshot file '{file.SnapshotFile}': {ex.Message}");
throw;
}
finally
{
_workspacePersistor.CloseSession();
}
_logger.AddInfo($"Project saved to '{file.ProjectFile};");
}

private async Task createSnapshotFromProjectFile(FileMap file)
Expand Down
2 changes: 1 addition & 1 deletion src/PKSim.CLI/PKSim.CLI.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@
<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" />

</ItemGroup>

Expand Down
53 changes: 43 additions & 10 deletions src/PKSim.Infrastructure/ORM/DAS/DAS.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using System;
using System.Data;
using System.Data.Common;
using System.Data.SQLite;
using Microsoft.Data.Sqlite;

namespace PKSim.Infrastructure.ORM.DAS
{
Expand All @@ -19,6 +19,12 @@ public class DAS : IDisposable

public DbConnection Connection { get; private set; }

public DAS()
{
// Initialize the provider factory to Microsoft.Data.Sqlite by default
_providerFactory = Microsoft.Data.Sqlite.SqliteFactory.Instance;
}

//this is just a dummy command to create a parameters collection to store parameters
private DbCommand _command;
private DbParameterCollection _parameters;
Expand Down Expand Up @@ -89,9 +95,9 @@ public bool Connect(string dataProvider, string connectionString)

if (!IsConnected)
{
if ((dataProvider == "System.Data.SQLite"))
if ((dataProvider == "Microsoft.Data.Sqlite"))
{
_providerFactory = new SQLiteFactory();
_providerFactory = SqliteFactory.Instance;
}
else
{
Expand Down Expand Up @@ -153,8 +159,9 @@ public bool Connect(string dbName, string workgroupDb, string user, string passw
switch (dataProvider)
{
case DataProviders.SQLite:
sProvider = "System.Data.SQLite";
sProvider = "Microsoft.Data.Sqlite";
connBuilder.Add("Data Source", dbName);
connBuilder.Add("Foreign Keys", "False");
if (!string.IsNullOrEmpty(password))
{
connBuilder.Add("Password", password);
Expand Down Expand Up @@ -508,10 +515,36 @@ public void FillDataTable(DASDataTable dataTable, string sql)
dataTable.Rows.Clear();
try
{
using (var adapter = _providerFactory.CreateDataAdapter())
// Manual data reading to avoid constraint issues with DataTable.Load()
using (var reader = cmd.ExecuteReader())
{
adapter.SelectCommand = cmd;
adapter.Fill(dataTable);
// Build column schema if table is empty
if (dataTable.Columns.Count() == 0)
{
var schemaTable = reader.GetSchemaTable();
if (schemaTable != null)
{
foreach (System.Data.DataRow schemaRow in schemaTable.Rows)
{
var columnName = schemaRow["ColumnName"].ToString();
var dataType = (Type)schemaRow["DataType"];
// Use base DataTable's Columns collection
((DataTable)dataTable).Columns.Add(columnName, dataType);
}
}
}

// Read data row by row to avoid constraint issues
while (reader.Read())
{
var row = dataTable.NewRow();
for (int fieldIndex = 0; fieldIndex < reader.FieldCount; fieldIndex++)
{
row[fieldIndex] = reader.IsDBNull(fieldIndex) ? DBNull.Value : reader.GetValue(fieldIndex);
}
// Use base DataTable's Rows collection
((DataTable)dataTable).Rows.Add(row);
}
}
}
catch (Exception ex)
Expand Down Expand Up @@ -564,7 +597,7 @@ public object GetAutoValue(string autoValueCreator)
/// <para>
/// Each parameter has an identifying name and an associated value.
/// You can automatically bind a parameter to SQL and PL/SQL statements of other objects,
/// by using the parameters name as a placeholder (@Name) in the SQL statement.
/// by using the parameter s name as a placeholder (@Name) in the SQL statement.
/// Such use of parameters can simplify dynamic queries and increase program performance.
/// </para>
/// <para>
Expand Down Expand Up @@ -676,7 +709,7 @@ public void AddParameter(string paramName, object paramValue, ParameterModes par
/// <para>
/// Each parameter has an identifying name and an associated value.
/// You can automatically bind a parameter to SQL and PL/SQL statements of other objects,
/// by using the parameters name as a placeholder (@Name) in the SQL statement.
/// by using the parameter s name as a placeholder (@Name) in the SQL statement.
/// Such use of parameters can simplify dynamic queries and increase program performance.
/// </para>
/// <para>
Expand Down Expand Up @@ -764,7 +797,7 @@ public void AddParameter(string paramName, object paramValue, ParameterModes par
/// <remarks>
/// Each parameter has an identifying name and an associated value.
/// You can automatically bind a parameter to SQL and PL/SQL statements of other objects,
/// by using the parameters name as a placeholder (:Name) in the SQL or PL/SQL statement.
/// by using the parameter s name as a placeholder (:Name) in the SQL or PL/SQL statement.
/// Such use of parameters can simplify dynamic queries and increase program performance.
/// If you set an incorrect <see cref="ParameterModes"></see>, such as <see cref="ParameterModes.PARM_INOUT"></see>
/// for a stored procedure parameter type IN, this can result in errors.
Expand Down
1 change: 1 addition & 0 deletions src/PKSim.Infrastructure/PKSim.Infrastructure.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
<PackageReference Include="OSPSuite.Infrastructure.Serialization" Version="12.2.17" />
<PackageReference Include="OSPSuite.Presentation.Serialization" Version="12.2.17" />
<PackageReference Include="OSPSuite.Utility" Version="4.1.1.1" />
<PackageReference Include="Microsoft.Data.Sqlite" Version="8.0.0" />
</ItemGroup>

<ItemGroup>
Expand Down
14 changes: 7 additions & 7 deletions src/PKSim.Infrastructure/Serialization/DatabaseSchemaMigrator.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using System;
using System.Data;
using System.Data.SQLite;
using Microsoft.Data.Sqlite;
using OSPSuite.Core.Extensions;

namespace PKSim.Infrastructure.Serialization
Expand All @@ -19,7 +19,7 @@ public class DatabaseSchemaMigrator : IDatabaseSchemaMigrator
public void MigrateSchema(string fileFullPath)
{
var path = fileFullPath.ToUNCPath();
using (var sqlLite = new SQLiteConnection($"Data Source={path}"))
using (var sqlLite = new SqliteConnection($"Data Source={path}"))
{
sqlLite.Open();
migrateTo5_3(sqlLite);
Expand All @@ -28,7 +28,7 @@ public void MigrateSchema(string fileFullPath)
}

//change from 5.2 to 5.3
private void migrateTo5_3(SQLiteConnection sqlite)
private void migrateTo5_3(SqliteConnection sqlite)
{
if (!needsConversionTo5_3(sqlite)) return;

Expand All @@ -53,27 +53,27 @@ PRIMARY KEY (Id),
}

//change from 6.1 to 6.2
private void migrateTo6_2(SQLiteConnection sqlite)
private void migrateTo6_2(SqliteConnection sqlite)
{
if (!needsConversionTo6_2(sqlite)) return;

//rename table SUMMARY_CHART to SIMULATION_COMPARISONS
sqlite.ExecuteNonQuery("ALTER TABLE OBSERVED_DATA RENAME TO USED_OBSERVED_DATA");
}

private bool needsConversionTo6_2(SQLiteConnection sqlite)
private bool needsConversionTo6_2(SqliteConnection sqlite)
{
//USED_OBSERVED_DATA table was added in 6.2
return !hasTable(sqlite, "USED_OBSERVED_DATA");
}

private bool needsConversionTo5_3(SQLiteConnection sqlLite)
private bool needsConversionTo5_3(SqliteConnection sqlLite)
{
//SIMULATION_COMPARISONS table was added in 5.3
return !hasTable(sqlLite, "SIMULATION_COMPARISONS");
}

private static bool hasTable(SQLiteConnection sqlLite, string tableName)
private static bool hasTable(SqliteConnection sqlLite, string tableName)
{
try
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ private Configuration createSqlLiteConfigurationFor(string dataSource)
configuration.SetProperty("dialect", "NHibernate.Dialect.SQLiteDialect");
configuration.SetProperty("query.substitutions", "true=1;false=0");
configuration.SetProperty("show_sql", "false");
configuration.SetProperty("connection.connection_string", $"Data Source={path};Version=3;New=False;Compress=True;");
configuration.SetProperty("connection.connection_string", $"Data Source={path};Cache=Shared");

return Fluently.Configure(configuration)
.Mappings(cfg =>
Expand Down
6 changes: 1 addition & 5 deletions src/PKSim.R/PKSim.R.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
<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" />

</ItemGroup>

Expand All @@ -69,10 +69,6 @@
</ItemGroup>

<PropertyGroup>
<ContentSQLiteInteropFiles>true</ContentSQLiteInteropFiles>
<CopySQLiteInteropFiles>false</CopySQLiteInteropFiles>
<CleanSQLiteInteropFiles>false</CleanSQLiteInteropFiles>
<CollectSQLiteInteropFiles>false</CollectSQLiteInteropFiles>
<PlatformTarget>AnyCPU</PlatformTarget>
</PropertyGroup>
</Project>
17 changes: 1 addition & 16 deletions src/PKSim/PKSim.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@
<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="OSPSuite.Presentation" Version="12.2.17" GeneratePathProperty="true" />
<PackageReference Include="OSPSuite.TeXReporting" Version="3.0.1.1" GeneratePathProperty="true" />
</ItemGroup>
Expand All @@ -99,19 +99,4 @@
<Exec Command="copy $(ProjectDir)..\PKSim.R\$(OutDir)PKSim.R.* $(TargetDir)&#xD;&#xA;copy $(ProjectDir)..\PKSim.Matlab\$(OutDir)PKSim.Matlab.* $(TargetDir)&#xD;&#xA;copy $(ProjectDir)..\PKSim.BatchTool\$(OutDir)PKSim.BatchTool.* $(TargetDir)&#xD;&#xA;copy $(ProjectDir)..\PKSim.CLI\$(OutDir)PKSim.CLI.* $(TargetDir)&#xD;&#xA;copy $(ProjectDir)..\PKSim.CLI\$(OutDir)CommandLine.* $(TargetDir)&#xD;&#xA;copy $(ProjectDir)..\PKSim.CLI\$(OutDir)Microsoft.Extensions.* $(TargetDir)&#xD;&#xA;" />
</Target>

<!-- Content comes from Stub.system.data.sqlite.core. Basically, implements the same task as if you
added this binary as content and copy to output folder -->
<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>
</Project>
18 changes: 2 additions & 16 deletions src/PKSimRDependencyResolution/PKSimRDependencyResolution.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
<Version Condition="'$(Version)' == ''">12.2.0</Version>
<PlatformTarget>x64</PlatformTarget>
<RuntimeIdentifiers>win-x64;linux-x64;osx-x64;osx-arm64</RuntimeIdentifiers>
</PropertyGroup>
<ItemGroup>
<Compile Include="..\..\SolutionInfo.cs" Link="Properties\SolutionInfo.cs" />
Expand All @@ -24,6 +25,7 @@
<PackageReference Include="OSPSuite.SimModel.MacOS.Arm64" Version="4.0.0.75" GeneratePathProperty="true" />
<PackageReference Include="OSPSuite.SimModelSolver_CVODES.Ubuntu22" Version="4.1.0.19" GeneratePathProperty="true" />
<PackageReference Include="OSPSuite.SimModelSolver_CVODES.MacOSArm64" Version="4.1.0.19" GeneratePathProperty="true" />
<PackageReference Include="SQLitePCLRaw.bundle_e_sqlite3" Version="2.1.8" GeneratePathProperty="true" />
</ItemGroup>
<ItemGroup>
<Content Include="$(PkgOSPSuite_FuncParser_Ubuntu22)\OSPSuite.FuncParserNative\bin\native\x64\Release\libOSPSuite.FuncParserNative.so" Link="libOSPSuite.FuncParserNative.so">
Expand All @@ -50,20 +52,4 @@
<ItemGroup>
<ProjectReference Include="..\PKSim.R\PKSim.R.csproj" />
</ItemGroup>
<PropertyGroup>
<ContentSQLiteInteropFiles>true</ContentSQLiteInteropFiles>
<CopySQLiteInteropFiles>false</CopySQLiteInteropFiles>
<CleanSQLiteInteropFiles>false</CleanSQLiteInteropFiles>
<CollectSQLiteInteropFiles>false</CollectSQLiteInteropFiles>
</PropertyGroup>
<Target Name="PostBuild" AfterTargets="PostBuildEvent">
<ItemGroup>
<LinuxFiles Include="$(TargetDir)runtimes/linux-x64/native/SQLite.Interop.dll" />
<WindowsFiles Include="$(TargetDir)runtimes/win-x64/native/SQLite.Interop.dll" />
<MacFiles Include="$(TargetDir)runtimes/osx-x64/native/SQLite.Interop.dll" />
</ItemGroup>
<Copy SourceFiles="@(WindowsFiles);" DestinationFolder="$(TargetFolder)" DestinationFiles="@(WindowsFiles-&gt;Replace('runtimes/win-x64/native/SQLite.Interop.dll', 'SQLite.Interop.dll'))" />
<Copy SourceFiles="@(LinuxFiles);" DestinationFolder="$(TargetFolder)" DestinationFiles="@(LinuxFiles-&gt;Replace('runtimes/linux-x64/native/SQLite.Interop.dll', 'libSQLite.Interop.dll'))" />
<Copy SourceFiles="@(MacFiles);" DestinationFolder="$(TargetFolder)" DestinationFiles="@(MacFiles-&gt;Replace('runtimes/osx-x64/native/SQLite.Interop.dll', 'SQLite.Interop.dll.dylib'))" />
</Target>
</Project>
2 changes: 1 addition & 1 deletion tests/PKSim.Matlab.Tests/PKSim.Matlab.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
<PackageReference Include="OSPSuite.FuncParser" Version="4.0.0.59" GeneratePathProperty="true" />
<PackageReference Include="OSPSuite.SimModel" Version="4.0.0.59" GeneratePathProperty="true" />
<PackageReference Include="OSPSuite.SimModelSolver_CVODES" Version="4.1.0.8" GeneratePathProperty="true" />
<PackageReference Include="System.Data.SQLite.Core" Version="1.0.112" GeneratePathProperty="true" />
<PackageReference Include="Microsoft.Data.Sqlite" Version="8.0.0" />
</ItemGroup>

<ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion tests/PKSim.R.Tests/PKSim.R.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
<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" />
</ItemGroup>

<ItemGroup>
Expand Down
Loading