Skip to content

Commit

Permalink
Add special case where an EXPLAIn query is used without initializing …
Browse files Browse the repository at this point in the history
…the parameters.
  • Loading branch information
AlexanderTaeschner authored and bricelam committed May 7, 2020
1 parent ba90a10 commit 4f6c41a
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 5 deletions.
8 changes: 4 additions & 4 deletions eng/Versions.props
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@
<NetTopologySuiteVersion>2.0.0</NetTopologySuiteVersion>
<NetTopologySuiteIOSpatiaLiteVersion>2.0.0</NetTopologySuiteIOSpatiaLiteVersion>
<NetTopologySuiteIOSqlServerBytesVersion>2.0.0</NetTopologySuiteIOSqlServerBytesVersion>
<SQLitePCLRawBundleESqlite3Version>2.0.2</SQLitePCLRawBundleESqlite3Version>
<SQLitePCLRawBundleESqlcipherVersion>2.0.2</SQLitePCLRawBundleESqlcipherVersion>
<SQLitePCLRawBundleWinsqlite3Version>2.0.2</SQLitePCLRawBundleWinsqlite3Version>
<SQLitePCLRawCoreVersion>2.0.2</SQLitePCLRawCoreVersion>
<SQLitePCLRawBundleESqlite3Version>2.0.3</SQLitePCLRawBundleESqlite3Version>
<SQLitePCLRawBundleESqlcipherVersion>2.0.3</SQLitePCLRawBundleESqlcipherVersion>
<SQLitePCLRawBundleWinsqlite3Version>2.0.3</SQLitePCLRawBundleWinsqlite3Version>
<SQLitePCLRawCoreVersion>2.0.3</SQLitePCLRawCoreVersion>
<IdentityServer4EntityFrameworkVersion>3.0.0</IdentityServer4EntityFrameworkVersion>
<StyleCopAnalyzersVersion>1.1.118</StyleCopAnalyzersVersion>
<BenchmarkDotNetVersion>0.12.0</BenchmarkDotNetVersion>
Expand Down
6 changes: 5 additions & 1 deletion src/Microsoft.Data.Sqlite.Core/SqliteCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,11 @@ private IEnumerable<sqlite3_stmt> 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;
Expand Down
24 changes: 24 additions & 0 deletions test/Microsoft.Data.Sqlite.Tests/SqliteCommandTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
{
Expand Down

0 comments on commit 4f6c41a

Please sign in to comment.