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

Where a command returns multiple tables, and the last table has no rows, it is not included in the DataAdapter #524

Closed
badbod99 opened this issue Jun 29, 2018 · 4 comments
Assignees
Labels

Comments

@badbod99
Copy link

I'm using MySqlDataAdapter.Fill to fill a DataSet like this:

public static DataSet RetrieveDataSet(string connectionString, string storedProcedure, params MySqlParameter[] parameters)
        {
            using (MySqlConnection conn = new MySqlConnection(connectionString))
            {
                conn.Open();

                using (MySqlCommand comm = conn.CreateCommand())
                {
                    comm.CommandText = storedProcedure;
                    comm.CommandType = CommandType.StoredProcedure;
                    if (parameters != null && parameters.Length > 0)
                    {
                        comm.Parameters.AddRange(parameters);
                    }

                    using (MySqlDataAdapter adapter = new MySqlDataAdapter(comm))
                    {
                        DataSet data = new DataSet();
                        adapter.Fill(data);
                        return data;
                    }
                }
            }
        }

My stored procedure returns 4 result sets. In the case that result set 4 (the last one) is empty, the data.Tables.Count equals 3. In the case that result set 4 has rows, data.Tables.Count equals 4. In the case that result set 2 has no rows, data.Tables.Count equals 4 still.

So it seems like if the last result set is blank, it is not being included as a table in the dataset. My guess is that this is a for loop error, but I couldn't identify it from the code of MySqlDataAdapter.

@bgrainger bgrainger added the bug label Jun 29, 2018
@bgrainger
Copy link
Member

Can repro with the test data set up in StoredProcedureFixture:

using (var command = new MySqlCommand("multiple_result_sets", connection))
{
	command.CommandType = CommandType.StoredProcedure;
	command.Parameters.AddWithValue("pivot", 8);
	using (MySqlDataAdapter adapter = new MySqlDataAdapter(command))
	{
		DataSet data = new DataSet();
		adapter.Fill(data);
		Console.WriteLine(data.Tables.Count); // prints 1, should be 2
	}
}

@bgrainger
Copy link
Member

Probably the underlying problem:

using (var reader = command.ExecuteReader())
{
	while (reader.Read())
	{
	}
	
	Console.WriteLine(reader.NextResult()); // false, should be true
}

@bgrainger
Copy link
Member

Which may be related to the fix for #135.

@bgrainger bgrainger self-assigned this Jun 29, 2018
@bgrainger
Copy link
Member

Fixed in 0.42.2.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

No branches or pull requests

2 participants