DeveelDB  20151217
complete SQL database system, primarly developed for .NET/Mono frameworks
Public Member Functions | Protected Member Functions | Private Member Functions | List of all members
Deveel.Data.Sql.Expressions.SqlQueryExpressionTests Class Reference
Inheritance diagram for Deveel.Data.Sql.Expressions.SqlQueryExpressionTests:
Deveel.Data.ContextBasedTest

Public Member Functions

void ExecuteSelectAll ()
 
void ParseSelectWithFromClause ()
 
void ParseSelectWithNaturalJoin ()
 
void ParseSelectWithInnerJoin ()
 
void ParseSelectFunction ()
 
void ParseSelectSubQuery ()
 
void ParseSimpleQuery ()
 
void ParseSelectGroupBy ()
 
- Public Member Functions inherited from Deveel.Data.ContextBasedTest
void TestSetUp ()
 
void TestFixtureSetUp ()
 
void TestTearDown ()
 
void TestFixtureTearDown ()
 

Protected Member Functions

override void OnSetUp (string testName)
 
- Protected Member Functions inherited from Deveel.Data.ContextBasedTest
virtual void RegisterServices (ServiceContainer container)
 
virtual ISystem CreateSystem ()
 
virtual IDatabase CreateDatabase (ISystem system, IConfiguration configuration)
 
virtual ISession CreateAdminSession (IDatabase database)
 
virtual IQuery CreateQuery (ISession session)
 
ISession CreateUserSession (string userName, string password)
 
virtual void OnTearDown ()
 

Private Member Functions

void CreateTestTable ()
 
void AddTestData ()
 

Additional Inherited Members

- Protected Attributes inherited from Deveel.Data.ContextBasedTest
const string AdminUserName = "SA"
 
const string AdminPassword = "1234567890"
 
const string DatabaseName = "testdb"
 
- Properties inherited from Deveel.Data.ContextBasedTest
virtual bool SingleContext [get]
 
IQuery Query [get, private set]
 
ISystem System [get, private set]
 
IDatabase Database [get, private set]
 
ISession Session [get, private set]
 

Detailed Description

Definition at line 28 of file SqlQueryExpressionTests.cs.

Member Function Documentation

void Deveel.Data.Sql.Expressions.SqlQueryExpressionTests.AddTestData ( )
inlineprivate

Definition at line 48 of file SqlQueryExpressionTests.cs.

48  {
49  var table = Query.GetMutableTable(ObjectName.Parse("APP.test_table"));
50  var row = table.NewRow();
51  row.SetValue("first_name", DataObject.String("John"));
52  row.SetValue("last_name", DataObject.String("Doe"));
53  row.SetValue("birth_date", DataObject.Date(new SqlDateTime(1977, 01, 01)));
54  row.SetValue("active", DataObject.Boolean(false));
55  table.AddRow(row);
56 
57  row = table.NewRow();
58  row.SetValue("first_name", DataObject.String("Jane"));
59  row.SetValue("last_name", DataObject.String("Doe"));
60  row.SetValue("birth_date", DataObject.Date(new SqlDateTime(1978, 11, 01)));
61  row.SetValue("active", DataObject.Boolean(true));
62  table.AddRow(row);
63 
64  row = table.NewRow();
65  row.SetValue("first_name", DataObject.String("Roger"));
66  row.SetValue("last_name", DataObject.String("Rabbit"));
67  row.SetValue("birth_date", DataObject.Date(new SqlDateTime(1985, 05, 05)));
68  row.SetValue("active", DataObject.Boolean(true));
69  table.AddRow(row);
70  }
static DataObject Date(DateTimeOffset value)
Definition: DataObject.cs:600
static DataObject String(string s)
Definition: DataObject.cs:592
static DataObject Boolean(SqlBoolean value)
Definition: DataObject.cs:544
Represents a dynamic object that encapsulates a defined SqlType and a compatible constant ISqlObject ...
Definition: DataObject.cs:35
void Deveel.Data.Sql.Expressions.SqlQueryExpressionTests.CreateTestTable ( )
inlineprivate

Definition at line 34 of file SqlQueryExpressionTests.cs.

34  {
35  var tableInfo = new TableInfo(ObjectName.Parse("APP.test_table"));
36  var idColumn = tableInfo.AddColumn("id", PrimitiveTypes.Integer());
37  idColumn.DefaultExpression = SqlExpression.FunctionCall("UNIQUE_KEY",
38  new SqlExpression[] {SqlExpression.Reference(tableInfo.TableName)});
39  tableInfo.AddColumn("first_name", PrimitiveTypes.String());
40  tableInfo.AddColumn("last_name", PrimitiveTypes.String());
41  tableInfo.AddColumn("birth_date", PrimitiveTypes.DateTime());
42  tableInfo.AddColumn("active", PrimitiveTypes.Boolean());
43 
44  Query.CreateTable(tableInfo);
45  Query.AddPrimaryKey(tableInfo.TableName, "id", "PK_TEST_TABLE");
46  }
Provides some helper functions for resolving and creating SqlType instances that are primitive to the...
static BooleanType Boolean()
void AddColumn(ColumnInfo column)
Adds a new column to the table at the last position of the columns list in the table metadata...
Definition: TableInfo.cs:230
Defines the metadata properties of a table existing within a database.
Definition: TableInfo.cs:41
void Deveel.Data.Sql.Expressions.SqlQueryExpressionTests.ExecuteSelectAll ( )
inline

Definition at line 74 of file SqlQueryExpressionTests.cs.

74  {
75  var expression =
76  new SqlQueryExpression(new[] {new SelectColumn(SqlExpression.Reference(new ObjectName("first_name")))});
77  expression.FromClause.AddTable("test_table");
78 
79  DataObject result = null;
80  Assert.DoesNotThrow(() => result = expression.EvaluateToConstant(Query, null));
81  Assert.IsNotNull(result);
82  Assert.IsInstanceOf<QueryType>(result.Type);
83  Assert.IsNotNull(result.Value);
84  Assert.IsInstanceOf<SqlQueryObject>(result.Value);
85 
86  ITable queryResult = null;
87 
88  Assert.DoesNotThrow(() => queryResult = ((SqlQueryObject) result.Value).QueryPlan.Evaluate(Query));
89  Assert.IsNotNull(queryResult);
90  Assert.AreEqual(3, queryResult.RowCount);
91  }
Defines the contract to access the data contained into a table of a database.
Definition: ITable.cs:40
SqlType Type
Gets the SqlType that defines the object properties
Definition: DataObject.cs:78
ISqlObject Value
Gets the underlined value that is handled.
Definition: DataObject.cs:84
Represents a dynamic object that encapsulates a defined SqlType and a compatible constant ISqlObject ...
Definition: DataObject.cs:35
override void Deveel.Data.Sql.Expressions.SqlQueryExpressionTests.OnSetUp ( string  testName)
inlineprotectedvirtual
void Deveel.Data.Sql.Expressions.SqlQueryExpressionTests.ParseSelectFunction ( )
inline

Definition at line 159 of file SqlQueryExpressionTests.cs.

159  {
160  const string sql = "SELECT user()";
161 
162  SqlExpression expression = null;
163  Assert.DoesNotThrow(() => expression = SqlExpression.Parse(sql));
164  Assert.IsNotNull(expression);
165  Assert.IsInstanceOf<SqlQueryExpression>(expression);
166 
167  var queryExpression = (SqlQueryExpression) expression;
168  Assert.IsNotEmpty(queryExpression.SelectColumns);
169  Assert.IsInstanceOf<SqlFunctionCallExpression>(queryExpression.SelectColumns.First().Expression);
170  Assert.AreEqual("user", ((SqlFunctionCallExpression) queryExpression.SelectColumns.First().Expression).FunctioName.FullName);
171  }
void Deveel.Data.Sql.Expressions.SqlQueryExpressionTests.ParseSelectGroupBy ( )
inline

Definition at line 216 of file SqlQueryExpressionTests.cs.

216  {
217  const string sql = "SELECT col1 AS a, AVG(col2) b FROM table WHERE b > 2 GROUP BY a";
218 
219  SqlExpression expression = null;
220  Assert.DoesNotThrow(() => expression = SqlExpression.Parse(sql));
221  Assert.IsNotNull(expression);
222  Assert.IsInstanceOf<SqlQueryExpression>(expression);
223 
224  var queryExpression = (SqlQueryExpression)expression;
225  Assert.IsNotEmpty(queryExpression.SelectColumns);
226 
227  var groupBy = queryExpression.GroupBy;
228  Assert.IsNotNull(groupBy);
229  Assert.IsNotEmpty(groupBy);
230  Assert.AreEqual(1, groupBy.Count());
231  }
void Deveel.Data.Sql.Expressions.SqlQueryExpressionTests.ParseSelectSubQuery ( )
inline

Definition at line 175 of file SqlQueryExpressionTests.cs.

175  {
176  const string sql = "SELECT * FROM (SELECT a, b FROM table1)";
177 
178  SqlExpression expression = null;
179  Assert.DoesNotThrow(() => expression = SqlExpression.Parse(sql));
180  Assert.IsNotNull(expression);
181  Assert.IsInstanceOf<SqlQueryExpression>(expression);
182 
183  var queryExpression = (SqlQueryExpression) 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);
188  }
void Deveel.Data.Sql.Expressions.SqlQueryExpressionTests.ParseSelectWithFromClause ( )
inline

Definition at line 95 of file SqlQueryExpressionTests.cs.

95  {
96  const string sql = "SELECT col1 AS a FROM table";
97 
98  var expression = SqlExpression.Parse(sql);
99  Assert.IsNotNull(expression);
100  Assert.IsInstanceOf<SqlQueryExpression>(expression);
101 
102  var queryExpression = (SqlQueryExpression) expression;
103  Assert.IsNotEmpty(queryExpression.SelectColumns);
104  Assert.IsInstanceOf<SqlReferenceExpression>(queryExpression.SelectColumns.First().Expression);
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);
109  }
void Deveel.Data.Sql.Expressions.SqlQueryExpressionTests.ParseSelectWithInnerJoin ( )
inline

Definition at line 135 of file SqlQueryExpressionTests.cs.

135  {
136  const string sql = "SELECT a.col1, b.col2 FROM table1 AS a INNER JOIN table2 b ON a.id = b.id";
137 
138  SqlExpression expression = null;
139  Assert.DoesNotThrow(() => expression = SqlExpression.Parse(sql));
140  Assert.IsNotNull(expression);
141  Assert.IsInstanceOf<SqlQueryExpression>(expression);
142 
143  var queryExpression = (SqlQueryExpression) expression;
144  Assert.IsNotEmpty(queryExpression.SelectColumns);
145  Assert.IsInstanceOf<SqlReferenceExpression>(queryExpression.SelectColumns.First().Expression);
146  Assert.IsInstanceOf<SqlReferenceExpression>(queryExpression.SelectColumns.Skip(1).First().Expression);
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);
155  }
JoinType
Enumerates the kind of group join in a selection query.
Definition: JoinType.cs:23
void Deveel.Data.Sql.Expressions.SqlQueryExpressionTests.ParseSelectWithNaturalJoin ( )
inline

Definition at line 113 of file SqlQueryExpressionTests.cs.

113  {
114  const string sql = "SELECT a.col1, b.col2 FROM table1 a, table2 b";
115 
116  SqlExpression expression = null;
117  Assert.DoesNotThrow(() => expression = SqlExpression.Parse(sql));
118  Assert.IsNotNull(expression);
119  Assert.IsInstanceOf<SqlQueryExpression>(expression);
120 
121  var queryExpression = (SqlQueryExpression) expression;
122  Assert.IsNotEmpty(queryExpression.SelectColumns);
123  Assert.IsInstanceOf<SqlReferenceExpression>(queryExpression.SelectColumns.First().Expression);
124  Assert.IsInstanceOf<SqlReferenceExpression>(queryExpression.SelectColumns.Skip(1).First().Expression);
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);
131  }
JoinType
Enumerates the kind of group join in a selection query.
Definition: JoinType.cs:23
void Deveel.Data.Sql.Expressions.SqlQueryExpressionTests.ParseSimpleQuery ( )
inline

Definition at line 197 of file SqlQueryExpressionTests.cs.

197  {
198  const string sql = "SELECT col1 AS a FROM table";
199 
200  SqlExpression expression = null;
201  Assert.DoesNotThrow(() => expression = SqlExpression.Parse(sql));
202  Assert.IsNotNull(expression);
203  Assert.IsInstanceOf<SqlQueryExpression>(expression);
204 
205  var queryExpression = (SqlQueryExpression)expression;
206  Assert.IsNotEmpty(queryExpression.SelectColumns);
207  Assert.IsInstanceOf<SqlReferenceExpression>(queryExpression.SelectColumns.First().Expression);
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);
212  }

The documentation for this class was generated from the following file: