DeveelDB  20151217
complete SQL database system, primarly developed for .NET/Mono frameworks
MutableTableTests.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;
19 using Deveel.Data.Sql.Tables;
20 using Deveel.Data.Types;
21 
22 using NUnit.Framework;
23 
24 namespace Deveel.Data.Sql {
25  [TestFixture]
27  protected override void OnSetUp(string testName) {
28  var table = CreateTable();
29 
30  if (testName != "InsertInto") {
31  InsertIntoTable(table);
32  }
33  }
34 
35  private void InsertIntoTable(IMutableTable table) {
36  var row = table.NewRow();
37  row.SetValue(0, "Antonello Provenzano");
38  row.SetValue(1, 33);
39  row.SetValue(2, 0);
40  table.AddRow(row);
41 
42  row = table.NewRow();
43  row.SetValue(0, "Maart Roosmaa");
44  row.SetValue(1, 28);
45  row.SetValue(2, 5);
46  table.AddRow(row);
47 
48  row = table.NewRow();
49  row.SetValue(0, "Rezaul Horaque");
50  row.SetValue(1, 27);
51  row.SetValue(2, 2);
52  table.AddRow(row);
53  }
54 
56  var tableName = ObjectName.Parse("APP.test_table");
57  var tableInfo = new TableInfo(tableName);
58  tableInfo.AddColumn("name", PrimitiveTypes.String(), true);
59  tableInfo.AddColumn("age", PrimitiveTypes.Integer());
60  tableInfo.AddColumn("order", PrimitiveTypes.Integer());
61 
62  Query.CreateTable(tableInfo);
63  return Query.GetMutableTable(tableName);
64  }
65 
66  [Test]
67  public void SameSessionInsertInto() {
68  Assert.Inconclusive();
69  }
70 
71  [Test]
72  public void SameSessionDeleteFrom() {
73  var queryExpression = SqlExpression.GreaterThan(SqlExpression.Reference(new ObjectName("order")), SqlExpression.Constant(2));
74 
75  int deleteCount = -1;
76  Assert.DoesNotThrow(() => deleteCount = Query.DeleteFrom(ObjectName.Parse("APP.test_table"), queryExpression));
77  Assert.AreEqual(1, deleteCount);
78  }
79  }
80 }
Provides some helper functions for resolving and creating SqlType instances that are primitive to the...
static ObjectName Parse(string s)
Parses the given string into a ObjectName object.
Definition: ObjectName.cs:139
override void OnSetUp(string testName)
Describes the name of an object within a database.
Definition: ObjectName.cs:44
void InsertIntoTable(IMutableTable table)
RowId AddRow(Row row)
Persists a new row to the table.
static SqlReferenceExpression Reference(ObjectName objectName)
Defines the base class for instances that represent SQL expression tree nodes.
static SqlConstantExpression Constant(object value)
Defines the metadata properties of a table existing within a database.
Definition: TableInfo.cs:41
An interface that defines contracts to alter the contents of a table.
static SqlBinaryExpression GreaterThan(SqlExpression left, SqlExpression right)