fix: handle db nulls

This commit is contained in:
Anna 2024-02-18 12:29:49 -05:00
parent b6fdf67368
commit ddbb06b170
Signed by: anna
GPG Key ID: D0943384CD9F87D1
2 changed files with 20 additions and 8 deletions

View File

@ -1,5 +1,6 @@
using ImGuiNET;
using Newtonsoft.Json;
using Screenie.Util;
namespace Screenie.Ui.Tabs;
@ -44,19 +45,19 @@ internal class DatabaseTab : ITab {
ActiveCharacter = JsonConvert.DeserializeObject<Character>(
reader.GetFieldValue<string>(2)
),
Location = reader.GetFieldValue<string?>(3),
LocationSub = reader.GetFieldValue<string?>(4),
Area = reader.GetFieldValue<string?>(5),
AreaSub = reader.GetFieldValue<string?>(6),
Location = reader.GetNullableFieldValue<string>(3),
LocationSub = reader.GetNullableFieldValue<string>(4),
Area = reader.GetNullableFieldValue<string>(5),
AreaSub = reader.GetNullableFieldValue<string>(6),
TerritoryType = (uint) reader.GetFieldValue<long>(7),
World = reader.GetFieldValue<string?>(8),
World = reader.GetNullableFieldValue<string>(8),
WorldId = (uint) reader.GetFieldValue<long>(9),
CapturedAtLocal = reader.GetFieldValue<DateTime>(10),
CapturedAtUtc = reader.GetFieldValue<DateTime>(11),
EorzeaTime = reader.GetFieldValue<string>(12),
Weather = reader.GetFieldValue<string?>(13),
Ward = (uint?) reader.GetFieldValue<long?>(14),
Plot = (uint?) reader.GetFieldValue<long?>(15),
Weather = reader.GetNullableFieldValue<string>(13),
Ward = (uint?) reader.GetNullableFieldValue<long>(14),
Plot = (uint?) reader.GetNullableFieldValue<long>(15),
VisibleCharacters = JsonConvert.DeserializeObject<Character[]>(
reader.GetFieldValue<string>(16)
) ?? [],

View File

@ -0,0 +1,11 @@
using System.Data.SQLite;
namespace Screenie.Util;
internal static class SQLiteDataReaderExt {
internal static T? GetNullableFieldValue<T>(this SQLiteDataReader reader, int index) {
return reader.IsDBNull(index)
? default
: reader.GetFieldValue<T>(index);
}
}