Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Return empty DataTable from GetSchemaTable. #419

Merged
merged 3 commits into from
Feb 13, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1476,7 +1476,7 @@ public override DataTable GetSchemaTable()
Debug.Assert(null != _metaData.schemaTable, "No schema information yet!");
}
}
return _metaData?.schemaTable;
return _metaData?.schemaTable ?? new DataTable();
}
finally
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1667,17 +1667,12 @@ override public DataTable GetSchemaTable()
{
if (null != this.MetaData)
{

_metaData.schemaTable = BuildSchemaTable();
Debug.Assert(null != _metaData.schemaTable, "No schema information yet!");
// filter table?
}
}
if (null != _metaData)
{
return _metaData.schemaTable;
}
return null;
return _metaData?.schemaTable ?? new DataTable();
}
finally
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ public static void LoadReaderIntoDataTableToTestGetSchemaTable()
[CheckConnStrSetupFact]
public static void MultiQuerySchema()
{
SqlConnectionStringBuilder builder = new SqlConnectionStringBuilder(DataTestUtility.TCPConnectionString);
using (SqlConnection connection = new SqlConnection(DataTestUtility.TCPConnectionString))
{
connection.Open();
Expand Down Expand Up @@ -65,7 +64,25 @@ public static void MultiQuerySchema()
}
}

[CheckConnStrSetupFact]
public static void GetSchemaTable_returns_null_when_no_resultset()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Test name is inversed :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh!

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Another possible note is the returned table should have no rows, but should still have the columns it has when there are rows.

{
using (SqlConnection connection = new SqlConnection(DataTestUtility.TCPConnectionString))
{
connection.Open();

using (SqlCommand command = connection.CreateCommand())
{
command.CommandText = "SELECT 1";
using (SqlDataReader reader = command.ExecuteReader())
{
reader.NextResult();
Assert.NotNull(reader.GetSchemaTable());
}
}
}
}

// Checks for the IsColumnSet bit in the GetSchemaTable for Sparse columns
[CheckConnStrSetupFact]
public static void CheckSparseColumnBit()
Expand Down