Skip to content
This repository was archived by the owner on Nov 1, 2018. It is now read-only.

Commit 49cf89e

Browse files
committed
Cleanup
1 parent 226cb50 commit 49cf89e

File tree

8 files changed

+25
-48
lines changed

8 files changed

+25
-48
lines changed

src/Microsoft.Data.Sqlite.Core/Microsoft.Data.Sqlite.Core.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ Microsoft.Data.Sqlite.SqliteTransaction</Description>
3939
<PrivateAssets>All</PrivateAssets>
4040
</PackageReference>
4141
<PackageReference Include="System.Data.Common" Version="$(CoreFxVersion)" />
42+
<PackageReference Include="System.ValueTuple" Version="$(CoreFxVersion)" />
4243
</ItemGroup>
4344

4445
<ItemGroup>

src/Microsoft.Data.Sqlite.Core/SqliteCommand.cs

Lines changed: 8 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,7 @@ public SqliteCommand()
3434
/// </summary>
3535
/// <param name="commandText">The SQL to execute against the database.</param>
3636
public SqliteCommand(string commandText)
37-
{
38-
CommandText = commandText;
39-
}
37+
=> CommandText = commandText;
4038

4139
/// <summary>
4240
/// Initializes a new instance of the <see cref="SqliteCommand" /> class.
@@ -45,9 +43,7 @@ public SqliteCommand(string commandText)
4543
/// <param name="connection">The connection used by the command.</param>
4644
public SqliteCommand(string commandText, SqliteConnection connection)
4745
: this(commandText)
48-
{
49-
Connection = connection;
50-
}
46+
=> Connection = connection;
5147

5248
/// <summary>
5349
/// Initializes a new instance of the <see cref="SqliteCommand" /> class.
@@ -57,9 +53,7 @@ public SqliteCommand(string commandText, SqliteConnection connection)
5753
/// <param name="transaction">The transaction within which the command executes.</param>
5854
public SqliteCommand(string commandText, SqliteConnection connection, SqliteTransaction transaction)
5955
: this(commandText, connection)
60-
{
61-
Transaction = transaction;
62-
}
56+
=> Transaction = transaction;
6357

6458
/// <summary>
6559
/// Gets or sets a value indicating how <see cref="CommandText" /> is interpreted. Only
@@ -199,8 +193,7 @@ public override void Prepare()
199193
throw new ArgumentException(Resources.InvalidCommandBehavior(behavior));
200194
}
201195

202-
if (Connection == null
203-
|| Connection.State != ConnectionState.Open)
196+
if (Connection?.State != ConnectionState.Open)
204197
{
205198
throw new InvalidOperationException(Resources.CallRequiresOpenConnection(nameof(ExecuteReader)));
206199
}
@@ -224,7 +217,7 @@ public override void Prepare()
224217

225218
var hasChanges = false;
226219
var changes = 0;
227-
var stmts = new Queue<Tuple<sqlite3_stmt, bool>>();
220+
var stmts = new Queue<(sqlite3_stmt, bool)>();
228221
var tail = CommandText;
229222

230223
do
@@ -303,7 +296,7 @@ public override void Prepare()
303296
// will result in unexpected corner cases, but it's the best we can do without re-parsing SQL
304297
if (raw.sqlite3_stmt_readonly(stmt) != 0)
305298
{
306-
stmts.Enqueue(Tuple.Create(stmt, rc != raw.SQLITE_DONE));
299+
stmts.Enqueue((stmt, rc != raw.SQLITE_DONE));
307300
}
308301
else
309302
{
@@ -399,8 +392,7 @@ protected override async Task<DbDataReader> ExecuteDbDataReaderAsync(
399392
/// <exception cref="SqliteException">A SQLite error occurs during execution.</exception>
400393
public override int ExecuteNonQuery()
401394
{
402-
if (Connection == null
403-
|| Connection.State != ConnectionState.Open)
395+
if (Connection?.State != ConnectionState.Open)
404396
{
405397
throw new InvalidOperationException(Resources.CallRequiresOpenConnection(nameof(ExecuteNonQuery)));
406398
}
@@ -422,8 +414,7 @@ public override int ExecuteNonQuery()
422414
/// <exception cref="SqliteException">A SQLite error occurs during execution.</exception>
423415
public override object ExecuteScalar()
424416
{
425-
if (Connection == null
426-
|| Connection.State != ConnectionState.Open)
417+
if (Connection?.State != ConnectionState.Open)
427418
{
428419
throw new InvalidOperationException(Resources.CallRequiresOpenConnection(nameof(ExecuteScalar)));
429420
}

src/Microsoft.Data.Sqlite.Core/SqliteConnection.cs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,7 @@ public partial class SqliteConnection : DbConnection
2727
private sqlite3 _db;
2828

2929
static SqliteConnection()
30-
{
31-
BundleInitializer.Initialize();
32-
}
30+
=> BundleInitializer.Initialize();
3331

3432
/// <summary>
3533
/// Initializes a new instance of the <see cref="SqliteConnection" /> class.
@@ -44,9 +42,7 @@ public SqliteConnection()
4442
/// <param name="connectionString">The string used to open the connection.</param>
4543
/// <seealso cref="SqliteConnectionStringBuilder" />
4644
public SqliteConnection(string connectionString)
47-
{
48-
ConnectionString = connectionString;
49-
}
45+
=> ConnectionString = connectionString;
5046

5147
/// <summary>
5248
/// Gets a handle to underlying database connection.

src/Microsoft.Data.Sqlite.Core/SqliteConnectionStringBuilder.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,9 +73,7 @@ public SqliteConnectionStringBuilder()
7373
/// The initial connection string the builder will represent. Can be null.
7474
/// </param>
7575
public SqliteConnectionStringBuilder(string connectionString)
76-
{
77-
ConnectionString = connectionString;
78-
}
76+
=> ConnectionString = connectionString;
7977

8078
/// <summary>
8179
/// Gets or sets the database file.

src/Microsoft.Data.Sqlite.Core/SqliteDataReader.cs

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
using System.Data.Common;
88
using System.Diagnostics;
99
using System.Globalization;
10+
using System.Text;
1011
using Microsoft.Data.Sqlite.Properties;
1112
using SQLitePCL;
1213

@@ -21,7 +22,7 @@ public class SqliteDataReader : DbDataReader
2122

2223
private readonly SqliteConnection _connection;
2324
private readonly bool _closeConnection;
24-
private readonly Queue<Tuple<sqlite3_stmt, bool>> _stmtQueue;
25+
private readonly Queue<(sqlite3_stmt stmt, bool)> _stmtQueue;
2526
private sqlite3_stmt _stmt;
2627
private bool _hasRows;
2728
private bool _stepped;
@@ -30,15 +31,13 @@ public class SqliteDataReader : DbDataReader
3031

3132
internal SqliteDataReader(
3233
SqliteConnection connection,
33-
Queue<Tuple<sqlite3_stmt, bool>> stmtQueue,
34+
Queue<(sqlite3_stmt, bool)> stmtQueue,
3435
int recordsAffected,
3536
bool closeConnection)
3637
{
3738
if (stmtQueue.Count != 0)
3839
{
39-
var tuple = stmtQueue.Dequeue();
40-
_stmt = tuple.Item1;
41-
_hasRows = tuple.Item2;
40+
(_stmt, _hasRows) = stmtQueue.Dequeue();
4241
}
4342

4443
_connection = connection;
@@ -153,9 +152,7 @@ public override bool NextResult()
153152

154153
_stmt.Dispose();
155154

156-
var tuple = _stmtQueue.Dequeue();
157-
_stmt = tuple.Item1;
158-
_hasRows = tuple.Item2;
155+
(_stmt, _hasRows) = _stmtQueue.Dequeue();
159156
_stepped = false;
160157
_done = false;
161158

@@ -191,7 +188,7 @@ protected override void Dispose(bool disposing)
191188

192189
while (_stmtQueue.Count != 0)
193190
{
194-
_stmtQueue.Dequeue().Item1.Dispose();
191+
_stmtQueue.Dequeue().stmt.Dispose();
195192
}
196193

197194
_closed = true;
@@ -458,12 +455,12 @@ public override Guid GetGuid(int ordinal)
458455
}
459456
else
460457
{
461-
return new Guid(System.Text.Encoding.UTF8.GetString(bytes, 0, bytes.Length));
458+
return new Guid(Encoding.UTF8.GetString(bytes, 0, bytes.Length));
462459
}
463460
default:
464461
return new Guid(GetString(ordinal));
465462
}
466-
}
463+
}
467464

468465
/// <summary>
469466
/// Gets the value of the specified column as a <see cref="short" />.

src/Microsoft.Data.Sqlite.Core/SqliteException.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,7 @@ public class SqliteException : DbException
2020
/// <param name="errorCode">The SQLite error code.</param>
2121
public SqliteException(string message, int errorCode)
2222
: base(message)
23-
{
24-
SqliteErrorCode = errorCode;
25-
}
23+
=> SqliteErrorCode = errorCode;
2624

2725
/// <summary>
2826
/// Gets the SQLite error code.

src/Microsoft.Data.Sqlite.Core/SqliteParameter.cs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -71,9 +71,7 @@ public SqliteParameter(string name, SqliteType type)
7171
/// <param name="size">The maximum size, in bytes, of the parameter.</param>
7272
public SqliteParameter(string name, SqliteType type, int size)
7373
: this(name, type)
74-
{
75-
Size = size;
76-
}
74+
=> Size = size;
7775

7876
/// <summary>
7977
/// Initializes a new instance of the <see cref="SqliteParameter" /> class.
@@ -84,9 +82,7 @@ public SqliteParameter(string name, SqliteType type, int size)
8482
/// <param name="sourceColumn">The source column used for loading the value. Can be null.</param>
8583
public SqliteParameter(string name, SqliteType type, int size, string sourceColumn)
8684
: this(name, type, size)
87-
{
88-
SourceColumn = sourceColumn;
89-
}
85+
=> SourceColumn = sourceColumn;
9086

9187
/// <summary>
9288
/// Gets or sets the type of the parameter.

test/Microsoft.Data.Sqlite.Tests/SqliteDataReaderTest.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,14 +111,14 @@ public void GetDateTime_works_with_real()
111111
=> GetX_works(
112112
"SELECT julianday('2013-10-07 08:23:19.120');",
113113
r => r.GetDateTime(0),
114-
new DateTime(2013,10,7,8,23,19,120));
114+
new DateTime(2013, 10, 7, 8, 23, 19, 120));
115115

116116
[Fact]
117117
public void GetDateTime_works_with_integer()
118118
=> GetX_works(
119119
"SELECT CAST(julianday('2013-10-07 12:00') AS INTEGER);",
120120
r => r.GetDateTime(0),
121-
new DateTime(2013,10,7,12,0,0));
121+
new DateTime(2013, 10, 7, 12, 0, 0));
122122

123123
[Fact]
124124
public void GetDateTimeOffset_works_with_text()

0 commit comments

Comments
 (0)