Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Big btrieve update #256

Merged
merged 17 commits into from
Nov 6, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions MBBSDatabase/MBBSDatabase.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp3.1</TargetFramework>
<LangVersion>8.0</LangVersion>
</PropertyGroup>

<ItemGroup>
<None Remove="MBBSDatabase.pdb" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\MBBSEmu\MBBSEmu.csproj" />
</ItemGroup>
</Project>
53 changes: 53 additions & 0 deletions MBBSDatabase/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
using MBBSEmu.Btrieve;
using MBBSEmu.DependencyInjection;
using NLog;
using System.Linq;
using System.IO;
using System;

namespace MBBSEmu
{
/// <summary>
/// An MBBSEmu database (.DB) utility program.
///
/// </para/>Currently supports two modes of operation, view and convert.
/// View mode shows information about the specified DAT file, such as key information.
/// Convert mode converts the DAT file into a .DB file.
/// </summary>
public class Program
{
static void Main(string[] args)
{
new Program().Run(args);
}

private void Run(string[] args)
{
var serviceResolver = new ServiceResolver();
var logger = serviceResolver.GetService<ILogger>();

if (args.Length == 0)
Console.WriteLine("Usage: MBBSDatabase [view|convert] [files]");

var convert = (args[0] == "convert");

foreach (string s in args.Skip(1))
{
BtrieveFile file = new BtrieveFile();
try
{
file.LoadFile(logger, s);
if (convert)
{
using var processor = new BtrieveFileProcessor();
processor.CreateSqliteDB(Path.ChangeExtension(s, ".DB"), file);
}
}
catch (Exception e)
{
logger.Error(e, $"Failed to load Btrieve file {s}: {e.Message}\n{e.StackTrace}");
}
}
}
}
}
Binary file modified MBBSEmu.Tests/Assets/MBBSEMU.DB
Binary file not shown.
12 changes: 7 additions & 5 deletions MBBSEmu.Tests/Btrieve/BtrieveFileProcessor_Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public class BtrieveFileProcessor_Tests : TestBase, IDisposable
{
const int RECORD_LENGTH = 74;

private const string EXPECTED_METADATA_T_SQL = "CREATE TABLE metadata_t(record_length INTEGER NOT NULL, physical_record_length INTEGER NOT NULL, page_length INTEGER NOT NULL)";
private const string EXPECTED_METADATA_T_SQL = "CREATE TABLE metadata_t(record_length INTEGER NOT NULL, physical_record_length INTEGER NOT NULL, page_length INTEGER NOT NULL, variable_length_records INTEGER NOT NULL)";
private const string EXPECTED_KEYS_T_SQL = "CREATE TABLE keys_t(id INTEGER PRIMARY KEY, number INTEGER NOT NULL, segment INTEGER NOT NULL, attributes INTEGER NOT NULL, data_type INTEGER NOT NULL, offset INTEGER NOT NULL, length INTEGER NOT NULL, null_value INTEGER NOT NULL, UNIQUE(number, segment))";
private const string EXPECTED_DATA_T_SQL = "CREATE TABLE data_t(id INTEGER PRIMARY KEY, data BLOB NOT NULL, key_0 TEXT, key_1 INTEGER NOT NULL UNIQUE, key_2 TEXT, key_3 INTEGER NOT NULL UNIQUE)";

Expand Down Expand Up @@ -99,6 +99,7 @@ public void LoadsFileAndConvertsProperly()
btrieve.Keys.Count.Should().Be(4);
btrieve.RecordLength.Should().Be(RECORD_LENGTH);
btrieve.PageLength.Should().Be(512);
btrieve.VariableLengthRecords.Should().BeFalse();

btrieve.Keys[0].PrimarySegment.Should().BeEquivalentTo(
new BtrieveKeyDefinition()
Expand Down Expand Up @@ -179,12 +180,13 @@ public void LoadsFileProperly()
btrieve.Keys.Count.Should().Be(4);
btrieve.RecordLength.Should().Be(RECORD_LENGTH);
btrieve.PageLength.Should().Be(512);
btrieve.VariableLengthRecords.Should().BeFalse();

btrieve.Keys[0].PrimarySegment.Should().BeEquivalentTo(
new BtrieveKeyDefinition()
{
Number = 0,
Attributes = EnumKeyAttributeMask.Duplicates,
Attributes = EnumKeyAttributeMask.Duplicates | EnumKeyAttributeMask.UseExtendedDataType,
DataType = EnumKeyDataType.Zstring,
Offset = 2,
Length = 32,
Expand All @@ -194,7 +196,7 @@ public void LoadsFileProperly()
new BtrieveKeyDefinition()
{
Number = 1,
Attributes = EnumKeyAttributeMask.Modifiable,
Attributes = EnumKeyAttributeMask.Modifiable | EnumKeyAttributeMask.UseExtendedDataType,
DataType = EnumKeyDataType.Integer,
Offset = 34,
Length = 4,
Expand All @@ -204,7 +206,7 @@ public void LoadsFileProperly()
new BtrieveKeyDefinition()
{
Number = 2,
Attributes = EnumKeyAttributeMask.Duplicates | EnumKeyAttributeMask.Modifiable,
Attributes = EnumKeyAttributeMask.Duplicates | EnumKeyAttributeMask.Modifiable | EnumKeyAttributeMask.UseExtendedDataType,
DataType = EnumKeyDataType.Zstring,
Offset = 38,
Length = 32,
Expand All @@ -214,7 +216,7 @@ public void LoadsFileProperly()
new BtrieveKeyDefinition()
{
Number = 3,
Attributes = 0,
Attributes = EnumKeyAttributeMask.UseExtendedDataType,
DataType = EnumKeyDataType.AutoInc,
Offset = 70,
Length = 4,
Expand Down
1 change: 1 addition & 0 deletions MBBSEmu.Tests/Btrieve/BtrieveFile_Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ public void LoadsFile()
Assert.Equal(512, btrieve.PageLength);
Assert.Equal(5, btrieve.PageCount);
Assert.False(btrieve.LogKeyPresent);
Assert.False(btrieve.VariableLengthRecords);

Assert.Single(btrieve.Keys[0].Segments);
Assert.Single(btrieve.Keys[1].Segments);
Expand Down
Binary file modified MBBSEmu/Assets/BBSGEN.DB
Binary file not shown.
Binary file modified MBBSEmu/Assets/BBSUSR.DB
Binary file not shown.
15 changes: 9 additions & 6 deletions MBBSEmu/Assets/bbsgen.db.sql
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
CREATE TABLE metadata_t(record_length INTEGER NOT NULL, physical_record_length INTEGER NOT NULL, page_length INTEGER NOT NULL);
CREATE TABLE metadata_t(record_length INTEGER NOT NULL, physical_record_length INTEGER NOT NULL, page_length INTEGER NOT NULL, variable_length_records INTEGER NOT NULL);

INSERT INTO metadata_t(record_length, physical_record_length, page_length) VALUES(55, 55, 1024);
INSERT INTO metadata_t(record_length, physical_record_length, page_length, variable_length_records) VALUES(55, 75, 1024, 1);

CREATE TABLE keys_t(id INTEGER PRIMARY KEY, number INTEGER NOT NULL, segment INTEGER NOT NULL, attributes INTEGER NOT NULL, data_type INTEGER NOT NULL, offset INTEGER NOT NULL, length INTEGER NOT NULL, UNIQUE (number, segment));
CREATE TABLE keys_t(id INTEGER PRIMARY KEY, number INTEGER NOT NULL, segment INTEGER NOT NULL, attributes INTEGER NOT NULL, data_type INTEGER NOT NULL, offset INTEGER NOT NULL, length INTEGER NOT NULL, null_value INTEGER NOT NULL, UNIQUE (number, segment));

INSERT INTO keys_t(number, segment, attributes, data_type, offset, length) VALUES(0, 0, 51, 11, 0, 30);
INSERT INTO keys_t(number, segment, attributes, data_type, offset, length) VALUES(0, 1, 35, 11, 30, 25);
INSERT INTO keys_t(number, segment, attributes, data_type, offset, length, null_value) VALUES(0, 0, 307, 11, 0, 30, 0);
INSERT INTO keys_t(number, segment, attributes, data_type, offset, length, null_value) VALUES(0, 1, 291, 11, 30, 25, 0);

INSERT INTO keys_t(number, segment, attributes, data_type, offset, length) VALUES(1, 0, 35, 11, 30, 25);
INSERT INTO keys_t(number, segment, attributes, data_type, offset, length, null_value) VALUES(1, 0, 291, 11, 30, 25, 0);

CREATE TABLE data_t(id INTEGER PRIMARY KEY, data BLOB NOT NULL, key_0 STRING NOT NULL, key_1 STRING NOT NULL);

CREATE INDEX key_0_index on data_t(key_0);
CREATE INDEX key_1_index on data_t(key_1);
10 changes: 6 additions & 4 deletions MBBSEmu/Assets/bbsusr.db.sql
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
CREATE TABLE metadata_t(record_length INTEGER NOT NULL, physical_record_length INTEGER NOT NULL, page_length INTEGER NOT NULL);
CREATE TABLE metadata_t(record_length INTEGER NOT NULL, physical_record_length INTEGER NOT NULL, page_length INTEGER NOT NULL, variable_length_records INTEGER NOT NULL);

INSERT INTO metadata_t(record_length, physical_record_length, page_length) VALUES(338, 338, 1024);
INSERT INTO metadata_t(record_length, physical_record_length, page_length, variable_length_records) VALUES(338, 338, 1024, 0);

CREATE TABLE keys_t(id INTEGER PRIMARY KEY, number INTEGER NOT NULL, segment INTEGER NOT NULL, attributes INTEGER NOT NULL, data_type INTEGER NOT NULL, offset INTEGER NOT NULL, length INTEGER NOT NULL, UNIQUE (number, segment));
CREATE TABLE keys_t(id INTEGER PRIMARY KEY, number INTEGER NOT NULL, segment INTEGER NOT NULL, attributes INTEGER NOT NULL, data_type INTEGER NOT NULL, offset INTEGER NOT NULL, length INTEGER NOT NULL, null_value INTEGER NOT NULL, UNIQUE (number, segment));

INSERT INTO keys_t(number, segment, attributes, data_type, offset, length) VALUES(0, 0, 0, 11, 0, 30);
INSERT INTO keys_t(number, segment, attributes, data_type, offset, length, null_value) VALUES(0, 0, 288, 11, 0, 30, 0);

CREATE TABLE data_t(id INTEGER PRIMARY KEY, data BLOB NOT NULL, key_0 STRING NOT NULL);

CREATE INDEX key_0_index on data_t(key_0);
Loading