DeveelDB  20151217
complete SQL database system, primarly developed for .NET/Mono frameworks
DeclareCursorStatementTests.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 using System.Linq;
17 
18 using Deveel.Data.Sql.Cursors;
19 using Deveel.Data.Sql.Tables;
20 using Deveel.Data.Types;
21 
22 using NUnit.Framework;
23 
24 namespace Deveel.Data.Sql.Statements {
25  [TestFixture]
27  protected override ISession CreateAdminSession(IDatabase database) {
28  using (var session = base.CreateAdminSession(database)) {
29  using (var query = session.CreateQuery()) {
30  var tableInfo = new TableInfo(ObjectName.Parse("APP.test_table"));
31  tableInfo.AddColumn("a", PrimitiveTypes.Integer());
32  tableInfo.AddColumn("b", PrimitiveTypes.String(), false);
33 
34  query.CreateTable(tableInfo, false, false);
35  query.Commit();
36  }
37  }
38 
39  return base.CreateAdminSession(database);
40  }
41 
42  [Test]
44  const string sql = "DECLARE CURSOR c1 INSENSITIVE IS SELECT * FROM test_table WHERE a = 1";
45 
46  var statements = SqlStatement.Parse(sql);
47  Assert.IsNotNull(statements);
48 
49  var statementList = statements.ToList();
50  Assert.IsNotEmpty(statementList);
51  Assert.AreEqual(1, statementList.Count);
52  Assert.IsInstanceOf<DeclareCursorStatement>(statementList[0]);
53 
54  var statement = (DeclareCursorStatement) statementList[0];
55  Assert.AreEqual("c1", statement.CursorName);
56  Assert.AreNotEqual(0, (statement.Flags & CursorFlags.Insensitive));
57  Assert.IsEmpty(statement.Parameters);
58  }
59 
60  [Test]
62  const string sql = "DECLARE CURSOR c1 (arg1 INT, arg2 VARCHAR) IS SELECT * FROM test_table WHERE a = arg1";
63 
64  var statements = SqlStatement.Parse(sql);
65  Assert.IsNotNull(statements);
66 
67  var statementList = statements.ToList();
68  Assert.IsNotEmpty(statementList);
69  Assert.AreEqual(1, statementList.Count);
70  Assert.IsInstanceOf<DeclareCursorStatement>(statementList[0]);
71 
72  var statement = (DeclareCursorStatement)statementList[0];
73  Assert.AreEqual("c1", statement.CursorName);
74  Assert.IsNotEmpty(statement.Parameters);
75 
76  var arg1 = statement.Parameters.First();
77  Assert.IsNotNull(arg1);
78  Assert.AreEqual("arg1", arg1.ParameterName);
79  Assert.IsInstanceOf<NumericType>(arg1.ParameterType);
80  Assert.AreEqual(0, arg1.Offset);
81  }
82  }
83 }
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
Describes the name of an object within a database.
Definition: ObjectName.cs:44
The representation of a single database in the system.
Definition: IDatabase.cs:40
Represents the foundation class of SQL statements to be executed.
Definition: SqlStatement.cs:32
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
An isolated session to a given database for a given user, encapsulating the transaction for operation...
Definition: ISession.cs:30
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.
Definition: TableInfo.cs:41