c# - Unexpected non-null value from mysql stored procedure call from mysqlconnector.net -
i ran surprise today, working on application in c# connects mysql database. worked fine until today when migrated stuff 1 server another. now, data missing in database , stored procedures expected return null values because of it. unfortunately instead of null values integers integer values of 0.
for simplicity lets have following stored procedure in our mysql server:
create definer=`root`@`localhost` procedure `get_config_code`( in order_n bigint, in order_position_n int, out out_config_code bigint) begin set out_config_code = null; end
then call stored procedure through mysqlconnector .net creating mysqlcommand instance adding parameters it. stored procedure called in straightforward way follows:
mreader = mcommand.executereader(); if ((mreader != null) && (mreader .hasrows)) { mreader .close(); }
then try check if parameter null this:
if (mcommand.parameters[param_id].value != system.dbnull.value)
unfortunately despite stored procedure explicitly setting output parameter null, parameter non null, , of type int64 , has value of 0 (checked through debugger)
the code works if data there, , correct integer value. best guess is not easy have null "integer value" in c# non-nullable type... expected parameter of type system.dbnull anyway, non-nullable types (it works strings)
what missing?
thanks in advance help
update: well... did archeology on testing of system... turns out null integer return stored procedure never tested before, , explains why problem did not arise earlier. executed stored procedure on server before migration, same data in dbs, , 'problem' there well.
my understanding non-nullable data types returned default, when output parameter value null; nullable data types instead returned expected system.dbnull.value when output parameter null.
what found interesting that, in case of int, reader returned call executereader, contains data matching value of output parameter; when checking reader found expected null value, instead of default value int.
Comments
Post a Comment