-
Notifications
You must be signed in to change notification settings - Fork 3.3k
SQLITE: EXPLAIN requires adding values for all query's parameters #16647
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
Comments
@bricelam Backlog/enhancement? |
👍 We can use sqlite3_stmt_isexplain to special case these statements. |
any workaround exists? |
Provide dummy parameter values |
Validation class works like a service, it does not know the list of parameters for each checked query. I can split statement to term (word) list, and take those that begin with @, but it does not look good enough... anyway thanks for the answer! :) |
Written in notepad, so it may not compile, but this should get you started in the right direction: static void AddDummyParameters(this SqliteCommand command)
{
var db = command.Connection.Handle;
var remainingSql = command.CommandText;
while (!string.IsNullOrEmpty(remainingSql))
{
var rc = raw.sqlite3_prepare_v2(db, remainingSql, out var stmt, out remainingSql);
SqliteException.ThrowExceptionForRC(rc, db);
if (stmt.ptr == IntPtr.Zero)
{
// Statement was empty, white space, or a comment
continue;
}
using (stmt)
{
var count = raw.sqlite3_bind_parameter_count(stmt);
for (var i = 1; i <= count; i++)
{
var name = raw.sqlite3_bind_parameter_name(stmt, i);
// Add a dummy value
command.Parameters.AddWithValue(name, "dummy");
}
}
}
} |
@bricelam it works, thank you! |
@AlexanderTaeschner Are you bored? lol, here's a good one if you're interested. |
Not really bored, but interested. Unfortunately the |
Ah, I didn’t realize that. Maybe I’ll prepare a few PRs for SQLitePCLRaw. I think we’re blocked on a few missing APIs in there. |
I just added PR ericsink/SQLitePCL.raw#328 to add |
I am not very familiar with SQLite and Microsoft.Data.SQLite in particular, but it's unclear for me why Microsoft.Data.SQLite requires a values for a query's parameters for EXPLAIN queries.
Please take a look at Visual Studio unit test screenshot

it fails with the exception 'Must add values for the following parameters: @A'.
At the same time 'DB browser for SQLite' process this query with no problem:

Looks like SQLite allows such things.
My task is to validate query syntax. My way is to add an 'explain' term in the head of the query and call ExecuteNonQuery.
How can I execute EXPLAIN-queries without parameter's values?
Thanks!
The text was updated successfully, but these errors were encountered: