Exemplo n.º 1
0
        public void FormatParameterName_ReturnsFormattedParameterName()
        {
            const string expected = "@Parameter";
            var          dialect  = new SqlDialect();

            var actual = dialect.FormatParameterName("Parameter");

            Assert.Equal(expected, actual);
        }
Exemplo n.º 2
0
            public override string ToString(SqlDialect dialect, int paramIndex)
            {
                if (dialect == null)
                {
                    throw new ArgumentNullException("dialect");
                }

                var sb = new StringBuilder();

                sb.Append(dialect.FormatFieldName(FieldName));
                sb.Append(' ');
                sb.Append(_operator);
                sb.Append(' ');
                sb.Append(dialect.FormatParameterName(paramIndex, CommandType.Text));

                return(sb.ToString());
            }
Exemplo n.º 3
0
            public override void AddToCommandParams(DbCommand command, SqlDialect dialect, int index)
            {
                if (command == null)
                {
                    throw new ArgumentNullException("command");
                }
                if (dialect == null)
                {
                    throw new ArgumentNullException("dialect");
                }

                DbParameter newParm = command.CreateParameter();

                newParm.ParameterName = dialect.FormatParameterName(index, command.CommandType);
                newParm.Value         = (_value ?? DBNull.Value);

                command.Parameters.Add(newParm);
            }
Exemplo n.º 4
0
        /// <summary>
        /// Adds the indexed parameter.
        /// </summary>
        /// <param name="command">The command.</param>
        /// <param name="dialect">The dialect.</param>
        /// <param name="placeholderPrefix">The placeholder prefix.</param>
        /// <param name="index">The index.</param>
        /// <param name="value">The value.</param>
        public static void AddIndexedParameter(DbCommand command, SqlDialect dialect, char placeholderPrefix, int index, object value)
        {
            if (command == null)
            {
                throw new ArgumentNullException("command");
            }
            if (dialect == null)
            {
                throw new ArgumentNullException("dialect");
            }

            DbParameter newParm = command.CreateParameter();

            newParm.Value         = (value ?? DBNull.Value);
            newParm.ParameterName = dialect.FormatParameterName(index, command.CommandType);

            string sParmHolder = string.Concat(placeholderPrefix, index);

            command.CommandText = command.CommandText.Replace(sParmHolder, newParm.ParameterName);

            command.Parameters.Add(newParm);
        }
        /// <summary>
        /// Creates the set param.
        /// </summary>
        /// <param name="command">The command.</param>
        /// <param name="column">The column.</param>
        /// <returns></returns>
        private DbParameter CreateSetParam(DbCommand command, DataColumn column)
        {
            DbParameter param = command.CreateParameter();

            param.ParameterName = SqlDialect.FormatParameterName(column.ColumnName, command.CommandType);
            param.SourceColumn  = column.ColumnName;

            if ((param is SqlParameter) && (column.DataType == typeof(TimeSpan)))     // hack M$ issue
            {
                ((SqlParameter)param).SqlDbType = SqlDbType.Time;
            }
            else
            {
                param.DbType = DataManager.GetDbType(column.DataType);
            }

            if (column.MaxLength > 0)
            {
                param.Size = column.MaxLength;
            }

            return(param);
        }