예제 #1
0
        public override string ToString()
        {
            if (i == null)
            {
                return(null);
            }

            var parts   = i.ToString().Split('?');
            var result  = new StringBuilder(parts[0]);
            var counter = 0;

            foreach (var p in i.GetParameters())
            {
                counter++;
                if (p == null)
                {
                    result.Append("null");
                }
                else
                {
                    var format = "{0}";
                    if (p is DateTime || p is Guid || p is string)
                    {
                        format = "'{0}'";
                    }
                    result.AppendFormat(format, p);
                }
                if (counter < parts.Length)
                {
                    result.Append(parts[counter]);
                }
            }
            return(result.ToString());
        }
예제 #2
0
        private string GetSqlWithParameters()
        {
            var sql        = instruction.ToString();
            var parameters = instruction.GetParameters();
            var sb         = new StringBuilder();
            var i          = 0;

            foreach (var part in sql.Split('?'))
            {
                sb.Append(part);
                if (i < parameters.Length)
                {
                    var p = parameters[i];
                    if (p == null)
                    {
                        sb.Append("null");
                    }
                    else if (p is string || p is char || p is DateTime || p is Guid)
                    {
                        sb.AppendFormat("'{0}'", p);
                    }
                    else
                    {
                        sb.Append(p);
                    }
                }
                i++;
            }
            return(sb.ToString());
        }
예제 #3
0
        private string GetSqlWithParameters()
        {
            var sql        = instruction.ToString();
            var parameters = instruction.GetParameters();
            var sb         = new StringBuilder();
            var i          = 0;
            var sqlParts   = sql.Split('?');
            var pCount     = parameters.Count();

            foreach (var p in parameters)
            {
                sb.Append(sqlParts[i]);
                if (i < pCount)
                {
                    if (p == null)
                    {
                        sb.Append("null");
                    }
                    else if (p is string || p is char || p is DateTime || p is Guid)
                    {
                        sb.AppendFormat("'{0}'", p);
                    }
                    else
                    {
                        sb.Append(p);
                    }
                }
                i++;
            }
            return(sb.ToString());
        }
예제 #4
0
        private IDbCommand CreateCommand(ISqlInstruction sql)
        {
            var command    = GetConnection().CreateCommand();
            var parameters = sql.GetParameters().ToArray();
            var parts      = sql.ToString(dialect).Split('?');
            var result     = new StringBuilder();

            for (var i = 0; i < parts.Length - 1; i++)
            {
                var p = command.CreateParameter();
                p.ParameterName = "p" + i;
                if (parameters[i] == null)
                {
                    p.Value = DBNull.Value;
                }
                else if (parameters[i] is Enum)
                {
                    p.Value = ((Enum)parameters[i]).ToString("d");
                }
                else
                {
                    p.Value = parameters[i];
                }
                command.Parameters.Add(p);
                result.AppendFormat("{0}@{1}", parts[i], p.ParameterName);
            }
            result.Append(parts[parts.Length - 1]);
            command.CommandText = result.ToString();
            return(command);
        }
예제 #5
0
        public override object[] GetParameters()
        {
            var parameters = new List <object>();

            parameters.AddRange(_condition.GetParameters());
            parameters.AddRange(new[] { _trueValue, _falseValue });
            return(parameters.ToArray());
        }
예제 #6
0
        public override IEnumerable <object> GetParameters()
        {
            var parameters = new List <object>();

            parameters.AddRange(_condition.GetParameters());
            parameters.AddRange(new[] { _trueValue, _falseValue });
            return(parameters);
        }
        private static void ApplySqlInstruction(IDbCommand command, ISqlInstruction sql, ISqlDialect dialect)
        {
            var sqlStr     = sql.ToString(dialect);
            var parameters = sql.GetParameters();

            command.Parameters.Clear();

            var sqlParts   = sqlStr.Split('?');
            var sqlBuilder = new StringBuilder();

            for (var i = 0; i < sqlParts.Length - 1; i++)
            {
                var name = "p" + i;
                command.AddParameter(name, parameters[i]);
                sqlBuilder.AppendFormat("{0}@{1}", sqlParts[i], name);
            }
            sqlBuilder.Append(sqlParts[sqlParts.Length - 1]);
            command.CommandText = sqlBuilder.ToString();
        }
예제 #8
0
 public override IEnumerable <object> GetParameters()
 {
     return(ins != null?ins.GetParameters() : (parameters ?? new object[0]));
 }
예제 #9
0
 public override object[] GetParameters()
 {
     return(column2.GetParameters());
 }
예제 #10
0
 public override IEnumerable <object> GetParameters()
 {
     return(column2.GetParameters());
 }
예제 #11
0
 public override object[] GetParameters()
 {
     return(ins != null?ins.GetParameters() : (parameters ?? new object[0]));
 }
예제 #12
0
 public override IEnumerable <object> GetParameters()
 {
     return(_exp.GetParameters());
 }
예제 #13
0
 public override object[] GetParameters()
 {
     return(_exp.GetParameters());
 }