Skip to content
This repository was archived by the owner on Nov 1, 2018. It is now read-only.

Commit 4f846d4

Browse files
author
Nate McMaster
committed
More PR feedback. Put all version switches into one class.
1 parent 3d11446 commit 4f846d4

File tree

9 files changed

+71
-59
lines changed

9 files changed

+71
-59
lines changed

.travis.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ env:
44
- MONO_THREADS_PER_CPU=2000 MONO_MANAGED_WATCHER=disabled
55
mono:
66
- beta
7-
- alpha
87
os:
98
- linux
109
- osx

src/Microsoft.Data.Sqlite/Interop/MarshalEx.cs

Lines changed: 1 addition & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -61,27 +61,7 @@ public static void ThrowExceptionForRC(int rc, Sqlite3Handle db)
6161
return;
6262
}
6363

64-
65-
string message;
66-
67-
if (db != null && !db.IsInvalid)
68-
{
69-
message = Strings.FormatSqliteNativeError(
70-
rc,
71-
NativeMethods.sqlite3_errmsg(db));
72-
}
73-
else if (SqliteVersion.Current >= new Version("3.7.15"))
74-
{
75-
message = Strings.FormatSqliteNativeError(
76-
rc,
77-
NativeMethods.sqlite3_errstr(rc));
78-
}
79-
else
80-
{
81-
message = Strings.FormatSqliteNativeErrorStringMissing(rc);
82-
}
83-
84-
throw new SqliteException(message, rc);
64+
throw new SqliteException(VersionedMethods.SqliteErrorMessage(rc, db), rc);
8565
}
8666
}
8767
}

src/Microsoft.Data.Sqlite/Interop/Sqlite3Handle.cs

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -18,19 +18,9 @@ private Sqlite3Handle()
1818

1919
protected override bool ReleaseHandle()
2020
{
21-
int rc = -1;
22-
if (SqliteVersion.Current < new Version("3.7.15"))
23-
{
24-
rc = NativeMethods.sqlite3_close(handle);
25-
handle = IntPtr.Zero;
26-
}
27-
else
28-
{
29-
rc = NativeMethods.sqlite3_close_v2(handle);
30-
handle = IntPtr.Zero;
31-
}
32-
33-
return rc == Constants.SQLITE_OK;
21+
var result = VersionedMethods.SqliteClose(handle);
22+
handle = IntPtr.Zero;
23+
return result;
3424
}
3525
}
3626
}
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
// Copyright (c) .NET Foundation. All rights reserved.
2+
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
3+
4+
using System;
5+
6+
namespace Microsoft.Data.Sqlite.Interop
7+
{
8+
internal class VersionedMethods
9+
{
10+
private static Version Current => new Version(NativeMethods.sqlite3_libversion());
11+
12+
public static string SqliteErrorMessage(int rc, Sqlite3Handle db)
13+
{
14+
if (db != null && !db.IsInvalid)
15+
{
16+
return Strings.FormatSqliteNativeError(
17+
rc,
18+
NativeMethods.sqlite3_errmsg(db));
19+
}
20+
else if (Current >= new Version("3.7.15"))
21+
{
22+
return Strings.FormatSqliteNativeError(
23+
rc,
24+
NativeMethods.sqlite3_errstr(rc));
25+
}
26+
return Strings.FormatSqliteNativeErrorStringMissing(rc);
27+
}
28+
29+
internal static bool SqliteClose(IntPtr handle)
30+
{
31+
int rc = -1;
32+
if (Current < new Version("3.7.15"))
33+
{
34+
rc = NativeMethods.sqlite3_close(handle);
35+
}
36+
else
37+
{
38+
rc = NativeMethods.sqlite3_close_v2(handle);
39+
}
40+
41+
return rc == Constants.SQLITE_OK;
42+
}
43+
44+
internal static string SqliteDbFilename(Sqlite3Handle db, string databaseName)
45+
{
46+
if(Current < new Version("3.7.10"))
47+
{
48+
return null;
49+
}
50+
return NativeMethods.sqlite3_db_filename(db, databaseName);
51+
}
52+
}
53+
}

src/Microsoft.Data.Sqlite/SqliteConnection.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,8 @@ public override string ConnectionString
6161
public override string Database => MainDatabaseName;
6262

6363
public override string DataSource =>
64-
State == ConnectionState.Open && SqliteVersion.Current >= new Version("3.7.10") ?
65-
NativeMethods.sqlite3_db_filename(_db, MainDatabaseName) :
64+
State == ConnectionState.Open ?
65+
VersionedMethods.SqliteDbFilename(_db, MainDatabaseName) ?? ConnectionStringBuilder.DataSource :
6666
ConnectionStringBuilder.DataSource;
6767

6868
/// <summary>

src/Microsoft.Data.Sqlite/Utilities/SqliteVersion.cs

Lines changed: 0 additions & 13 deletions
This file was deleted.

test/Microsoft.Data.Sqlite.Tests/SqliteConcurrencyTest.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ public void It_throws_sqlite_busy_on_deadlock()
116116

117117
Assert.Equal(SQLITE_BUSY, ex.SqliteErrorCode);
118118

119-
if (SqliteVersion.Current >= new Version("3.7.15"))
119+
if (CurrentVersion >= new Version("3.7.15"))
120120
{
121121
var message = NativeMethods.sqlite3_errstr(SQLITE_BUSY);
122122
Assert.Equal(Strings.FormatSqliteNativeError(SQLITE_BUSY, message), ex.Message);
@@ -195,7 +195,7 @@ public void Command_times_out()
195195

196196
Assert.Equal(SQLITE_BUSY, ex.SqliteErrorCode);
197197

198-
if (SqliteVersion.Current >= new Version("3.7.15"))
198+
if (CurrentVersion >= new Version("3.7.15"))
199199
{
200200
var message = NativeMethods.sqlite3_errstr(SQLITE_BUSY);
201201
Assert.Equal(Strings.FormatSqliteNativeError(SQLITE_BUSY, message), ex.Message);
@@ -209,6 +209,8 @@ public void Command_times_out()
209209
}
210210
}
211211
}
212+
213+
private Version CurrentVersion => new Version(NativeMethods.sqlite3_libversion());
212214

213215
private const string FileName = "./concurrency.db";
214216

test/Microsoft.Data.Sqlite.Tests/TestUtilities/SqliteTestFramework.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
33

44
using System.Reflection;
5-
using Microsoft.Data.Sqlite.Utilities;
5+
using Microsoft.Data.Sqlite.Interop;
66
using Xunit;
77
using Xunit.Abstractions;
88
using Xunit.Sdk;
@@ -25,7 +25,7 @@ protected override ITestFrameworkExecutor CreateExecutor(AssemblyName assemblyNa
2525
{
2626
_messageSink.OnMessage(new Xunit.Sdk.DiagnosticMessage
2727
{
28-
Message = $"Using SQLite v{ SqliteVersion.Current }"
28+
Message = $"Using SQLite v{ NativeMethods.sqlite3_libversion() }"
2929
});
3030

3131
return base.CreateExecutor(assemblyName);

test/Microsoft.Data.Sqlite.Tests/TestUtilities/SqliteVersionConditionAttribute.cs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33

44
using System;
55
using Microsoft.AspNet.Testing.xunit;
6-
using Microsoft.Data.Sqlite.Utilities;
76

87
namespace Microsoft.Data.Sqlite
98
{
@@ -17,11 +16,13 @@ internal class SqliteVersionConditionAttribute : Attribute, ITestCondition
1716
public string Max { get { return _max.ToString(); } set { _max = new Version(value); } }
1817
public string Skip { get { return _skip.ToString(); } set { _skip = new Version(value); } }
1918

19+
private Version Current = new Version(NativeMethods.sqlite3_libversion());
20+
2021
public bool IsMet
2122
{
2223
get
2324
{
24-
if (SqliteVersion.Current == _skip)
25+
if (Current == _skip)
2526
{
2627
return false;
2728
}
@@ -33,15 +34,15 @@ public bool IsMet
3334

3435
if (_min == null)
3536
{
36-
return SqliteVersion.Current <= _max;
37+
return Current <= _max;
3738
}
3839

3940
if (_max == null)
4041
{
41-
return SqliteVersion.Current >= _min;
42+
return Current >= _min;
4243
}
4344

44-
return SqliteVersion.Current <= _max && SqliteVersion.Current >= _min;
45+
return Current <= _max && Current >= _min;
4546
}
4647
}
4748

0 commit comments

Comments
 (0)