NETProvider
NETProvider copied to clipboard
DbCommand.ExecuteReader throws "Unable to cast object of type 'System.Int32' to type 'System.Numerics.BigInteger'"
In Firebird4, when parameter get up-scaled to INT128 in the query ExecuteReader throws an InvalidCastException due to attempt to cast a boxed _value to BigInteger even if parameter was explicitly set to a different type.
https://github.com/FirebirdSQL/NETProvider/blob/ebd58c427de8fcdc3c5b08541a450dc09831e023/src/FirebirdSql.Data.FirebirdClient/Common/DbValue.cs#L250-L253
Code to reproduce:
var cmd = connection.CreateCommand();
cmd.CommandText = "select 1 from RDB$DATABASE where (cast(1 as bigint) * cast(1 as bigint)) = @x";
var p = cmd.CreateParameter();
p.ParameterName = "x";
p.DbType = DbType.Int32;
p.Value = 2;
cmd.Parameters.Add(p);
_ = cmd.ExecuteReader();
Stack trace:
System.InvalidCastException : Unable to cast object of type 'System.Int32' to type 'System.Numerics.BigInteger'.
at FirebirdSql.Data.Common.DbValue.GetInt128()
at FirebirdSql.Data.Client.Managed.Version10.GdsStatement.WriteRawParameter(IXdrWriter xdr, DbField field)
at FirebirdSql.Data.Client.Managed.Version13.GdsStatement.WriteParameters()
at FirebirdSql.Data.Client.Managed.Version10.GdsStatement.SendExecuteToBuffer()
at FirebirdSql.Data.Client.Managed.Version12.GdsStatement.Execute()
at FirebirdSql.Data.FirebirdClient.FbCommand.ExecuteCommand(CommandBehavior behavior, Boolean returnsSet)
at FirebirdSql.Data.FirebirdClient.FbCommand.ExecuteReader(CommandBehavior behavior)
at FirebirdSql.Data.FirebirdClient.FbCommand.ExecuteDbDataReader(CommandBehavior behavior)
at System.Data.Common.DbCommand.ExecuteReader()