diff --git a/src/MySqlConnector/Core/CachedParameter.cs b/src/MySqlConnector/Core/CachedParameter.cs index 16db1c75a..2f38defbc 100644 --- a/src/MySqlConnector/Core/CachedParameter.cs +++ b/src/MySqlConnector/Core/CachedParameter.cs @@ -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) @@ -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; } } } diff --git a/src/MySqlConnector/Core/CachedProcedure.cs b/src/MySqlConnector/Core/CachedProcedure.cs index 8b6a0e34a..3793b0d2e 100644 --- a/src/MySqlConnector/Core/CachedProcedure.cs +++ b/src/MySqlConnector/Core/CachedProcedure.cs @@ -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); @@ -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 @@ -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 { diff --git a/src/MySqlConnector/MySql.Data.MySqlClient/MySqlCommand.cs b/src/MySqlConnector/MySql.Data.MySqlClient/MySqlCommand.cs index 63bbed70b..bbfac92f5 100644 --- a/src/MySqlConnector/MySql.Data.MySqlClient/MySqlCommand.cs +++ b/src/MySqlConnector/MySql.Data.MySqlClient/MySqlCommand.cs @@ -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(); @@ -238,10 +238,10 @@ internal async Task ExecuteNonQueryAsync(IOBehavior ioBehavior, Cancellatio return reader.RecordsAffected; } - public override Task ExecuteScalarAsync(CancellationToken cancellationToken) => + public override Task ExecuteScalarAsync(CancellationToken cancellationToken) => ExecuteScalarAsync(AsyncIOBehavior, cancellationToken); - internal async Task ExecuteScalarAsync(IOBehavior ioBehavior, CancellationToken cancellationToken) + internal async Task ExecuteScalarAsync(IOBehavior ioBehavior, CancellationToken cancellationToken) { this.ResetCommandTimeout(); var hasSetResult = false; @@ -257,7 +257,7 @@ internal async Task ExecuteScalarAsync(IOBehavior ioBehavior, Cancellati hasSetResult = true; } } while (await reader.NextResultAsync(ioBehavior, cancellationToken).ConfigureAwait(false)); - return result!; + return result; } protected override Task ExecuteDbDataReaderAsync(CommandBehavior behavior, CancellationToken cancellationToken) diff --git a/src/MySqlConnector/MySql.Data.MySqlClient/MySqlConnection.cs b/src/MySqlConnector/MySql.Data.MySqlClient/MySqlConnection.cs index b5f9a3f5f..4b9263a5e 100644 --- a/src/MySqlConnector/MySql.Data.MySqlClient/MySqlConnection.cs +++ b/src/MySqlConnector/MySql.Data.MySqlClient/MySqlConnection.cs @@ -388,7 +388,7 @@ private static async Task ClearPoolAsync(MySqlConnection connection, IOBehavior public override DataTable GetSchema(string collectionName) => GetSchemaProvider().GetSchema(collectionName); /// - 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() { diff --git a/src/MySqlConnector/MySql.Data.MySqlClient/MySqlDataAdapter.cs b/src/MySqlConnector/MySql.Data.MySqlClient/MySqlDataAdapter.cs index a2339e766..47d9ab35b 100644 --- a/src/MySqlConnector/MySql.Data.MySqlClient/MySqlDataAdapter.cs +++ b/src/MySqlConnector/MySql.Data.MySqlClient/MySqlDataAdapter.cs @@ -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); diff --git a/src/MySqlConnector/MySql.Data.MySqlClient/MySqlDbColumn.cs b/src/MySqlConnector/MySql.Data.MySqlClient/MySqlDbColumn.cs index adbf94d4e..e9495afd8 100644 --- a/src/MySqlConnector/MySql.Data.MySqlClient/MySqlDbColumn.cs +++ b/src/MySqlConnector/MySql.Data.MySqlClient/MySqlDbColumn.cs @@ -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; } @@ -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 diff --git a/src/MySqlConnector/MySql.Data.MySqlClient/MySqlParameter.cs b/src/MySqlConnector/MySql.Data.MySqlClient/MySqlParameter.cs index 65b6f7049..9d566bbd5 100644 --- a/src/MySqlConnector/MySql.Data.MySqlClient/MySqlParameter.cs +++ b/src/MySqlConnector/MySql.Data.MySqlClient/MySqlParameter.cs @@ -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); @@ -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; @@ -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 @@ -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 ?? ""; diff --git a/src/MySqlConnector/MySql.Data.MySqlClient/MySqlParameterCollection.cs b/src/MySqlConnector/MySql.Data.MySqlClient/MySqlParameterCollection.cs index 0ac62beb0..ad6386521 100644 --- a/src/MySqlConnector/MySql.Data.MySqlClient/MySqlParameterCollection.cs +++ b/src/MySqlConnector/MySql.Data.MySqlClient/MySqlParameterCollection.cs @@ -17,7 +17,7 @@ internal MySqlParameterCollection() m_nameToIndex = new Dictionary(StringComparer.OrdinalIgnoreCase); } - public MySqlParameter Add(string? parameterName, DbType dbType) + public MySqlParameter Add(string parameterName, DbType dbType) { MySqlParameter parameter = new MySqlParameter { @@ -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; @@ -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 { @@ -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; @@ -78,7 +78,7 @@ 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) @@ -86,9 +86,9 @@ protected override DbParameter GetParameter(string? 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 '@'. @@ -98,7 +98,7 @@ 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; @@ -106,7 +106,7 @@ internal int NormalizedIndexOf(string? parameterName) 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) { @@ -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]; @@ -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; @@ -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);