Skip to content

Commit da206eb

Browse files
committed
Proper return value for ExecuteNonQuery according to "spec" (DNET-927).
1 parent db3591f commit da206eb

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

Provider/src/FirebirdSql.Data.FirebirdClient.Tests/FbCommandTests.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -844,6 +844,17 @@ public void PassesDateTimeWithProperPrecision()
844844
}
845845
}
846846

847+
[Test]
848+
public void ExecuteNonQueryReturnsMinusOneOnNonInsertUpdateDelete()
849+
{
850+
using (var cmd = Connection.CreateCommand())
851+
{
852+
cmd.CommandText = "select 1 from rdb$database";
853+
var ra = cmd.ExecuteNonQuery();
854+
Assert.AreEqual(-1, ra);
855+
}
856+
}
857+
847858
#endregion
848859
}
849860
}

Provider/src/FirebirdSql.Data.FirebirdClient/FirebirdClient/FbCommand.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -463,7 +463,13 @@ public override int ExecuteNonQuery()
463463
throw;
464464
}
465465

466-
return RecordsAffected;
466+
return _statement.StatementType switch
467+
{
468+
DbStatementType.Insert => RecordsAffected,
469+
DbStatementType.Update => RecordsAffected,
470+
DbStatementType.Delete => RecordsAffected,
471+
_ => -1,
472+
};
467473
}
468474

469475
public new FbDataReader ExecuteReader() => ExecuteReader(CommandBehavior.Default);

0 commit comments

Comments
 (0)