Finishing up unit tests

This commit is contained in:
Benjamin Russell
2016-08-10 15:14:56 -07:00
parent 430860dd5d
commit 8167330e16
7 changed files with 718 additions and 266 deletions

View File

@@ -42,7 +42,7 @@ namespace Microsoft.SqlTools.ServiceLayer.QueryExecution
public Query(string queryText, ConnectionInfo connection)
{
// Sanity check for input
if (queryText == null)
if (String.IsNullOrWhiteSpace(queryText))
{
throw new ArgumentNullException(nameof(queryText), "Query text cannot be null");
}
@@ -68,50 +68,55 @@ namespace Microsoft.SqlTools.ServiceLayer.QueryExecution
}
// Create a connection from the connection details
string connectionString = ConnectionService.BuildConnectionString(EditorConnection.ConnectionDetails);
using (DbConnection conn = EditorConnection.Factory.CreateSqlConnection(connectionString))
try
{
await conn.OpenAsync(cancellationSource.Token);
// Create a command that we'll use for executing the query
using (DbCommand command = conn.CreateCommand())
string connectionString = ConnectionService.BuildConnectionString(EditorConnection.ConnectionDetails);
using (DbConnection conn = EditorConnection.Factory.CreateSqlConnection(connectionString))
{
command.CommandText = QueryText;
command.CommandType = CommandType.Text;
await conn.OpenAsync(cancellationSource.Token);
// Execute the command to get back a reader
using (DbDataReader reader = await command.ExecuteReaderAsync(cancellationSource.Token))
// Create a command that we'll use for executing the query
using (DbCommand command = conn.CreateCommand())
{
do
command.CommandText = QueryText;
command.CommandType = CommandType.Text;
// Execute the command to get back a reader
using (DbDataReader reader = await command.ExecuteReaderAsync(cancellationSource.Token))
{
// TODO: This doesn't properly handle scenarios where the query is SELECT but does not have rows
if (!reader.HasRows)
do
{
continue;
}
// TODO: This doesn't properly handle scenarios where the query is SELECT but does not have rows
if (!reader.HasRows)
{
continue;
}
// Read until we hit the end of the result set
ResultSet resultSet = new ResultSet();
while (await reader.ReadAsync(cancellationSource.Token))
{
resultSet.AddRow(reader);
}
// Read until we hit the end of the result set
ResultSet resultSet = new ResultSet();
while (await reader.ReadAsync(cancellationSource.Token))
{
resultSet.AddRow(reader);
}
// Read off the column schema information
if (reader.CanGetColumnSchema())
{
resultSet.Columns = reader.GetColumnSchema().ToArray();
}
// Read off the column schema information
if (reader.CanGetColumnSchema())
{
resultSet.Columns = reader.GetColumnSchema().ToArray();
}
// Add the result set to the results of the query
ResultSets.Add(resultSet);
} while (await reader.NextResultAsync(cancellationSource.Token));
// Add the result set to the results of the query
ResultSets.Add(resultSet);
} while (await reader.NextResultAsync(cancellationSource.Token));
}
}
}
}
// Mark that we have executed
HasExecuted = true;
finally
{
// Mark that we have executed
HasExecuted = true;
}
}
public ResultSetSubset GetSubset(int resultSetIndex, int startRow, int rowCount)