Skip to content

Commit 973fe42

Browse files
committed
v0.1.2
1 parent 64ab9ea commit 973fe42

File tree

4 files changed

+35
-7
lines changed

4 files changed

+35
-7
lines changed

samples/MoviesAppSample/DataAccess/MovieDal.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ public MovieDal(Func<SQLiteDbConnection> createConnection) : base(createConnecti
1616
{
1717
}
1818

19-
#region Properites
19+
#region Properties
2020

2121
protected override string[] Columns => s_columns;
2222
protected override string TableName => "Movies";

samples/MoviesAppSample/DataAccess/PersonDal.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ public PersonDal(Func<SQLiteDbConnection> createConnection) : base(createConnect
2020
{
2121
}
2222

23-
#region Properites
23+
#region Properties
2424

2525
protected override string[] Columns => s_columns;
2626
protected override string TableName => "Persons";

src/NuExt.System.Data.SQLite.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ System.Data.SQLite.SQLiteDbConnection
1414
System.Data.SQLite.SQLiteDbContext
1515
System.Data.SQLite.SQLiteDbConverter
1616
System.Data.SQLite.SQLiteDbTransaction</Description>
17-
<Version>0.1.1</Version>
17+
<Version>0.1.2</Version>
1818
<RootNamespace />
1919
<GenerateDocumentationFile>True</GenerateDocumentationFile>
2020
<NoWarn>$(NoWarn);1591</NoWarn>

src/System/Data/SQLite/SQLiteDbContext.cs

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,19 +11,36 @@ public sealed class SQLiteDbContext: Disposable, IDbContext
1111
{
1212
private readonly SQLiteDbTransaction _transaction;
1313
private readonly Lifetime _lifetime = new();
14+
private readonly bool _checkAcquired;
1415

1516
/// <summary>
1617
/// Initializes a new instance of the <see cref="SQLiteDbContext"/> class with the specified SQLite database connection.
1718
/// </summary>
1819
/// <param name="connection">The SQLite database connection.</param>
1920
/// <exception cref="ArgumentNullException">Thrown when the provided connection is null.</exception>
2021
public SQLiteDbContext(SQLiteDbConnection connection)
22+
: this(connection, true) // Default behavior is to check acquisition state
23+
{
24+
}
25+
26+
/// <summary>
27+
/// Initializes a new instance of the <see cref="SQLiteDbContext"/> class with the specified SQLite database connection
28+
/// and a flag indicating whether to check if the connection is acquired.
29+
/// </summary>
30+
/// <param name="connection">The SQLite database connection.</param>
31+
/// <param name="checkAcquired">Whether to check if the connection is acquired to prevent "database is locked" exception.</param>
32+
/// <exception cref="ArgumentNullException">Thrown when the provided connection is null.</exception>
33+
public SQLiteDbContext(SQLiteDbConnection connection, bool checkAcquired)
2134
{
2235
try
2336
{
2437
_lifetime.Add(() => GC.SuppressFinalize(this));
2538
Connection = connection ?? throw new ArgumentNullException(nameof(connection));
26-
CheckAcquired();
39+
_checkAcquired = checkAcquired;
40+
if (checkAcquired)
41+
{
42+
CheckAcquired();
43+
}
2744
Debug.Assert(!connection.InTransaction, $"{nameof(connection)} in transaction.");
2845
Throw.InvalidOperationExceptionIf(connection.InTransaction, $"{nameof(connection)} in transaction.");
2946
Connection.Open(out var originalState);
@@ -70,7 +87,11 @@ private void CheckAcquired()
7087
/// </summary>
7188
public void Commit()
7289
{
73-
CheckAcquired();
90+
CheckDisposed();
91+
if (_checkAcquired)
92+
{
93+
CheckAcquired();
94+
}
7495
_transaction.Commit();
7596
}
7697

@@ -79,7 +100,10 @@ public void Commit()
79100
/// </summary>
80101
protected override void OnDispose()
81102
{
82-
CheckAcquired();
103+
if (_checkAcquired)
104+
{
105+
CheckAcquired();
106+
}
83107
_lifetime.Dispose();
84108
base.OnDispose();
85109
}
@@ -89,7 +113,11 @@ protected override void OnDispose()
89113
/// </summary>
90114
public void Rollback()
91115
{
92-
CheckAcquired();
116+
CheckDisposed();
117+
if (_checkAcquired)
118+
{
119+
CheckAcquired();
120+
}
93121
_transaction.Rollback();
94122
}
95123

0 commit comments

Comments
 (0)