fix database problem
This commit is contained in:
@@ -19,20 +19,23 @@ public class ManifestDB
|
|||||||
{
|
{
|
||||||
string DBPath = $"{Config.Instance.MainPath}\\meta";
|
string DBPath = $"{Config.Instance.MainPath}\\meta";
|
||||||
ManifestDB.DBPath = DBPath;
|
ManifestDB.DBPath = DBPath;
|
||||||
if (File.Exists(DBPath))
|
if (!File.Exists(DBPath))
|
||||||
{
|
|
||||||
MetaDB = new SqliteConnection($@"Data Source={DBPath}");
|
|
||||||
MetaDB.Open();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
{
|
||||||
Directory.CreateDirectory(Path.GetDirectoryName(DBPath));
|
Directory.CreateDirectory(Path.GetDirectoryName(DBPath));
|
||||||
SqliteConnection.CreateFile(DBPath);
|
}
|
||||||
MetaDB = new SqliteConnection($@"Data Source={DBPath}");
|
|
||||||
MetaDB.Open();
|
Directory.CreateDirectory(Path.GetDirectoryName(DBPath));
|
||||||
SqliteCommand cmd = new SqliteCommand(
|
MetaDB = new SqliteConnection($@"Data Source={DBPath}");
|
||||||
"CREATE TABLE `a` ( `i` INTEGER PRIMARY KEY,`n` TEXT NOT NULL,`d` TEXT,`g` INTEGER(4) NOT NULL,`l` INTEGER(8) NOT NULL,`c` INTEGER(8) NOT NULL,`h` TEXT NOT NULL,`m` TEXT NOT NULL,`k` INTEGER(1) NOT NULL,`s` INTEGER(1) NOT NULL,`p` INTEGER(4) NOT NULL DEFAULT 0)");
|
MetaDB.Open();
|
||||||
cmd.Connection = MetaDB;
|
SqliteCommand cmd = new SqliteCommand("SELECT name FROM sqlite_master");
|
||||||
|
cmd.Connection = MetaDB;
|
||||||
|
var reader = cmd.ExecuteReader();
|
||||||
|
var hasrows = reader.HasRows;
|
||||||
|
reader.Close();
|
||||||
|
if (!hasrows) //Is Empty DB
|
||||||
|
{
|
||||||
|
SqliteTransaction tran = MetaDB.BeginTransaction();
|
||||||
|
cmd.CommandText = "CREATE TABLE `a` ( `i` INTEGER PRIMARY KEY,`n` TEXT NOT NULL,`d` TEXT,`g` INTEGER(4) NOT NULL,`l` INTEGER(8) NOT NULL,`c` INTEGER(8) NOT NULL,`h` TEXT NOT NULL,`m` TEXT NOT NULL,`k` INTEGER(1) NOT NULL,`s` INTEGER(1) NOT NULL,`p` INTEGER(4) NOT NULL DEFAULT 0)";
|
||||||
cmd.ExecuteNonQuery();
|
cmd.ExecuteNonQuery();
|
||||||
cmd.CommandText = "CREATE INDEX `a0` ON `a`(`n`, `s`)";
|
cmd.CommandText = "CREATE INDEX `a0` ON `a`(`n`, `s`)";
|
||||||
cmd.ExecuteNonQuery();
|
cmd.ExecuteNonQuery();
|
||||||
@@ -44,6 +47,7 @@ public class ManifestDB
|
|||||||
cmd.ExecuteNonQuery();
|
cmd.ExecuteNonQuery();
|
||||||
cmd.CommandText = "CREATE INDEX `a1` ON `a`(`s`)";
|
cmd.CommandText = "CREATE INDEX `a1` ON `a`(`s`)";
|
||||||
cmd.ExecuteNonQuery();
|
cmd.ExecuteNonQuery();
|
||||||
|
tran.Commit();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -316,5 +320,6 @@ public class ManifestDB
|
|||||||
}
|
}
|
||||||
return platformEntrys[0];
|
return platformEntrys[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -67,8 +67,10 @@ public class UmaDatabaseController
|
|||||||
}
|
}
|
||||||
catch
|
catch
|
||||||
{
|
{
|
||||||
UmaViewerUI.Instance.LyricsText.text = $"Database not found: \n{Config.Instance.MainPath}/meta\n{Config.Instance.MainPath}/master/master.mdb";
|
UmaViewerUI.Instance.LyricsText.text = $"Database not found: \n{Config.Instance.MainPath}\\meta\n{Config.Instance.MainPath}\\master\\master.mdb";
|
||||||
UmaViewerUI.Instance.LyricsText.color = Color.red;
|
UmaViewerUI.Instance.LyricsText.color = Color.red;
|
||||||
|
masterDb.Close();
|
||||||
|
metaDb.Close();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user