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 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
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 All @@ -77,16 +94,9 @@ public static void CheckSparseColumnBit()
// table name will be provided as an argument
StringBuilder createBuilder = new StringBuilder("CREATE TABLE {0} ([ID] int PRIMARY KEY, [CSET] xml COLUMN_SET FOR ALL_SPARSE_COLUMNS NULL");

// TSQL to create the same table, but without the column set column and without sparse
// also, it has only 1024 columns, which is the server limit in this case
StringBuilder createNonSparseBuilder = new StringBuilder("CREATE TABLE {0} ([ID] int PRIMARY KEY");

// TSQL to select all columns from the sparse table, without columnset one
StringBuilder selectBuilder = new StringBuilder("SELECT [ID]");

// TSQL to select all columns from the sparse table, with a limit of 1024 (for bulk-copy test)
StringBuilder selectNonSparseBuilder = new StringBuilder("SELECT [ID]");

// add sparse columns
for (int c = 0; c < sparseColumns; c++)
{
Expand All @@ -98,7 +108,6 @@ public static void CheckSparseColumnBit()
// table name provided as an argument
selectBuilder.Append(" FROM {0}");

string selectStatementFormat = selectBuilder.ToString();
string createStatementFormat = createBuilder.ToString();

// add a row with nulls only
Expand Down