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.Statements.SelectStatementTests Class Reference
Inheritance diagram for Deveel.Data.Sql.Statements.SelectStatementTests:
Deveel.Data.ContextBasedTest

Public Member Functions

void ParseWithFromClause ()
 
void ParseWithVariable ()
 
void ParseWithFunction ()
 
void ParseWithOrderByClause ()
 
void ExecuteSimpleSelect ()
 
void ExecuteSimpleOrderedSelect ()
 
void SelectAliasedWithGroupedExpression ()
 
void SelectFromAliased ()
 
- Public Member Functions inherited from Deveel.Data.ContextBasedTest
void TestSetUp ()
 
void TestFixtureSetUp ()
 
void TestTearDown ()
 
void TestFixtureTearDown ()
 

Protected Member Functions

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

Private Member Functions

void CreateTestTable (IQuery context)
 
void AddTestData (IQuery context)
 

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 30 of file SelectStatementTests.cs.

Member Function Documentation

void Deveel.Data.Sql.Statements.SelectStatementTests.AddTestData ( IQuery  context)
inlineprivate

Definition at line 58 of file SelectStatementTests.cs.

58  {
59  var table = context.GetMutableTable(ObjectName.Parse("APP.test_table"));
60  var row = table.NewRow();
61 
62  // row.SetValue("id", DataObject.Integer(0));
63  row.SetDefault(0, context);
64  row.SetValue("first_name", DataObject.String("John"));
65  row.SetValue("last_name", DataObject.String("Doe"));
66  row.SetValue("birth_date", DataObject.Date(new SqlDateTime(1977, 01, 01)));
67  row.SetValue("active", DataObject.Boolean(false));
68  table.AddRow(row);
69 
70  row = table.NewRow();
71 
72  // row.SetValue("id", DataObject.Integer(1));
73  row.SetDefault(0, context);
74  row.SetValue("first_name", DataObject.String("Jane"));
75  row.SetValue("last_name", DataObject.String("Doe"));
76  row.SetValue("birth_date", DataObject.Date(new SqlDateTime(1978, 11, 01)));
77  row.SetValue("active", DataObject.Boolean(true));
78  table.AddRow(row);
79 
80  row = table.NewRow();
81 
82  // row.SetValue("id", DataObject.Integer(2));
83  row.SetDefault(0, context);
84  row.SetValue("first_name", DataObject.String("Roger"));
85  row.SetValue("last_name", DataObject.String("Rabbit"));
86  row.SetValue("birth_date", DataObject.Date(new SqlDateTime(1985, 05, 05)));
87  row.SetValue("active", DataObject.Boolean(true));
88  table.AddRow(row);
89 
90  context.Commit();
91  }
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
override ISession Deveel.Data.Sql.Statements.SelectStatementTests.CreateAdminSession ( IDatabase  database)
inlineprotectedvirtual

Reimplemented from Deveel.Data.ContextBasedTest.

Definition at line 31 of file SelectStatementTests.cs.

31  {
32  using (var session = base.CreateAdminSession(database)) {
33  using (var query = session.CreateQuery()) {
34  CreateTestTable(query);
35  AddTestData(query);
36 
37  query.Commit();
38  }
39  }
40 
41  return base.CreateAdminSession(database);
42  }
void Deveel.Data.Sql.Statements.SelectStatementTests.CreateTestTable ( IQuery  context)
inlineprivate

Definition at line 44 of file SelectStatementTests.cs.

44  {
45  var tableInfo = new TableInfo(ObjectName.Parse("APP.test_table"));
46  var idColumn = tableInfo.AddColumn("id", PrimitiveTypes.Integer());
47  idColumn.DefaultExpression = SqlExpression.FunctionCall("UNIQUEKEY",
48  new SqlExpression[] { SqlExpression.Constant(tableInfo.TableName.FullName) });
49  tableInfo.AddColumn("first_name", PrimitiveTypes.String());
50  tableInfo.AddColumn("last_name", PrimitiveTypes.String());
51  tableInfo.AddColumn("birth_date", PrimitiveTypes.DateTime());
52  tableInfo.AddColumn("active", PrimitiveTypes.Boolean());
53 
54  context.CreateTable(tableInfo);
55  context.AddPrimaryKey(tableInfo.TableName, "id", "PK_TEST_TABLE");
56  }
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 base class for instances that represent SQL expression tree nodes.
static SqlConstantExpression Constant(object value)
static SqlFunctionCallExpression FunctionCall(ObjectName functionName)
Defines the metadata properties of a table existing within a database.
Definition: TableInfo.cs:41
void Deveel.Data.Sql.Statements.SelectStatementTests.ExecuteSimpleOrderedSelect ( )
inline

Definition at line 197 of file SelectStatementTests.cs.

197  {
198  const string sql = "SELECT * FROM test_table ORDER BY birth_date DESC";
199 
200  IEnumerable<SqlStatement> statements = null;
201  Assert.DoesNotThrow(() => statements = SqlStatement.Parse(sql));
202  Assert.IsNotNull(statements);
203 
204  var statement = statements.FirstOrDefault();
205 
206  Assert.IsNotNull(statement);
207  Assert.IsInstanceOf<SelectStatement>(statement);
208 
209  ITable result = null;
210  Assert.DoesNotThrow(() => result = statement.Execute(Query));
211  Assert.IsNotNull(result);
212  Assert.AreEqual(3, result.RowCount);
213 
214  var firstName = result.GetValue(0, 1);
215 
216  Assert.AreEqual("Roger", firstName.Value.ToString());
217  }
Defines the contract to access the data contained into a table of a database.
Definition: ITable.cs:40
DataObject GetValue(long rowNumber, int columnOffset)
Gets a single cell within the table that is located at the given column offset and row...
void Deveel.Data.Sql.Statements.SelectStatementTests.ExecuteSimpleSelect ( )
inline

Definition at line 178 of file SelectStatementTests.cs.

178  {
179  const string sql = "SELECT * FROM test_table";
180 
181  IEnumerable<SqlStatement> statements = null;
182  Assert.DoesNotThrow(() => statements = SqlStatement.Parse(sql));
183  Assert.IsNotNull(statements);
184 
185  var statement = statements.FirstOrDefault();
186 
187  Assert.IsNotNull(statement);
188  Assert.IsInstanceOf<SelectStatement>(statement);
189 
190  ITable result = null;
191  Assert.DoesNotThrow(() => result = statement.Execute(Query));
192  Assert.IsNotNull(result);
193  Assert.AreEqual(3, result.RowCount);
194  }
Defines the contract to access the data contained into a table of a database.
Definition: ITable.cs:40
void Deveel.Data.Sql.Statements.SelectStatementTests.ParseWithFromClause ( )
inline

Definition at line 94 of file SelectStatementTests.cs.

94  {
95  const string sql = "SELECT col1 AS a FROM table";
96 
97  IEnumerable<SqlStatement> statements = null;
98  Assert.DoesNotThrow(() => statements = SqlStatement.Parse(sql));
99  Assert.IsNotNull(statements);
100 
101  var statement = statements.FirstOrDefault();
102 
103  Assert.IsNotNull(statement);
104  Assert.IsInstanceOf<SelectStatement>(statement);
105 
106  var selectStatement = (SelectStatement) statement;
107  Assert.IsNotNull(selectStatement.QueryExpression);
108  Assert.IsNull(selectStatement.OrderBy);
109  }
void Deveel.Data.Sql.Statements.SelectStatementTests.ParseWithFunction ( )
inline

Definition at line 136 of file SelectStatementTests.cs.

136  {
137  const string sql = "SELECT user()";
138 
139  IEnumerable<SqlStatement> statements = null;
140  Assert.DoesNotThrow(() => statements = SqlStatement.Parse(sql));
141  Assert.IsNotNull(statements);
142 
143  var statement = statements.FirstOrDefault();
144 
145  Assert.IsNotNull(statement);
146  Assert.IsInstanceOf<SelectStatement>(statement);
147 
148  var selectStatement = (SelectStatement)statement;
149  Assert.IsNotNull(selectStatement.QueryExpression);
150  Assert.IsNull(selectStatement.OrderBy);
151 
152  Assert.IsNotNull(selectStatement.QueryExpression.SelectColumns);
153 
154  var selectCols = selectStatement.QueryExpression.SelectColumns.ToList();
155  Assert.AreEqual(1, selectCols.Count);
156  Assert.IsInstanceOf<SqlFunctionCallExpression>(selectCols[0].Expression);
157  }
void Deveel.Data.Sql.Statements.SelectStatementTests.ParseWithOrderByClause ( )
inline

Definition at line 160 of file SelectStatementTests.cs.

160  {
161  const string sql = "SELECT col1 AS a FROM table ORDER BY a ASC";
162 
163  IEnumerable<SqlStatement> statements = null;
164  Assert.DoesNotThrow(() => statements = SqlStatement.Parse(sql));
165  Assert.IsNotNull(statements);
166 
167  var statement = statements.FirstOrDefault();
168 
169  Assert.IsNotNull(statement);
170  Assert.IsInstanceOf<SelectStatement>(statement);
171 
172  var selectStatement = (SelectStatement)statement;
173  Assert.IsNotNull(selectStatement.QueryExpression);
174  Assert.IsNotNull(selectStatement.OrderBy);
175  }
void Deveel.Data.Sql.Statements.SelectStatementTests.ParseWithVariable ( )
inline

Definition at line 112 of file SelectStatementTests.cs.

112  {
113  const string sql = "SELECT :a";
114 
115  IEnumerable<SqlStatement> statements = null;
116  Assert.DoesNotThrow(() => statements = SqlStatement.Parse(sql));
117  Assert.IsNotNull(statements);
118 
119  var statement = statements.FirstOrDefault();
120 
121  Assert.IsNotNull(statement);
122  Assert.IsInstanceOf<SelectStatement>(statement);
123 
124  var selectStatement = (SelectStatement)statement;
125  Assert.IsNotNull(selectStatement.QueryExpression);
126  Assert.IsNull(selectStatement.OrderBy);
127 
128  Assert.IsNotNull(selectStatement.QueryExpression.SelectColumns);
129 
130  var selectCols = selectStatement.QueryExpression.SelectColumns.ToList();
131  Assert.AreEqual(1, selectCols.Count);
132  Assert.IsInstanceOf<SqlVariableReferenceExpression>(selectCols[0].Expression);
133  }
void Deveel.Data.Sql.Statements.SelectStatementTests.SelectAliasedWithGroupedExpression ( )
inline

Definition at line 220 of file SelectStatementTests.cs.

220  {
221  const string sql = "SELECT * FROM test_table t0 WHERE (t0.id = 1 AND t0.id <> 0)";
222 
223  IEnumerable<SqlStatement> statements = null;
224  Assert.DoesNotThrow(() => statements = SqlStatement.Parse(sql));
225  Assert.IsNotNull(statements);
226 
227  var statement = statements.FirstOrDefault();
228 
229  Assert.IsNotNull(statement);
230  Assert.IsInstanceOf<SelectStatement>(statement);
231 
232  ITable result = null;
233  Assert.DoesNotThrow(() => result = statement.Execute(Query));
234  Assert.IsNotNull(result);
235  Assert.AreEqual(1, result.RowCount);
236  }
Defines the contract to access the data contained into a table of a database.
Definition: ITable.cs:40
void Deveel.Data.Sql.Statements.SelectStatementTests.SelectFromAliased ( )
inline

Definition at line 239 of file SelectStatementTests.cs.

239  {
240  const string sql = "SELECT * FROM test_table t0 WHERE t0.id = 1";
241 
242  IEnumerable<SqlStatement> statements = null;
243  Assert.DoesNotThrow(() => statements = SqlStatement.Parse(sql));
244  Assert.IsNotNull(statements);
245 
246  var statement = statements.FirstOrDefault();
247 
248  Assert.IsNotNull(statement);
249  Assert.IsInstanceOf<SelectStatement>(statement);
250 
251  ITable result = null;
252  Assert.DoesNotThrow(() => result = statement.Execute(Query));
253  Assert.IsNotNull(result);
254  Assert.AreEqual(1, result.RowCount);
255  }
Defines the contract to access the data contained into a table of a database.
Definition: ITable.cs:40

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