Skip to content

Commit 35599a2

Browse files
committed
Refactoring
1 parent f4c58b0 commit 35599a2

2 files changed

Lines changed: 11 additions & 7 deletions

File tree

DuckDB.NET.Data/DuckDBTransaction.cs

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@ public class DuckDBTransaction : DbTransaction
99
{
1010
private bool finished = false;
1111
private readonly DuckDBConnection connection;
12-
12+
1313
protected override DbConnection DbConnection => connection;
14-
14+
1515
public override IsolationLevel IsolationLevel { get; }
1616

1717
public DuckDBTransaction(DuckDBConnection connection, IsolationLevel isolationLevel)
@@ -41,17 +41,21 @@ private void FinishTransaction(string finalizer)
4141
try
4242
{
4343
connection.ExecuteNonQuery(finalizer);
44-
connection.Transaction = null;
45-
finished = true;
44+
Cleanup();
4645
}
4746
// If something goes wrong with the transaction, to match the
4847
// transaction's internal duckdb state it should still be considered
4948
// finished and should no longer be used
5049
catch (DuckDBException ex) when (ex.ErrorType == Native.DuckDBErrorType.Transaction)
50+
{
51+
Cleanup();
52+
throw;
53+
}
54+
55+
void Cleanup()
5156
{
5257
connection.Transaction = null;
5358
finished = true;
54-
throw;
5559
}
5660
}
5761

DuckDB.NET.Data/PreparedStatement/ClrToDuckDBConverter.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ private static DuckDBValue DecimalToDuckDBValue(decimal value)
163163
{
164164
var bits = decimal.GetBits(value);
165165
var scale = (byte)((bits[3] >> 16) & 0x7F);
166-
166+
167167
var power = Math.Pow(10, scale);
168168

169169
var integralPart = decimal.Truncate(value);
@@ -173,7 +173,7 @@ private static DuckDBValue DecimalToDuckDBValue(decimal value)
173173

174174
result += new BigInteger(decimal.Multiply(fractionalPart, (decimal)power));
175175

176-
int width = Math.Max(scale, result.IsZero ? 1 : (int)Math.Floor(BigInteger.Log10(BigInteger.Abs(result))) + 1);
176+
var width = integralPart == 0 ? scale + 1 : (int)Math.Floor(BigInteger.Log10(BigInteger.Abs(result))) + 1;
177177

178178
return NativeMethods.Value.DuckDBCreateDecimal(new DuckDBDecimal((byte)width, scale, new DuckDBHugeInt(result)));
179179
}

0 commit comments

Comments
 (0)