Skip to content

Commit

Permalink
Fix for snowflakedb#69
Browse files Browse the repository at this point in the history
Handle the OverflowExcpetion and return -1.
  • Loading branch information
akrock committed Oct 3, 2018
1 parent f392faa commit b428d87
Showing 1 changed file with 48 additions and 23 deletions.
71 changes: 48 additions & 23 deletions Snowflake.Data/Core/ResultSetUtil.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,32 +17,57 @@ internal static int CalculateUpdateCount(this SFBaseResultSet resultSet)
SFResultSetMetaData metaData = resultSet.sfResultSetMetaData;
SFStatementType statementType = metaData.statementType;

int updateCount = 0;
switch (statementType)
try
{
case SFStatementType.INSERT:
case SFStatementType.UPDATE:
case SFStatementType.DELETE:
case SFStatementType.MERGE:
case SFStatementType.MULTI_INSERT:
for (int i = 0; i < resultSet.columnCount; i++)
{
updateCount += resultSet.GetValue<int>(i);
}
break;
case SFStatementType.COPY:
var index = resultSet.sfResultSetMetaData.getColumnIndexByName("rows_loaded");
if (index >= 0) updateCount = resultSet.GetValue<int>(index);
break;
case SFStatementType.SELECT:
updateCount = -1;
break;
default:
updateCount = 0;
break;
int updateCount = 0;
switch (statementType)
{
case SFStatementType.INSERT:
case SFStatementType.UPDATE:
case SFStatementType.DELETE:
case SFStatementType.MERGE:
case SFStatementType.MULTI_INSERT:
for (int i = 0; i < resultSet.columnCount; i++)
{
updateCount += resultSet.GetValue<int>(i);
}

break;
case SFStatementType.COPY:
var index = resultSet.sfResultSetMetaData.getColumnIndexByName("rows_loaded");
if (index >= 0) updateCount = resultSet.GetValue<int>(index);
break;
case SFStatementType.SELECT:
updateCount = -1;
break;
default:
updateCount = 0;
break;
}

return updateCount;
}
catch (Exception ex)
{
if (IsOverflowException(ex))
return -1;

throw;
}
}

private static bool IsOverflowException(Exception ex)
{
if (ex is OverflowException)
return true;

if (ex.InnerException != null)
return IsOverflowException(ex.InnerException);

if (ex is AggregateException aggEx)
return aggEx.InnerExceptions.Any(IsOverflowException);

return updateCount;
return false;
}
}
}

0 comments on commit b428d87

Please sign in to comment.