コード例 #1
0
        internal void Append(SqlCommand command)
        {
            ADP.CheckArgumentNull(command, nameof(command));

            string cmdText = command.CommandText;

            if (string.IsNullOrEmpty(cmdText))
            {
                throw ADP.CommandTextRequired(nameof(Append));
            }

            CommandType commandType = command.CommandType;

            switch (commandType)
            {
            case CommandType.Text:
            case CommandType.StoredProcedure:
                break;

            case CommandType.TableDirect:
                throw SQL.NotSupportedCommandType(commandType);

            default:
                throw ADP.InvalidCommandType(commandType);
            }

            SqlParameterCollection parameters = null;

            SqlParameterCollection collection = command.Parameters;

            if (0 < collection.Count)
            {
                parameters = new SqlParameterCollection();

                // clone parameters so they aren't destroyed
                for (int i = 0; i < collection.Count; ++i)
                {
                    SqlParameter p = new SqlParameter();
                    collection[i].CopyTo(p);
                    parameters.Add(p);

                    // SQL Injection awareness
                    if (!s_sqlIdentifierParser.IsMatch(p.ParameterName))
                    {
                        throw ADP.BadParameterName(p.ParameterName);
                    }
                }

                foreach (SqlParameter p in parameters)
                {
                    // deep clone the parameter value if byte[] or char[]
                    object obj        = p.Value;
                    byte[] byteValues = (obj as byte[]);
                    if (null != byteValues)
                    {
                        int offset       = p.Offset;
                        int size         = p.Size;
                        int countOfBytes = byteValues.Length - offset;
                        if ((0 != size) && (size < countOfBytes))
                        {
                            countOfBytes = size;
                        }
                        byte[] copy = new byte[Math.Max(countOfBytes, 0)];
                        Buffer.BlockCopy(byteValues, offset, copy, 0, copy.Length);
                        p.Offset = 0;
                        p.Value  = copy;
                    }
                    else
                    {
                        char[] charValues = (obj as char[]);
                        if (null != charValues)
                        {
                            int offset       = p.Offset;
                            int size         = p.Size;
                            int countOfChars = charValues.Length - offset;
                            if ((0 != size) && (size < countOfChars))
                            {
                                countOfChars = size;
                            }
                            char[] copy = new char[Math.Max(countOfChars, 0)];
                            Buffer.BlockCopy(charValues, offset, copy, 0, copy.Length * 2);
                            p.Offset = 0;
                            p.Value  = copy;
                        }
                        else
                        {
                            ICloneable cloneable = (obj as ICloneable);
                            if (null != cloneable)
                            {
                                p.Value = cloneable.Clone();
                            }
                        }
                    }
                }
            }

            int returnParameterIndex = -1;

            if (null != parameters)
            {
                for (int i = 0; i < parameters.Count; ++i)
                {
                    if (ParameterDirection.ReturnValue == parameters[i].Direction)
                    {
                        returnParameterIndex = i;
                        break;
                    }
                }
            }
            LocalCommand cmd = new LocalCommand(cmdText, parameters, returnParameterIndex, command.CommandType, command.ColumnEncryptionSetting);

            CommandList.Add(cmd);
        }
コード例 #2
0
        internal void Append(SqlCommand command)
        {
            SqlParameterCollection parameters;
            int num7;

            ADP.CheckArgumentNull(command, "command");
            Bid.Trace("<sc.SqlCommandSet.Append|API> %d#, command=%d, parameterCount=%d\n", this.ObjectID, command.ObjectID, command.Parameters.Count);
            string commandText = command.CommandText;

            if (ADP.IsEmpty(commandText))
            {
                throw ADP.CommandTextRequired("Append");
            }
            CommandType commandType = command.CommandType;

            switch (commandType)
            {
            case CommandType.Text:
            case CommandType.StoredProcedure:
            {
                parameters = null;
                SqlParameterCollection parameters2 = command.Parameters;
                if (0 < parameters2.Count)
                {
                    parameters = new SqlParameterCollection();
                    for (int i = 0; i < parameters2.Count; i++)
                    {
                        SqlParameter destination = new SqlParameter();
                        parameters2[i].CopyTo(destination);
                        parameters.Add(destination);
                        if (!SqlIdentifierParser.IsMatch(destination.ParameterName))
                        {
                            throw ADP.BadParameterName(destination.ParameterName);
                        }
                    }
                    foreach (SqlParameter parameter in parameters)
                    {
                        object obj2 = parameter.Value;
                        byte[] src  = obj2 as byte[];
                        if (src != null)
                        {
                            int offset = parameter.Offset;
                            int size   = parameter.Size;
                            int num5   = src.Length - offset;
                            if ((size != 0) && (size < num5))
                            {
                                num5 = size;
                            }
                            byte[] dst = new byte[Math.Max(num5, 0)];
                            Buffer.BlockCopy(src, offset, dst, 0, dst.Length);
                            parameter.Offset = 0;
                            parameter.Value  = dst;
                        }
                        else
                        {
                            char[] chArray2 = obj2 as char[];
                            if (chArray2 != null)
                            {
                                int srcOffset = parameter.Offset;
                                int num4      = parameter.Size;
                                int num3      = chArray2.Length - srcOffset;
                                if ((num4 != 0) && (num4 < num3))
                                {
                                    num3 = num4;
                                }
                                char[] chArray = new char[Math.Max(num3, 0)];
                                Buffer.BlockCopy(chArray2, srcOffset, chArray, 0, chArray.Length * 2);
                                parameter.Offset = 0;
                                parameter.Value  = chArray;
                            }
                            else
                            {
                                ICloneable cloneable = obj2 as ICloneable;
                                if (cloneable != null)
                                {
                                    parameter.Value = cloneable.Clone();
                                }
                            }
                        }
                    }
                }
                num7 = -1;
                if (parameters != null)
                {
                    for (int j = 0; j < parameters.Count; j++)
                    {
                        if (ParameterDirection.ReturnValue == parameters[j].Direction)
                        {
                            num7 = j;
                            break;
                        }
                    }
                }
                break;
            }

            case CommandType.TableDirect:
                throw SQL.NotSupportedCommandType(commandType);

            default:
                throw ADP.InvalidCommandType(commandType);
            }
            LocalCommand item = new LocalCommand(commandText, parameters, num7, command.CommandType);

            this.CommandList.Add(item);
        }