Exemplo n.º 1
0
        public IQueryBuilder <TRecord> Where(string fieldName, SqlOperand operand, object value)
        {
            switch (operand)
            {
            case SqlOperand.Contains:
                QueryGenerator.WhereContains(fieldName, value);
                break;

            case SqlOperand.EndsWith:
                QueryGenerator.WhereEndsWith(fieldName, value);
                break;

            case SqlOperand.Equal:
                QueryGenerator.WhereEquals(fieldName, value);
                break;

            case SqlOperand.NotEqual:
                QueryGenerator.WhereNotEquals(fieldName, value);
                break;

            case SqlOperand.GreaterThan:
                QueryGenerator.WhereGreaterThan(fieldName, value);
                break;

            case SqlOperand.GreaterThanOrEqual:
                QueryGenerator.WhereGreaterThanOrEqual(fieldName, value);
                break;

            case SqlOperand.LessThan:
                QueryGenerator.WhereLessThan(fieldName, value);
                break;

            case SqlOperand.LessThanOrEqual:
                QueryGenerator.WhereLessThanOrEqual(fieldName, value);
                break;

            case SqlOperand.StartsWith:
                QueryGenerator.WhereStartsWith(fieldName, value);
                break;

            case SqlOperand.In:
                if (value is IEnumerable)
                {
                    QueryGenerator.WhereIn(fieldName, value);
                }
                else
                {
                    throw new ArgumentException($"The operand {operand} is not valid with only one value", nameof(operand));
                }
                break;

            default:
                throw new ArgumentException($"The operand {operand} is not valid with only one value", nameof(operand));
            }

            return(this);
        }
Exemplo n.º 2
0
        public IQueryBuilder <TRecord> Where(string fieldName, SqlOperand operand, object startValue, object endValue)
        {
            switch (operand)
            {
            case SqlOperand.Between:
                QueryGenerator.WhereBetween(fieldName, startValue, endValue);
                break;

            case SqlOperand.BetweenOrEqual:
                QueryGenerator.WhereBetweenOrEqual(fieldName, startValue, endValue);
                break;

            default:
                throw new ArgumentException($"The operand {operand} is not valid with two values", nameof(operand));
            }

            return(this);
        }
Exemplo n.º 3
0
        public IQueryBuilder <TRecord> Where(string fieldName, SqlOperand operand, IEnumerable <object> values)
        {
            switch (operand)
            {
            case SqlOperand.In:
                QueryGenerator.WhereIn(fieldName, values);
                break;

            case SqlOperand.ContainsAll:
                break;

            case SqlOperand.ContainsAny:
                break;

            default:
                throw new ArgumentException($"The operand {operand} is not valid with a list of values", nameof(operand));
            }

            return(this);
        }
Exemplo n.º 4
0
        string GetQueryOperand(SqlOperand operand)
        {
            switch (operand)
            {
            case SqlOperand.Between:
                return("BETWEEN");

            case SqlOperand.Contains:
            case SqlOperand.ContainsAll:
            case SqlOperand.ContainsAny:
            case SqlOperand.EndsWith:
            case SqlOperand.StartsWith:
                return("LIKE");

            case SqlOperand.Equal:
                return("=");

            case SqlOperand.NotEqual:
                return("<>");

            case SqlOperand.GreaterThan:
                return(">");

            case SqlOperand.GreaterThanOrEqual:
                return(">=");

            case SqlOperand.LessThan:
                return("<");

            case SqlOperand.LessThanOrEqual:
                return("<=");

            case SqlOperand.In:
                return("IN");

            default:
                throw new NotSupportedException("Operand " + operand + " is not supported!");
            }
        }
Exemplo n.º 5
0
 string Operand(SqlOperand operand)
 {
     return($" {GetQueryOperand(operand)} ");
 }
Exemplo n.º 6
0
 void AppendOperand(SqlOperand operand)
 {
     queryText.Append(Operand(operand));
 }