Exemplo n.º 1
0
 internal override void BuildQueryString(StringBuilder queryStringBuilder, ConditionCollectionContext buildContext)
 {
     base.BuildQueryString(queryStringBuilder, buildContext);
     if (buildContext.FirstGroupConditionFlags.Count > 0)
     {
         bool   isFirstGroupCondition = buildContext.FirstGroupConditionFlags.Pop();
         string currentQueryString    = queryStringBuilder.ToString().Trim();
         if (currentQueryString.Substring(currentQueryString.Length - 1, 1) == "(")
         {
             if (isFirstGroupCondition == true)
             {
                 queryStringBuilder.Remove(queryStringBuilder.Length - 1, 1);
             }
             else
             {
                 queryStringBuilder.Remove(queryStringBuilder.Length - 5, 5);
                 buildContext.IsFirstCondition = false;
             }
         }
         else
         {
             queryStringBuilder.Append(" )");
             buildContext.IsFirstCondition = false;
         }
     }
 }
Exemplo n.º 2
0
 internal override void BuildQueryString(StringBuilder queryStringBuilder, ConditionCollectionContext buildContext)
 {
     base.BuildQueryString(queryStringBuilder, buildContext);
     queryStringBuilder.Append(string.Format(" {0} {1}",
                                             buildContext.IsFirstCondition ? string.Empty : this.ConditionRelationType.ToString(),
                                             this.CustomQueryString));
     buildContext.IsFirstCondition = false;
 }
Exemplo n.º 3
0
 internal override void BuildQueryString(StringBuilder queryStringBuilder, ConditionCollectionContext buildContext)
 {
     base.BuildQueryString(queryStringBuilder, buildContext);
     queryStringBuilder.Append(string.Format(" {0} (",
                                             buildContext.IsFirstCondition ? string.Empty : this.GroupConditionRelationType.ToString()));
     buildContext.FirstGroupConditionFlags.Push(buildContext.IsFirstCondition);
     buildContext.IsFirstCondition = true;
 }
Exemplo n.º 4
0
        private string BuildSqlConditionString(ConditionCollectionContext buildContext)
        {
            string result = string.Empty;

            if (this.OperatorType == QueryConditionOperatorType.IsNull ||
                this.OperatorType == QueryConditionOperatorType.IsNotNull)
            {
                result = string.Format(" {0} {1} {2}", buildContext.IsFirstCondition ? string.Empty : this.ConditionRelationType.ToString(),
                                       this.FieldName, GetOperatorString(this.OperatorType));
            }
            else if (this.OperatorType == QueryConditionOperatorType.In ||
                     this.OperatorType == QueryConditionOperatorType.NotIn)
            {
                List <Object> parameterValues       = this.ParameterValue as List <Object>;
                StringBuilder parameterNamesBuilder = new StringBuilder();
                for (int i = 0; i < parameterValues.Count; i++)
                {
                    string parameterName = string.Format("@{0}_Values{1}", this.FieldName.Replace(".", string.Empty).Replace("[", string.Empty).Replace("]", string.Empty), i);
                    parameterNamesBuilder.AppendFormat("{0},", parameterName);
                    if (buildContext.DataCommand.HasDefinedParameter(parameterName))
                    {
                        buildContext.DataCommand.SetParameterValue(parameterName, this.ParameterDbType, parameterValues[i]);
                    }
                    else
                    {
                        buildContext.DataCommand.AddInputParameter(parameterName, this.ParameterDbType, parameterValues[i]);
                    }
                }
                string parameterNames = parameterNamesBuilder.ToString();
                parameterNames = parameterNames.Substring(0, parameterNames.Length - 1);
                result         = string.Format(" {0} {1} {2} ({3})", buildContext.IsFirstCondition ? string.Empty : this.ConditionRelationType.ToString(),
                                               this.FieldName, GetOperatorString(this.OperatorType), parameterNames);
            }
            else
            {
                result = string.Format(" {0} {1} {2} {3}", buildContext.IsFirstCondition ? string.Empty : this.ConditionRelationType.ToString(),
                                       this.FieldName, GetOperatorString(this.OperatorType), this.ParameterName);
                if (!buildContext.AddedParameterNames.Contains(this.ParameterName))
                {
                    object val = (this.OperatorType == QueryConditionOperatorType.Like || this.OperatorType == QueryConditionOperatorType.LeftLike || this.OperatorType == QueryConditionOperatorType.RightLike) ?
                                 TryConvertToLikeString(this.ParameterValue, this.OperatorType) : this.ParameterValue;
                    if (buildContext.DataCommand.HasDefinedParameter(this.ParameterName))
                    {
                        buildContext.DataCommand.SetParameterValue(this.ParameterName, this.ParameterDbType, val);
                    }
                    else
                    {
                        buildContext.DataCommand.AddInputParameter(this.ParameterName, this.ParameterDbType, val);
                    }
                    buildContext.AddedParameterNames.Add(this.ParameterName);
                }
            }
            return(result);
        }
Exemplo n.º 5
0
 internal virtual void BuildQueryString(StringBuilder queryStringBuilder, ConditionCollectionContext buildContext)
 {
     if (queryStringBuilder == null)
     {
         throw new ArgumentException("Input query string builder can not be null.");
     }
     if (buildContext == null)
     {
         throw new ArgumentException("Input build context can not be null.");
     }
 }
Exemplo n.º 6
0
        internal override void BuildQueryString(StringBuilder queryStringBuilder, ConditionCollectionContext buildContext)
        {
            base.BuildQueryString(queryStringBuilder, buildContext);
            ConditionCollectionContext subQueryBuildCondition = new ConditionCollectionContext(buildContext.DataCommand);

            subQueryBuildCondition.AddedParameterNames = buildContext.AddedParameterNames;
            queryStringBuilder.Append(string.Format(" {0} {1} {2} ({3} {4})",
                                                    buildContext.IsFirstCondition ? string.Empty : this.ConditionRelationType.ToString(),
                                                    this.FieldName, GetOperatorString(this.OperatorType), this.SubQuerySQLTemplate,
                                                    ConditionConstructor.BuildQuerySqlConditionString(this.SubQueryConditions, subQueryBuildCondition)));
            buildContext.IsFirstCondition = false;
        }
Exemplo n.º 7
0
        public string BuildQuerySql()
        {
            // Build Query Condition
            ConditionCollectionContext buildContext = new ConditionCollectionContext(m_dataCommand);
            string result = m_querySqlTemplate.Replace("#StrWhere#", m_conditionConstructor.BuildQuerySqlConditionString(buildContext));

            // Build OrderBy String
            result = result.Replace("#SortColumnName#", BuildOrderByString());
            // Set Paging Information
            SetPagingInformation();
            return(result);
        }
Exemplo n.º 8
0
 internal override void BuildQueryString(StringBuilder queryStringBuilder, ConditionCollectionContext buildContext)
 {
     base.BuildQueryString(queryStringBuilder, buildContext);
     queryStringBuilder.Append(BuildSqlConditionString(buildContext));
     buildContext.IsFirstCondition = false;
 }
Exemplo n.º 9
0
 internal string BuildQuerySqlConditionString(ConditionCollectionContext buildContext)
 {
     return(BuildQuerySqlConditionString(m_conditions, buildContext));
 }
Exemplo n.º 10
0
        internal static string BuildQuerySqlConditionString(List <Condition> conditions, ConditionCollectionContext buildContext)
        {
            if (conditions == null || conditions.Count == 0)
            {
                return(string.Empty);
            }
            StringBuilder resultBuilder = new StringBuilder();

            resultBuilder.Append("WHERE ");
            foreach (Condition condition in conditions)
            {
                condition.BuildQueryString(resultBuilder, buildContext);
            }
            string result = resultBuilder.ToString().Trim();

            return(result == "WHERE" ? string.Empty : result);
        }