예제 #1
0
        public void CanInsertRecordWithByte()
        {
            var fn    = RandomFilename;
            var block = new Block(fn, 0);

            var sch = new Schema();

            sch.AddByteField("field");

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

            recordPage.SetByte("field", 20);
            recordPage.Close();
            _transaction.Commit();

            var page = _fileManager.ResolvePage(block);

            page.Read(block);

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

            Assert.IsTrue(canInsert);
            Assert.AreEqual(1, isUsed);
            Assert.AreEqual(20, value);
        }
예제 #2
0
        public void CanReadWrittenByteRecord()
        {
            var tableFile = RandomFilename;
            var schema    = new Schema();

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

            _recordFile = new RecordFile(_tableInfo, _transaction);
            _recordFile.MoveToRID(new RID(0, 0));
            _recordFile.SetByte("field", 10);
            _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.GetByte("field");

            Assert.AreEqual(10, value);
        }
예제 #3
0
파일: SchemaTests.cs 프로젝트: SaberMK/BiBi
        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);
        }
예제 #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);
        }
예제 #5
0
        public void CanFormatPageWithOneByteFieldInside()
        {
            _schema.AddByteField("field");

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

            var page = _fileManager.ResolvePage();

            Assert.DoesNotThrow(() =>
            {
                _recordFormatter.Format(page);
            });
        }
예제 #6
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);
        }
예제 #7
0
파일: SchemaTests.cs 프로젝트: SaberMK/BiBi
        public void CanAddByteField()
        {
            var schema = new Schema();

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

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

            Assert.IsNotNull(fields);
            Assert.AreEqual(1, fields.Count);
            Assert.AreEqual(FieldType.Byte, field.Value.Type);
            Assert.AreEqual("field", field.Key);
        }
예제 #8
0
        public void CanCreateByteIndex()
        {
            var indexTableName = RandomFilename;

            var schema = new Schema();

            schema.AddByteField("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();
        }
예제 #9
0
        public void CanReadByteFromRecord()
        {
            var fn    = RandomFilename;
            var block = new Block(fn, 0);

            var sch = new Schema();

            sch.AddByteField("field");

            var page = _fileManager.ResolvePage(block);

            page.Read(block);

            page.SetInt(0, 4);
            page.SetByte(4, 10);

            page.Write(block);

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

            Assert.AreEqual(10, value);
        }