Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master' into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
tmenier committed Jul 15, 2019
2 parents a2b2591 + 991781b commit a4bae91
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 38 deletions.
2 changes: 1 addition & 1 deletion AsyncPoco/Core/Transaction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public class Transaction : ITransaction
public static async Task<ITransaction> BeginAsync(Database db)
{
var trans = new Transaction(db);
await db.BeginTransactionAsync();
await db.BeginTransactionAsync().ConfigureAwait(false);
return trans;
}

Expand Down
67 changes: 38 additions & 29 deletions AsyncPoco/Database.cs
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ public virtual async Task OpenSharedConnectionAsync() {
_sharedConnection.Close();

if (_sharedConnection.State == ConnectionState.Closed)
await _sharedConnection.OpenAsync();
await _sharedConnection.OpenAsync().ConfigureAwait(false);

_sharedConnection = OnConnectionOpened(_sharedConnection);

Expand Down Expand Up @@ -270,7 +270,7 @@ public virtual async Task BeginTransactionAsync() {
_transactionDepth++;

if (_transactionDepth == 1) {
await OpenSharedConnectionAsync();
await OpenSharedConnectionAsync().ConfigureAwait(false);
_transaction = _sharedConnection.BeginTransaction();
_transactionCancelled = false;
OnBeginTransaction();
Expand Down Expand Up @@ -496,10 +496,10 @@ public virtual void OnExecutedCommand(IDbCommand cmd) { }
/// <returns>The number of rows affected</returns>
public virtual async Task<int> ExecuteAsync(string sql, params object[] args) {
try {
await OpenSharedConnectionAsync();
await OpenSharedConnectionAsync().ConfigureAwait(false);
try {
using (var cmd = CreateCommand(_sharedConnection, sql, args)) {
var retv = await cmd.ExecuteNonQueryAsync();
var retv = await cmd.ExecuteNonQueryAsync().ConfigureAwait(false);
OnExecutedCommand(cmd);
return retv;
}
Expand Down Expand Up @@ -537,10 +537,10 @@ public Task<int> ExecuteAsync(Sql sql) {
/// <returns>The scalar value cast to T</returns>
public virtual async Task<T> ExecuteScalarAsync<T>(string sql, params object[] args) {
try {
await OpenSharedConnectionAsync();
await OpenSharedConnectionAsync().ConfigureAwait(false);
try {
using (var cmd = CreateCommand(_sharedConnection, sql, args)) {
var val = await cmd.ExecuteScalarAsync();
var val = await cmd.ExecuteScalarAsync().ConfigureAwait(false);
OnExecutedCommand(cmd);

// Handle nullable types
Expand Down Expand Up @@ -585,7 +585,7 @@ public Task<T> ExecuteScalarAsync<T>(Sql sql) {
/// <returns>A List holding the results of the query</returns>
public async Task<List<T>> FetchAsync<T>(string sql, params object[] args) {
var list = new List<T>();
await QueryAsync<T>(sql, args, v => list.Add(v));
await QueryAsync<T>(sql, args, v => list.Add(v)).ConfigureAwait(false);
return list;
}

Expand Down Expand Up @@ -654,8 +654,8 @@ public async Task<Page<T>> PageAsync<T>(long page, long itemsPerPage, string sql
var result = new Page<T> {
CurrentPage = page,
ItemsPerPage = itemsPerPage,
TotalItems = await ExecuteScalarAsync<long>(sqlCount, countArgs)
};
TotalItems = await ExecuteScalarAsync<long>(sqlCount, countArgs).ConfigureAwait(false)
};
result.TotalPages = result.TotalItems / itemsPerPage;

if (result.TotalItems % itemsPerPage != 0)
Expand All @@ -664,7 +664,7 @@ public async Task<Page<T>> PageAsync<T>(long page, long itemsPerPage, string sql
OneTimeCommandTimeout = saveTimeout;

// Get the records
result.Items = await FetchAsync<T>(sqlPage, pageArgs);
result.Items = await FetchAsync<T>(sqlPage, pageArgs).ConfigureAwait(false);

// Done
return result;
Expand Down Expand Up @@ -870,13 +870,13 @@ public virtual async Task QueryAsync<T>(string sql, object[] args, Func<T, bool>
if (EnableAutoSelect)
sql = AutoSelectHelper.AddSelectClause<T>(_dbType, sql);

await OpenSharedConnectionAsync();
await OpenSharedConnectionAsync().ConfigureAwait(false);
try {
using (var cmd = CreateCommand(_sharedConnection, sql, args)) {
DbDataReader r;
var pd = PocoData.ForType(typeof(T));
try {
r = await cmd.ExecuteReaderAsync();
r = await cmd.ExecuteReaderAsync().ConfigureAwait(false);
OnExecutedCommand(cmd);
}
catch (Exception x) {
Expand All @@ -893,7 +893,7 @@ public virtual async Task QueryAsync<T>(string sql, object[] args, Func<T, bool>
while (keepGoing) {
T poco;
try {
if (!await r.ReadAsync())
if (!await r.ReadAsync().ConfigureAwait(false))
break;

poco = factory(r);
Expand Down Expand Up @@ -958,7 +958,8 @@ public Task QueryAsync<T>(Sql sql, Func<T, bool> func) {
/// <returns>True if a record matching the condition is found.</returns>
public async Task<bool> ExistsAsync<T>(string sqlCondition, params object[] args) {
var poco = PocoData.ForType(typeof(T)).TableInfo;
var result = await ExecuteScalarAsync<int>(string.Format(_dbType.GetExistsSql(), poco.TableName, sqlCondition), args);
var result = await ExecuteScalarAsync<int>(string.Format(_dbType.GetExistsSql(), poco.TableName, sqlCondition), args)
.ConfigureAwait(false);
return result != 0;
}

Expand Down Expand Up @@ -1021,11 +1022,13 @@ public Task<T> SingleOrDefaultAsync<T>(object primaryKey) {
public async Task<T> SingleAsync<T>(string sql, params object[] args) {
var count = 0;
var poco = default(T);

await QueryAsync<T>(sql, args, v => {
poco = v;
count++;
return count <= 2;
});
}).ConfigureAwait(false);

if (count == 0)
throw new InvalidOperationException("Sequence contains no elements.");
if (count > 1)
Expand All @@ -1044,11 +1047,13 @@ await QueryAsync<T>(sql, args, v => {
public async Task<T> SingleOrDefaultAsync<T>(string sql, params object[] args) {
var count = 0;
var poco = default(T);

await QueryAsync<T>(sql, args, v => {
poco = v;
count++;
return count <= 2;
});
}).ConfigureAwait(false);

if (count > 1)
throw new InvalidOperationException("Sequence contains more than one element.");

Expand All @@ -1065,11 +1070,13 @@ await QueryAsync<T>(sql, args, v => {
public async Task<T> FirstAsync<T>(string sql, params object[] args) {
var gotIt = false;
var poco = default(T);

await QueryAsync<T>(sql, args, v => {
poco = v;
gotIt = true;
return false;
});
}).ConfigureAwait(false);

if (!gotIt)
throw new InvalidOperationException("Sequence contains no elements.");

Expand All @@ -1085,10 +1092,12 @@ await QueryAsync<T>(sql, args, v => {
/// <returns>The first record in the result set, or default(T) if no matching rows</returns>
public async Task<T> FirstOrDefaultAsync<T>(string sql, params object[] args) {
var poco = default(T);

await QueryAsync<T>(sql, args, v => {
poco = v;
return false;
});
}).ConfigureAwait(false);

return poco;
}

Expand Down Expand Up @@ -1165,7 +1174,7 @@ public Task<object> InsertAsync(string tableName, string primaryKeyName, object
/// </remarks>
public virtual async Task<object> InsertAsync(string tableName, string primaryKeyName, bool autoIncrement, object poco) {
try {
await OpenSharedConnectionAsync();
await OpenSharedConnectionAsync().ConfigureAwait(false);
try {
using (var cmd = CreateCommand(_sharedConnection, "")) {
var pd = PocoData.ForObject(poco, primaryKeyName);
Expand Down Expand Up @@ -1213,7 +1222,7 @@ public virtual async Task<object> InsertAsync(string tableName, string primaryKe

if (!autoIncrement) {
DoPreExecute(cmd);
await cmd.ExecuteNonQueryAsync();
await cmd.ExecuteNonQueryAsync().ConfigureAwait(false);
OnExecutedCommand(cmd);

PocoColumn pkColumn;
Expand All @@ -1224,7 +1233,7 @@ public virtual async Task<object> InsertAsync(string tableName, string primaryKe
}


var id = await _dbType.ExecuteInsertAsync(this, cmd, primaryKeyName);
var id = await _dbType.ExecuteInsertAsync(this, cmd, primaryKeyName).ConfigureAwait(false);

// Assign the ID back to the primary key property
if (primaryKeyName != null) {
Expand Down Expand Up @@ -1290,7 +1299,7 @@ public Task<int> UpdateAsync(string tableName, string primaryKeyName, object poc
public virtual async Task<int> UpdateAsync(string tableName, string primaryKeyName, object poco,
object primaryKeyValue, IEnumerable<string> columns) {
try {
await OpenSharedConnectionAsync();
await OpenSharedConnectionAsync().ConfigureAwait(false);
try {
// update
using (var cmd = CreateCommand(_sharedConnection, "")) {
Expand Down Expand Up @@ -1351,7 +1360,7 @@ public virtual async Task<int> UpdateAsync(string tableName, string primaryKeyNa
DoPreExecute(cmd);

// Do it
var retv = await cmd.ExecuteNonQueryAsync();
var retv = await cmd.ExecuteNonQueryAsync().ConfigureAwait(false);
OnExecutedCommand(cmd);
return retv;
}
Expand Down Expand Up @@ -1991,7 +2000,7 @@ public Task QueryAsync<T1, T2, T3, T4>(Sql sql, Action<T1> action) {
/// <returns>A collection of POCO's as a List</returns>
public async Task<List<TRet>> FetchAsync<TRet>(Type[] types, object cb, string sql, params object[] args) {
var list = new List<TRet>();
await QueryAsync<TRet>(types, cb, sql, args, list.Add);
await QueryAsync<TRet>(types, cb, sql, args, list.Add).ConfigureAwait(false);
return list;
}

Expand All @@ -2005,12 +2014,12 @@ public async Task<List<TRet>> FetchAsync<TRet>(Type[] types, object cb, string s
/// <param name="args">Arguments to any embedded parameters in the SQL</param>
/// <param name="action">Callback to process each result</param>
public virtual async Task QueryAsync<TRet>(Type[] types, object cb, string sql, object[] args, Action<TRet> action) {
await OpenSharedConnectionAsync();
await OpenSharedConnectionAsync().ConfigureAwait(false);
try {
using (var cmd = CreateCommand(_sharedConnection, sql, args)) {
DbDataReader r;
try {
r = await cmd.ExecuteReaderAsync();
r = await cmd.ExecuteReaderAsync().ConfigureAwait(false);
OnExecutedCommand(cmd);
}
catch (Exception x) {
Expand All @@ -2027,7 +2036,7 @@ public virtual async Task QueryAsync<TRet>(Type[] types, object cb, string sql,
while (true) {
TRet poco;
try {
if (!await r.ReadAsync())
if (!await r.ReadAsync().ConfigureAwait(false))
break;
poco = factory(r, cb);
}
Expand Down Expand Up @@ -2157,13 +2166,13 @@ public string FormatCommand(string sql, object[] args) {

internal async Task ExecuteNonQueryHelperAsync(DbCommand cmd) {
DoPreExecute(cmd);
await cmd.ExecuteNonQueryAsync();
await cmd.ExecuteNonQueryAsync().ConfigureAwait(false);
OnExecutedCommand(cmd);
}

internal async Task<object> ExecuteScalarHelperAsync(DbCommand cmd) {
DoPreExecute(cmd);
var r = await cmd.ExecuteScalarAsync();
var r = await cmd.ExecuteScalarAsync().ConfigureAwait(false);
OnExecutedCommand(cmd);
return r;
}
Expand Down
4 changes: 2 additions & 2 deletions AsyncPoco/DatabaseTypes/OracleDatabaseType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,12 @@ public override async Task<object> ExecuteInsertAsync(Database db, DbCommand cmd
param.Direction = ParameterDirection.ReturnValue;
param.DbType = DbType.Int64;
cmd.Parameters.Add(param);
await db.ExecuteNonQueryHelperAsync(cmd);
await db.ExecuteNonQueryHelperAsync(cmd).ConfigureAwait(false);
return param.Value;
}
else
{
await db.ExecuteNonQueryHelperAsync(cmd);
await db.ExecuteNonQueryHelperAsync(cmd).ConfigureAwait(false);
return -1;
}
}
Expand Down
4 changes: 2 additions & 2 deletions AsyncPoco/DatabaseTypes/PostgreSQLDatabaseType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,11 @@ public override async Task<object> ExecuteInsertAsync(Database db, DbCommand cmd
if (PrimaryKeyName != null && !PrimaryKeyName.Contains(","))
{
cmd.CommandText += string.Format("returning {0} as NewID", EscapeSqlIdentifier(PrimaryKeyName));
return await db.ExecuteScalarHelperAsync(cmd);
return await db.ExecuteScalarHelperAsync(cmd).ConfigureAwait(false);
}
else
{
await db.ExecuteNonQueryHelperAsync(cmd);
await db.ExecuteNonQueryHelperAsync(cmd).ConfigureAwait(false);
return -1;
}
}
Expand Down
4 changes: 2 additions & 2 deletions AsyncPoco/DatabaseTypes/SQLiteDatabaseType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@ public override async Task<object> ExecuteInsertAsync(Database db, DbCommand cmd
if (PrimaryKeyName != null)
{
cmd.CommandText += ";\nSELECT last_insert_rowid();";
return await db.ExecuteScalarHelperAsync(cmd);
return await db.ExecuteScalarHelperAsync(cmd).ConfigureAwait(false);
}
else
{
await db.ExecuteNonQueryHelperAsync(cmd);
await db.ExecuteNonQueryHelperAsync(cmd).ConfigureAwait(false);
return -1;
}
}
Expand Down
4 changes: 2 additions & 2 deletions AsyncPoco/DatabaseTypes/SqlServerCEDatabaseType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ public override string BuildPageQuery(long skip, long take, PagingHelper.SQLPart

public override async Task<object> ExecuteInsertAsync(Database db, DbCommand cmd, string PrimaryKeyName)
{
await db.ExecuteNonQueryHelperAsync(cmd);
return await db.ExecuteScalarAsync<object>("SELECT @@@IDENTITY AS NewID;");
await db.ExecuteNonQueryHelperAsync(cmd).ConfigureAwait(false);
return await db.ExecuteScalarAsync<object>("SELECT @@@IDENTITY AS NewID;").ConfigureAwait(false);
}

}
Expand Down

0 comments on commit a4bae91

Please sign in to comment.