Esempio n. 1
0
        public IUnaryParameterQueryBuilder <TRecord> WhereParameterised(string fieldName, UnarySqlOperand operand, Parameter parameter)
        {
            var uniqueParameter = new UniqueParameter(uniqueParameterNameGenerator, parameter);

            selectBuilder.AddWhere(new UnaryWhereParameter(fieldName, operand, uniqueParameter));
            return(new UnaryParameterQueryBuilder <TRecord>(Parameter(uniqueParameter), uniqueParameter));
        }
Esempio n. 2
0
        public List <TRecord> ToList(int skip, int take)
        {
            const string rowNumberColumnName = "RowNum";
            var          minRowParameter     = new UniqueParameter(uniqueParameterNameGenerator, new Parameter("_minrow"));
            var          maxRowParameter     = new UniqueParameter(uniqueParameterNameGenerator, new Parameter("_maxrow"));

            var clonedSelectBuilder = selectBuilder.Clone();

            clonedSelectBuilder.AddDefaultColumnSelection();
            clonedSelectBuilder.AddRowNumberColumn(rowNumberColumnName, new List <Column>());

            var subqueryBuilder = CreateSubqueryBuilder(clonedSelectBuilder);

            subqueryBuilder.AddWhere(new UnaryWhereParameter(rowNumberColumnName, UnarySqlOperand.GreaterThanOrEqual, minRowParameter));
            subqueryBuilder.AddWhere(new UnaryWhereParameter(rowNumberColumnName, UnarySqlOperand.LessThanOrEqual, maxRowParameter));
            subqueryBuilder.AddOrder("RowNum", false);

            var parmeterValues = new CommandParameterValues(paramValues)
            {
                { minRowParameter.ParameterName, skip + 1 },
                { maxRowParameter.ParameterName, take + skip }
            };

            return(transaction.ExecuteReader <TRecord>(subqueryBuilder.GenerateSelect().GenerateSql(), parmeterValues).ToList());
        }
Esempio n. 3
0
        public bool Any()
        {
            const int trueValue      = 1;
            const int falseValue     = 0;
            var       trueParameter  = new UniqueParameter(uniqueParameterNameGenerator, new Parameter("true"));
            var       falseParameter = new UniqueParameter(uniqueParameterNameGenerator, new Parameter("false"));

            var result = transaction.ExecuteScalar <int>(CreateQuery().GenerateSql(), CreateParameterValues());

            return(result != falseValue);

            CommandParameterValues CreateParameterValues()
            {
                return(new CommandParameterValues(paramValues)
                {
                    { trueParameter.ParameterName, trueValue },
                    { falseParameter.ParameterName, falseValue }
                });
            }

            IExpression CreateQuery()
            {
                var clonedSelectBuilder = selectBuilder.Clone();

                clonedSelectBuilder.RemoveOrderBys();
                return(new IfExpression(new ExistsExpression(clonedSelectBuilder.GenerateSelectWithoutDefaultOrderBy()),
                                        new SelectConstant(trueParameter),
                                        new SelectConstant(falseParameter)));
            }
        }
Esempio n. 4
0
        public IBinaryParametersQueryBuilder <TRecord> WhereParameterised(string fieldName, BinarySqlOperand operand,
                                                                          Parameter startValueParameter, Parameter endValueParameter)
        {
            var uniqueStartParameter = new UniqueParameter(uniqueParameterNameGenerator, startValueParameter);
            var uniqueEndParameter   = new UniqueParameter(uniqueParameterNameGenerator, endValueParameter);

            selectBuilder.AddWhere(new BinaryWhereParameter(fieldName, operand, uniqueStartParameter, uniqueEndParameter));
            return(new BinaryParametersQueryBuilder <TRecord>(Parameter(uniqueStartParameter).Parameter(uniqueEndParameter), uniqueStartParameter, uniqueEndParameter));
        }
Esempio n. 5
0
        public IUnaryParameterDeleteQueryBuilder <TRecord> WhereParameterised(string fieldName, UnarySqlOperand operand,
                                                                              Parameter parameter)
        {
            var uniqueParameter = new UniqueParameter(uniqueParameterNameGenerator, parameter);

            return(new UnaryParameterDeleteQueryBuilder <TRecord>(
                       AddWhereClause(new UnaryWhereClause(new WhereFieldReference(fieldName), operand, uniqueParameter.ParameterName)),
                       uniqueParameter));
        }
Esempio n. 6
0
        public IBinaryParametersDeleteQueryBuilder <TRecord> WhereParameterised(string fieldName,
                                                                                BinarySqlOperand operand, Parameter startValueParameter,
                                                                                Parameter endValueParameter)
        {
            var uniqueStartParameter = new UniqueParameter(uniqueParameterNameGenerator, startValueParameter);
            var uniqueEndParameter   = new UniqueParameter(uniqueParameterNameGenerator, endValueParameter);

            return(new BinaryParametersDeleteQueryBuilder <TRecord>(
                       AddWhereClause(new BinaryWhereClause(new WhereFieldReference(fieldName), operand, uniqueStartParameter.ParameterName, uniqueEndParameter.ParameterName)),
                       uniqueStartParameter,
                       uniqueEndParameter));
        }
 public UnaryParameterDeleteQueryBuilder(IDeleteQueryBuilder <TRecord> deleteQueryBuilder, UniqueParameter parameter)
 {
     this.deleteQueryBuilder = deleteQueryBuilder;
     this.parameter          = parameter;
 }