Skip to content

Sqlite: Support uninitialized EXPLAIN queries #19630

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Merged
merged 1 commit into from
May 8, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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