Skip to content
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
15 changes: 15 additions & 0 deletions DBCD.Tests/WritingTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,21 @@
Assert.AreEqual(116146, outputStorage.Count);
}

[TestMethod]
public void TestWritingNewRowDb2WithArrayOfStringsField()
{
DBCD dbcd = new(wagoDBCProvider, githubDBDProvider);
IDBCDStorage storage = dbcd.Load("BattlePetEffectProperties", "9.2.7.45745");

storage.Add(10, storage.ConstructRow(10));
storage.Save(Path.Join(OutputPath, "BattlePetEffectProperties.db2"));

DBCD localDbcd = new(new FilesystemDBCProvider(OutputPath), githubDBDProvider);
IDBCDStorage outputStorage = localDbcd.Load("BattlePetEffectProperties", "9.2.7.45745");

Assert.AreEqual(134, outputStorage.Count);
}

[TestMethod]
public void TestSavingSameStorageTwice()
{
Expand All @@ -80,7 +95,7 @@
{
return; // Only run this test manually

var localDBDProvider = new FilesystemDBDProvider("D:\\Projects\\WoWDBDefs\\definitions");

Check warning on line 98 in DBCD.Tests/WritingTest.cs

View workflow job for this annotation

GitHub Actions / tests

Unreachable code detected

//var build = "3.3.5.12340"; // WDBC
//var build = "6.0.1.18179"; // WDB2
Expand Down Expand Up @@ -139,7 +154,7 @@
originalValues.AddRange(originalStorage.Values);
originalStorage.Save($"tmp/{tableName}.db2");
}
catch (FileNotFoundException e)

Check warning on line 157 in DBCD.Tests/WritingTest.cs

View workflow job for this annotation

GitHub Actions / tests

The variable 'e' is declared but never used
{
// This is not a reading test, I could not care less
attemptedTables--;
Expand Down
13 changes: 11 additions & 2 deletions DBCD/DBCDStorage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -204,10 +204,19 @@ public DBCDRow ConstructRow(int index)
foreach (var arrayField in arrayFields)
{
var count = arrayField.GetCustomAttribute<CardinalityAttribute>().Count;
Array rowRecords = Array.CreateInstance(arrayField.FieldType.GetElementType(), count);
var elementType = arrayField.FieldType.GetElementType();
var isStringField = elementType == typeof(string);

Array rowRecords = Array.CreateInstance(elementType, count);
for (var i = 0; i < count; i++)
{
rowRecords.SetValue(Activator.CreateInstance(arrayField.FieldType.GetElementType()), i);
if (isStringField)
{
rowRecords.SetValue(string.Empty, i);
} else
{
rowRecords.SetValue(Activator.CreateInstance(elementType), i);
}
}
arrayField.SetValue(raw, rowRecords);
}
Expand Down
Loading