Example #1
0
        public void CanCreateViewDefinition()
        {
            var viewMetadataStorageFilename = RandomFilename;

            viewManager = new ViewManager(true, tableManager, _transaction, viewMetadataStorageFilename);

            viewManager.CreateView("view1", "viewDefinition1", _transaction);

            _transaction.Commit();

            var schema = new Schema();

            schema.AddStringField("viewname", ViewManager.MAX_VIEW_LENGTH);
            schema.AddStringField("viewdef", ViewManager.MAX_VIEW_LENGTH);

            var viewTableInfo = tableManager.GetTableInfo(viewMetadataStorageFilename, _transaction);
            var viewTableCatalogRecordPage = new RecordFile(viewTableInfo, _transaction);

            viewTableCatalogRecordPage.BeforeFirst();
            viewTableCatalogRecordPage.Next();

            var viewName       = viewTableCatalogRecordPage.GetString("viewname");
            var viewDefinition = viewTableCatalogRecordPage.GetString("viewdef");

            Assert.AreEqual("view1", viewName);
            Assert.AreEqual("viewDefinition1", viewDefinition);
        }
Example #2
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);
        }
Example #3
0
        public string GetViewDefinition(string viewName, Transaction transaction)
        {
            var result     = string.Empty;
            var tableInfo  = _tableManager.GetTableInfo(_viewTableName, transaction);
            var recordFile = new RecordFile(tableInfo, transaction);

            while (recordFile.Next())
            {
                if (recordFile.GetString("viewname") == viewName)
                {
                    result = recordFile.GetString("viewdef");
                    break;
                }
            }

            recordFile.Close();
            return(result);
        }
Example #4
0
        public TableInfo GetTableInfo(string tableName, Transaction transaction)
        {
            var tableCatalogFile = new RecordFile(_tableCatalogInfo, transaction);
            var recordLength     = -1;

            while (tableCatalogFile.Next())
            {
                if (tableCatalogFile.GetString("tblname") == tableName)
                {
                    recordLength = tableCatalogFile.GetInt("reclength");
                    break;
                }
            }
            tableCatalogFile.Close();

            if (recordLength == -1)
            {
                return(null);
            }

            var fieldCatalogFile = new RecordFile(_fieldCatalogInfo, transaction);
            var schema           = new Schema();
            var offsets          = new Dictionary <string, int>();

            while (fieldCatalogFile.Next())
            {
                if (fieldCatalogFile.GetString("tblname") == tableName)
                {
                    var fieldName   = fieldCatalogFile.GetString("fldname");
                    int fieldType   = fieldCatalogFile.GetInt("type");
                    int fieldLength = fieldCatalogFile.GetInt("length");
                    int offset      = fieldCatalogFile.GetInt("offset");
                    offsets.Add(fieldName, offset);
                    schema.AddField(fieldName, (FieldType)fieldType, fieldLength);
                }
            }
            fieldCatalogFile.Close();

            return(new TableInfo(tableName, schema, offsets, recordLength));
        }
Example #5
0
        public Dictionary <string, IndexInfo> GetIndexInfo(string tableName, Transaction transaction)
        {
            var result     = new Dictionary <string, IndexInfo>();
            var recordFile = new RecordFile(_tableInfo, transaction);

            while (recordFile.Next())
            {
                if (recordFile.GetString("tblname") == tableName)
                {
                    var indexName = recordFile.GetString("idxname");
                    var fieldName = recordFile.GetString("fldname");

                    var indexInfo = new IndexInfo(indexName, tableName, fieldName, _tableManager, _statisticsManager, transaction, _blockSize);

                    result.Add(fieldName, indexInfo);
                }
            }

            recordFile.Close();

            return(result);
        }
Example #6
0
        private void RefreshStatistics(Transaction transaction)
        {
            _tableStats.Clear();

            _callsNumber = 0;

            var tableCatalogInfo = _tableManager.GetTableInfo(_tableCatalogName, transaction);

            var recordFile = new RecordFile(tableCatalogInfo, transaction);

            while (recordFile.Next())
            {
                var tableName = recordFile.GetString("tblname");
                _ = RefreshTableStatistics(tableName, transaction);
            }
        }
Example #7
0
        public void CanCreateTable()
        {
            var tableMetadataStorageFilename = RandomFilename;
            var fieldMetadataStorageFilename = RandomFilename;

            tableManager = new TableManager(true, _transaction, tableMetadataStorageFilename, fieldMetadataStorageFilename);
            var schema = new Schema();

            schema.AddIntField("field1");
            schema.AddBlobField("field2", 40);

            tableManager.CreateTable("table1", schema, _transaction);

            _transaction.Commit();

            _concurrencyManager = new ConcurrencyManager();
            _transaction        = new Transaction(_dispatcher, _bufferManager, _concurrencyManager, _fileManager, _logManager);

            var tableCatalogSchema = new Schema();

            tableCatalogSchema.AddStringField("tblname", TableManager.MAX_NAME_LENGTH);
            tableCatalogSchema.AddIntField("reclength");

            var tableCatalogInfo       = new TableInfo(tableMetadataStorageFilename, tableCatalogSchema);
            var tableCatalogRecordPage = new RecordFile(tableCatalogInfo, _transaction);

            tableCatalogRecordPage.BeforeFirst();
            tableCatalogRecordPage.Next();

            // skip all tables definition and all fields definition tables
            tableCatalogRecordPage.Next();
            tableCatalogRecordPage.Next();

            var tableName    = tableCatalogRecordPage.GetString("tblname");
            var recordLength = tableCatalogRecordPage.GetInt("reclength");

            Assert.AreEqual("table1", tableName);
            Assert.AreEqual(new TableInfo("table1", schema).RecordLength, recordLength);

            var fieldCatalogSchema = new Schema();

            fieldCatalogSchema.AddStringField("tblname", TableManager.MAX_NAME_LENGTH);
            fieldCatalogSchema.AddStringField("fldname", TableManager.MAX_NAME_LENGTH);
            fieldCatalogSchema.AddIntField("type");
            fieldCatalogSchema.AddIntField("length");
            fieldCatalogSchema.AddIntField("offset");
            var fieldCatalogInfo       = new TableInfo(fieldMetadataStorageFilename, fieldCatalogSchema);
            var fieldCatalogRecordPage = new RecordFile(fieldCatalogInfo, _transaction);

            fieldCatalogRecordPage.BeforeFirst();
            fieldCatalogRecordPage.Next();

            // 2 field for table metadata table, 5 fields for field metadata table
            fieldCatalogRecordPage.Next();
            fieldCatalogRecordPage.Next();
            fieldCatalogRecordPage.Next();
            fieldCatalogRecordPage.Next();
            fieldCatalogRecordPage.Next();
            fieldCatalogRecordPage.Next();
            fieldCatalogRecordPage.Next();

            var field1Table  = fieldCatalogRecordPage.GetString("tblname");
            var field1Name   = fieldCatalogRecordPage.GetString("fldname");
            var field1Type   = fieldCatalogRecordPage.GetInt("type");
            var field1Length = fieldCatalogRecordPage.GetInt("length");
            var field1Offset = fieldCatalogRecordPage.GetInt("offset");

            Assert.AreEqual("table1", field1Table);
            Assert.AreEqual("field1", field1Name);
            Assert.AreEqual(2, field1Type);
            Assert.AreEqual(sizeof(int), field1Length);
            Assert.AreEqual(0, field1Offset);

            fieldCatalogRecordPage.Next();

            var field2Table  = fieldCatalogRecordPage.GetString("tblname");
            var field2Name   = fieldCatalogRecordPage.GetString("fldname");
            var field2Type   = fieldCatalogRecordPage.GetInt("type");
            var field2Length = fieldCatalogRecordPage.GetInt("length");
            var field2Offset = fieldCatalogRecordPage.GetInt("offset");

            Assert.AreEqual("table1", field2Table);
            Assert.AreEqual("field2", field2Name);
            Assert.AreEqual(4, field2Type);
            Assert.AreEqual(40, field2Length);
            Assert.AreEqual(4, field2Offset);
        }
Example #8
0
 public string GetString(string fieldName)
 => _recordFile.GetString(fieldName);