コード例 #1
0
        /// <summary>
        /// Create IDataParameters for command text statement.
        /// </summary>
        private void CreateParametersForTextCommand()
        {
            string sqlParamName              = string.Empty;
            string dbTypePropertyName        = _session.DataSource.DbProvider.ParameterDbTypeProperty;
            Type   enumDbType                = _session.DataSource.DbProvider.ParameterDbType;
            ParameterPropertyCollection list = null;

            if (_session.DataSource.DbProvider.UsePositionalParameters)             //obdc/oledb
            {
                list = _request.ParameterMap.Properties;
            }
            else
            {
                list = _request.ParameterMap.PropertiesList;
            }

            _preparedStatement.DbParameters = new IDbDataParameter[list.Count];

            for (int i = 0; i < list.Count; i++)
            {
                ParameterProperty property = list[i];

                if (_session.DataSource.DbProvider.UseParameterPrefixInParameter)
                {
                    // From Ryan Yao: JIRA-27, used "param" + i++ for sqlParamName
                    sqlParamName = _parameterPrefix + "param" + i;
                }
                else
                {
                    sqlParamName = "param" + i;
                }

                IDbDataParameter dataParameter = _session.CreateDataParameter();

                // Manage dbType attribute if any
                if (property.DbType != null && property.DbType.Length > 0)
                {
                    // Exemple : Enum.parse(System.Data.SqlDbType, 'VarChar')
                    object dbType = Enum.Parse(enumDbType, property.DbType, true);

                    // Exemple : ObjectHelper.SetProperty(sqlparameter, 'SqlDbType', SqlDbType.Int);
                    ObjectProbe.SetMemberValue(dataParameter, dbTypePropertyName, dbType,
                                               _request.DataExchangeFactory.ObjectFactory,
                                               _request.DataExchangeFactory.AccessorFactory);
                }

                // Set IDbDataParameter
                // JIRA-49 Fixes (size, precision, and scale)
                if (_session.DataSource.DbProvider.SetDbParameterSize)
                {
                    if (property.Size != -1)
                    {
                        dataParameter.Size = property.Size;
                    }
                }

                if (_session.DataSource.DbProvider.SetDbParameterPrecision)
                {
                    dataParameter.Precision = property.Precision;
                }

                if (_session.DataSource.DbProvider.SetDbParameterScale)
                {
                    dataParameter.Scale = property.Scale;
                }

                // Set as direction parameter
                dataParameter.Direction = property.Direction;

                dataParameter.ParameterName = sqlParamName;

                _preparedStatement.DbParametersName.Add(property.PropertyName);
                _preparedStatement.DbParameters[i] = dataParameter;

                if (_session.DataSource.DbProvider.UsePositionalParameters == false)
                {
                    _propertyDbParameterMap.Add(property, dataParameter);
                }
            }
        }