public void CanInsertRecordWithDate() { var fn = RandomFilename; var block = new Block(fn, 0); var sch = new Schema(); sch.AddDateField("field"); recordPage = new RecordPage(block, _tableInfo, _transaction, _fileManager); var canInsert = recordPage.Insert(); recordPage.SetDate("field", new DateTime(2020, 1, 1)); recordPage.Close(); _transaction.Commit(); var page = _fileManager.ResolvePage(block); page.Read(block); page.GetInt(0, out var isUsed); page.GetDate(4, out var value); Assert.IsTrue(canInsert); Assert.AreEqual(1, isUsed); Assert.AreEqual(new DateTime(2020, 1, 1), value); }
public void CanReadWrittenDateRecord() { var tableFile = RandomFilename; var schema = new Schema(); schema.AddDateField("field"); _tableInfo = new TableInfo(tableFile, schema); _recordFile = new RecordFile(_tableInfo, _transaction); _recordFile.MoveToRID(new RID(0, 0)); _recordFile.SetDate("field", new DateTime(2020, 1, 1)); _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.GetDate("field"); Assert.AreEqual(new DateTime(2020, 1, 1), value); }
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); }
public void CanFormatPageWithOneDateFieldInside() { _schema.AddDateField("field"); _tableInfo = new TableInfo(RandomFilename, _schema); _recordFormatter = new RecordFormatter(_tableInfo, _fileManager); var page = _fileManager.ResolvePage(); Assert.DoesNotThrow(() => { _recordFormatter.Format(page); }); }
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); }
public void CanAddDateField() { var schema = new Schema(); Assert.DoesNotThrow(() => { schema.AddDateField("field"); }); var fields = schema.Fields; var field = fields.First(); Assert.IsNotNull(fields); Assert.AreEqual(1, fields.Count); Assert.AreEqual(FieldType.Date, field.Value.Type); Assert.AreEqual("field", field.Key); }
public void CanCreateDateIndex() { var indexTableName = RandomFilename; var schema = new Schema(); schema.AddDateField("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(); }
public void CanWriteDateOnARecord() { var tableFile = RandomFilename; var schema = new Schema(); schema.AddDateField("field"); _tableInfo = new TableInfo(tableFile, schema); _recordFile = new RecordFile(_tableInfo, _transaction); _recordFile.MoveToRID(new RID(0, 0)); _recordFile.SetDate("field", new DateTime(2020, 1, 1)); _recordFile.Close(); _transaction.Commit(); var block = new IO.Primitives.Block(tableFile + ".tbl", 0); var page = _fileManager.ResolvePage(block); page.Read(block); _ = page.GetDate(4, out var value); Assert.AreEqual(new DateTime(2020, 1, 1), value); }
public void CanReadDateFromRecord() { var fn = RandomFilename; var block = new Block(fn, 0); var sch = new Schema(); sch.AddDateField("field"); var page = _fileManager.ResolvePage(block); page.Read(block); page.SetInt(0, 4); page.SetDate(4, new DateTime(2020, 1, 1)); page.Write(block); recordPage = new RecordPage(block, _tableInfo, _transaction, _fileManager); recordPage.MoveToId(0); var value = recordPage.GetDate("field"); Assert.AreEqual(new DateTime(2020, 1, 1), value); }