Permalink
Browse files

Cleanup

  • Loading branch information...
bricelam committed Apr 4, 2017
1 parent 226cb50 commit 49cf89ec0eca722bd2fb5308ef110c82107f4a3d
@@ -39,6 +39,7 @@ Microsoft.Data.Sqlite.SqliteTransaction</Description>
<PrivateAssets>All</PrivateAssets>
</PackageReference>
<PackageReference Include="System.Data.Common" Version="$(CoreFxVersion)" />
+ <PackageReference Include="System.ValueTuple" Version="$(CoreFxVersion)" />
</ItemGroup>
<ItemGroup>
@@ -34,9 +34,7 @@ public SqliteCommand()
/// </summary>
/// <param name="commandText">The SQL to execute against the database.</param>
public SqliteCommand(string commandText)
- {
- CommandText = commandText;
- }
+ => CommandText = commandText;
/// <summary>
/// Initializes a new instance of the <see cref="SqliteCommand" /> class.
@@ -45,9 +43,7 @@ public SqliteCommand(string commandText)
/// <param name="connection">The connection used by the command.</param>
public SqliteCommand(string commandText, SqliteConnection connection)
: this(commandText)
- {
- Connection = connection;
- }
+ => Connection = connection;
/// <summary>
/// Initializes a new instance of the <see cref="SqliteCommand" /> class.
@@ -57,9 +53,7 @@ public SqliteCommand(string commandText, SqliteConnection connection)
/// <param name="transaction">The transaction within which the command executes.</param>
public SqliteCommand(string commandText, SqliteConnection connection, SqliteTransaction transaction)
: this(commandText, connection)
- {
- Transaction = transaction;
- }
+ => Transaction = transaction;
/// <summary>
/// Gets or sets a value indicating how <see cref="CommandText" /> is interpreted. Only
@@ -199,8 +193,7 @@ public new virtual SqliteDataReader ExecuteReader(CommandBehavior behavior)
throw new ArgumentException(Resources.InvalidCommandBehavior(behavior));
}
- if (Connection == null
- || Connection.State != ConnectionState.Open)
+ if (Connection?.State != ConnectionState.Open)
{
throw new InvalidOperationException(Resources.CallRequiresOpenConnection(nameof(ExecuteReader)));
}
@@ -224,7 +217,7 @@ public new virtual SqliteDataReader ExecuteReader(CommandBehavior behavior)
var hasChanges = false;
var changes = 0;
- var stmts = new Queue<Tuple<sqlite3_stmt, bool>>();
+ var stmts = new Queue<(sqlite3_stmt, bool)>();
var tail = CommandText;
do
@@ -303,7 +296,7 @@ public new virtual SqliteDataReader ExecuteReader(CommandBehavior behavior)
// will result in unexpected corner cases, but it's the best we can do without re-parsing SQL
if (raw.sqlite3_stmt_readonly(stmt) != 0)
{
- stmts.Enqueue(Tuple.Create(stmt, rc != raw.SQLITE_DONE));
+ stmts.Enqueue((stmt, rc != raw.SQLITE_DONE));
}
else
{
@@ -399,8 +392,7 @@ public new virtual Task<SqliteDataReader> ExecuteReaderAsync(CommandBehavior beh
/// <exception cref="SqliteException">A SQLite error occurs during execution.</exception>
public override int ExecuteNonQuery()
{
- if (Connection == null
- || Connection.State != ConnectionState.Open)
+ if (Connection?.State != ConnectionState.Open)
{
throw new InvalidOperationException(Resources.CallRequiresOpenConnection(nameof(ExecuteNonQuery)));
}
@@ -422,8 +414,7 @@ public override int ExecuteNonQuery()
/// <exception cref="SqliteException">A SQLite error occurs during execution.</exception>
public override object ExecuteScalar()
{
- if (Connection == null
- || Connection.State != ConnectionState.Open)
+ if (Connection?.State != ConnectionState.Open)
{
throw new InvalidOperationException(Resources.CallRequiresOpenConnection(nameof(ExecuteScalar)));
}
@@ -27,9 +27,7 @@ public partial class SqliteConnection : DbConnection
private sqlite3 _db;
static SqliteConnection()
- {
- BundleInitializer.Initialize();
- }
+ => BundleInitializer.Initialize();
/// <summary>
/// Initializes a new instance of the <see cref="SqliteConnection" /> class.
@@ -44,9 +42,7 @@ public SqliteConnection()
/// <param name="connectionString">The string used to open the connection.</param>
/// <seealso cref="SqliteConnectionStringBuilder" />
public SqliteConnection(string connectionString)
- {
- ConnectionString = connectionString;
- }
+ => ConnectionString = connectionString;
/// <summary>
/// Gets a handle to underlying database connection.
@@ -73,9 +73,7 @@ public SqliteConnectionStringBuilder()
/// The initial connection string the builder will represent. Can be null.
/// </param>
public SqliteConnectionStringBuilder(string connectionString)
- {
- ConnectionString = connectionString;
- }
+ => ConnectionString = connectionString;
/// <summary>
/// Gets or sets the database file.
@@ -7,6 +7,7 @@
using System.Data.Common;
using System.Diagnostics;
using System.Globalization;
+using System.Text;
using Microsoft.Data.Sqlite.Properties;
using SQLitePCL;
@@ -21,7 +22,7 @@ public class SqliteDataReader : DbDataReader
private readonly SqliteConnection _connection;
private readonly bool _closeConnection;
- private readonly Queue<Tuple<sqlite3_stmt, bool>> _stmtQueue;
+ private readonly Queue<(sqlite3_stmt stmt, bool)> _stmtQueue;
private sqlite3_stmt _stmt;
private bool _hasRows;
private bool _stepped;
@@ -30,15 +31,13 @@ public class SqliteDataReader : DbDataReader
internal SqliteDataReader(
SqliteConnection connection,
- Queue<Tuple<sqlite3_stmt, bool>> stmtQueue,
+ Queue<(sqlite3_stmt, bool)> stmtQueue,
int recordsAffected,
bool closeConnection)
{
if (stmtQueue.Count != 0)
{
- var tuple = stmtQueue.Dequeue();
- _stmt = tuple.Item1;
- _hasRows = tuple.Item2;
+ (_stmt, _hasRows) = stmtQueue.Dequeue();
}
_connection = connection;
@@ -153,9 +152,7 @@ public override bool NextResult()
_stmt.Dispose();
- var tuple = _stmtQueue.Dequeue();
- _stmt = tuple.Item1;
- _hasRows = tuple.Item2;
+ (_stmt, _hasRows) = _stmtQueue.Dequeue();
_stepped = false;
_done = false;
@@ -191,7 +188,7 @@ protected override void Dispose(bool disposing)
while (_stmtQueue.Count != 0)
{
- _stmtQueue.Dequeue().Item1.Dispose();
+ _stmtQueue.Dequeue().stmt.Dispose();
}
_closed = true;
@@ -458,12 +455,12 @@ public override Guid GetGuid(int ordinal)
}
else
{
- return new Guid(System.Text.Encoding.UTF8.GetString(bytes, 0, bytes.Length));
+ return new Guid(Encoding.UTF8.GetString(bytes, 0, bytes.Length));
}
default:
return new Guid(GetString(ordinal));
}
- }
+ }
/// <summary>
/// Gets the value of the specified column as a <see cref="short" />.
@@ -20,9 +20,7 @@ public class SqliteException : DbException
/// <param name="errorCode">The SQLite error code.</param>
public SqliteException(string message, int errorCode)
: base(message)
- {
- SqliteErrorCode = errorCode;
- }
+ => SqliteErrorCode = errorCode;
/// <summary>
/// Gets the SQLite error code.
@@ -71,9 +71,7 @@ public SqliteParameter(string name, SqliteType type)
/// <param name="size">The maximum size, in bytes, of the parameter.</param>
public SqliteParameter(string name, SqliteType type, int size)
: this(name, type)
- {
- Size = size;
- }
+ => Size = size;
/// <summary>
/// Initializes a new instance of the <see cref="SqliteParameter" /> class.
@@ -84,9 +82,7 @@ public SqliteParameter(string name, SqliteType type, int size)
/// <param name="sourceColumn">The source column used for loading the value. Can be null.</param>
public SqliteParameter(string name, SqliteType type, int size, string sourceColumn)
: this(name, type, size)
- {
- SourceColumn = sourceColumn;
- }
+ => SourceColumn = sourceColumn;
/// <summary>
/// Gets or sets the type of the parameter.
@@ -111,14 +111,14 @@ public void GetDateTime_works_with_real()
=> GetX_works(
"SELECT julianday('2013-10-07 08:23:19.120');",
r => r.GetDateTime(0),
- new DateTime(2013,10,7,8,23,19,120));
+ new DateTime(2013, 10, 7, 8, 23, 19, 120));
[Fact]
public void GetDateTime_works_with_integer()
=> GetX_works(
"SELECT CAST(julianday('2013-10-07 12:00') AS INTEGER);",
r => r.GetDateTime(0),
- new DateTime(2013,10,7,12,0,0));
+ new DateTime(2013, 10, 7, 12, 0, 0));
[Fact]
public void GetDateTimeOffset_works_with_text()

0 comments on commit 49cf89e

Please sign in to comment.