Skip to content

Commit 3584a6d

Browse files
authored
Merge pull request praeclarum#856 from Pythians/master
Issues: The right way to do prepared statements
2 parents feb4d49 + 2e7e4bc commit 3584a6d

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

src/SQLite.cs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -871,6 +871,33 @@ public SQLiteCommand CreateCommand (string cmdText, params object[] ps)
871871
return cmd;
872872
}
873873

874+
/// <summary>
875+
/// Creates a new SQLiteCommand given the command text with arguments. Place a "[@:]VVV"
876+
/// in the command text for each of the arguments.
877+
/// </summary>
878+
/// <param name="cmdText">
879+
/// The fully escaped SQL.
880+
/// </param>
881+
/// <param name="args">
882+
/// Arguments to substitute for the occurences of "[@:]VVV" in the command text.
883+
/// </param>
884+
/// <returns>
885+
/// A <see cref="SQLiteCommand" />
886+
/// </returns>
887+
public SQLiteCommand CreateCommand(string cmdText, Dictionary<string, object> args)
888+
{
889+
if (!this._open)
890+
throw SQLiteException.New(SQLite3.Result.Error, "Cannot create commands from unopened database");
891+
892+
SQLiteCommand cmd = NewCommand();
893+
cmd.CommandText = cmdText;
894+
foreach (var kv in args)
895+
{
896+
cmd.Bind(kv.Key, kv.Value);
897+
}
898+
return cmd;
899+
}
900+
874901
/// <summary>
875902
/// Creates a SQLiteCommand given the command text (SQL) with arguments. Place a '?'
876903
/// in the command text for each of the arguments and then executes that command.

0 commit comments

Comments
 (0)