Example #1
0
        private ExecuteCommand CreateDeleteCommandWithPK(IDbEngine engine, TypeMapper mapper, object value, string tableName)
        {
            var parSettings  = this.ParameterSettings;
            var whereBuilder = new StringBuilder();
            var ps           = new ExecuteParameterCollection(mapper.Count);

            foreach (var property in mapper.Properties)
            {
                if (property.IsKey)
                {
                    var arrayValue   = value as Array;
                    var isArrayValue = arrayValue != null;
                    int index        = 0;
                    var fName        = property.Name;
ARRAY_LABEL:
                    var pName = fName;
                    if (isArrayValue)
                    {
                        pName += index;
                    }

                    DefaultAppendField(property, whereBuilder, parSettings);
                    whereBuilder.Append('=');
                    whereBuilder
                    .Append(parSettings.PrefixWithText)
                    .Append(pName);
                    if (isArrayValue)
                    {
                        ps.Add(parSettings.PrefixWithCollection + pName, arrayValue.GetValue(index++));
                        if (index < arrayValue.Length)
                        {
                            whereBuilder.Append(" OR ");
                            goto ARRAY_LABEL;
                        }
                    }
                    else
                    {
                        ps.Add(parSettings.PrefixWithCollection + pName, value);
                    }
                    break;
                }
            }
            return(this.CreateDeleteCommand(mapper, whereBuilder, parSettings, ps, tableName));
        }
Example #2
0
        private void DefaultAppendValue(PropertyMapper property, StringBuilder builder, DefaultParameterSettings parameterSettings
                                        , object value
                                        , ExecuteParameterCollection ps)
        {
            var upperName = property.Name.ToUpper();

            builder.Append(parameterSettings.PrefixWithText)
            .Append(upperName);
            ps.Add(parameterSettings.PrefixWithCollection + upperName, value);
        }
Example #3
0
                public string Format(string format, object arg, IFormatProvider formatProvider)
                {
                    if (format == ":")
                    {
                        return(Convert.ToString(arg));
                    }
                    var name = "p" + index++;

                    _parameters.Add(_engineProvider.SqlFactory.EscapeName(name, NamePoint.Parameter), arg);
                    return(_engineProvider.SqlFactory.EscapeName(name, NamePoint.Value));
                }
Example #4
0
        ///// <summary>
        ///// 将字符串隐式转换为 <see cref="Aoite.Data.ExecuteCommand"/> 类的新实例。
        ///// </summary>
        ///// <param name="commandText">Transact-SQL 语句。第一个字符为“>”时,表示一个存储过程。</param>
        //public static implicit operator ExecuteCommand(string commandText)
        //{
        //    return new ExecuteCommand(commandText);
        //}

        /// <summary>
        /// 创建作为当前实例副本的新对象。
        /// </summary>
        /// <returns>作为此实例副本的新对象。</returns>
        public object Clone()
        {
            ExecuteParameterCollection newParameters = null;

            if (this._Parameters != null)
            {
                newParameters = new ExecuteParameterCollection(this._Parameters.Count);
                foreach (var p in this._Parameters)
                {
                    newParameters.Add(p.Clone() as ExecuteParameter);
                }
            }
            return(new ExecuteCommand(this._CommandText, newParameters));
        }