From 64f150cf1c03bc42c65c579d9e473f616791cda1 Mon Sep 17 00:00:00 2001 From: Brice Lambson Date: Fri, 28 Aug 2020 09:55:39 -0700 Subject: [PATCH] :arrow_up: Update to SQLitePCLRaw 2.0.4 Resolves #22198 --- All.sln | 7 ++++ Microsoft.Data.Sqlite.slnf | 1 + .../EFCore.Sqlite.Benchmarks.csproj | 2 +- src/EFCore.Sqlite/EFCore.Sqlite.csproj | 2 +- .../Microsoft.Data.Sqlite.Core.csproj | 2 +- .../Properties/InternalsVisibleTo.cs | 2 ++ .../Microsoft.Data.Sqlite.csproj | 2 +- .../EFCore.Sqlite.FunctionalTests.csproj | 2 +- .../MigrationsSqliteTest.cs | 18 +--------- .../Microsoft.Data.Sqlite.Tests.csproj | 2 +- ...osoft.Data.Sqlite.e_sqlcipher.Tests.csproj | 2 +- ...Microsoft.Data.Sqlite.sqlite3.Tests.csproj | 16 +++++++++ ...rosoft.Data.Sqlite.winsqlite3.Tests.csproj | 2 +- .../SqliteConnectionTest.cs | 34 +++++++++++++++++++ .../TestUtilities/SqliteTestFramework.cs | 22 ++++++------ 15 files changed, 81 insertions(+), 35 deletions(-) create mode 100644 test/Microsoft.Data.Sqlite.Tests/Microsoft.Data.Sqlite.sqlite3.Tests.csproj diff --git a/All.sln b/All.sln index 1400f2ef3cb..22981381fbc 100644 --- a/All.sln +++ b/All.sln @@ -108,6 +108,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Microsoft.Data.Sqlite.e_sql EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Microsoft.Data.Sqlite.winsqlite3.Tests", "test\Microsoft.Data.Sqlite.Tests\Microsoft.Data.Sqlite.winsqlite3.Tests.csproj", "{B163761D-FB4A-4C80-BAB9-01905E1351EF}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Microsoft.Data.Sqlite.sqlite3.Tests", "test\Microsoft.Data.Sqlite.Tests\Microsoft.Data.Sqlite.sqlite3.Tests.csproj", "{E0FF35C8-8038-4394-9C2A-AF34BE3CC61F}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -282,6 +284,10 @@ Global {B163761D-FB4A-4C80-BAB9-01905E1351EF}.Debug|Any CPU.Build.0 = Debug|Any CPU {B163761D-FB4A-4C80-BAB9-01905E1351EF}.Release|Any CPU.ActiveCfg = Release|Any CPU {B163761D-FB4A-4C80-BAB9-01905E1351EF}.Release|Any CPU.Build.0 = Release|Any CPU + {E0FF35C8-8038-4394-9C2A-AF34BE3CC61F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {E0FF35C8-8038-4394-9C2A-AF34BE3CC61F}.Debug|Any CPU.Build.0 = Debug|Any CPU + {E0FF35C8-8038-4394-9C2A-AF34BE3CC61F}.Release|Any CPU.ActiveCfg = Release|Any CPU + {E0FF35C8-8038-4394-9C2A-AF34BE3CC61F}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -329,6 +335,7 @@ Global {2642F4F0-69BE-4C43-94B7-B298FEC87D89} = {293B4F79-3CB9-402A-A74C-B8108C41A7CF} {7B598E0C-B8E2-4F1F-B53C-ED84178E65BE} = {258D5057-81B9-40EC-A872-D21E27452749} {B163761D-FB4A-4C80-BAB9-01905E1351EF} = {258D5057-81B9-40EC-A872-D21E27452749} + {E0FF35C8-8038-4394-9C2A-AF34BE3CC61F} = {258D5057-81B9-40EC-A872-D21E27452749} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {285A5EB4-BCF4-40EB-B9E1-DF6DBCB5E705} diff --git a/Microsoft.Data.Sqlite.slnf b/Microsoft.Data.Sqlite.slnf index 02eee0ff2f8..e3ba0427f1f 100644 --- a/Microsoft.Data.Sqlite.slnf +++ b/Microsoft.Data.Sqlite.slnf @@ -6,6 +6,7 @@ "src\\Microsoft.Data.Sqlite\\Microsoft.Data.Sqlite.csproj", "test\\Microsoft.Data.Sqlite.Tests\\Microsoft.Data.Sqlite.Tests.csproj", "test\\Microsoft.Data.Sqlite.Tests\\Microsoft.Data.Sqlite.e_sqlcipher.Tests.csproj", + "test\\Microsoft.Data.Sqlite.Tests\\Microsoft.Data.Sqlite.sqlite3.Tests.csproj", "test\\Microsoft.Data.Sqlite.Tests\\Microsoft.Data.Sqlite.winsqlite3.Tests.csproj" ] } diff --git a/benchmark/EFCore.Sqlite.Benchmarks/EFCore.Sqlite.Benchmarks.csproj b/benchmark/EFCore.Sqlite.Benchmarks/EFCore.Sqlite.Benchmarks.csproj index 7db570635c0..15da48e2843 100644 --- a/benchmark/EFCore.Sqlite.Benchmarks/EFCore.Sqlite.Benchmarks.csproj +++ b/benchmark/EFCore.Sqlite.Benchmarks/EFCore.Sqlite.Benchmarks.csproj @@ -20,7 +20,7 @@ - + diff --git a/src/EFCore.Sqlite/EFCore.Sqlite.csproj b/src/EFCore.Sqlite/EFCore.Sqlite.csproj index bbfdacb17ca..93b90ef1463 100644 --- a/src/EFCore.Sqlite/EFCore.Sqlite.csproj +++ b/src/EFCore.Sqlite/EFCore.Sqlite.csproj @@ -19,7 +19,7 @@ - + diff --git a/src/Microsoft.Data.Sqlite.Core/Microsoft.Data.Sqlite.Core.csproj b/src/Microsoft.Data.Sqlite.Core/Microsoft.Data.Sqlite.Core.csproj index 118b49bd201..027520179af 100644 --- a/src/Microsoft.Data.Sqlite.Core/Microsoft.Data.Sqlite.Core.csproj +++ b/src/Microsoft.Data.Sqlite.Core/Microsoft.Data.Sqlite.Core.csproj @@ -39,7 +39,7 @@ Microsoft.Data.Sqlite.SqliteTransaction - + diff --git a/src/Microsoft.Data.Sqlite.Core/Properties/InternalsVisibleTo.cs b/src/Microsoft.Data.Sqlite.Core/Properties/InternalsVisibleTo.cs index da0899d9556..4a37d33ae5f 100644 --- a/src/Microsoft.Data.Sqlite.Core/Properties/InternalsVisibleTo.cs +++ b/src/Microsoft.Data.Sqlite.Core/Properties/InternalsVisibleTo.cs @@ -5,6 +5,8 @@ [assembly: InternalsVisibleTo( "Microsoft.Data.Sqlite.e_sqlcipher.Tests, PublicKey=0024000004800000940000000602000000240000525341310004000001000100f33a29044fa9d740c9b3213a93e57c84b472c84e0b8a0e1ae48e67a9f8f6de9d5f7f3d52ac23e48ac51801f1dc950abe901da34d2a9e3baadb141a17c77ef3c565dd5ee5054b91cf63bb3c6ab83f72ab3aafe93d0fc3c2348b764fafb0b1c0733de51459aeab46580384bf9d74c4e28164b7cde247f891ba07891c9d872ad2bb")] +[assembly: InternalsVisibleTo( + "Microsoft.Data.Sqlite.sqlite3.Tests, PublicKey=0024000004800000940000000602000000240000525341310004000001000100f33a29044fa9d740c9b3213a93e57c84b472c84e0b8a0e1ae48e67a9f8f6de9d5f7f3d52ac23e48ac51801f1dc950abe901da34d2a9e3baadb141a17c77ef3c565dd5ee5054b91cf63bb3c6ab83f72ab3aafe93d0fc3c2348b764fafb0b1c0733de51459aeab46580384bf9d74c4e28164b7cde247f891ba07891c9d872ad2bb")] [assembly: InternalsVisibleTo( "Microsoft.Data.Sqlite.Tests, PublicKey=0024000004800000940000000602000000240000525341310004000001000100f33a29044fa9d740c9b3213a93e57c84b472c84e0b8a0e1ae48e67a9f8f6de9d5f7f3d52ac23e48ac51801f1dc950abe901da34d2a9e3baadb141a17c77ef3c565dd5ee5054b91cf63bb3c6ab83f72ab3aafe93d0fc3c2348b764fafb0b1c0733de51459aeab46580384bf9d74c4e28164b7cde247f891ba07891c9d872ad2bb")] [assembly: InternalsVisibleTo( diff --git a/src/Microsoft.Data.Sqlite/Microsoft.Data.Sqlite.csproj b/src/Microsoft.Data.Sqlite/Microsoft.Data.Sqlite.csproj index 4a113f328ae..9ce620f8e70 100644 --- a/src/Microsoft.Data.Sqlite/Microsoft.Data.Sqlite.csproj +++ b/src/Microsoft.Data.Sqlite/Microsoft.Data.Sqlite.csproj @@ -24,7 +24,7 @@ Microsoft.Data.Sqlite.SqliteTransaction - + diff --git a/test/EFCore.Sqlite.FunctionalTests/EFCore.Sqlite.FunctionalTests.csproj b/test/EFCore.Sqlite.FunctionalTests/EFCore.Sqlite.FunctionalTests.csproj index 21912cfdd38..c58af715a5e 100644 --- a/test/EFCore.Sqlite.FunctionalTests/EFCore.Sqlite.FunctionalTests.csproj +++ b/test/EFCore.Sqlite.FunctionalTests/EFCore.Sqlite.FunctionalTests.csproj @@ -21,7 +21,7 @@ - + diff --git a/test/EFCore.Sqlite.FunctionalTests/MigrationsSqliteTest.cs b/test/EFCore.Sqlite.FunctionalTests/MigrationsSqliteTest.cs index da3536e3378..75594724fec 100644 --- a/test/EFCore.Sqlite.FunctionalTests/MigrationsSqliteTest.cs +++ b/test/EFCore.Sqlite.FunctionalTests/MigrationsSqliteTest.cs @@ -244,30 +244,14 @@ public override async Task Add_column_with_defaultValue_datetime() public override async Task Add_column_with_defaultValueSql() { - if (new Version(new SqliteConnection().ServerVersion) < new Version(3, 32, 0)) - { - var ex = await Assert.ThrowsAsync(base.Add_column_with_defaultValueSql); - Assert.Contains("Cannot add a column with non-constant default", ex.Message); - - return; - } - await base.Add_column_with_defaultValueSql(); AssertSql( - @"ALTER TABLE ""People"" ADD ""Sum"" INTEGER NULL DEFAULT (1 + 2);"); + @"ALTER TABLE ""People"" ADD ""Sum"" INTEGER NOT NULL DEFAULT (1 + 2);"); } public override async Task Add_column_with_computedSql(bool? stored) { - if (stored == true && new Version(new SqliteConnection().ServerVersion) < new Version(3, 32, 0)) - { - var ex = await Assert.ThrowsAsync - (() => base.Add_column_with_computedSql(stored)); - Assert.Contains("cannot add a STORED column", ex.Message); - return; - } - await base.Add_column_with_computedSql(stored); var storedSql = stored == true ? " STORED" : ""; diff --git a/test/Microsoft.Data.Sqlite.Tests/Microsoft.Data.Sqlite.Tests.csproj b/test/Microsoft.Data.Sqlite.Tests/Microsoft.Data.Sqlite.Tests.csproj index d1b83c8a1e9..a515f6863ea 100644 --- a/test/Microsoft.Data.Sqlite.Tests/Microsoft.Data.Sqlite.Tests.csproj +++ b/test/Microsoft.Data.Sqlite.Tests/Microsoft.Data.Sqlite.Tests.csproj @@ -10,7 +10,7 @@ - + diff --git a/test/Microsoft.Data.Sqlite.Tests/Microsoft.Data.Sqlite.e_sqlcipher.Tests.csproj b/test/Microsoft.Data.Sqlite.Tests/Microsoft.Data.Sqlite.e_sqlcipher.Tests.csproj index 56342e1a08b..eb2f6086a3f 100644 --- a/test/Microsoft.Data.Sqlite.Tests/Microsoft.Data.Sqlite.e_sqlcipher.Tests.csproj +++ b/test/Microsoft.Data.Sqlite.Tests/Microsoft.Data.Sqlite.e_sqlcipher.Tests.csproj @@ -10,7 +10,7 @@ - + diff --git a/test/Microsoft.Data.Sqlite.Tests/Microsoft.Data.Sqlite.sqlite3.Tests.csproj b/test/Microsoft.Data.Sqlite.Tests/Microsoft.Data.Sqlite.sqlite3.Tests.csproj new file mode 100644 index 00000000000..13e3baf36f0 --- /dev/null +++ b/test/Microsoft.Data.Sqlite.Tests/Microsoft.Data.Sqlite.sqlite3.Tests.csproj @@ -0,0 +1,16 @@ + + + + $(StandardTestTfms) + $(DefineConstants);SQLITE3 + + + + + + + + + + + diff --git a/test/Microsoft.Data.Sqlite.Tests/Microsoft.Data.Sqlite.winsqlite3.Tests.csproj b/test/Microsoft.Data.Sqlite.Tests/Microsoft.Data.Sqlite.winsqlite3.Tests.csproj index 9a915996fae..d737a5df060 100644 --- a/test/Microsoft.Data.Sqlite.Tests/Microsoft.Data.Sqlite.winsqlite3.Tests.csproj +++ b/test/Microsoft.Data.Sqlite.Tests/Microsoft.Data.Sqlite.winsqlite3.Tests.csproj @@ -10,7 +10,7 @@ - + diff --git a/test/Microsoft.Data.Sqlite.Tests/SqliteConnectionTest.cs b/test/Microsoft.Data.Sqlite.Tests/SqliteConnectionTest.cs index 9785e440f04..76b2dccca1d 100644 --- a/test/Microsoft.Data.Sqlite.Tests/SqliteConnectionTest.cs +++ b/test/Microsoft.Data.Sqlite.Tests/SqliteConnectionTest.cs @@ -1083,6 +1083,13 @@ public void EnableExtensions_works() { connection.Open(); + var loadExtensionOmitted = connection.ExecuteScalar( + "SELECT COUNT(*) FROM pragma_compile_options WHERE compile_options = 'OMIT_LOAD_EXTENSION';"); + if (loadExtensionOmitted != 0L) + { + return; + } + var sql = "SELECT load_extension('unknown');"; var ex = Assert.Throws(() => connection.ExecuteNonQuery(sql)); @@ -1110,6 +1117,13 @@ public void EnableExtensions_works_when_closed() { connection.Open(); + var loadExtensionOmitted = connection.ExecuteScalar( + "SELECT COUNT(*) FROM pragma_compile_options WHERE compile_options = 'OMIT_LOAD_EXTENSION';"); + if (loadExtensionOmitted != 0L) + { + return; + } + var sql = "SELECT load_extension('unknown');"; var ex = Assert.Throws(() => connection.ExecuteNonQuery(sql)); @@ -1131,6 +1145,16 @@ public void LoadExtension_works() { using (var connection = new SqliteConnection("Data Source=:memory:")) { + connection.Open(); + + var loadExtensionOmitted = connection.ExecuteScalar( + "SELECT COUNT(*) FROM pragma_compile_options WHERE compile_options = 'OMIT_LOAD_EXTENSION';"); + if (loadExtensionOmitted != 0L) + { + return; + } + + connection.Close(); connection.EnableExtensions(false); connection.Open(); @@ -1149,6 +1173,16 @@ public void LoadExtension_works_when_closed() { using (var connection = new SqliteConnection("Data Source=:memory:")) { + connection.Open(); + + var loadExtensionOmitted = connection.ExecuteScalar( + "SELECT COUNT(*) FROM pragma_compile_options WHERE compile_options = 'OMIT_LOAD_EXTENSION';"); + if (loadExtensionOmitted != 0L) + { + return; + } + + connection.Close(); connection.EnableExtensions(false); connection.Open(); diff --git a/test/Microsoft.Data.Sqlite.Tests/TestUtilities/SqliteTestFramework.cs b/test/Microsoft.Data.Sqlite.Tests/TestUtilities/SqliteTestFramework.cs index e475625eb10..b4c9319c5b5 100644 --- a/test/Microsoft.Data.Sqlite.Tests/TestUtilities/SqliteTestFramework.cs +++ b/test/Microsoft.Data.Sqlite.Tests/TestUtilities/SqliteTestFramework.cs @@ -1,15 +1,13 @@ -using System.Collections.Generic; +using System; +using System.Collections.Generic; using System.Reflection; using System.Threading; using System.Threading.Tasks; using Xunit; using Xunit.Abstractions; using Xunit.Sdk; -using System; -#if WINSQLITE3 -using System.Runtime.InteropServices; -#endif +using static SQLitePCL.raw; [assembly: TestFramework( "Microsoft.Data.Sqlite.Tests.TestUtilities.SqliteTestFramework", @@ -19,6 +17,8 @@ "Microsoft.Data.Sqlite.e_sqlcipher.Tests")] #elif WINSQLITE3 "Microsoft.Data.Sqlite.winsqlite3.Tests")] +#elif SQLITE3 + "Microsoft.Data.Sqlite.sqlite3.Tests")] #else #error Unexpected native library #endif @@ -80,14 +80,16 @@ protected override Task RunTestCollectionAsync( IEnumerable testCases, CancellationTokenSource cancellationTokenSource) { -#if WINSQLITE3 - if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) + try + { + SQLitePCL.Batteries_V2.Init(); + } + catch (DllNotFoundException ex) { - return SkipAll("winsqlite3 isn't supported on " + RuntimeInformation.OSDescription); + return SkipAll(ex.Message); } -#endif - var version = new SqliteConnection().ServerVersion; + var version = sqlite3_libversion().utf8_to_string(); if (new Version(version) < new Version(3, 16, 0)) { return SkipAll("SQLite " + version + " isn't supported. Upgrade to 3.16.0 or higher");