Skip to content

Commit

Permalink
Fixed issue DapperTable
Browse files Browse the repository at this point in the history
This fixes a bug found in CS 5150996 where the following sequence would
result in an InvalidOperationException being thrown due to an attempt to
access a disposed of DataReader:

- Perform a dynamic query that yields no results
- Add data to the source of that query
- Perform a the same query again
  • Loading branch information
Dave Peters committed Nov 15, 2012
1 parent 8b405c7 commit b82c275
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Dapper/SqlMapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1524,7 +1524,7 @@ internal static Func<IDataReader, object> GetDapperRowDeserializer(IDataRecord r
string[] names = new string[effectiveFieldCount];
for (int i = 0; i < effectiveFieldCount; i++)
{
names[i] = reader.GetName(i + startBound);
names[i] = r.GetName(i + startBound);
}
table = new DapperTable(names);
}
Expand Down
18 changes: 18 additions & 0 deletions Tests/Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2253,6 +2253,24 @@ public void Open()
}
}

public void TestDapperTableMetadataRetrieval()
{
// Test for a bug found in CS 51509960 where the following sequence would result in an InvalidOperationException being
// thrown due to an attempt to access a disposed of DataReader:
//
// - Perform a dynamic query that yields no results
// - Add data to the source of that query
// - Perform a the same query again
connection.Execute("CREATE TABLE #sut (value varchar(10) NOT NULL PRIMARY KEY)");
connection.Query("SELECT value FROM #sut").IsSequenceEqualTo(Enumerable.Empty<dynamic>());

connection.Execute("INSERT INTO #sut (value) VALUES ('test')").IsEqualTo(1);
var result = connection.Query("SELECT value FROM #sut");

var first = result.First();
((string)first.value).IsEqualTo("test");
}

#if POSTGRESQL

class Cat
Expand Down

0 comments on commit b82c275

Please sign in to comment.