diff --git a/MBBSEmu.Tests/Btrieve/BtrieveFileProcessor_Tests.cs b/MBBSEmu.Tests/Btrieve/BtrieveFileProcessor_Tests.cs index e402e187..b62736f9 100644 --- a/MBBSEmu.Tests/Btrieve/BtrieveFileProcessor_Tests.cs +++ b/MBBSEmu.Tests/Btrieve/BtrieveFileProcessor_Tests.cs @@ -155,12 +155,7 @@ public void LoadsFileAndConvertsProperly() private void AssertSqlStructure(string fullPath) { - var connectionString = new SqliteConnectionStringBuilder() - { - Mode = SqliteOpenMode.ReadWriteCreate, - DataSource = fullPath, - }.ToString(); - + var connectionString = BtrieveFileProcessor.GetDefaultConnectionStringBuilder(fullPath).ToString(); using var connection = new SqliteConnection(connectionString); connection.Open(); @@ -1169,7 +1164,8 @@ private static BtrieveFile CreateACSBtrieveFile() public void CreatesACS() { var btrieve = new BtrieveFileProcessor(); - var connectionString = "Data Source=acs.db;Mode=Memory"; + var connectionString = BtrieveFileProcessor.GetDefaultConnectionStringBuilder("acs.db"); + connectionString.Mode = SqliteOpenMode.Memory; btrieve.CreateSqliteDBWithConnectionString(connectionString, CreateACSBtrieveFile()); @@ -1188,7 +1184,8 @@ public void CreatesACS() public void ACSSeekByKey() { var btrieve = new BtrieveFileProcessor(); - var connectionString = "Data Source=acs.db;Mode=Memory"; + var connectionString = BtrieveFileProcessor.GetDefaultConnectionStringBuilder("acs.db"); + connectionString.Mode = SqliteOpenMode.Memory; btrieve.CreateSqliteDBWithConnectionString(connectionString, CreateACSBtrieveFile()); @@ -1207,7 +1204,8 @@ public void ACSSeekByKey() public void ACSInsertDuplicateFails() { var btrieve = new BtrieveFileProcessor(); - var connectionString = "Data Source=acs.db;Mode=Memory"; + var connectionString = BtrieveFileProcessor.GetDefaultConnectionStringBuilder("acs.db"); + connectionString.Mode = SqliteOpenMode.Memory; btrieve.CreateSqliteDBWithConnectionString(connectionString, CreateACSBtrieveFile()); @@ -1236,7 +1234,8 @@ private static BtrieveFile CreateKeylessBtrieveFile() public void KeylessDatabaseEnumeration() { var btrieve = new BtrieveFileProcessor(); - var connectionString = "Data Source=acs.db;Mode=Memory"; + var connectionString = BtrieveFileProcessor.GetDefaultConnectionStringBuilder("acs.db"); + connectionString.Mode = SqliteOpenMode.Memory; btrieve.CreateSqliteDBWithConnectionString(connectionString, CreateKeylessBtrieveFile()); @@ -1266,7 +1265,8 @@ public void KeylessDatabaseEnumeration() public void KeylessDataQueryFails() { var btrieve = new BtrieveFileProcessor(); - var connectionString = "Data Source=acs.db;Mode=Memory"; + var connectionString = BtrieveFileProcessor.GetDefaultConnectionStringBuilder("acs.db"); + connectionString.Mode = SqliteOpenMode.Memory; btrieve.CreateSqliteDBWithConnectionString(connectionString, CreateKeylessBtrieveFile()); diff --git a/MBBSEmu.Tests/ExportedModules/ExportedModuleTestBase.cs b/MBBSEmu.Tests/ExportedModules/ExportedModuleTestBase.cs index 0e17bfe7..144a2ba3 100644 --- a/MBBSEmu.Tests/ExportedModules/ExportedModuleTestBase.cs +++ b/MBBSEmu.Tests/ExportedModules/ExportedModuleTestBase.cs @@ -11,6 +11,7 @@ using MBBSEmu.Module; using MBBSEmu.Session; using MBBSEmu.TextVariables; +using Microsoft.Data.Sqlite; using NLog; using System; using System.Collections.Generic; @@ -290,7 +291,8 @@ protected List GenerateParameters(object[] values) protected void AllocateBB(BtrieveFile btrieveFile, ushort maxRecordLength) { var btrieve = new BtrieveFileProcessor() { FullPath = Path.Combine(mbbsModule.ModulePath, btrieveFile.FileName) }; - var connectionString = "Data Source=acs.db;Mode=Memory"; + var connectionString = BtrieveFileProcessor.GetDefaultConnectionStringBuilder("acs.db"); + connectionString.Mode = SqliteOpenMode.Memory; btrieve.CreateSqliteDBWithConnectionString(connectionString, btrieveFile); majorbbs.AllocateBB(btrieve, maxRecordLength, Path.GetFileName(btrieve.FullPath)); diff --git a/MBBSEmu/Btrieve/BtrieveFileProcessor.cs b/MBBSEmu/Btrieve/BtrieveFileProcessor.cs index de514b72..52d3b8c9 100644 --- a/MBBSEmu/Btrieve/BtrieveFileProcessor.cs +++ b/MBBSEmu/Btrieve/BtrieveFileProcessor.cs @@ -201,13 +201,7 @@ private void LoadSqlite(string fullPath) FullPath = fullPath; - var connectionString = new Microsoft.Data.Sqlite.SqliteConnectionStringBuilder() - { - Mode = Microsoft.Data.Sqlite.SqliteOpenMode.ReadWriteCreate, - DataSource = fullPath, - }.ToString(); - - Connection = new SqliteConnection(connectionString); + Connection = new SqliteConnection(GetDefaultConnectionStringBuilder(fullPath).ToString()); Connection.Open(); LoadSqliteMetadata(); @@ -1145,16 +1139,13 @@ public void CreateSqliteDB(string fullpath, BtrieveFile btrieveFile) FullPath = fullpath; - var connectionString = new Microsoft.Data.Sqlite.SqliteConnectionStringBuilder() - { - Mode = Microsoft.Data.Sqlite.SqliteOpenMode.ReadWriteCreate, - DataSource = fullpath, - }.ToString(); - - CreateSqliteDBWithConnectionString(connectionString, btrieveFile); + CreateSqliteDBWithConnectionString(GetDefaultConnectionStringBuilder(fullpath), btrieveFile); } - public void CreateSqliteDBWithConnectionString(string connectionString, BtrieveFile btrieveFile) + public void CreateSqliteDBWithConnectionString(SqliteConnectionStringBuilder connectionString, BtrieveFile btrieveFile) => + CreateSqliteDBWithConnectionString(connectionString.ToString(), btrieveFile); + + private void CreateSqliteDBWithConnectionString(string connectionString, BtrieveFile btrieveFile) { Connection = new SqliteConnection(connectionString); Connection.Open(); @@ -1183,5 +1174,12 @@ public SqliteCommand GetSqliteCommand(string sql, SqliteTransaction transaction cmd.Parameters.Clear(); return cmd; } + + public static SqliteConnectionStringBuilder GetDefaultConnectionStringBuilder(string filepath) => new Microsoft.Data.Sqlite.SqliteConnectionStringBuilder() + { + Mode = Microsoft.Data.Sqlite.SqliteOpenMode.ReadWriteCreate, + DataSource = filepath, + Pooling = false, + }; } } diff --git a/MBBSEmu/DOS/Interrupts/Int7Bh.cs b/MBBSEmu/DOS/Interrupts/Int7Bh.cs index cc10726f..1eba4506 100644 --- a/MBBSEmu/DOS/Interrupts/Int7Bh.cs +++ b/MBBSEmu/DOS/Interrupts/Int7Bh.cs @@ -1,4 +1,3 @@ - using MBBSEmu.Btrieve; using MBBSEmu.Btrieve.Enums; using MBBSEmu.CPU;