Skip to content

Commit 918132b

Browse files
committed
Simplify CreateCommand
1 parent 2b42ad9 commit 918132b

File tree

1 file changed

+10
-44
lines changed

1 file changed

+10
-44
lines changed

SQLiteSharp/SQLiteConnection.cs

Lines changed: 10 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -326,60 +326,26 @@ private void MigrateTable(TableMapping map, List<ColumnInfo> existingColumns) {
326326
}
327327

328328
/// <summary>
329-
/// Creates a new SQLiteCommand. Can be overridden to provide a sub-class.
329+
/// Creates a new SQLiteCommand given the command text with parameters.<br/>
330+
/// Place <c>?</c> in the command text for each argument.
330331
/// </summary>
331-
/// <seealso cref="SQLiteCommand.OnInstanceCreated"/>
332-
protected virtual SQLiteCommand NewCommand() {
333-
return new SQLiteCommand(this);
334-
}
335-
336-
/// <summary>
337-
/// Creates a new SQLiteCommand given the command text with arguments. Place a '?'
338-
/// in the command text for each of the arguments.
339-
/// </summary>
340-
/// <param name="commandText">
341-
/// The fully escaped SQL.
342-
/// </param>
343-
/// <param name="parameters">
344-
/// Arguments to substitute for the occurences of '?' in the command text.
345-
/// </param>
346-
/// <returns>
347-
/// A <see cref="SQLiteCommand"/>
348-
/// </returns>
349332
public SQLiteCommand CreateCommand(string commandText, params IEnumerable<object?> parameters) {
350-
if (Handle.IsInvalid) {
351-
throw new SQLiteException(SQLiteRaw.Result.Error, "Cannot create commands from unopened database");
352-
}
353-
354-
SQLiteCommand command = NewCommand();
355-
command.CommandText = commandText;
333+
SQLiteCommand command = new(this) {
334+
CommandText = commandText,
335+
};
356336
foreach (object? parameter in parameters) {
357337
command.Bind(parameter);
358338
}
359339
return command;
360340
}
361-
362341
/// <summary>
363-
/// Creates a new SQLiteCommand given the command text with named arguments. Place a "[@:$]VVV"
364-
/// in the command text for each of the arguments. VVV represents an alphanumeric identifier.
365-
/// For example, @name :name and $name can all be used in the query.
342+
/// Creates a new SQLiteCommand given the command text with named parameters. Place <c>@</c> or <c>:</c> or <c>$</c> followed by an alphanumeric identifier for each argument.<br/>
343+
/// For example, <c>@name</c>, <c>:name</c> and <c>$name</c> can all be used.
366344
/// </summary>
367-
/// <param name="commandText">
368-
/// The fully escaped SQL.
369-
/// </param>
370-
/// <param name="parameters">
371-
/// Arguments to substitute for the occurences of "[@:$]VVV" in the command text.
372-
/// </param>
373-
/// <returns>
374-
/// A <see cref="SQLiteCommand" />
375-
/// </returns>
376345
public SQLiteCommand CreateCommand(string commandText, Dictionary<string, object> parameters) {
377-
if (Handle.IsInvalid) {
378-
throw new SQLiteException(SQLiteRaw.Result.Error, "Cannot create commands from unopened database");
379-
}
380-
381-
SQLiteCommand command = NewCommand();
382-
command.CommandText = commandText;
346+
SQLiteCommand command = new(this) {
347+
CommandText = commandText,
348+
};
383349
foreach (KeyValuePair<string, object> parameter in parameters) {
384350
command.Bind(parameter.Key, parameter.Value);
385351
}

0 commit comments

Comments
 (0)