Skip to content

Commit

Permalink
Remove cursor dereferencing
Browse files Browse the repository at this point in the history
Closes #438
  • Loading branch information
roji committed Jun 3, 2015
1 parent 642b3ce commit 567a05c
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 37 deletions.
19 changes: 1 addition & 18 deletions src/Npgsql/NpgsqlCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -940,24 +940,7 @@ NpgsqlDataReader ExecuteDbDataReaderInternal(CommandBehavior behavior)
try
{
ValidateAndCreateMessages(behavior);
var reader = Execute(behavior);

// Transparently dereference cursors returned from functions
if (CommandType == CommandType.StoredProcedure &&
reader.FieldCount == 1 &&
reader.GetDataTypeName(0) == "refcursor")
{
var sb = new StringBuilder();
while (reader.Read()) {
sb.AppendFormat(@"FETCH ALL FROM ""{0}"";", reader.GetString(0));
}
reader.Dispose();

var dereferenceCmd = new NpgsqlCommand(sb.ToString(), Connection);
return dereferenceCmd.ExecuteReader(behavior);
}

return reader;
return Execute(behavior);
}
catch
{
Expand Down
19 changes: 0 additions & 19 deletions test/Npgsql.Tests/FunctionTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -105,25 +105,6 @@ public void TooManyOutputParams()
Assert.That(command.Parameters["c"].Value, Is.EqualTo(-1));
}

[Test]
public void MultipleRefCursorSupport()
{
ExecuteNonQuery(@"CREATE FUNCTION pg_temp.func() RETURNS SETOF refcursor AS 'DECLARE ref1 refcursor; ref2 refcursor; BEGIN OPEN ref1 FOR SELECT 1; RETURN NEXT ref1; OPEN ref2 FOR SELECT 2; RETURN next ref2; RETURN; END;' LANGUAGE 'plpgsql';");
using (Conn.BeginTransaction())
{
var command = new NpgsqlCommand("pg_temp.func", Conn);
command.CommandType = CommandType.StoredProcedure;
using (var dr = command.ExecuteReader())
{
dr.Read();
Assert.That(dr.GetInt32(0), Is.EqualTo(1));
dr.NextResult();
dr.Read();
Assert.That(dr.GetInt32(0), Is.EqualTo(2));
}
}
}

[Test]
public void SingleRow()
{
Expand Down

0 comments on commit 567a05c

Please sign in to comment.