From 4f6c41aa6f60d4163fce9bda5b02876531993b4e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexander=20T=C3=A4schner?= Date: Sat, 18 Jan 2020 08:09:13 +0100 Subject: [PATCH] Add special case where an EXPLAIn query is used without initializing the parameters. --- eng/Versions.props | 8 +++---- .../SqliteCommand.cs | 6 ++++- .../SqliteCommandTest.cs | 24 +++++++++++++++++++ 3 files changed, 33 insertions(+), 5 deletions(-) diff --git a/eng/Versions.props b/eng/Versions.props index 45d62b39253..6ec4c65cfae 100644 --- a/eng/Versions.props +++ b/eng/Versions.props @@ -23,10 +23,10 @@ 2.0.0 2.0.0 2.0.0 - 2.0.2 - 2.0.2 - 2.0.2 - 2.0.2 + 2.0.3 + 2.0.3 + 2.0.3 + 2.0.3 3.0.0 1.1.118 0.12.0 diff --git a/src/Microsoft.Data.Sqlite.Core/SqliteCommand.cs b/src/Microsoft.Data.Sqlite.Core/SqliteCommand.cs index 8a3e3a041c6..9a64392a91c 100644 --- a/src/Microsoft.Data.Sqlite.Core/SqliteCommand.cs +++ b/src/Microsoft.Data.Sqlite.Core/SqliteCommand.cs @@ -342,7 +342,11 @@ private IEnumerable GetStatements(Stopwatch timer) } } - throw new InvalidOperationException(Resources.MissingParameters(string.Join(", ", unboundParams))); + if (sqlite3_libversion_number() < 3028000 || + sqlite3_stmt_isexplain(stmt) == 0) + { + throw new InvalidOperationException(Resources.MissingParameters(string.Join(", ", unboundParams))); + } } yield return stmt; diff --git a/test/Microsoft.Data.Sqlite.Tests/SqliteCommandTest.cs b/test/Microsoft.Data.Sqlite.Tests/SqliteCommandTest.cs index 8daec2a1619..0f5cbe3756d 100644 --- a/test/Microsoft.Data.Sqlite.Tests/SqliteCommandTest.cs +++ b/test/Microsoft.Data.Sqlite.Tests/SqliteCommandTest.cs @@ -609,6 +609,30 @@ public void ExecuteNonQuery_works() } } + [Fact] + public void ExecuteReader_works_on_EXPLAIN() + { + using (var connection = new SqliteConnection("Data Source=:memory:")) + { + var command = connection.CreateCommand(); + command.CommandText = " EXPLAIN SELECT 1 WHERE 1 = @a;"; + connection.Open(); + + if (new Version(connection.ServerVersion) < new Version(3, 28, 0)) + { + command.Parameters.AddWithValue("@a", 1); + } + + using (var reader = command.ExecuteReader()) + { + var hasData = reader.Read(); + Assert.True(hasData); + Assert.Equal(8, reader.FieldCount); + Assert.Equal("Init", reader.GetString(1)); + } + } + } + [Fact] public void ExecuteReader_works() {