DeveelDB  20151217
complete SQL database system, primarly developed for .NET/Mono frameworks
SqlBetweenEspressionTests.cs
Go to the documentation of this file.
1 //
2 // Copyright 2010-2014 Deveel
3 //
4 // Licensed under the Apache License, Version 2.0 (the "License");
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
7 //
8 // http://www.apache.org/licenses/LICENSE-2.0
9 //
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an "AS IS" BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
15 using System;
16 
17 using Deveel.Data.Sql.Objects;
18 using Deveel.Data.Types;
19 
20 using NUnit.Framework;
21 
22 namespace Deveel.Data.Sql.Expressions {
23  [TestFixture]
25  [Test]
26  public void BetweenNumerics() {
27  const string sql = "22 BETWEEN 10 AND 54";
28 
29  SqlExpression expression = null;
30  Assert.DoesNotThrow(() => expression = SqlExpression.Parse(sql));
31  Assert.IsNotNull(expression);
32 
33  Assert.IsInstanceOf<SqlBinaryExpression>(expression);
34  Assert.AreEqual(SqlExpressionType.And, expression.ExpressionType);
35 
36  SqlExpression resultExpression = null;
37  Assert.DoesNotThrow(() => resultExpression = expression.Evaluate());
38  Assert.IsNotNull(resultExpression);
39  Assert.AreEqual(SqlExpressionType.Constant, resultExpression.ExpressionType);
40 
41  var value = ((SqlConstantExpression) resultExpression).Value;
42 
43  Assert.IsInstanceOf<BooleanType>(value.Type);
44  Assert.AreEqual(SqlBoolean.True, (SqlBoolean)value.Value);
45  }
46 
47  [Test]
48  public void BetweenDates() {
49  const string sql = "TODATE('2001-02-12') BETWEEN TODATE('2000-01-20') AND TODATE('2003-01-01')";
50 
51  SqlExpression expression = null;
52  Assert.DoesNotThrow(() => expression = SqlExpression.Parse(sql));
53  Assert.IsNotNull(expression);
54 
55  Assert.IsInstanceOf<SqlBinaryExpression>(expression);
56  Assert.AreEqual(SqlExpressionType.And, expression.ExpressionType);
57 
58  SqlExpression resultExpression = null;
59  Assert.DoesNotThrow(() => resultExpression = expression.Evaluate());
60  Assert.IsNotNull(resultExpression);
61  Assert.AreEqual(SqlExpressionType.Constant, resultExpression.ExpressionType);
62 
63  var value = ((SqlConstantExpression)resultExpression).Value;
64 
65  Assert.IsInstanceOf<BooleanType>(value.Type);
66  Assert.AreEqual(SqlBoolean.True, (SqlBoolean)value.Value);
67  }
68  }
69 }
static SqlExpression Parse(string s)
Parses the given SQL string to an expression that can be evaluated.
SqlExpressionType
All the possible type of SqlExpression supported
virtual SqlExpression Evaluate(EvaluateContext context)
When overridden by a derived class, this method evaluates the expression within the provided context...
An expression that holds a constant value.
Defines the base class for instances that represent SQL expression tree nodes.
abstract SqlExpressionType ExpressionType
Gets the type code of this SQL expression.