Proper rework attributes, update functional

This commit is contained in:
Daniel_I_Am 2020-06-04 15:50:21 +02:00
parent c8f174d3e8
commit 8e53d012c1
No known key found for this signature in database
GPG Key ID: 80C428FCC9743E84

View File

@ -19,6 +19,8 @@ namespace ChaosBot.Attribute
if (dbEntityAssembly != null) if (dbEntityAssembly != null)
{ {
foreach (Type type in dbEntityAssembly.GetTypes()) foreach (Type type in dbEntityAssembly.GetTypes())
{
try
{ {
if (type.GetCustomAttributes(typeof(DBEntity), true).Length > 0) if (type.GetCustomAttributes(typeof(DBEntity), true).Length > 0)
{ {
@ -70,35 +72,33 @@ namespace ChaosBot.Attribute
Controller.RawQuery($"SELECT name FROM sqlite_master WHERE type='table' AND name='{table}'") Controller.RawQuery($"SELECT name FROM sqlite_master WHERE type='table' AND name='{table}'")
.Rows.Count > 0; .Rows.Count > 0;
try
{
if (!tableExists) if (!tableExists)
{ {
string columnDefs = String.Join(", ", columnList.Select(c => $"{c.Item1} {c.Item2} {c.Item4}")); string columnDefs = String.Join(", ", columnList.Select(c => $"{c.Item1} {c.Item2} {c.Item4}"));
string query = $"CREATE TABLE {table} ({columnDefs})"; string query = $"CREATE TABLE {table} ({columnDefs})";
Controller.RawQuery(query); Controller.RawQuery(query, false);
}
// // TODO: Generate this in one go instead of many separate commands
// Controller.RawQuery($"CREATE TABLE IF NOT EXISTS {table} (id INTEGER NOT NULL CONSTRAINT {table}_pk PRIMARY KEY AUTOINCREMENT)");
// Controller.RawQuery($"CREATE UNIQUE INDEX {table}_id_uindex ON {table} (id)", false, true);
// string query = $"ALTER TABLE {table} ADD COLUMN {fieldname} {fieldType} {fieldModifiers}";
}
catch (Exception ex)
{
if (ex is SqliteException sqliteException)
{
if (!sqliteException.Message.Contains("duplicate column name"))
{
_logger.Fatal(
$"AssemblyController.Register: Exception [{ex}] thrown, <[{ex.Message}]>.");
}
} }
else else
{ {
_logger.Error( foreach (Tuple<string,string,string,string> column in columnList)
$"AssemblyController.Register: Exception [{ex}] thrown, <[{ex.Message}]>."); {
} try
} {
string query =
$"ALTER TABLE {table} ADD COLUMN {column.Item1} {column.Item2} {column.Item4}";
Controller.RawQuery(query, false, true);
}
catch
{
// ignored
}
}
}
}
}
catch (Exception ex)
{
_logger.Error($"AssemblyController.Register: Exception [{ex}] thrown, <[{ex.Message}]>.");
} }
} }
} }