DeveelDB  20151217
complete SQL database system, primarly developed for .NET/Mono frameworks
OpenStatementTests.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 
19 
20 using NUnit.Framework;
21 
22 namespace Deveel.Data.Sql.Statements {
23  [TestFixture]
25  [Test]
27  const string sql = "OPEN c1";
28 
29  var statements = SqlStatement.Parse(sql);
30  Assert.IsNotNull(statements);
31 
32  var statementList = statements.ToList();
33  Assert.IsNotEmpty(statementList);
34  Assert.AreEqual(1, statementList.Count);
35  Assert.IsInstanceOf<OpenStatement>(statementList[0]);
36 
37  var statement = (OpenStatement) statementList[0];
38  Assert.AreEqual("c1", statement.CursorName);
39  Assert.IsEmpty(statement.Arguments);
40  }
41 
42  [Test]
43  public void OpenCursorWithArguments() {
44  const string sql = "OPEN c1(34, 'user')";
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<OpenStatement>(statementList[0]);
53 
54  var statement = (OpenStatement)statementList[0];
55  Assert.AreEqual("c1", statement.CursorName);
56  Assert.IsNotEmpty(statement.Arguments);
57 
58  var arg1 = statement.Arguments.First();
59  Assert.IsNotNull(arg1);
60  Assert.IsInstanceOf<SqlConstantExpression>(arg1);
61  }
62  }
63 }
Represents the foundation class of SQL statements to be executed.
Definition: SqlStatement.cs:32
An expression that holds a constant value.
static IEnumerable< SqlStatement > Parse(string sqlSource)
Parses a given string into one of more statements.