Ejemplo n.º 1
0
        public void SetValue(string fieldName, Constant value)
        {
            var type = _schema.FieldType(fieldName);

            switch (type)
            {
            case FieldType.Bool:
                _recordFile.SetBool(fieldName, (value as Constant <bool>).Value);
                return;

            case FieldType.Byte:
                _recordFile.SetByte(fieldName, (value as Constant <byte>).Value);
                return;

            case FieldType.Integer:
                _recordFile.SetInt(fieldName, (value as Constant <int>).Value);
                return;

            case FieldType.Blob:
                _recordFile.SetBlob(fieldName, (value as Constant <byte[]>).Value);
                return;

            case FieldType.Date:
                _recordFile.SetDate(fieldName, (value as Constant <DateTime>).Value);
                return;
            }
        }
Ejemplo n.º 2
0
        public void CanReadWrittenBlobRecord()
        {
            var tableFile = RandomFilename;
            var schema    = new Schema();

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

            _recordFile = new RecordFile(_tableInfo, _transaction);
            _recordFile.MoveToRID(new RID(0, 0));
            _recordFile.SetBlob("field", new byte[] { 1, 2, 3, 4, 5 });
            _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.GetBlob("field");

            Assert.AreEqual(new byte[] { 1, 2, 3, 4, 5 }, value);
        }
Ejemplo n.º 3
0
        public void CanWriteBlobOnARecord()
        {
            var tableFile = RandomFilename;
            var schema    = new Schema();

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

            _recordFile = new RecordFile(_tableInfo, _transaction);
            _recordFile.MoveToRID(new RID(0, 0));
            _recordFile.SetBlob("field", new byte[] { 10, 20 });
            _recordFile.Close();

            _transaction.Commit();

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

            page.Read(block);


            _ = page.GetBlob(4, out var value);
            Assert.AreEqual(new byte[] { 10, 20 }, value);
        }