Skip to content

Commit

Permalink
Differentiate pooled connections by their OpenFlags
Browse files Browse the repository at this point in the history
  • Loading branch information
praeclarum committed Jan 25, 2019
1 parent ca1c06b commit 91c17ad
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 7 deletions.
4 changes: 2 additions & 2 deletions src/SQLite.cs
Expand Up @@ -2091,7 +2091,7 @@ public enum NotifyTableChangedAction
/// </summary>
public class SQLiteConnectionString
{
public string ConnectionString { get; }
public string UniqueKey { get; }
public string DatabasePath { get; }
public bool StoreDateTimeAsTicks { get; }
public object Key { get; }
Expand Down Expand Up @@ -2200,7 +2200,7 @@ public SQLiteConnectionString (string databasePath, SQLiteOpenFlags openFlags, b
if (key != null && !((key is byte[]) || (key is string)))
throw new ArgumentException ("Encryption keys must be strings or byte arrays", nameof (key));

ConnectionString = databasePath;
UniqueKey = string.Format ("{0}_{1:X8}", databasePath, (uint)openFlags);
StoreDateTimeAsTicks = storeDateTimeAsTicks;
Key = key;
PreKeyAction = preKeyAction;
Expand Down
9 changes: 4 additions & 5 deletions src/SQLiteAsync.cs
Expand Up @@ -1363,9 +1363,9 @@ public void Close ()

public SQLiteConnectionWithLock GetConnection (SQLiteConnectionString connectionString)
{
var key = connectionString.UniqueKey;
Entry entry;
lock (_entriesLock) {
string key = connectionString.ConnectionString;
if (!_entries.TryGetValue (key, out entry)) {
entry = new Entry (connectionString);
_entries[key] = entry;
Expand All @@ -1376,15 +1376,13 @@ public SQLiteConnectionWithLock GetConnection (SQLiteConnectionString connection

public void CloseConnection (SQLiteConnectionString connectionString)
{
var key = connectionString.ConnectionString;

var key = connectionString.UniqueKey;
Entry entry;
lock (_entriesLock) {
if (_entries.TryGetValue (key, out entry)) {
_entries.Remove (key);
}
}

entry?.Close ();
}

Expand All @@ -1407,7 +1405,8 @@ public void Reset ()

/// <summary>
/// This is a normal connection except it contains a Lock method that
/// can be used to serialize access to the database.
/// can be used to serialize access to the database
/// in lieu of using the sqlite's FullMutex support.
/// </summary>
public class SQLiteConnectionWithLock : SQLiteConnection
{
Expand Down

0 comments on commit 91c17ad

Please sign in to comment.