Skip to content

Commit

Permalink
Merge pull request praeclarum#856 from Pythians/master
Browse files Browse the repository at this point in the history
Issues: The right way to do prepared statements
  • Loading branch information
praeclarum authored May 16, 2020
2 parents feb4d49 + 2e7e4bc commit 3584a6d
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions src/SQLite.cs
Original file line number Diff line number Diff line change
Expand Up @@ -871,6 +871,33 @@ public SQLiteCommand CreateCommand (string cmdText, params object[] ps)
return cmd;
}

/// <summary>
/// Creates a new SQLiteCommand given the command text with arguments. Place a "[@:]VVV"
/// in the command text for each of the arguments.
/// </summary>
/// <param name="cmdText">
/// The fully escaped SQL.
/// </param>
/// <param name="args">
/// Arguments to substitute for the occurences of "[@:]VVV" in the command text.
/// </param>
/// <returns>
/// A <see cref="SQLiteCommand" />
/// </returns>
public SQLiteCommand CreateCommand(string cmdText, Dictionary<string, object> args)
{
if (!this._open)
throw SQLiteException.New(SQLite3.Result.Error, "Cannot create commands from unopened database");

SQLiteCommand cmd = NewCommand();
cmd.CommandText = cmdText;
foreach (var kv in args)
{
cmd.Bind(kv.Key, kv.Value);
}
return cmd;
}

/// <summary>
/// Creates a SQLiteCommand given the command text (SQL) with arguments. Place a '?'
/// in the command text for each of the arguments and then executes that command.
Expand Down

0 comments on commit 3584a6d

Please sign in to comment.