This repository was archived by the owner on Nov 1, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 98
Support SQLite 3.7.9 #171
Merged
Merged
Support SQLite 3.7.9 #171
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,19 +1,21 @@ | ||
| language: csharp | ||
| sudo: false | ||
| env: | ||
| - MONO_THREADS_PER_CPU=2000 MONO_MANAGED_WATCHER=disabled | ||
| mono: | ||
| - beta | ||
| os: | ||
| - linux | ||
| - osx | ||
|
|
||
| addons: | ||
| apt: | ||
| sources: | ||
| - debian-sid | ||
| packages: | ||
| - libunwind8 | ||
| - sqlite3 | ||
|
|
||
|
|
||
| before_script: | ||
| - sqlite3 -version | ||
| before_install: | ||
| - if test "$TRAVIS_OS_NAME" == "osx"; then brew update; brew install icu4c; fi | ||
| script: | ||
| - ./build.sh --quiet verify |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,74 @@ | ||
| // Copyright (c) .NET Foundation. All rights reserved. | ||
| // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. | ||
|
|
||
| using System; | ||
|
|
||
| namespace Microsoft.Data.Sqlite.Interop | ||
| { | ||
| internal class VersionedMethods | ||
| { | ||
| public static string SqliteErrorMessage(int rc, Sqlite3Handle db) | ||
| { | ||
| var message = db == null || db.IsInvalid | ||
| ? _strategy.ErrorString(rc) | ||
| : NativeMethods.sqlite3_errmsg(db); | ||
|
|
||
| return Strings.FormatSqliteNativeError(rc, message); | ||
| } | ||
|
|
||
| public static int SqliteClose(IntPtr handle) | ||
| => _strategy.Close(handle); | ||
|
|
||
| public static string SqliteDbFilename(Sqlite3Handle db, string databaseName) | ||
| => _strategy.DbFilename(db, databaseName); | ||
|
|
||
| private static readonly StrategyBase _strategy = GetStrategy(new Version(NativeMethods.sqlite3_libversion())); | ||
|
|
||
| private static StrategyBase GetStrategy(Version current) | ||
| { | ||
| if (current >= new Version("3.7.15")) | ||
| { | ||
| return new Strategy3_7_15(); | ||
| } | ||
| if (current >= new Version("3.7.14")) | ||
| { | ||
| return new Strategy3_7_14(); | ||
| } | ||
| if (current >= new Version("3.7.10")) | ||
| { | ||
| return new Strategy3_7_10(); | ||
| } | ||
| return new StrategyBase(); | ||
| } | ||
|
|
||
| private class Strategy3_7_15 : Strategy3_7_14 | ||
| { | ||
| public override string ErrorString(int rc) | ||
| => NativeMethods.sqlite3_errstr(rc) + " " + base.ErrorString(rc); | ||
| } | ||
|
|
||
| private class Strategy3_7_14 : Strategy3_7_10 | ||
| { | ||
| public override int Close(IntPtr handle) | ||
| => NativeMethods.sqlite3_close_v2(handle); | ||
| } | ||
|
|
||
| private class Strategy3_7_10 : StrategyBase | ||
| { | ||
| public override string DbFilename(Sqlite3Handle db, string databaseName) | ||
| => NativeMethods.sqlite3_db_filename(db, databaseName); | ||
| } | ||
|
|
||
| private class StrategyBase | ||
| { | ||
| public virtual string ErrorString(int rc) | ||
| => Strings.DefaultNativeError; | ||
|
|
||
| public virtual int Close(IntPtr handle) | ||
| => NativeMethods.sqlite3_close(handle); | ||
|
|
||
| public virtual string DbFilename(Sqlite3Handle db, string databaseName) | ||
| => null; | ||
| } | ||
| } | ||
| } | ||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
63 changes: 63 additions & 0 deletions
63
test/Microsoft.Data.Sqlite.Tests/TestUtilities/SqliteVersionConditionAttribute.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,63 @@ | ||
| // Copyright (c) .NET Foundation. All rights reserved. | ||
| // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. | ||
|
|
||
| using System; | ||
| using Microsoft.Data.Sqlite.Interop; | ||
| using Microsoft.AspNet.Testing.xunit; | ||
|
|
||
| namespace Microsoft.Data.Sqlite | ||
| { | ||
| [AttributeUsage(AttributeTargets.Method, Inherited = true)] | ||
| internal class SqliteVersionConditionAttribute : Attribute, ITestCondition | ||
| { | ||
| private Version _min; | ||
| private Version _max; | ||
| private Version _skip; | ||
| public string Min { get { return _min.ToString(); } set { _min = new Version(value); } } | ||
| public string Max { get { return _max.ToString(); } set { _max = new Version(value); } } | ||
| public string Skip { get { return _skip.ToString(); } set { _skip = new Version(value); } } | ||
|
|
||
| private Version Current = new Version(NativeMethods.sqlite3_libversion()); | ||
|
|
||
| public bool IsMet | ||
| { | ||
| get | ||
| { | ||
| if (Current == _skip) | ||
| { | ||
| return false; | ||
| } | ||
|
|
||
| if (_min == null && _max == null) | ||
| { | ||
| return true; | ||
| } | ||
|
|
||
| if (_min == null) | ||
| { | ||
| return Current <= _max; | ||
| } | ||
|
|
||
| if (_max == null) | ||
| { | ||
| return Current >= _min; | ||
| } | ||
|
|
||
| return Current <= _max && Current >= _min; | ||
| } | ||
| } | ||
|
|
||
| private string _skipReason; | ||
|
|
||
| public string SkipReason | ||
| { | ||
| set { _skipReason = value; } | ||
| get | ||
| { | ||
| return _skipReason ?? | ||
| $"Test only runs for SQLite versions >= { Min ?? "Any"} and <= { Max ?? "Any" }" | ||
| + (Skip == null ? "" : "and skipping on " + Skip); | ||
| } | ||
| } | ||
| } | ||
| } |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could take this one step further with the strategy pattern. You'd set the strategy once in the static constructor based on the version then each method wouldn't have to check each time.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, strategy pattern is a lot cleaner. I updated the implementation.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This class is beautiful now. Well done.