DeveelDB  20151217
complete SQL database system, primarly developed for .NET/Mono frameworks
BlindSearchTests.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 
16 using System;
17 using System.Collections.Generic;
18 using System.Linq;
19 
20 using Deveel.Data;
21 using Deveel.Data.Sql;
22 using Deveel.Data.Sql.Tables;
23 using Deveel.Data.Types;
24 
25 using NUnit.Framework;
26 
27 namespace Deveel.Data.Index {
28  [TestFixture]
29  public sealed class BlindSearchTests {
30  private ITable table;
31 
32  private DateTimeOffset cornerTime;
33 
34  [SetUp]
35  public void TestSetUp() {
36  var tableName = ObjectName.Parse("APP.test_table");
37  var tableInfo = new TableInfo(tableName);
38  tableInfo.AddColumn("id", PrimitiveTypes.Numeric(), true);
39  tableInfo.AddColumn("name", PrimitiveTypes.String(SqlTypeCode.VarChar));
40  tableInfo.AddColumn("date", PrimitiveTypes.DateTime());
41 
42  cornerTime = DateTimeOffset.UtcNow;
43 
44  var tmpTable = new TemporaryTable(tableInfo);
45 
46  AddRow(tmpTable, 1, "test1", cornerTime);
47  AddRow(tmpTable, 2, "test2", cornerTime.AddSeconds(2));
48  AddRow(tmpTable, 3, "test3", cornerTime.AddSeconds(5));
49 
50  tmpTable.BuildIndexes(DefaultIndexTypes.BlindSearch);
51 
52  table = tmpTable;
53  }
54 
55  private void AddRow(TemporaryTable tmpTable, long id, string name, DateTimeOffset date) {
56  var row = new DataObject[3];
57  row[0] = DataObject.BigInt(id);
58  row[1] = DataObject.String(name);
59  row[2] = DataObject.Date(date);
60  tmpTable.NewRow(row);
61  }
62 
63  [Test]
64  public void SelectEqualOneColumn() {
65  var name = DataObject.String("test1");
66  var result = table.SelectRowsEqual(1, name);
67 
68  Assert.IsNotNull(result);
69  Assert.IsNotEmpty(result);
70 
71  var index = result.First();
72  Assert.AreEqual(0, index);
73  }
74 
75  [Test]
76  public void SelectEqualTwoColumns() {
77  var name = DataObject.String("test1");
78  var id = DataObject.BigInt(1);
79 
80  var result = table.SelectRowsEqual(1, name, 0, id);
81  Assert.IsNotNull(result);
82  Assert.IsNotEmpty(result);
83 
84  var index = result.First();
85  Assert.AreEqual(0, index);
86  }
87 
88  [Test]
89  public void SelectGreater() {
90  var id = DataObject.BigInt(1);
91 
92  var result = table.SelectRowsGreater(0, id);
93 
94  Assert.IsNotNull(result);
95  Assert.IsNotEmpty(result);
96  Assert.AreEqual(2, result.Count());
97 
98  Assert.AreEqual(1, result.First());
99  }
100  }
101 }
Provides some helper functions for resolving and creating SqlType instances that are primitive to the...
static DataObject Date(DateTimeOffset value)
Definition: DataObject.cs:600
Defines the contract to access the data contained into a table of a database.
Definition: ITable.cs:40
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 DataObject String(string s)
Definition: DataObject.cs:592
static NumericType Numeric()
Represents a dynamic object that encapsulates a defined SqlType and a compatible constant ISqlObject ...
Definition: DataObject.cs:35
SqlTypeCode
Enumerates the codes of all SQL types handled by the system.
Definition: SqlTypeCode.cs:23
static DataObject BigInt(long value)
Definition: DataObject.cs:580
Defines the metadata properties of a table existing within a database.
Definition: TableInfo.cs:41
void AddRow(TemporaryTable tmpTable, long id, string name, DateTimeOffset date)