mirror of
https://github.com/ClassiCube/MCGalaxy.git
synced 2025-09-24 05:03:34 -04:00
Rewrite DB backup code so it doesn't need to reference System.Data.DataExtensions.
This commit is contained in:
parent
9b9cd3535f
commit
c417e33743
@ -86,7 +86,6 @@
|
|||||||
</Reference>
|
</Reference>
|
||||||
<Reference Include="System" />
|
<Reference Include="System" />
|
||||||
<Reference Include="System.Core" />
|
<Reference Include="System.Core" />
|
||||||
<Reference Include="System.Data.DataSetExtensions" />
|
|
||||||
<Reference Include="System.Data.SQLite">
|
<Reference Include="System.Data.SQLite">
|
||||||
<HintPath>System.Data.SQLite.dll</HintPath>
|
<HintPath>System.Data.SQLite.dll</HintPath>
|
||||||
</Reference>
|
</Reference>
|
||||||
|
@ -83,20 +83,22 @@ namespace MCGalaxy {
|
|||||||
|
|
||||||
sql.WriteLine();
|
sql.WriteLine();
|
||||||
sql.Write("(");
|
sql.Write("(");
|
||||||
for (int col = 0; col < row.ItemArray.Length; col++) {
|
for (int col = 0; col < data.Columns.Count; col++) {
|
||||||
//The values themselves can be integers or strings, or null
|
//The values themselves can be integers or strings, or null
|
||||||
Type eleType = allCols[col].DataType;
|
Type type = allCols[col].DataType;
|
||||||
if (row.IsNull(col)) {
|
if (row.IsNull(col)) {
|
||||||
sql.Write("NULL");
|
sql.Write("NULL");
|
||||||
} else if (eleType.Name.Equals("DateTime")) { // special format
|
} else if (type == typeof(DateTime)) { // special format
|
||||||
DateTime dt = row.Field<DateTime>(col);
|
sql.Write("'{0:yyyy-MM-dd HH:mm:ss.ffff}'", (DateTime)row[col]);
|
||||||
sql.Write("'{0:yyyy-MM-dd HH:mm:ss.ffff}'", dt);
|
} else if (type == typeof(bool)) {
|
||||||
} else if (eleType.Name.Equals("Boolean")) {
|
sql.Write((bool)row[col] ? "1" : "0");
|
||||||
sql.Write(row.Field<Boolean>(col) ? "1" : "0");
|
} else if (type == typeof(string)) { // Requires ''
|
||||||
} else if (eleType.Name.Equals("String")) { // Requires ''
|
string value = row[col].ToString();
|
||||||
sql.Write("'{0}'", row.Field<string>(col));
|
if (value.IndexOf(' ') >= 0)
|
||||||
|
value = value.Replace("'", "''");
|
||||||
|
sql.Write("'{0}'", value);
|
||||||
} else {
|
} else {
|
||||||
sql.Write(row.Field<Object>(col)); // We assume all other data is left as-is
|
sql.Write(row[col]); // We assume all other data is left as-is
|
||||||
//This includes numbers, blobs, etc. (As well as objects, but we don't save them into the database)
|
//This includes numbers, blobs, etc. (As well as objects, but we don't save them into the database)
|
||||||
}
|
}
|
||||||
sql.Write((col < row.ItemArray.Length - 1 ? ", " : ");"));
|
sql.Write((col < row.ItemArray.Length - 1 ? ", " : ");"));
|
||||||
@ -119,7 +121,7 @@ namespace MCGalaxy {
|
|||||||
//Save the info contained to file
|
//Save the info contained to file
|
||||||
List<string> tmp = new List<string>();
|
List<string> tmp = new List<string>();
|
||||||
for (int col = 0; col < schema.Columns.Count; col++)
|
for (int col = 0; col < schema.Columns.Count; col++)
|
||||||
tmp.Add(row.Field<string>(col));
|
tmp.Add(row[col].ToString());
|
||||||
|
|
||||||
rowParams = tmp.ToArray();
|
rowParams = tmp.ToArray();
|
||||||
rowParams[2] = (rowParams[2].ToLower().Equals("no") ? "NOT " : "DEFAULT ") + "NULL";
|
rowParams[2] = (rowParams[2].ToLower().Equals("no") ? "NOT " : "DEFAULT ") + "NULL";
|
||||||
@ -148,7 +150,7 @@ namespace MCGalaxy {
|
|||||||
{
|
{
|
||||||
//just print out the data in the table.
|
//just print out the data in the table.
|
||||||
foreach (DataRow row in tableSQL.Rows) {
|
foreach (DataRow row in tableSQL.Rows) {
|
||||||
string tableSQLString = row.Field<string>(0);
|
string tableSQLString = row[0].ToString();
|
||||||
sql.WriteLine(tableSQLString.Replace(" " + tableName, " `" + tableName + "`").Replace("CREATE TABLE `" + tableName + "`", "CREATE TABLE IF NOT EXISTS `" + tableName + "`") + ";");
|
sql.WriteLine(tableSQLString.Replace(" " + tableName, " `" + tableName + "`").Replace("CREATE TABLE `" + tableName + "`", "CREATE TABLE IF NOT EXISTS `" + tableName + "`") + ";");
|
||||||
//We parse this ourselves to find the actual types.
|
//We parse this ourselves to find the actual types.
|
||||||
tableSchema = getSchema(tableSQLString);
|
tableSchema = getSchema(tableSQLString);
|
||||||
@ -188,7 +190,7 @@ namespace MCGalaxy {
|
|||||||
string syntax = Server.useMySQL ? "SHOW TABLES" : "SELECT * FROM sqlite_master WHERE type='table' AND name NOT LIKE 'sqlite_%'";
|
string syntax = Server.useMySQL ? "SHOW TABLES" : "SELECT * FROM sqlite_master WHERE type='table' AND name NOT LIKE 'sqlite_%'";
|
||||||
using (DataTable tables = Database.Fill(syntax)) {
|
using (DataTable tables = Database.Fill(syntax)) {
|
||||||
foreach (DataRow row in tables.Rows) {
|
foreach (DataRow row in tables.Rows) {
|
||||||
string tableName = row.Field<string>((Server.useMySQL ? 0 : 1));
|
string tableName = row[Server.useMySQL ? 0 : 1].ToString();
|
||||||
tableNames.Add(tableName);
|
tableNames.Add(tableName);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user