Compare commits
1 Commits
Author | SHA1 | Date | |
---|---|---|---|
![]() |
f2a58d23f0 |
@@ -205,18 +205,25 @@ namespace gaseous_server.Classes
|
|||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
switch ((int)dataRow["ValueType"])
|
if (Database.schema_version >= 1016)
|
||||||
{
|
{
|
||||||
case 0:
|
switch ((int)dataRow["ValueType"])
|
||||||
default:
|
{
|
||||||
// value is a string
|
case 0:
|
||||||
AppSettings.Add(SettingName, dataRow["Value"]);
|
default:
|
||||||
break;
|
// value is a string
|
||||||
|
AppSettings.Add(SettingName, dataRow["Value"]);
|
||||||
|
break;
|
||||||
|
|
||||||
case 1:
|
case 1:
|
||||||
// value is a datetime
|
// value is a datetime
|
||||||
AppSettings.Add(SettingName, dataRow["ValueDate"]);
|
AppSettings.Add(SettingName, dataRow["ValueDate"]);
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
AppSettings.Add(SettingName, dataRow["Value"]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (InvalidCastException castEx)
|
catch (InvalidCastException castEx)
|
||||||
@@ -249,34 +256,58 @@ namespace gaseous_server.Classes
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
string sql;
|
||||||
string sql = "SELECT Value, ValueDate FROM Settings WHERE Setting = @SettingName";
|
|
||||||
Dictionary<string, object> dbDict = new Dictionary<string, object>
|
Dictionary<string, object> dbDict = new Dictionary<string, object>
|
||||||
{
|
{
|
||||||
{ "SettingName", SettingName }
|
{ "SettingName", SettingName }
|
||||||
};
|
};
|
||||||
|
DataTable dbResponse;
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
Logging.Log(Logging.LogType.Debug, "Database", "Reading setting '" + SettingName + "'");
|
Logging.Log(Logging.LogType.Debug, "Database", "Reading setting '" + SettingName + "'");
|
||||||
DataTable dbResponse = db.ExecuteCMD(sql, dbDict);
|
|
||||||
Type type = typeof(T);
|
if (Database.schema_version >= 1016)
|
||||||
if (dbResponse.Rows.Count == 0)
|
|
||||||
{
|
{
|
||||||
// no value with that name stored - respond with the default value
|
sql = "SELECT Value, ValueDate FROM Settings WHERE Setting = @SettingName";
|
||||||
SetSetting<T>(SettingName, DefaultValue);
|
|
||||||
return DefaultValue;
|
dbResponse = db.ExecuteCMD(sql, dbDict);
|
||||||
}
|
Type type = typeof(T);
|
||||||
else
|
if (dbResponse.Rows.Count == 0)
|
||||||
{
|
|
||||||
if (type.ToString() == "System.DateTime")
|
|
||||||
{
|
{
|
||||||
AppSettings.Add(SettingName, dbResponse.Rows[0]["ValueDate"]);
|
// no value with that name stored - respond with the default value
|
||||||
return (T)dbResponse.Rows[0]["ValueDate"];
|
SetSetting<T>(SettingName, DefaultValue);
|
||||||
|
return DefaultValue;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
AppSettings.Add(SettingName, dbResponse.Rows[0]["Value"]);
|
if (type.ToString() == "System.DateTime")
|
||||||
|
{
|
||||||
|
AppSettings.Add(SettingName, (T)dbResponse.Rows[0]["ValueDate"]);
|
||||||
|
return (T)dbResponse.Rows[0]["ValueDate"];
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
AppSettings.Add(SettingName, (T)dbResponse.Rows[0]["Value"]);
|
||||||
|
return (T)dbResponse.Rows[0]["Value"];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
sql = "SELECT Value FROM Settings WHERE Setting = @SettingName";
|
||||||
|
|
||||||
|
dbResponse = db.ExecuteCMD(sql, dbDict);
|
||||||
|
Type type = typeof(T);
|
||||||
|
if (dbResponse.Rows.Count == 0)
|
||||||
|
{
|
||||||
|
// no value with that name stored - respond with the default value
|
||||||
|
SetSetting<T>(SettingName, DefaultValue);
|
||||||
|
return DefaultValue;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
AppSettings.Add(SettingName, (T)dbResponse.Rows[0]["Value"]);
|
||||||
return (T)dbResponse.Rows[0]["Value"];
|
return (T)dbResponse.Rows[0]["Value"];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -317,27 +348,41 @@ namespace gaseous_server.Classes
|
|||||||
public static void SetSetting<T>(string SettingName, T Value)
|
public static void SetSetting<T>(string SettingName, T Value)
|
||||||
{
|
{
|
||||||
Database db = new Database(Database.databaseType.MySql, Config.DatabaseConfiguration.ConnectionString);
|
Database db = new Database(Database.databaseType.MySql, Config.DatabaseConfiguration.ConnectionString);
|
||||||
string sql = "REPLACE INTO Settings (Setting, ValueType, Value, ValueDate) VALUES (@SettingName, @ValueType, @Value, @ValueDate)";
|
string sql;
|
||||||
Dictionary<string, object> dbDict;
|
Dictionary<string, object> dbDict;
|
||||||
Type type = typeof(T);
|
|
||||||
if (type.ToString() == "System.DateTime")
|
if (Database.schema_version >= 1016)
|
||||||
{
|
{
|
||||||
dbDict = new Dictionary<string, object>
|
sql = "REPLACE INTO Settings (Setting, ValueType, Value, ValueDate) VALUES (@SettingName, @ValueType, @Value, @ValueDate)";
|
||||||
|
Type type = typeof(T);
|
||||||
|
if (type.ToString() == "System.DateTime")
|
||||||
{
|
{
|
||||||
{ "SettingName", SettingName },
|
dbDict = new Dictionary<string, object>
|
||||||
{ "ValueType", 1 },
|
{
|
||||||
{ "Value", null },
|
{ "SettingName", SettingName },
|
||||||
{ "ValueDate", Value }
|
{ "ValueType", 1 },
|
||||||
};
|
{ "Value", null },
|
||||||
|
{ "ValueDate", Value }
|
||||||
|
};
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
dbDict = new Dictionary<string, object>
|
||||||
|
{
|
||||||
|
{ "SettingName", SettingName },
|
||||||
|
{ "ValueType", 0 },
|
||||||
|
{ "Value", Value },
|
||||||
|
{ "ValueDate", null }
|
||||||
|
};
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
sql = "REPLACE INTO Settings (Setting, Value) VALUES (@SettingName, @Value)";
|
||||||
dbDict = new Dictionary<string, object>
|
dbDict = new Dictionary<string, object>
|
||||||
{
|
{
|
||||||
{ "SettingName", SettingName },
|
{ "SettingName", SettingName },
|
||||||
{ "ValueType", 0 },
|
{ "Value", Value }
|
||||||
{ "Value", Value },
|
|
||||||
{ "ValueDate", null }
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -9,6 +9,8 @@ namespace gaseous_server.Classes
|
|||||||
{
|
{
|
||||||
public class Database
|
public class Database
|
||||||
{
|
{
|
||||||
|
public static int schema_version = 0;
|
||||||
|
|
||||||
public Database()
|
public Database()
|
||||||
{
|
{
|
||||||
|
|
||||||
@@ -123,6 +125,9 @@ namespace gaseous_server.Classes
|
|||||||
|
|
||||||
// run post-upgrade code
|
// run post-upgrade code
|
||||||
DatabaseMigration.PostUpgradeScript(i, _ConnectorType);
|
DatabaseMigration.PostUpgradeScript(i, _ConnectorType);
|
||||||
|
|
||||||
|
// update schema version variable
|
||||||
|
Database.schema_version = i;
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
|
Reference in New Issue
Block a user