Fixing bug with incorrect row count returned (#58)

This commit is contained in:
Benjamin Russell
2016-09-20 21:04:22 -07:00
committed by Karl Burtram
parent bf6a0e52e2
commit 8f4caa80c2
2 changed files with 11 additions and 2 deletions

View File

@@ -153,7 +153,7 @@ namespace Microsoft.SqlTools.ServiceLayer.QueryExecution
{ {
do do
{ {
// Skip this result set if there aren't any rows // Skip this result set if there aren't any rows (ie, UPDATE/DELETE/etc queries)
if (!reader.HasRows && reader.FieldCount == 0) if (!reader.HasRows && reader.FieldCount == 0)
{ {
// Create a message with the number of affected rows -- IF the query affects rows // Create a message with the number of affected rows -- IF the query affects rows
@@ -163,6 +163,7 @@ namespace Microsoft.SqlTools.ServiceLayer.QueryExecution
continue; continue;
} }
// This resultset has results (ie, SELECT/etc queries)
// Read until we hit the end of the result set // Read until we hit the end of the result set
ResultSet resultSet = new ResultSet(reader, outputFileFactory); ResultSet resultSet = new ResultSet(reader, outputFileFactory);
await resultSet.ReadResultToEnd(cancellationToken); await resultSet.ReadResultToEnd(cancellationToken);
@@ -171,7 +172,7 @@ namespace Microsoft.SqlTools.ServiceLayer.QueryExecution
resultSets.Add(resultSet); resultSets.Add(resultSet);
// Add a message for the number of rows the query returned // Add a message for the number of rows the query returned
resultMessages.Add(SR.QueryServiceAffectedRows(reader.RecordsAffected)); resultMessages.Add(SR.QueryServiceAffectedRows(resultSet.RowCount));
} while (await reader.NextResultAsync(cancellationToken)); } while (await reader.NextResultAsync(cancellationToken));
} }
} }

View File

@@ -70,6 +70,9 @@ namespace Microsoft.SqlTools.ServiceLayer.Test.QueryExecution
// ... There should be a message for how many rows were affected // ... There should be a message for how many rows were affected
Assert.Equal(1, batch.ResultMessages.Count()); Assert.Equal(1, batch.ResultMessages.Count());
Assert.Contains("1 ", batch.ResultMessages.First());
// NOTE: 1 is expected because this test simulates a 'update' statement where 1 row was affected.
// The 1 in quotes is to make sure the 1 isn't part of a larger number
} }
[Fact] [Fact]
@@ -101,6 +104,7 @@ namespace Microsoft.SqlTools.ServiceLayer.Test.QueryExecution
// ... There should be a message for how many rows were affected // ... There should be a message for how many rows were affected
Assert.Equal(resultSets, batch.ResultMessages.Count()); Assert.Equal(resultSets, batch.ResultMessages.Count());
Assert.Contains(Common.StandardRows.ToString(), batch.ResultMessages.First());
} }
[Fact] [Fact]
@@ -145,6 +149,10 @@ namespace Microsoft.SqlTools.ServiceLayer.Test.QueryExecution
// ... There should be a message for how many rows were affected // ... There should be a message for how many rows were affected
Assert.Equal(resultSets, batch.ResultMessages.Count()); Assert.Equal(resultSets, batch.ResultMessages.Count());
foreach (var rsm in batch.ResultMessages)
{
Assert.Contains(Common.StandardRows.ToString(), rsm);
}
} }
[Fact] [Fact]