Beispiel #1
0
        public void CreateIndex(string indexName, string tableName, string fieldName, Transaction transaction)
        {
            var recordFile = new RecordFile(_tableInfo, transaction);

            recordFile.Insert();
            recordFile.SetString("idxname", indexName);
            recordFile.SetString("tblname", tableName);
            recordFile.SetString("fldname", fieldName);
            recordFile.Close();
        }
Beispiel #2
0
        public void CreateView(string viewName, string viewDefinition, Transaction transaction)
        {
            var tableInfo  = _tableManager.GetTableInfo(_viewTableName, transaction);
            var recordFile = new RecordFile(tableInfo, transaction);

            recordFile.Insert();
            recordFile.SetString("viewname", viewName);
            recordFile.SetString("viewdef", viewDefinition);
            recordFile.Close();
        }
Beispiel #3
0
        public void CanReadWrittenStringRecord()
        {
            var tableFile = RandomFilename;
            var schema    = new Schema();

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

            _recordFile = new RecordFile(_tableInfo, _transaction);
            _recordFile.MoveToRID(new RID(0, 0));
            _recordFile.SetString("field", "huge string lol");
            _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.GetString("field");

            Assert.AreEqual("huge string lol", value);
        }
Beispiel #4
0
        public void CanGetStatisticsFromNewTableInTheSameTransaction()
        {
            manager = new StatisticsManager(tableManager, _transaction, tableCatalogName, fieldCatalogName, 1);


            var newTableName = RandomFilename;

            var schema = new Schema();

            schema.AddIntField("Id");
            schema.AddStringField("Guid", 40);

            var newTableInfo = new TableInfo(newTableName, schema);

            tableManager.CreateTable(newTableName, schema, _transaction);

            var recordFile = new RecordFile(newTableInfo, _transaction);

            recordFile.BeforeFirst();

            for (int i = 0; i < 50; ++i)
            {
                recordFile.Insert();
                recordFile.SetInt("Id", i + 10);
                recordFile.SetString("Guid", Guid.NewGuid().ToString());
            }

            var updatedData = manager.GetStatisticalInfo(newTableName, _transaction);

            Assert.AreEqual(50, updatedData.RecordsOutput);
            Assert.AreEqual(3, updatedData.BlocksAccessed);
            Assert.AreEqual(17, updatedData.DistinctValues("Id"));
        }
Beispiel #5
0
        public void CreateTable(string tableName, Schema schema, Transaction transaction)
        {
            var tableInfo = new TableInfo(tableName, schema);

            var tableCatalogFile = new RecordFile(_tableCatalogInfo, transaction);

            tableCatalogFile.Insert();
            tableCatalogFile.SetString("tblname", tableName);
            tableCatalogFile.SetInt("reclength", tableInfo.RecordLength);
            tableCatalogFile.Close();

            var fieldCatalogFile = new RecordFile(_fieldCatalogInfo, transaction);

            foreach (var fieldName in schema.Fields)
            {
                fieldCatalogFile.Insert();
                fieldCatalogFile.SetString("tblname", tableName);
                fieldCatalogFile.SetString("fldname", fieldName.Key);
                fieldCatalogFile.SetInt("type", (int)fieldName.Value.Type);
                fieldCatalogFile.SetInt("length", fieldName.Value.Length);
                fieldCatalogFile.SetInt("offset", tableInfo.Offset(fieldName.Key));
            }
            fieldCatalogFile.Close();
        }
Beispiel #6
0
        public void CanWriteStringOnARecord()
        {
            var tableFile = RandomFilename;
            var schema    = new Schema();

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

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

            _transaction.Commit();

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

            page.Read(block);

            _ = page.GetString(4, out var value);
            Assert.AreEqual("temporary", value);
        }
Beispiel #7
0
 public void SetString(string fieldName, string value)
 => _recordFile.SetString(fieldName, value);