DeveelDB  20151217
complete SQL database system, primarly developed for .NET/Mono frameworks
DropTableStatementTests.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;
18 using Deveel.Data.Sql.Tables;
19 using Deveel.Data.Types;
20 
21 using NUnit.Framework;
22 
23 namespace Deveel.Data.Sql.Statements {
24  [TestFixture]
25  public sealed class DropTableStatementTests : ContextBasedTest {
26  protected override IQuery CreateQuery(ISession session) {
27  var query = base.CreateQuery(session);
28  CreateTestTables(query);
29  return query;
30  }
31 
32  private void CreateTestTables(IQuery context) {
33  var tn1 = ObjectName.Parse("APP.test_table1");
34  var tableInfo1 = new TableInfo(tn1);
35  tableInfo1.AddColumn(new ColumnInfo("id", PrimitiveTypes.Integer()));
36  tableInfo1.AddColumn(new ColumnInfo("name", PrimitiveTypes.String()));
37  tableInfo1.AddColumn(new ColumnInfo("date", PrimitiveTypes.DateTime()));
38  context.CreateTable(tableInfo1);
39  context.AddPrimaryKey(tn1, "id");
40 
41  var tn2 = ObjectName.Parse("APP.test_table2");
42  var tableInfo2 = new TableInfo(tn2);
43  tableInfo2.AddColumn(new ColumnInfo("id", PrimitiveTypes.Integer()));
44  tableInfo2.AddColumn(new ColumnInfo("other_id", PrimitiveTypes.Integer()));
45  tableInfo2.AddColumn(new ColumnInfo("count", PrimitiveTypes.Integer()));
46  context.CreateTable(tableInfo2);
47  context.AddPrimaryKey(tn2, "id");
48  context.AddForeignKey(tn2, new[] { "other_id" }, tn1, new[] { "id" }, ForeignKeyAction.Cascade, ForeignKeyAction.Cascade, null);
49  }
50 
51  [Test]
52  public void DropNonReferencedTable() {
53  const string sql = "DROP TABLE test_table2";
54 
55  Assert.DoesNotThrow(() => Query.ExecuteQuery(sql));
56  }
57 
58  [Test]
59  public void DropReferencedTable() {
60  const string sql = "DROP TABLE APP.test_table1";
61 
62  Assert.Throws<StatementException>(() => Query.ExecuteQuery(sql));
63  }
64 
65  [Test]
66  public void DropAllTables() {
67  const string sql = "DROP TABLE IF EXISTS APP.test_table1, test_table2";
68 
69  Assert.DoesNotThrow(() => Query.ExecuteQuery(sql));
70  }
71  }
72 }
Provides some helper functions for resolving and creating SqlType instances that are primitive to the...
Defines the metadata properties of a column within a table of a database.
Definition: ColumnInfo.cs:36
static ObjectName Parse(string s)
Parses the given string into a ObjectName object.
Definition: ObjectName.cs:139
Describes the name of an object within a database.
Definition: ObjectName.cs:44
ForeignKeyAction
Enumerates the foreign key referential trigger actions.
An isolated session to a given database for a given user, encapsulating the transaction for operation...
Definition: ISession.cs:30
Defines the metadata properties of a table existing within a database.
Definition: TableInfo.cs:41