|
@@ -1423,14 +1423,16 @@ public class SQLiteProvider : IProvider
|
|
|
return _result;
|
|
|
}
|
|
|
|
|
|
- public bool TableExists<T>()
|
|
|
+ public bool TableExists<T>() => TableExists(typeof(T));
|
|
|
+
|
|
|
+ public bool TableExists(Type t)
|
|
|
{
|
|
|
bool _result = false;
|
|
|
using (var access = GetReadAccess())
|
|
|
{
|
|
|
using (var _check = access.CreateCommand())
|
|
|
{
|
|
|
- _check.CommandText = $"select name from sqlite_master where type='table' and name='{typeof(T).Name.Split('.').Last()}';";
|
|
|
+ _check.CommandText = $"select name from sqlite_master where type='table' and name='{t.Name.Split('.').Last()}';";
|
|
|
using (var _reader = _check.ExecuteReader())
|
|
|
{
|
|
|
_result = _reader.HasRows;
|
|
@@ -1440,15 +1442,18 @@ public class SQLiteProvider : IProvider
|
|
|
}
|
|
|
return _result;
|
|
|
}
|
|
|
-
|
|
|
- public CoreTable? GetTable<T>()
|
|
|
+
|
|
|
+ public CoreTable? GetTable<T>() => GetTable(typeof(T));
|
|
|
+
|
|
|
+ public CoreTable? GetTable(Type t)
|
|
|
{
|
|
|
- var _tablename = typeof(T).Name.Split('.').Last();
|
|
|
- if (!TableExists<T>())
|
|
|
+ if (!TableExists(t))
|
|
|
return null;
|
|
|
-
|
|
|
+
|
|
|
+ var _tablename = t.Name.Split('.').Last();
|
|
|
+
|
|
|
CoreTable? _result = null;
|
|
|
- var props = CoreUtils.PropertyInfoList(typeof(T), p => true, true);
|
|
|
+ var props = CoreUtils.PropertyInfoList(t, p => true, true);
|
|
|
try
|
|
|
{
|
|
|
using (var access = GetReadAccess())
|
|
@@ -1487,15 +1492,18 @@ public class SQLiteProvider : IProvider
|
|
|
Logger.Send(LogType.Error,"",$"Exception in GetTable: {_tablename}\nMessage: {e.Message}\nStackTrace: {e.StackTrace}");
|
|
|
}
|
|
|
return _result;
|
|
|
+
|
|
|
}
|
|
|
-
|
|
|
- public void DropTable<T>()
|
|
|
+
|
|
|
+ public void DropTable<T>() => DropTable(typeof(T));
|
|
|
+
|
|
|
+ public void DropTable(Type t)
|
|
|
{
|
|
|
- if (typeof(T).IsSubclassOf(typeof(Entity)) || !TableExists<T>())
|
|
|
+ if (t.IsSubclassOf(typeof(Entity)) || !TableExists(t))
|
|
|
return;
|
|
|
using (var _access = GetWriteAccess())
|
|
|
{
|
|
|
- ExecuteSQL(_access, $"DROP TABLE {typeof(T).EntityName().Split('.').Last()}");
|
|
|
+ ExecuteSQL(_access, $"DROP TABLE {t.EntityName().Split('.').Last()}");
|
|
|
}
|
|
|
}
|
|
|
|