Skip to content

Commit

Permalink
Return empty DataTable from GetSchemaTable. (#419)
Browse files Browse the repository at this point in the history
  • Loading branch information
ErikEJ authored Feb 13, 2020
1 parent bac3ab4 commit 2edfd2a
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 8 deletions.
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()
{
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

0 comments on commit 2edfd2a

Please sign in to comment.