Skip to content

Commit 4df36e0

Browse files
committed
Don't use rollback to if depth is 1
1 parent 8b4d748 commit 4df36e0

2 files changed

Lines changed: 18 additions & 5 deletions

File tree

nuget/pack.ps1

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ if ($IsMacOS) {
77
$msbuild = join-path $msbuild 'MSBuild\Current\Bin\MSBuild.exe'
88
}
99
$version="2.1.0"
10-
$versionSuffix="-pre4"
10+
$versionSuffix="-pre6"
1111

1212
#####################
1313
#Build release config
@@ -17,3 +17,4 @@ del *.nupkg
1717
if ($lastexitcode -ne 0) { exit $lastexitcode; }
1818

1919
nuget push "sqlite-net2.$version$versionSuffix.nupkg" -Source $nugetServer
20+
#copy "sqlite-net2.$version$versionSuffix.nupkg" "D:\repos\localnugets"

src/SQLite.Net/SQLiteConnection.cs

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -110,9 +110,9 @@ public virtual SQLiteConnection Clone()
110110
/// <param name="extraTypeMappings">Any extra type mappings that you wish to use for overriding the default for creating column definitions for SQLite DDL in the class Orm (snake in Swedish).</param>
111111
/// <param name="resolver">A contract resovler for resolving interfaces to concreate types during object creation</param>
112112
/// <param name="encryptionKey">When using SQL CIPHER, automatically sets the key (you won't need to override Clone() in this case)</param>
113-
/// <param name="configOption">Mode in which to open the db</param>
113+
/// <param name="configOption">Mode in which to open the db. Default to Serialized</param>
114114
public SQLiteConnection(string databasePath, SQLiteOpenFlags openFlags = SQLiteOpenFlags.ReadWrite | SQLiteOpenFlags.Create, bool storeDateTimeAsTicks = true, IBlobSerializer? serializer = null, IDictionary<string, TableMapping>? tableMappings = null,
115-
IDictionary<Type, string>? extraTypeMappings = null, IContractResolver? resolver = null, string? encryptionKey = null, ConfigOption configOption = ConfigOption.MultiThread)
115+
IDictionary<Type, string>? extraTypeMappings = null, IContractResolver? resolver = null, string? encryptionKey = null, ConfigOption configOption = ConfigOption.Serialized)
116116
{
117117
if (string.IsNullOrEmpty(databasePath))
118118
throw new ArgumentException("Must be specified", nameof(databasePath));
@@ -917,6 +917,7 @@ public void Commit()
917917
/// <returns>A string naming the savepoint.</returns>
918918
/// <remarks>
919919
/// All transactions methods creates a state in this connection. Be sure to not share it with other calls.
920+
/// Not thread safe.
920921
/// </remarks>
921922
public string SaveTransactionPoint()
922923
{
@@ -981,7 +982,12 @@ private void RollbackTo(string? savepoint, bool noThrow)
981982
}
982983
}
983984
else
984-
DoSavePointExecute(savepoint!, "rollback to ");
985+
{
986+
if (IsInTransaction)
987+
DoSavePointExecute(savepoint!, "rollback to ");
988+
else
989+
transactionDepth = 0;
990+
}
985991
}
986992
catch (SQLiteException)
987993
{
@@ -1014,6 +1020,12 @@ private void DoSavePointExecute(string savePoint, string cmd)
10141020

10151021
if (!int.TryParse(savePoint.Substring(firstLen + 1), out var depth) || depth < 0)
10161022
throw new ArgumentException($"savePoint '{savePoint}' is not valid, and should be the result of a call to SaveTransactionPoint.", nameof(savePoint));
1023+
1024+
if (depth == 1)
1025+
{
1026+
RollbackTo(null, true);
1027+
return;
1028+
}
10171029

10181030
if (depth > transactionDepth)
10191031
throw new ArgumentException($"savePoint '{savePoint}' is not valid: depth ({depth}) >= transactionDepth ({transactionDepth})", nameof(savePoint));
@@ -1358,13 +1370,13 @@ public int Insert(object? obj, string extra, Type? objType)
13581370
for (var i = 0; i < vals.Length; i++)
13591371
vals[i] = cols[i].GetValue(obj);
13601372

1361-
var insertCmd = GetInsertCommand(map, extra);
13621373
int count;
13631374

13641375
try
13651376
{
13661377
// We lock here to protect the prepared statement returned via GetInsertCommand.
13671378
// A SQLite prepared statement can be bound for only one operation at a time.
1379+
var insertCmd = GetInsertCommand(map, extra);
13681380
lock (insertCmd)
13691381
{
13701382
count = insertCmd.ExecuteNonQuery(vals);

0 commit comments

Comments
 (0)