Beispiel #1
0
        public void CanInsertRecordWithBool()
        {
            var fn    = RandomFilename;
            var block = new Block(fn, 0);

            var sch = new Schema();

            sch.AddBoolField("field");

            recordPage = new RecordPage(block, _tableInfo, _transaction, _fileManager);
            var canInsert = recordPage.Insert();

            recordPage.SetBool("field", true);
            recordPage.Close();
            _transaction.Commit();

            var page = _fileManager.ResolvePage(block);

            page.Read(block);

            page.GetInt(0, out var isUsed);
            page.GetBool(4, out var value);

            Assert.IsTrue(canInsert);
            Assert.AreEqual(1, isUsed);
            Assert.AreEqual(true, value);
        }
Beispiel #2
0
        public void CanReadWrittenBoolRecord()
        {
            var tableFile = RandomFilename;
            var schema    = new Schema();

            schema.AddBoolField("field");
            _tableInfo = new TableInfo(tableFile, schema);

            _recordFile = new RecordFile(_tableInfo, _transaction);
            _recordFile.MoveToRID(new RID(0, 0));
            _recordFile.SetBool("field", true);
            _recordFile.Close();

            _transaction.Commit();

            var cm    = new ConcurrencyManager();
            var newTr = new Transaction(_dispatcher, _bufferManager, cm, _fileManager, _logManager);

            var rf = new RecordFile(_tableInfo, newTr);

            rf.MoveToRID(new RID(0, 0));
            var value = rf.GetBool("field");

            Assert.AreEqual(true, value);
        }
Beispiel #3
0
        public void CanAddAllFieldsFromSchema()
        {
            var schema    = new Schema();
            var newSchema = new Schema();

            Assert.DoesNotThrow(() =>
            {
                schema.AddBoolField("field1");
                schema.AddByteField("field2");

                newSchema.AddAll(schema);
            });

            var fields = newSchema.Fields;

            var field1 = fields.First();
            var field2 = fields.Last();

            Assert.IsNotNull(fields);
            Assert.AreEqual(2, fields.Count);
            Assert.AreEqual(FieldType.Bool, field1.Value.Type);
            Assert.AreEqual("field1", field1.Key);
            Assert.AreEqual(FieldType.Byte, field2.Value.Type);
            Assert.AreEqual("field2", field2.Key);
        }
Beispiel #4
0
        private Schema CreateSchema()
        {
            var schema = new Schema();

            schema.AddIntField("blk");
            schema.AddIntField("id");

            // TODO for all types
            var indexType = _tableInfo.Schema.FieldType(_fieldName);

            switch (indexType)
            {
            case FieldType.Bool:
                // lol dude why u want BTree on bool??? Are you insane?

                schema.AddBoolField("val");
                break;


            case FieldType.Byte:

                schema.AddByteField("val");
                break;


            case FieldType.Integer:

                schema.AddIntField("val");
                break;


            case FieldType.Date:

                schema.AddDateField("val");
                break;


            case FieldType.Blob:

                var blobFieldLength = _tableInfo.Schema.Length(_fieldName);
                schema.AddBlobField("val", blobFieldLength);
                break;


            case FieldType.String:

                var stringFieldLength = _tableInfo.Schema.Length(_fieldName);
                schema.AddStringField("val", stringFieldLength);
                break;
            }

            return(schema);
        }
Beispiel #5
0
        public void CanCheckFieldType()
        {
            var schema = new Schema();

            Assert.DoesNotThrow(() =>
            {
                schema.AddBoolField("field");
            });

            var type = schema.FieldType("field");

            Assert.AreEqual(FieldType.Bool, type);
        }
Beispiel #6
0
        public void CanFormatPageWithOneBoolFieldInside()
        {
            _schema.AddBoolField("field");

            _tableInfo       = new TableInfo(RandomFilename, _schema);
            _recordFormatter = new RecordFormatter(_tableInfo, _fileManager);

            var page = _fileManager.ResolvePage();

            Assert.DoesNotThrow(() =>
            {
                _recordFormatter.Format(page);
            });
        }
Beispiel #7
0
        public void CanCheckWhichFieldsArePresented()
        {
            var schema = new Schema();

            Assert.DoesNotThrow(() =>
            {
                schema.AddBoolField("field");
            });

            bool hasField = schema.HasField("field");
            bool noField  = schema.HasField("random name");

            Assert.IsTrue(hasField);
            Assert.IsFalse(noField);
        }
Beispiel #8
0
        public void CanCreateCompleteRecord()
        {
            var schema = new Schema();

            schema.AddIntField("field1");
            schema.AddBoolField("field2");
            schema.AddByteField("field3");
            schema.AddBlobField("field4", 10);
            schema.AddStringField("field5", 10);
            schema.AddDateField("field6");

            var tableInfo = new TableInfo("table", schema);

            Assert.AreEqual(42, tableInfo.RecordLength);
        }
Beispiel #9
0
        public void CanAddBoolField()
        {
            var schema = new Schema();

            Assert.DoesNotThrow(() =>
            {
                schema.AddBoolField("field");
            });

            var fields = schema.Fields;
            var field  = fields.First();

            Assert.IsNotNull(fields);
            Assert.AreEqual(1, fields.Count);
            Assert.AreEqual(FieldType.Bool, field.Value.Type);
            Assert.AreEqual("field", field.Key);
        }
Beispiel #10
0
        public void CanCreateBoolIndex()
        {
            var indexTableName = RandomFilename;

            var schema = new Schema();

            schema.AddBoolField("Field");

            tableInfo = new TableInfo(indexTableName, schema);
            tableManager.CreateTable(indexTableName, schema, _transaction);


            indexInfo = new IndexInfo("index", indexTableName, "Field", tableManager, statisticsManager, _transaction, 1024);

            // Todo check them out
            var indexSchema = indexInfo.Open();

            Assert.Pass();
        }
Beispiel #11
0
        public void CanWriteBoolOnARecord()
        {
            var tableFile = RandomFilename;
            var schema    = new Schema();

            schema.AddBoolField("field");
            _tableInfo = new TableInfo(tableFile, schema);

            _recordFile = new RecordFile(_tableInfo, _transaction);
            _recordFile.MoveToRID(new RID(0, 0));
            _recordFile.SetBool("field", true);
            _recordFile.Close();

            _transaction.Commit();

            var block = new IO.Primitives.Block(tableFile + ".tbl", 0);
            var page  = _fileManager.ResolvePage(block);

            page.Read(block);


            _ = page.GetBool(4, out var value);
            Assert.AreEqual(true, value);
        }
Beispiel #12
0
        public void CanReadBoolFromRecord()
        {
            var fn    = RandomFilename;
            var block = new Block(fn, 0);

            var sch = new Schema();

            sch.AddBoolField("field");

            var page = _fileManager.ResolvePage(block);

            page.Read(block);

            page.SetInt(0, 4);
            page.SetBool(4, true);

            page.Write(block);

            recordPage = new RecordPage(block, _tableInfo, _transaction, _fileManager);
            recordPage.MoveToId(0);
            var value = recordPage.GetBool("field");

            Assert.AreEqual(true, value);
        }