Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Microsoft.Data.Sqlite.Core/SqliteCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ public override string CommandText
if (value != _commandText)
{
DisposePreparedStatements();
_commandText = value;
_commandText = value ?? string.Empty;
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/Microsoft.Data.Sqlite.Core/SqliteConnection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public partial class SqliteConnection : DbConnection

private HashSet<(string file, string proc)> _extensions;

private string _connectionString;
private string _connectionString = string.Empty;
private ConnectionState _state;
private sqlite3 _db;
private bool _extensionsEnabled;
Expand Down Expand Up @@ -84,7 +84,7 @@ public override string ConnectionString
throw new InvalidOperationException(Resources.ConnectionStringRequiresClosedConnection);
}

_connectionString = value;
_connectionString = value ?? string.Empty;
ConnectionOptions = new SqliteConnectionStringBuilder(value);
}
}
Expand Down Expand Up @@ -164,7 +164,7 @@ public override void Open()
return;
}

if (ConnectionString == null)
if (string.IsNullOrEmpty(ConnectionString))
{
throw new InvalidOperationException(Resources.OpenRequiresSetConnectionString);
}
Expand Down
14 changes: 12 additions & 2 deletions src/Microsoft.Data.Sqlite.Core/SqliteParameter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,11 @@ namespace Microsoft.Data.Sqlite
/// <seealso href="https://docs.microsoft.com/dotnet/standard/data/sqlite/types">Data Types</seealso>
public class SqliteParameter : DbParameter
{
private string _parameterName = string.Empty;
private object _value;
private int? _size;
private SqliteType? _sqliteType;
private string _sourceColumn = string.Empty;

/// <summary>
/// Initializes a new instance of the <see cref="SqliteParameter" /> class.
Expand Down Expand Up @@ -122,7 +124,11 @@ public override ParameterDirection Direction
/// Gets or sets the name of the parameter.
/// </summary>
/// <value>The name of the parameter.</value>
public override string ParameterName { get; set; } = string.Empty;
public override string ParameterName
{
get => _parameterName;
set => _parameterName = value ?? String.Empty;
}

/// <summary>
/// Gets or sets the maximum size, in bytes, of the parameter.
Expand Down Expand Up @@ -154,7 +160,11 @@ public override int Size
/// Gets or sets the source column used for loading the value.
/// </summary>
/// <value>The source column used for loading the value.</value>
public override string SourceColumn { get; set; } = string.Empty;
public override string SourceColumn
{
get => _sourceColumn;
set => _sourceColumn = value ?? string.Empty;
}

/// <summary>
/// Gets or sets a value indicating whether the source column is nullable.
Expand Down
11 changes: 11 additions & 0 deletions test/Microsoft.Data.Sqlite.Tests/SqliteCommandTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,17 @@ public void CommandText_defaults_to_empty()
Assert.Empty(command.CommandText);
}

[Fact]
public void CommandText_coalesces_to_empty()
{
var command = new SqliteCommand
{
CommandText = null
};

Assert.Empty(command.CommandText);
}

[Fact]
public void CommandText_throws_when_set_when_open_reader()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,25 @@ public void Ctor_parses_mode()
Assert.Equal(SqliteOpenMode.Memory, builder.Mode);
}

[Fact]
public void ConnectionString_defaults_to_empty()
{
var builder = new SqliteConnectionStringBuilder();

Assert.Empty(builder.ConnectionString);
}

[Fact]
public void ConnectionString_coalesces_to_empty()
{
var builder = new SqliteConnectionStringBuilder
{
ConnectionString = null
};

Assert.Empty(builder.ConnectionString);
}

[Fact]
public void Filename_is_alias_for_DataSource()
{
Expand Down
19 changes: 19 additions & 0 deletions test/Microsoft.Data.Sqlite.Tests/SqliteConnectionTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,25 @@ public void Ctor_sets_connection_string()
Assert.Equal(connectionString, connection.ConnectionString);
}

[Fact]
public void ConnectionString_defaults_to_empty()
{
var connection = new SqliteConnection();

Assert.Empty(connection.ConnectionString);
}

[Fact]
public void ConnectionString_coalesces_to_empty()
{
var connection = new SqliteConnection
{
ConnectionString = null
};

Assert.Empty(connection.ConnectionString);
}

[Fact]
public void ConnectionString_setter_throws_when_open()
{
Expand Down
38 changes: 38 additions & 0 deletions test/Microsoft.Data.Sqlite.Tests/SqliteParameterTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,44 @@ public void Ctor_sets_other_values()
Assert.Equal("Column", result.SourceColumn);
}

[Fact]
public void ParameterName_defaults_to_empty()
{
var parameter = new SqliteParameter();

Assert.Empty(parameter.ParameterName);
}

[Fact]
public void ParameterName_coalesces_to_empty()
{
var parameter = new SqliteParameter
{
ParameterName = null
};

Assert.Empty(parameter.ParameterName);
}

[Fact]
public void SourceColumn_defaults_to_empty()
{
var parameter = new SqliteParameter();

Assert.Empty(parameter.SourceColumn);
}

[Fact]
public void SourceColumn_coalesces_to_empty()
{
var parameter = new SqliteParameter
{
SourceColumn = null
};

Assert.Empty(parameter.SourceColumn);
}

[Fact]
public void DbType_defaults_to_string()
{
Expand Down