1
Vote

EntiLib Contrib for OdpNet Bug

description

Hello I'm trying to do this:

Database database = DatabaseFactory.CreateDatabase(ConnectionStringName);
database.ExecuteNonQuery("MyPackage.MySP", ApplicationId);

where ApplicationId is a Guid. And this lead me to a problem in EntiLib Contrib for odp.net.

From what I've seen It seems to be a problem in this method:
    public override void SetParameterValue(DbCommand command, string parameterName, object value)
    {
        object convertedValue = value;

        ParameterTypeRegistry registry = GetParameterTypeRegistry(command.CommandText);
        if (registry != null)
        {
            if (registry.HasRegisteredParameterType(parameterName))
            {
                DbType dbType = registry.GetRegisteredParameterType(parameterName);

                if (DbType.Guid == dbType)
                {
                    convertedValue = ConvertGuidToByteArray(value);
                }
                else if (DbType.Boolean == dbType)
                {
                    convertedValue = ConvertBoolToShort(value);
                }
            }
        }

        base.SetParameterValue(command, parameterName, convertedValue);
    }
This method works when I create all the parameters manually but when I call ExecuteNonQuery without create any parameter I got an error executing the query. because nobody converted the guid to a byte array

After some analysis it seems that the previous method should be changed to:
    public override void SetParameterValue(DbCommand command, string parameterName, object value)
    {
        object convertedValue = value;

        ParameterTypeRegistry registry = GetParameterTypeRegistry(command.CommandText);
        if (registry != null)
        {
            if (registry.HasRegisteredParameterType(parameterName))
            {
                DbType dbType = registry.GetRegisteredParameterType(parameterName);

                if (DbType.Guid == dbType)
                {
                    convertedValue = ConvertGuidToByteArray(value);
                }
                else if (DbType.Boolean == dbType)
                {
                    convertedValue = ConvertBoolToShort(value);
                }
            }
            else{
            if (value is Guid)
            {
                convertedValue = ConvertGuidToByteArray(value);
            }
            else if (value is bool)
            {
                convertedValue = ConvertBoolToShort(value);
            }
            }
        }

        base.SetParameterValue(command, parameterName, convertedValue);
    }
this way it should work when calling ExecuteNonQuery without creating the parameters.

comments

oeN wrote Feb 27, 2013 at 10:51 AM

Does anyone read this? and can anyone please make the change and make a new build?