Skip to content

Commit

Permalink
Update nullable annotations.
Browse files Browse the repository at this point in the history
Updated to follow latest proposal at dotnet/runtime#689.
  • Loading branch information
bgrainger committed Dec 9, 2019
1 parent 1da01e0 commit 633eea3
Show file tree
Hide file tree
Showing 8 changed files with 46 additions and 48 deletions.
4 changes: 2 additions & 2 deletions src/MySqlConnector/Core/CachedParameter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ namespace MySqlConnector.Core
{
internal sealed class CachedParameter
{
public CachedParameter(int ordinalPosition, string? mode, string? name, string dataType, bool unsigned, int length)
public CachedParameter(int ordinalPosition, string? mode, string name, string dataType, bool unsigned, int length)
{
Position = ordinalPosition;
if (Position == 0)
Expand All @@ -23,7 +23,7 @@ public CachedParameter(int ordinalPosition, string? mode, string? name, string d

public int Position { get; }
public ParameterDirection Direction { get; }
public string? Name { get; }
public string Name { get; }
public MySqlDbType MySqlDbType { get; }
}
}
6 changes: 3 additions & 3 deletions src/MySqlConnector/Core/CachedProcedure.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ internal sealed class CachedProcedure
if (returnsSql.Length != 0)
{
var returnDataType = ParseDataType(returnsSql, out var unsigned, out var length);
parsedParameters.Insert(0, CreateCachedParameter(0, null, null, returnDataType, unsigned, length, returnsSql));
parsedParameters.Insert(0, CreateCachedParameter(0, null, "", returnDataType, unsigned, length, returnsSql));
}

return new CachedProcedure(schema, component, parsedParameters);
Expand Down Expand Up @@ -90,7 +90,7 @@ FROM information_schema.parameters
parameters.Add(new CachedParameter(
reader.GetInt32(0),
!reader.IsDBNull(1) ? reader.GetString(1) : null,
!reader.IsDBNull(2) ? reader.GetString(2) : null,
!reader.IsDBNull(2) ? reader.GetString(2) : "",
dataType,
unsigned,
length
Expand Down Expand Up @@ -247,7 +247,7 @@ internal static string ParseDataType(string sql, out bool unsigned, out int leng
return sql;
}

private static CachedParameter CreateCachedParameter(int ordinal, string? direction, string? name, string dataType, bool unsigned, int length, string originalSql)
private static CachedParameter CreateCachedParameter(int ordinal, string? direction, string name, string dataType, bool unsigned, int length, string originalSql)
{
try
{
Expand Down
8 changes: 4 additions & 4 deletions src/MySqlConnector/MySql.Data.MySqlClient/MySqlCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ private MySqlCommand(MySqlCommand other)

public override int ExecuteNonQuery() => ExecuteNonQueryAsync(IOBehavior.Synchronous, CancellationToken.None).GetAwaiter().GetResult();

public override object ExecuteScalar() => ExecuteScalarAsync(IOBehavior.Synchronous, CancellationToken.None).GetAwaiter().GetResult();
public override object? ExecuteScalar() => ExecuteScalarAsync(IOBehavior.Synchronous, CancellationToken.None).GetAwaiter().GetResult();

public new MySqlDataReader ExecuteReader() => (MySqlDataReader) base.ExecuteReader();

Expand Down Expand Up @@ -238,10 +238,10 @@ internal async Task<int> ExecuteNonQueryAsync(IOBehavior ioBehavior, Cancellatio
return reader.RecordsAffected;
}

public override Task<object> ExecuteScalarAsync(CancellationToken cancellationToken) =>
public override Task<object?> ExecuteScalarAsync(CancellationToken cancellationToken) =>
ExecuteScalarAsync(AsyncIOBehavior, cancellationToken);

internal async Task<object> ExecuteScalarAsync(IOBehavior ioBehavior, CancellationToken cancellationToken)
internal async Task<object?> ExecuteScalarAsync(IOBehavior ioBehavior, CancellationToken cancellationToken)
{
this.ResetCommandTimeout();
var hasSetResult = false;
Expand All @@ -257,7 +257,7 @@ internal async Task<object> ExecuteScalarAsync(IOBehavior ioBehavior, Cancellati
hasSetResult = true;
}
} while (await reader.NextResultAsync(ioBehavior, cancellationToken).ConfigureAwait(false));
return result!;
return result;
}

protected override Task<DbDataReader> ExecuteDbDataReaderAsync(CommandBehavior behavior, CancellationToken cancellationToken)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -388,7 +388,7 @@ private static async Task ClearPoolAsync(MySqlConnection connection, IOBehavior
public override DataTable GetSchema(string collectionName) => GetSchemaProvider().GetSchema(collectionName);

/// <inheritdoc cref="DbConnection.GetSchema(string)"/>
public override DataTable GetSchema(string collectionName, string?[]? restrictions) => GetSchemaProvider().GetSchema(collectionName);
public override DataTable GetSchema(string collectionName, string?[] restrictions) => GetSchemaProvider().GetSchema(collectionName);

private SchemaProvider GetSchemaProvider()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ protected override int AddToBatch(IDbCommand command)
if (mySqlCommand.CloneRawParameters() is MySqlParameterCollection clonedParameters)
{
foreach (var clonedParameter in clonedParameters)
batchCommand.Parameters.Add(clonedParameter);
batchCommand.Parameters.Add(clonedParameter!);
}

m_batch.BatchCommands.Add(batchCommand);
Expand Down
22 changes: 10 additions & 12 deletions src/MySqlConnector/MySql.Data.MySqlClient/MySqlDbColumn.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,17 @@
using MySqlConnector.Protocol.Serialization;

#if NET45
#nullable disable
namespace System.Data.Common
{
public abstract class DbColumn
{
public bool? AllowDBNull { get; protected set; }
public string BaseCatalogName { get; protected set; }
public string BaseColumnName { get; protected set; }
public string BaseSchemaName { get; protected set; }
public string BaseServerName { get; protected set; }
public string BaseTableName { get; protected set; }
public string ColumnName { get; protected set; }
public string? BaseCatalogName { get; protected set; }
public string? BaseColumnName { get; protected set; }
public string? BaseSchemaName { get; protected set; }
public string? BaseServerName { get; protected set; }
public string? BaseTableName { get; protected set; }
public string ColumnName { get; protected set; } = "";
public int? ColumnOrdinal { get; protected set; }
public int? ColumnSize { get; protected set; }
public bool? IsAliased { get; protected set; }
Expand All @@ -32,13 +31,12 @@ public abstract class DbColumn
public bool? IsUnique { get; protected set; }
public int? NumericPrecision { get; protected set; }
public int? NumericScale { get; protected set; }
public string UdtAssemblyQualifiedName { get; protected set; }
public Type DataType { get; protected set; }
public string DataTypeName { get; protected set; }
public virtual object this[string property] => null;
public string? UdtAssemblyQualifiedName { get; protected set; }
public Type? DataType { get; protected set; }
public string? DataTypeName { get; protected set; }
public virtual object? this[string property] => null;
}
}
#nullable enable
#endif

namespace MySql.Data.MySqlClient
Expand Down
18 changes: 9 additions & 9 deletions src/MySqlConnector/MySql.Data.MySqlClient/MySqlParameter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,17 +33,17 @@ public MySqlParameter(string? name, object? value)
#endif
}

public MySqlParameter(string? name, MySqlDbType mySqlDbType)
public MySqlParameter(string name, MySqlDbType mySqlDbType)
: this(name, mySqlDbType, 0)
{
}

public MySqlParameter(string? name, MySqlDbType mySqlDbType, int size)
: this(name, mySqlDbType, size, null)
public MySqlParameter(string name, MySqlDbType mySqlDbType, int size)
: this(name, mySqlDbType, size, "")
{
}

public MySqlParameter(string? name, MySqlDbType mySqlDbType, int size, string? sourceColumn)
public MySqlParameter(string name, MySqlDbType mySqlDbType, int size, string sourceColumn)
{
m_name = name ?? "";
NormalizedParameterName = NormalizeParameterName(m_name);
Expand All @@ -56,7 +56,7 @@ public MySqlParameter(string? name, MySqlDbType mySqlDbType, int size, string? s
}

#if !NETSTANDARD1_3
public MySqlParameter(string? name, MySqlDbType mySqlDbType, int size, ParameterDirection direction, bool isNullable, byte precision, byte scale, string? sourceColumn, DataRowVersion sourceVersion, object value)
public MySqlParameter(string name, MySqlDbType mySqlDbType, int size, ParameterDirection direction, bool isNullable, byte precision, byte scale, string sourceColumn, DataRowVersion sourceVersion, object value)
: this(name, mySqlDbType, size, sourceColumn)
{
Direction = direction;
Expand Down Expand Up @@ -114,8 +114,8 @@ public override ParameterDirection Direction
public override byte Scale { get; set; }
#endif

[NotNull]
public override string? ParameterName
[AllowNull]
public override string ParameterName
{
get => m_name;
set
Expand All @@ -127,8 +127,8 @@ public override string? ParameterName

public override int Size { get; set; }

[NotNull]
public override string? SourceColumn
[AllowNull]
public override string SourceColumn
{
get => m_sourceColumn;
set => m_sourceColumn = value ?? "";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ internal MySqlParameterCollection()
m_nameToIndex = new Dictionary<string, int>(StringComparer.OrdinalIgnoreCase);
}

public MySqlParameter Add(string? parameterName, DbType dbType)
public MySqlParameter Add(string parameterName, DbType dbType)
{
MySqlParameter parameter = new MySqlParameter
{
Expand All @@ -28,7 +28,7 @@ public MySqlParameter Add(string? parameterName, DbType dbType)
return parameter;
}

public override int Add(object? value)
public override int Add(object value)
{
AddParameter((MySqlParameter) (value ?? throw new ArgumentNullException(nameof(value))));
return m_parameters.Count - 1;
Expand All @@ -40,16 +40,16 @@ public MySqlParameter Add(MySqlParameter parameter)
return parameter;
}

public MySqlParameter Add(string? parameterName, MySqlDbType mySqlDbType) => Add(new MySqlParameter(parameterName, mySqlDbType));
public MySqlParameter Add(string? parameterName, MySqlDbType mySqlDbType, int size) => Add(new MySqlParameter(parameterName, mySqlDbType, size));
public MySqlParameter Add(string parameterName, MySqlDbType mySqlDbType) => Add(new MySqlParameter(parameterName, mySqlDbType));
public MySqlParameter Add(string parameterName, MySqlDbType mySqlDbType, int size) => Add(new MySqlParameter(parameterName, mySqlDbType, size));

public override void AddRange(Array values)
{
foreach (var obj in values)
Add(obj);
Add(obj!);
}

public MySqlParameter AddWithValue(string? parameterName, object? value)
public MySqlParameter AddWithValue(string parameterName, object? value)
{
var parameter = new MySqlParameter
{
Expand All @@ -60,7 +60,7 @@ public MySqlParameter AddWithValue(string? parameterName, object? value)
return parameter;
}

public override bool Contains(object? value) => value is MySqlParameter parameter && m_parameters.Contains(parameter);
public override bool Contains(object value) => value is MySqlParameter parameter && m_parameters.Contains(parameter);

public override bool Contains(string value) => IndexOf(value) != -1;

Expand All @@ -78,17 +78,17 @@ public override void Clear()

protected override DbParameter GetParameter(int index) => m_parameters[index];

protected override DbParameter GetParameter(string? parameterName)
protected override DbParameter GetParameter(string parameterName)
{
var index = IndexOf(parameterName);
if (index == -1)
throw new ArgumentException("Parameter '{0}' not found in the collection".FormatInvariant(parameterName), nameof(parameterName));
return m_parameters[index];
}

public override int IndexOf(object? value) => value is MySqlParameter parameter ? m_parameters.IndexOf(parameter) : -1;
public override int IndexOf(object value) => value is MySqlParameter parameter ? m_parameters.IndexOf(parameter) : -1;

public override int IndexOf(string? parameterName) => NormalizedIndexOf(parameterName);
public override int IndexOf(string parameterName) => NormalizedIndexOf(parameterName);

// Finds the index of a parameter by name, regardless of whether 'parameterName' or the matching
// MySqlParameter.ParameterName has a leading '?' or '@'.
Expand All @@ -98,15 +98,15 @@ internal int NormalizedIndexOf(string? parameterName)
return m_nameToIndex.TryGetValue(normalizedName, out var index) ? index : -1;
}

public override void Insert(int index, object? value) => m_parameters.Insert(index, (MySqlParameter) (value ?? throw new ArgumentNullException(nameof(value))));
public override void Insert(int index, object value) => m_parameters.Insert(index, (MySqlParameter) (value ?? throw new ArgumentNullException(nameof(value))));

#if !NETSTANDARD1_3
public override bool IsFixedSize => false;
public override bool IsReadOnly => false;
public override bool IsSynchronized => false;
#endif

public override void Remove(object? value) => RemoveAt(IndexOf(value ?? throw new ArgumentNullException(nameof(value))));
public override void Remove(object value) => RemoveAt(IndexOf(value ?? throw new ArgumentNullException(nameof(value))));

public override void RemoveAt(int index)
{
Expand All @@ -122,9 +122,9 @@ public override void RemoveAt(int index)
}
}

public override void RemoveAt(string? parameterName) => RemoveAt(IndexOf(parameterName));
public override void RemoveAt(string parameterName) => RemoveAt(IndexOf(parameterName));

protected override void SetParameter(int index, DbParameter? value)
protected override void SetParameter(int index, DbParameter value)
{
var newParameter = (MySqlParameter) (value ?? throw new ArgumentNullException(nameof(value)));
var oldParameter = m_parameters[index];
Expand All @@ -135,7 +135,7 @@ protected override void SetParameter(int index, DbParameter? value)
m_nameToIndex.Add(newParameter.NormalizedParameterName, index);
}

protected override void SetParameter(string? parameterName, DbParameter? value) => SetParameter(IndexOf(parameterName), value);
protected override void SetParameter(string parameterName, DbParameter value) => SetParameter(IndexOf(parameterName), value);

public override int Count => m_parameters.Count;

Expand All @@ -147,7 +147,7 @@ protected override void SetParameter(int index, DbParameter? value)
set => SetParameter(index, value);
}

public new MySqlParameter this[string? name]
public new MySqlParameter this[string name]
{
get => (MySqlParameter) GetParameter(name);
set => SetParameter(name, value);
Expand Down

0 comments on commit 633eea3

Please sign in to comment.