コード例 #1
0
        /// <summary>
        /// 生成查询语句
        /// </summary>
        /// <param name="query"></param>
        /// <param name="command"></param>
        public static void TranslateIntoSelect(Query query, SqlCommand command)
        {
            StringBuilder selectString = new StringBuilder();

            selectString.Append(baseSelect);
            selectString.Append(query.TableName);

            TranslateHelper.GetCriterionString(selectString, query.Criterions, command, query.SqlOperator);

            if (query.OrderByClauses.Count() > 0)
            {
                selectString.Append(TranslateHelper.GetStringFromOrderByClause(query.OrderByClauses));
            }

            command.CommandText = selectString.ToString();
        }
コード例 #2
0
        public static void TranslateIntoComplexQuery(ComplexQuery complexQuery, SqlCommand command)
        {
            string        baseString = "SELECT ";
            StringBuilder result     = new StringBuilder();

            result.Append(baseString);

            if (complexQuery.IsDictinct == true)
            {
                result.Append("DISTINCT ");
            }

            if (complexQuery.TopNumber != 0)
            {
                result.Append(TranslateHelper.GetTopNumber(complexQuery.TopNumber));
            }

            foreach (var item in complexQuery.NeedFields)
            {
                result.Append(TranslateHelper.GetFieldString(item));
            }
            result.Remove(result.Length - 1, 1);

            result.Append(TranslateHelper.GetJoinConditionString(complexQuery.NeedFields, complexQuery.JoinCriterion));

            if (complexQuery.Criterions.Count() > 0)
            {
                TranslateHelper.GetCriterionString(result, complexQuery.Criterions, command, complexQuery.SqlOperator);
            }

            if (complexQuery.OrderByClauses.Count > 0)
            {
                result.Append(TranslateHelper.GetStringFromOrderByClause(complexQuery.OrderByClauses));
            }

            command.CommandText = result.ToString();
        }