Skip to content

Commit

Permalink
Update DbCommandExtensions.cs
Browse files Browse the repository at this point in the history
  • Loading branch information
odinserj committed Oct 17, 2024
1 parent fd76906 commit fa52c27
Showing 1 changed file with 52 additions and 51 deletions.
103 changes: 52 additions & 51 deletions src/Hangfire.SqlServer/DbCommandExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,69 +18,70 @@
using System.Data.Common;
using Hangfire.Annotations;

namespace Hangfire.SqlServer;

internal static class DbCommandExtensions
namespace Hangfire.SqlServer
{
public static DbCommand Create(
[NotNull] this DbConnection connection,
[NotNull] string text,
CommandType type = CommandType.Text,
int? timeout = null)
internal static class DbCommandExtensions
{
if (connection == null) throw new ArgumentNullException(nameof(connection));
if (text == null) throw new ArgumentNullException(nameof(text));
public static DbCommand Create(
[NotNull] this DbConnection connection,
[NotNull] string text,
CommandType type = CommandType.Text,
int? timeout = null)
{
if (connection == null) throw new ArgumentNullException(nameof(connection));
if (text == null) throw new ArgumentNullException(nameof(text));

var command = connection.CreateCommand();
command.CommandType = type;
command.CommandText = text;
var command = connection.CreateCommand();
command.CommandType = type;
command.CommandText = text;

if (timeout.HasValue)
{
command.CommandTimeout = timeout.Value;
}
if (timeout.HasValue)
{
command.CommandTimeout = timeout.Value;
}

return command;
}
return command;
}

public static DbCommand AddParameter(
[NotNull] this DbCommand command,
[NotNull] string parameterName,
[CanBeNull] object value,
DbType dbType,
[CanBeNull] int? size = null)
{
if (command == null) throw new ArgumentNullException(nameof(command));
if (parameterName == null) throw new ArgumentNullException(nameof(parameterName));
public static DbCommand AddParameter(
[NotNull] this DbCommand command,
[NotNull] string parameterName,
[CanBeNull] object value,
DbType dbType,
[CanBeNull] int? size = null)
{
if (command == null) throw new ArgumentNullException(nameof(command));
if (parameterName == null) throw new ArgumentNullException(nameof(parameterName));

var parameter = command.CreateParameter();
parameter.ParameterName = parameterName;
parameter.DbType = dbType;
parameter.Value = value ?? DBNull.Value;
var parameter = command.CreateParameter();
parameter.ParameterName = parameterName;
parameter.DbType = dbType;
parameter.Value = value ?? DBNull.Value;

if (size.HasValue) parameter.Size = size.Value;
if (size.HasValue) parameter.Size = size.Value;

command.Parameters.Add(parameter);
return command;
}
command.Parameters.Add(parameter);
return command;
}

public static DbCommand AddReturnParameter(
[NotNull] this DbCommand command,
string parameterName,
out DbParameter parameter,
DbType dbType,
int? size = null)
{
if (command == null) throw new ArgumentNullException(nameof(command));
public static DbCommand AddReturnParameter(
[NotNull] this DbCommand command,
string parameterName,
out DbParameter parameter,
DbType dbType,
int? size = null)
{
if (command == null) throw new ArgumentNullException(nameof(command));

parameter = command.CreateParameter();
parameter.ParameterName = parameterName;
parameter.DbType = dbType;
parameter.Direction = ParameterDirection.ReturnValue;
parameter = command.CreateParameter();
parameter.ParameterName = parameterName;
parameter.DbType = dbType;
parameter.Direction = ParameterDirection.ReturnValue;

if (size.HasValue) parameter.Size = size.Value;
if (size.HasValue) parameter.Size = size.Value;

command.Parameters.Add(parameter);
return command;
command.Parameters.Add(parameter);
return command;
}
}
}

0 comments on commit fa52c27

Please sign in to comment.