コード例 #1
0
ファイル: TableManagerTest.cs プロジェクト: pavitrarai/RDBMS
        private void TestDeleteRecordsOnIndex()
        {
            try
            {
                _logger.Message("Testing DeleteRecordsOnIndex");
                //making the table
                Column indexedColumn = new Column(Column.DataType.Int, "Int", 100);
                String indexPath     = GetFilePath.TableColumnIndex(dbName, tableName, indexedColumn.Name);

                List <Column> cols = new List <Column>();
                cols.Add(indexedColumn);
                cols.Add(new Column(Column.DataType.Double, "Double", 1));
                cols.Add(new Column(Column.DataType.Char, "String", 20));
                manager.CreateTable(dbName, tableName, cols);

                //making records to be inserted
                List <String> l1 = new List <string>();
                l1.Add("5");
                l1.Add("5.1");
                l1.Add("random1");
                Record r1 = new Record(l1);

                List <String> l2 = new List <string>();
                l2.Add("2048000");
                l2.Add("5.2");
                l2.Add("random2");
                Record r2 = new Record(l2);

                List <String> l3 = new List <string>();
                l3.Add("-409600");
                l3.Add("5.3");
                l3.Add("random3");
                Record r3 = new Record(l3);

                manager.InsertRecord(r1);
                manager.InsertRecord(r2);
                manager.InsertRecord(r3);

                manager.AddIndex(indexedColumn);

                List <Record> records = manager.SelectRecordsOnIndex(new Condition(indexedColumn, Condition.ConditionType.Equal, "5"));
                Assert.AreEqual(1, records.Count);
                AssertRecords(r1, records[0]);

                records = manager.SelectRecordsOnIndex(new Condition(indexedColumn, Condition.ConditionType.Less, "100"));
                Assert.AreEqual(2, records.Count);
                AssertRecords(r3, records[0]);
                AssertRecords(r1, records[1]);

                records = manager.SelectRecordsOnIndex(new Condition(indexedColumn, Condition.ConditionType.GreaterEqual, "5"));
                Assert.AreEqual(2, records.Count);
                AssertRecords(r1, records[0]);
                AssertRecords(r2, records[1]);

                Dictionary <int, Record> dict = new Dictionary <int, Record>();
                dict.Add(54, r2);
                dict.Add(12, r1);

                manager.DeleteRecordsFromIndices(dict);

                records = manager.SelectRecordsOnIndex(new Condition(indexedColumn, Condition.ConditionType.Less, "10"));
                Assert.AreEqual(1, records.Count);
                AssertRecords(r3, records[0]);
            }
            catch (Exception e)
            {
                _logger.Error(e.Message);
            }
            finally
            {
                manager.DropTable(dbName, tableName);
            }
        }