示例#1
0
 public CreatingSelectSqlParameter(CreatingSqlParameter paremeter)
     : base(paremeter.Subquery, paremeter.TableIndex, paremeter.JoinStartIndex, paremeter.ValueIndex)
 {
     base.SyncModel = paremeter;
 }
示例#2
0
 public CreateSqlResult CreateSql(CreatingSqlParameter parameter)
 {
     return(_createSql(parameter));
 }
示例#3
0
        private static string Parse(this ConditionOperator clauseOperator, ref object[] values, ref int tableIndex, ref int joinStartIndex, ref int valueIndex)
        {
            switch (clauseOperator)
            {
            case ConditionOperator.Between:
                return(string.Format("BETWEEN {{{0}}} AND {{{1}}}", valueIndex++, valueIndex++));

            case ConditionOperator.Equal:
            case ConditionOperator.Like:
            {
                if (values == null || values.Length == 0)
                {
                    return("IS NULL");
                }
                return(string.Format("{0} {{{1}}}", values[0] is string && ((string)values[0]).IndexOfAny("_%".ToArray()) >= 0 ? "LIKE" : "=", valueIndex++));
            }

            case ConditionOperator.GreaterThan:
                return(string.Format("> {{{0}}}", valueIndex++));

            case ConditionOperator.GreaterThanEqual:
                return(string.Format(">= {{{0}}}", valueIndex++));

            case ConditionOperator.In:
            case ConditionOperator.NotIn:
            {
                if (values == null || values.Length == 0)
                {
                    return("");
                }

                if (values.Length == 1)
                {
                    var value = values[0];
                    if (value is ObjectAccessResult)
                    {
                        var objectAccessResult = (ObjectAccessResult)value;
                        var parameter          = new CreatingSqlParameter(true, tableIndex, joinStartIndex, valueIndex);
                        parameter.ConditionOperator = clauseOperator;
                        var result = objectAccessResult.CreateSql(parameter);

                        tableIndex     = parameter.TableIndex;
                        joinStartIndex = parameter.JoinStartIndex;
                        valueIndex     = parameter.ValueIndex;
                        values         = result.Values;

                        return(string.Format("{0} ({1})", clauseOperator == ConditionOperator.NotIn ? "NOT IN" : "IN", result.Sql));
                    }
                    return(string.Format("{0} {{{1}}}", clauseOperator == ConditionOperator.NotIn ? "!=" : "=", valueIndex++));
                }

                var list = new List <string>();
                for (int i = 0; i < values.Length; i++)
                {
                    list.Add(string.Format("{{{0}}}", valueIndex + i));
                }

                valueIndex += values.Length;
                return(string.Format("{0} ({1})", clauseOperator == ConditionOperator.NotIn ? "NOT IN" : "IN", string.Join(",", list)));
            }

            case ConditionOperator.LessThan:
                return(string.Format("< {{{0}}}", valueIndex++));

            case ConditionOperator.LessThanEqual:
                return(string.Format("<= {{{0}}}", valueIndex++));

            case ConditionOperator.NotEqual:
            {
                if (values == null || values.Length == 0)
                {
                    return("IS NOT NULL");
                }

                return(string.Format("!= {{{0}}}", valueIndex++));
            }

            default:
                throw new ArgumentOutOfRangeException("未知的clauseOperator");
            }
        }