Example #1
0
        /// <summary>
        /// 初始化<c>SqlBag</c>实例
        /// </summary>
        /// <param name="tableOrViewName">表/视图名称</param>
        /// <param name="tableOrViewAlias">表/视图的匿名, 为 null 表示不用匿名表/视图</param>
        /// <param name="fields">SELECT 字段集合(field/alias field), 值为 null 表示改字段不使用匿名</param>
        /// <param name="operators">字段操作集合</param>
        /// <param name="model">生成 SELECT 子句的模式 [Raw, WithAlias, StringWithAlias]</param>
        public SqlBag(string tableOrViewName, string tableOrViewAlias, IDictionary<string, string> fields, IEnumerable<SqlOperator> operators, SelectClauseBuildMode model)
        {
            this.sqlSelectBuilder = new SqlSelectClauseBuilder(tableOrViewName, tableOrViewAlias, model);
            foreach (var field in fields)
                this.sqlSelectBuilder.AddField(field.Key, field.Value);

            this.sqlWhereBuilder = new SqlWhereClauseBuilder();
            foreach (var item in operators)
                this.sqlWhereBuilder.AddParameterValue(item.Name, item.Operator, item.Value);
        }
Example #2
0
        /// <summary>
        /// 初始化<c>SqlBag</c>实例
        /// </summary>
        /// <param name="tableOrViewName">表/视图名称</param>
        /// <param name="tableOrViewAlias">表/视图的匿名, 为 null 表示不用匿名表/视图</param>
        /// <param name="fields">SELECT 字段集合(field/alias field), 值为 null 表示改字段不使用匿名</param>
        /// <param name="operators">字段操作集合</param>
        /// <param name="model">生成 SELECT 子句的模式 [Raw, WithAlias, StringWithAlias]</param>
        public SqlBag(string tableOrViewName, string tableOrViewAlias, IDictionary <string, string> fields, IEnumerable <SqlOperator> operators, SelectClauseBuildMode model)
        {
            this.sqlSelectBuilder = new SqlSelectClauseBuilder(tableOrViewName, tableOrViewAlias, model);
            foreach (var field in fields)
            {
                this.sqlSelectBuilder.AddField(field.Key, field.Value);
            }

            this.sqlWhereBuilder = new SqlWhereClauseBuilder();
            foreach (var item in operators)
            {
                this.sqlWhereBuilder.AddParameterValue(item.Name, item.Operator, item.Value);
            }
        }
Example #3
0
        public void SqlClauseBuilderTest()
        {
            var selectBuilder = new SqlSelectClauseBuilder(this._tableName, SelectClauseBuildMode.StringWithAlias);
            foreach (var field in this._fields)
                selectBuilder.AddField(field.Item1, field.Item2);

            var whereBuilder = new SqlWhereClauseBuilder();
            this._operators.ForEach(o =>
            {
                whereBuilder.AddParameterValue(o.Item1, o.Item2, o.Item3);
            });

            var sqlResult = selectBuilder.ToString() + whereBuilder.ToString();
            Assert.IsNull(sqlResult, sqlResult);
        }
Example #4
0
        public void SqlSelectClauseBuilderTest()
        {
            var selectBuilder = new SqlSelectClauseBuilder(this._tableName, SelectClauseBuildMode.StringWithAlias);
            foreach (var field in this._fields)
                selectBuilder.AddField(field.Item1, field.Item2);

            var selectResult = selectBuilder.ToString();
            Assert.IsTrue(String.IsNullOrWhiteSpace(selectResult), selectResult);
        }