Skip to content

Commit

Permalink
Disable SQLite connection pooling on BTRIEVE connections (#536)
Browse files Browse the repository at this point in the history
  • Loading branch information
paladine authored Jan 6, 2022
1 parent 28580a3 commit 17e489f
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 28 deletions.
22 changes: 11 additions & 11 deletions MBBSEmu.Tests/Btrieve/BtrieveFileProcessor_Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down Expand Up @@ -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());

Expand All @@ -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());

Expand All @@ -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());

Expand Down Expand Up @@ -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());

Expand Down Expand Up @@ -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());

Expand Down
4 changes: 3 additions & 1 deletion MBBSEmu.Tests/ExportedModules/ExportedModuleTestBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -290,7 +291,8 @@ protected List<ushort> 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));
Expand Down
28 changes: 13 additions & 15 deletions MBBSEmu/Btrieve/BtrieveFileProcessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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,
};
}
}
1 change: 0 additions & 1 deletion MBBSEmu/DOS/Interrupts/Int7Bh.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

using MBBSEmu.Btrieve;
using MBBSEmu.Btrieve.Enums;
using MBBSEmu.CPU;
Expand Down

0 comments on commit 17e489f

Please sign in to comment.