Skip to content

Commit 4dd6d59

Browse files
committed
Add logs. Update nugets. Start alignment with praeclarum changes.
1 parent 8b7586d commit 4dd6d59

10 files changed

+254
-278
lines changed

SQLite.Net.Tests/SQLite.Net2.Tests.csproj

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,13 @@
77
</PropertyGroup>
88

99
<ItemGroup>
10-
<PackageReference Include="nunit" Version="3.12.0" />
11-
<PackageReference Include="NUnit3TestAdapter" Version="3.16.1">
10+
<PackageReference Include="nunit" Version="3.13.1" />
11+
<PackageReference Include="NUnit3TestAdapter" Version="3.17.0">
1212
<PrivateAssets>all</PrivateAssets>
1313
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
1414
</PackageReference>
15-
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.6.1" />
16-
<PackageReference Include="SQLitePCLRaw.bundle_e_sqlite3" Version="2.0.3" />
15+
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.9.1" />
16+
<PackageReference Include="SQLitePCLRaw.bundle_e_sqlite3" Version="2.0.4" />
1717
</ItemGroup>
1818

1919
<ItemGroup>

SQLite.Net.Tests/TransactionTest.cs

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,5 +125,34 @@ public void SuccessfulSavepointTransaction()
125125

126126
Assert.AreEqual(testObjects.Count - 1, db.Table<TestObj>().Count());
127127
}
128+
129+
130+
[Test]
131+
public void FailSavepointTransactionException()
132+
{
133+
try
134+
{
135+
db.RunInTransaction(() =>
136+
{
137+
throw new TransactionTestException();
138+
});
139+
}
140+
catch(TransactionTestException)
141+
{
142+
return;
143+
}
144+
145+
Assert.Fail("Incorrect exception thrown");
146+
}
147+
148+
149+
[Test]
150+
public void SuccesfulSavepointTransaction()
151+
{
152+
db.RunInTransaction(() =>
153+
{
154+
db.InsertOrReplaceAll(testObjects);
155+
});
156+
}
128157
}
129158
}

examples/Stocks/Stocks.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@
8080
</ItemGroup>
8181
<ItemGroup>
8282
<PackageReference Include="SQLitePCLRaw.bundle_e_sqlcipher">
83-
<Version>2.0.3</Version>
83+
<Version>2.0.4</Version>
8484
</PackageReference>
8585
</ItemGroup>
8686
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />

nuget/pack.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ if ($IsMacOS) {
66
$msbuild = & $vswhere -latest -products * -requires Microsoft.Component.MSBuild -property installationPath
77
$msbuild = join-path $msbuild 'MSBuild\Current\Bin\MSBuild.exe'
88
}
9-
$version="2.0.3"
9+
$version="2.0.4"
1010
$versionSuffix=""
1111

1212
#####################

src/SQLite.Net/ActiveInsertCommand.cs

Lines changed: 61 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -1,77 +1,69 @@
1-
// Author: Prasanna V. Loganathar
2-
// Created: 2:37 PM 07-03-2015
3-
// Project: SQLite.Net
4-
// License: See project license
1+
//using System;
2+
//using System.Linq;
53

6-
using System;
7-
using System.Linq;
4+
//namespace SQLite.Net2
5+
//{
6+
// internal class ActiveInsertCommand
7+
// {
8+
// private readonly TableMapping _tableMapping;
9+
// private PreparedSqlLiteInsertCommand _insertCommand;
10+
// private string _insertCommandExtra;
811

9-
namespace SQLite.Net2
10-
{
11-
internal class ActiveInsertCommand
12-
{
13-
private readonly TableMapping _tableMapping;
14-
private PreparedSqlLiteInsertCommand _insertCommand;
15-
private string _insertCommandExtra;
12+
// public ActiveInsertCommand(TableMapping tableMapping)
13+
// {
14+
// _tableMapping = tableMapping;
15+
// }
1616

17-
public ActiveInsertCommand(TableMapping tableMapping)
18-
{
19-
_tableMapping = tableMapping;
20-
}
17+
// public PreparedSqlLiteInsertCommand GetCommand(SQLiteConnection conn, string extra)
18+
// {
19+
// if (_insertCommand == null)
20+
// {
21+
// _insertCommand = CreateCommand(conn, extra);
22+
// _insertCommandExtra = extra;
23+
// }
24+
// else if (_insertCommandExtra != extra)
25+
// {
26+
// _insertCommand.Dispose();
27+
// _insertCommand = CreateCommand(conn, extra);
28+
// _insertCommandExtra = extra;
29+
// }
30+
// return _insertCommand;
31+
// }
2132

22-
public PreparedSqlLiteInsertCommand GetCommand(SQLiteConnection conn, string extra)
23-
{
24-
if (_insertCommand == null)
25-
{
26-
_insertCommand = CreateCommand(conn, extra);
27-
_insertCommandExtra = extra;
28-
}
29-
else if (_insertCommandExtra != extra)
30-
{
31-
_insertCommand.Dispose();
32-
_insertCommand = CreateCommand(conn, extra);
33-
_insertCommandExtra = extra;
34-
}
35-
return _insertCommand;
36-
}
33+
// protected internal void Dispose()
34+
// {
35+
// if (_insertCommand != null)
36+
// {
37+
// _insertCommand.Dispose();
38+
// _insertCommand = null;
39+
// }
40+
// }
3741

38-
protected internal void Dispose()
39-
{
40-
if (_insertCommand != null)
41-
{
42-
_insertCommand.Dispose();
43-
_insertCommand = null;
44-
}
45-
}
42+
// private PreparedSqlLiteInsertCommand CreateCommand(SQLiteConnection conn, string extra)
43+
// {
44+
// var cols = _tableMapping.InsertColumns;
45+
// string insertSql;
46+
// if (!cols.Any() && _tableMapping.Columns.Count() == 1 && _tableMapping.Columns[0].IsAutoInc)
47+
// {
48+
// insertSql = string.Format("insert {1} into \"{0}\" default values", _tableMapping.TableName, extra);
49+
// }
50+
// else
51+
// {
52+
// var replacing = string.Compare(extra, "OR REPLACE", StringComparison.OrdinalIgnoreCase) == 0;
4653

47-
private PreparedSqlLiteInsertCommand CreateCommand(SQLiteConnection conn, string extra)
48-
{
49-
var cols = _tableMapping.InsertColumns;
50-
string insertSql;
51-
if (!cols.Any() && _tableMapping.Columns.Count() == 1 && _tableMapping.Columns[0].IsAutoInc)
52-
{
53-
insertSql = string.Format("insert {1} into \"{0}\" default values", _tableMapping.TableName, extra);
54-
}
55-
else
56-
{
57-
var replacing = string.Compare(extra, "OR REPLACE", StringComparison.OrdinalIgnoreCase) == 0;
54+
// if (replacing)
55+
// {
56+
// cols = _tableMapping.Columns;
57+
// }
5858

59-
if (replacing)
60-
{
61-
cols = _tableMapping.Columns;
62-
}
59+
// insertSql = string.Format("insert {3} into \"{0}\"({1}) values ({2})", _tableMapping.TableName,
60+
// string.Join(",", (from c in cols
61+
// select "\"" + c.Name + "\"").ToArray()),
62+
// string.Join(",", (from c in cols
63+
// select "?").ToArray()), extra);
64+
// }
6365

64-
insertSql = string.Format("insert {3} into \"{0}\"({1}) values ({2})", _tableMapping.TableName,
65-
string.Join(",", (from c in cols
66-
select "\"" + c.Name + "\"").ToArray()),
67-
string.Join(",", (from c in cols
68-
select "?").ToArray()), extra);
69-
}
70-
71-
return new PreparedSqlLiteInsertCommand(conn)
72-
{
73-
CommandText = insertSql
74-
};
75-
}
76-
}
77-
}
66+
// return new PreparedSqlLiteInsertCommand(conn, insertSql);
67+
// }
68+
// }
69+
//}

src/SQLite.Net/Orm.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,15 @@ public static IColumnInformationProvider ColumnInformationProvider
4545
set { _columnInformationProvider = value; }
4646
}
4747

48+
public static Type GetObjType(object obj)
49+
{
50+
if (obj == null)
51+
return typeof(object);
52+
if (obj is IReflectableType rt)
53+
return rt.GetTypeInfo().AsType();
54+
return obj.GetType();
55+
}
56+
4857
internal static string SqlDecl(TableMapping.Column p, bool storeDateTimeAsTicks, IBlobSerializer serializer,
4958
IDictionary<Type, string> extraTypeMappings)
5059
{

src/SQLite.Net/PreparedSqlLiteInsertCommand.cs

Lines changed: 36 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -30,44 +30,28 @@ namespace SQLite.Net2
3030
/// </summary>
3131
public class PreparedSqlLiteInsertCommand : IDisposable
3232
{
33-
private static readonly IDbStatement NullStatement = default(IDbStatement);
33+
static readonly IDbStatement NullStatement = default(IDbStatement);
34+
//static readonly object _locker = new object();
3435
readonly SqliteApi sqlite = SqliteApi.Instance;
35-
36-
internal PreparedSqlLiteInsertCommand(SQLiteConnection conn)
37-
{
38-
Connection = conn;
39-
}
40-
36+
SQLiteConnection Connection { get; set; }
37+
IDbStatement Statement { get; set; }
38+
string commandText;
4139

4240
public bool Initialized { get; set; }
4341

44-
45-
public string CommandText { get; set; }
46-
47-
48-
protected SQLiteConnection Connection { get; set; }
49-
50-
51-
protected IDbStatement Statement { get; set; }
52-
53-
54-
public void Dispose()
42+
internal PreparedSqlLiteInsertCommand(SQLiteConnection conn, string commandText)
5543
{
56-
Dispose(true);
57-
GC.SuppressFinalize(this);
44+
Connection = conn;
45+
this.commandText = commandText;
5846
}
5947

60-
~PreparedSqlLiteInsertCommand()
48+
public int ExecuteNonQuery(object[] source)
6149
{
62-
Dispose(false);
63-
}
64-
65-
static readonly object _locker = new object();
50+
Connection.TraceListener.WriteLine("Executing: {0}", commandText);
6651

52+
if (Initialized && Statement == NullStatement)
53+
throw new ObjectDisposedException(nameof(PreparedSqlLiteInsertCommand));
6754

68-
public int ExecuteNonQuery(object[] source)
69-
{
70-
Connection.TraceListener.WriteLine("Executing: {0}", CommandText);
7155
if (!Initialized)
7256
{
7357
Statement = Prepare();
@@ -82,7 +66,7 @@ public int ExecuteNonQuery(object[] source)
8266
}
8367

8468
Result r;
85-
lock (_locker)
69+
//lock (_locker)
8670
{
8771
r = sqlite.Step(Statement);
8872
}
@@ -93,50 +77,56 @@ public int ExecuteNonQuery(object[] source)
9377
sqlite.Reset(Statement);
9478
return rowsAffected;
9579
}
80+
9681
if (r == Result.Error)
9782
{
9883
var msg = sqlite.Errmsg16(Connection.Handle);
9984
sqlite.Reset(Statement);
10085
throw new SQLiteException(r, msg);
10186
}
87+
10288
if (r == Result.Constraint && sqlite.ExtendedErrCode(Connection.Handle) == ExtendedResult.ConstraintNotNull)
10389
{
10490
sqlite.Reset(Statement);
10591
throw new NotNullConstraintViolationException(r, sqlite.Errmsg16(Connection.Handle));
10692
}
93+
10794
sqlite.Reset(Statement);
108-
109-
throw new SQLiteException(r, r.ToString());
95+
throw new SQLiteException(r, sqlite.Errmsg16(Connection.Handle));
11096
}
11197

11298

113-
protected virtual IDbStatement Prepare()
99+
IDbStatement Prepare()
114100
{
115101
try
116102
{
117-
var stmt = sqlite.Prepare2(Connection.Handle, CommandText);
103+
var stmt = sqlite.Prepare2(Connection.Handle, commandText);
118104
return stmt;
119105
}
120106
catch (Exception e)
121107
{
122-
throw new Exception($"Sqlite prepareinsert failed for sql: {CommandText}", e);
108+
throw new Exception($"Sqlite prepareinsert failed for sql: {commandText}", e);
123109
}
124110
}
125111

112+
public void Dispose()
113+
{
114+
Dispose(true);
115+
GC.SuppressFinalize(this);
116+
}
117+
126118
private void Dispose(bool disposing)
127119
{
128-
if (Statement != NullStatement)
129-
{
130-
try
131-
{
132-
sqlite.Finalize(Statement);
133-
}
134-
finally
135-
{
136-
Statement = NullStatement;
137-
Connection = null;
138-
}
139-
}
120+
var s = Statement;
121+
Statement = NullStatement;
122+
Connection = null;
123+
if (s != NullStatement)
124+
sqlite.Finalize (s);
125+
}
126+
127+
~PreparedSqlLiteInsertCommand()
128+
{
129+
Dispose(false);
140130
}
141131
}
142132
}

src/SQLite.Net/SQLite.Net2.csproj

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
<DebugType>portable</DebugType>
99
<AssemblyProduct>SQLite.Net2</AssemblyProduct>
1010
<AssemblyCopyright>Copyright ©2020 Benjamin Mayrargue</AssemblyCopyright>
11+
<LangVersion>Latest</LangVersion>
1112
</PropertyGroup>
1213

1314
<!-- nuget configurable properties -->
@@ -45,7 +46,7 @@
4546
</PropertyGroup>
4647

4748
<ItemGroup>
48-
<PackageReference Include="SQLitePCLRaw.core" Version="2.0.3" />
49+
<PackageReference Include="SQLitePCLRaw.core" Version="2.0.4" />
4950
<None Include="..\..\LICENSE.md" Pack="true" PackagePath="" />
5051
</ItemGroup>
5152

0 commit comments

Comments
 (0)