24 using NUnit.Framework;
26 namespace Deveel.Data.Sql.Expressions {
29 protected override void OnSetUp(
string testName) {
44 Query.CreateTable(tableInfo);
45 Query.AddPrimaryKey(tableInfo.TableName,
"id",
"PK_TEST_TABLE");
50 var row = table.NewRow();
77 expression.FromClause.AddTable(
"test_table");
80 Assert.DoesNotThrow(() => result = expression.EvaluateToConstant(
Query, null));
81 Assert.IsNotNull(result);
83 Assert.IsNotNull(result.
Value);
89 Assert.IsNotNull(queryResult);
90 Assert.AreEqual(3, queryResult.RowCount);
94 [Category(
"SQL Parse")]
96 const string sql =
"SELECT col1 AS a FROM table";
99 Assert.IsNotNull(expression);
103 Assert.IsNotEmpty(queryExpression.SelectColumns);
105 Assert.AreEqual(
"a", queryExpression.SelectColumns.First().Alias);
106 Assert.IsNotNull(queryExpression.FromClause);
107 Assert.AreEqual(1, queryExpression.FromClause.AllTables.Count());
108 Assert.AreEqual(
"table", queryExpression.FromClause.AllTables.First().Name);
112 [Category(
"SQL Parse")]
114 const string sql =
"SELECT a.col1, b.col2 FROM table1 a, table2 b";
118 Assert.IsNotNull(expression);
122 Assert.IsNotEmpty(queryExpression.SelectColumns);
125 Assert.IsNotNull(queryExpression.FromClause);
126 Assert.IsNotEmpty(queryExpression.FromClause.AllTables);
127 Assert.AreEqual(2, queryExpression.FromClause.AllTables.Count());
128 Assert.AreEqual(1, queryExpression.FromClause.JoinPartCount);
129 Assert.IsNotNull(queryExpression.FromClause.GetJoinPart(0));
130 Assert.AreEqual(
JoinType.Inner, queryExpression.FromClause.GetJoinPart(0).JoinType);
134 [Category(
"SQL Parse")]
136 const string sql =
"SELECT a.col1, b.col2 FROM table1 AS a INNER JOIN table2 b ON a.id = b.id";
140 Assert.IsNotNull(expression);
144 Assert.IsNotEmpty(queryExpression.SelectColumns);
147 Assert.IsNotNull(queryExpression.FromClause);
148 Assert.IsNotEmpty(queryExpression.FromClause.AllTables);
149 Assert.AreEqual(2, queryExpression.FromClause.AllTables.Count());
150 Assert.AreEqual(1, queryExpression.FromClause.JoinPartCount);
151 Assert.IsNotNull(queryExpression.FromClause.GetJoinPart(0));
152 Assert.AreEqual(
JoinType.Inner, queryExpression.FromClause.GetJoinPart(0).JoinType);
153 Assert.IsNotNull(queryExpression.FromClause.GetJoinPart(0).OnExpression);
154 Assert.IsInstanceOf<
SqlBinaryExpression>(queryExpression.FromClause.GetJoinPart(0).OnExpression);
158 [Category(
"SQL Parse")]
160 const string sql =
"SELECT user()";
164 Assert.IsNotNull(expression);
168 Assert.IsNotEmpty(queryExpression.SelectColumns);
170 Assert.AreEqual(
"user", ((
SqlFunctionCallExpression) queryExpression.SelectColumns.First().Expression).FunctioName.FullName);
174 [Category(
"SQL Parse")]
176 const string sql =
"SELECT * FROM (SELECT a, b FROM table1)";
180 Assert.IsNotNull(expression);
184 Assert.IsNotEmpty(queryExpression.SelectColumns);
185 Assert.IsNotEmpty(queryExpression.FromClause.AllTables);
186 Assert.AreEqual(1, queryExpression.FromClause.AllTables.Count());
187 Assert.IsTrue(queryExpression.FromClause.AllTables.First().IsSubQuery);
196 [Category(
"SQL Parse")]
198 const string sql =
"SELECT col1 AS a FROM table";
202 Assert.IsNotNull(expression);
206 Assert.IsNotEmpty(queryExpression.SelectColumns);
208 Assert.AreEqual(
"a", queryExpression.SelectColumns.First().Alias);
209 Assert.IsNotNull(queryExpression.FromClause);
210 Assert.AreEqual(1, queryExpression.FromClause.AllTables.Count());
211 Assert.AreEqual(
"table", queryExpression.FromClause.AllTables.First().Name);
215 [Category(
"SQL Parse")]
217 const string sql =
"SELECT col1 AS a, AVG(col2) b FROM table WHERE b > 2 GROUP BY a";
221 Assert.IsNotNull(expression);
225 Assert.IsNotEmpty(queryExpression.SelectColumns);
227 var groupBy = queryExpression.GroupBy;
228 Assert.IsNotNull(groupBy);
229 Assert.IsNotEmpty(groupBy);
230 Assert.AreEqual(1, groupBy.Count());
Provides some helper functions for resolving and creating SqlType instances that are primitive to the...
static DataObject Date(DateTimeOffset value)
Defines the contract to access the data contained into a table of a database.
SqlType Type
Gets the SqlType that defines the object properties
static ObjectName Parse(string s)
Parses the given string into a ObjectName object.
static SqlExpression Parse(string s)
Parses the given SQL string to an expression that can be evaluated.
void ParseSelectGroupBy()
An expression that references an object within a context.
override void OnSetUp(string testName)
JoinType
Enumerates the kind of group join in a selection query.
static BooleanType Boolean()
static NumericType Integer()
Describes the name of an object within a database.
ISqlObject Value
Gets the underlined value that is handled.
static DataObject String(string s)
static DataObject Boolean(SqlBoolean value)
void ParseSelectSubQuery()
void ParseSelectWithInnerJoin()
void AddColumn(ColumnInfo column)
Adds a new column to the table at the last position of the columns list in the table metadata...
Represents a dynamic object that encapsulates a defined SqlType and a compatible constant ISqlObject ...
static DateType DateTime()
Represents a column selected to be in the output of a select statement.
void ParseSelectWithFromClause()
static SqlReferenceExpression Reference(ObjectName objectName)
static StringType String()
Defines the base class for instances that represent SQL expression tree nodes.
void ParseSelectWithNaturalJoin()
void ParseSelectFunction()
static SqlFunctionCallExpression FunctionCall(ObjectName functionName)
Defines the metadata properties of a table existing within a database.