DeveelDB  20151217
complete SQL database system, primarly developed for .NET/Mono frameworks
InsertTests.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 
18 using Deveel.Data.Sql.Tables;
19 using Deveel.Data.Types;
20 
21 using NUnit.Framework;
22 
23 namespace Deveel.Data.Sql {
24  [TestFixture]
25  public class InsertTests : ContextBasedTest {
26  protected override ISession CreateAdminSession(IDatabase database) {
27  using (var session = base.CreateAdminSession(database)) {
28  using (var query = session.CreateQuery()) {
29  var tableInfo = new TableInfo(ObjectName.Parse("APP.people"));
30  tableInfo.AddColumn("id", PrimitiveTypes.BigInt());
31  tableInfo.AddColumn("first_name", PrimitiveTypes.String(), true);
32  tableInfo.AddColumn("last_name", PrimitiveTypes.String());
33  tableInfo.AddColumn("age", PrimitiveTypes.TinyInt());
34 
35  query.CreateTable(tableInfo);
36  query.Commit();
37  }
38  }
39 
40  return base.CreateAdminSession(database);
41  }
42 
43  [Test]
44  public void InsertRegular() {
45  var tableName = ObjectName.Parse("APP.people");
46  var assignments = new SqlAssignExpression[] {
49  SqlExpression.Assign(SqlExpression.Reference(new ObjectName(tableName, "first_name")),
50  SqlExpression.Constant("Antonello")),
51  SqlExpression.Assign(SqlExpression.Reference(new ObjectName(tableName, "last_name")),
52  SqlExpression.Constant("Provenzano"))
53  };
54 
55  Query.InsertIntoTable(tableName, assignments);
56  }
57  }
58 }
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
static SqlAssignExpression Assign(SqlExpression reference, SqlExpression valueExpression)
The representation of a single database in the system.
Definition: IDatabase.cs:40
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
override ISession CreateAdminSession(IDatabase database)
Definition: InsertTests.cs:26
An isolated session to a given database for a given user, encapsulating the transaction for operation...
Definition: ISession.cs:30
static NumericType TinyInt(int size)
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