17 using System.Collections.Generic;
26 using NUnit.Framework;
28 namespace Deveel.Data.Sql.Statements {
32 using (var session = base.CreateAdminSession(database)) {
33 using (var query = session.CreateQuery()) {
34 CreateTestTable(query);
41 return base.CreateAdminSession(database);
54 context.CreateTable(tableInfo);
55 context.AddPrimaryKey(tableInfo.TableName,
"id",
"PK_TEST_TABLE");
59 var table = context.GetMutableTable(
ObjectName.
Parse(
"APP.test_table"));
60 var row = table.NewRow();
63 row.SetDefault(0, context);
73 row.SetDefault(0, context);
83 row.SetDefault(0, context);
95 const string sql =
"SELECT col1 AS a FROM table";
97 IEnumerable<SqlStatement> statements = null;
99 Assert.IsNotNull(statements);
101 var statement = statements.FirstOrDefault();
103 Assert.IsNotNull(statement);
107 Assert.IsNotNull(selectStatement.QueryExpression);
108 Assert.IsNull(selectStatement.OrderBy);
113 const string sql =
"SELECT :a";
115 IEnumerable<SqlStatement> statements = null;
117 Assert.IsNotNull(statements);
119 var statement = statements.FirstOrDefault();
121 Assert.IsNotNull(statement);
125 Assert.IsNotNull(selectStatement.QueryExpression);
126 Assert.IsNull(selectStatement.OrderBy);
128 Assert.IsNotNull(selectStatement.QueryExpression.SelectColumns);
131 Assert.AreEqual(1, selectCols.Count);
137 const string sql =
"SELECT user()";
139 IEnumerable<SqlStatement> statements = null;
141 Assert.IsNotNull(statements);
143 var statement = statements.FirstOrDefault();
145 Assert.IsNotNull(statement);
149 Assert.IsNotNull(selectStatement.QueryExpression);
150 Assert.IsNull(selectStatement.OrderBy);
152 Assert.IsNotNull(selectStatement.QueryExpression.SelectColumns);
155 Assert.AreEqual(1, selectCols.Count);
161 const string sql =
"SELECT col1 AS a FROM table ORDER BY a ASC";
163 IEnumerable<SqlStatement> statements = null;
165 Assert.IsNotNull(statements);
167 var statement = statements.FirstOrDefault();
169 Assert.IsNotNull(statement);
173 Assert.IsNotNull(selectStatement.QueryExpression);
174 Assert.IsNotNull(selectStatement.OrderBy);
179 const string sql =
"SELECT * FROM test_table";
181 IEnumerable<SqlStatement> statements = null;
183 Assert.IsNotNull(statements);
185 var statement = statements.FirstOrDefault();
187 Assert.IsNotNull(statement);
191 Assert.DoesNotThrow(() => result = statement.Execute(
Query));
192 Assert.IsNotNull(result);
193 Assert.AreEqual(3, result.RowCount);
198 const string sql =
"SELECT * FROM test_table ORDER BY birth_date DESC";
200 IEnumerable<SqlStatement> statements = null;
202 Assert.IsNotNull(statements);
204 var statement = statements.FirstOrDefault();
206 Assert.IsNotNull(statement);
210 Assert.DoesNotThrow(() => result = statement.Execute(
Query));
211 Assert.IsNotNull(result);
212 Assert.AreEqual(3, result.RowCount);
214 var firstName = result.
GetValue(0, 1);
216 Assert.AreEqual(
"Roger", firstName.Value.ToString());
221 const string sql =
"SELECT * FROM test_table t0 WHERE (t0.id = 1 AND t0.id <> 0)";
223 IEnumerable<SqlStatement> statements = null;
225 Assert.IsNotNull(statements);
227 var statement = statements.FirstOrDefault();
229 Assert.IsNotNull(statement);
233 Assert.DoesNotThrow(() => result = statement.Execute(
Query));
234 Assert.IsNotNull(result);
235 Assert.AreEqual(1, result.RowCount);
240 const string sql =
"SELECT * FROM test_table t0 WHERE t0.id = 1";
242 IEnumerable<SqlStatement> statements = null;
244 Assert.IsNotNull(statements);
246 var statement = statements.FirstOrDefault();
248 Assert.IsNotNull(statement);
252 Assert.DoesNotThrow(() => result = statement.Execute(
Query));
253 Assert.IsNotNull(result);
254 Assert.AreEqual(1, result.RowCount);
Provides some helper functions for resolving and creating SqlType instances that are primitive to the...
void SelectAliasedWithGroupedExpression()
static DataObject Date(DateTimeOffset value)
IEnumerable< SelectColumn > SelectColumns
Defines the contract to access the data contained into a table of a database.
static ObjectName Parse(string s)
Parses the given string into a ObjectName object.
void AddTestData(IQuery context)
static BooleanType Boolean()
void ExecuteSimpleOrderedSelect()
override ISession CreateAdminSession(IDatabase database)
static NumericType Integer()
Describes the name of an object within a database.
static DataObject String(string s)
static DataObject Boolean(SqlBoolean value)
The representation of a single database in the system.
DataObject GetValue(long rowNumber, int columnOffset)
Gets a single cell within the table that is located at the given column offset and row...
Represents the foundation class of SQL statements to be executed.
void AddColumn(ColumnInfo column)
Adds a new column to the table at the last position of the columns list in the table metadata...
An isolated session to a given database for a given user, encapsulating the transaction for operation...
Represents a dynamic object that encapsulates a defined SqlType and a compatible constant ISqlObject ...
static DateType DateTime()
void CreateTestTable(IQuery context)
void ParseWithFromClause()
static StringType String()
void ParseWithOrderByClause()
SqlQueryExpression QueryExpression
Defines the base class for instances that represent SQL expression tree nodes.
static SqlConstantExpression Constant(object value)
static SqlFunctionCallExpression FunctionCall(ObjectName functionName)
static IEnumerable< SqlStatement > Parse(string sqlSource)
Parses a given string into one of more statements.
Defines the metadata properties of a table existing within a database.
void ExecuteSimpleSelect()