diff --git a/Deheader/Headerer.cs b/Deheader/Headerer.cs index ba5e022c..18489be1 100644 --- a/Deheader/Headerer.cs +++ b/Deheader/Headerer.cs @@ -17,6 +17,7 @@ namespace SabreTools private Logger _logger; // Private required variables + private static string _dbSchema = "Headerer"; private static string _dbName = "Headerer.sqlite"; private static string _connectionString = "Data Source=" + _dbName + ";Version = 3;"; @@ -48,7 +49,7 @@ namespace SabreTools // Perform initial setup and verification Logger logger = new Logger(true, "headerer.log"); logger.Start(); - DBTools.EnsureDatabase(_dbName, _connectionString); + DBTools.EnsureDatabase(_dbSchema, _dbName, _connectionString); // Credits take precidence over all if ((new List(args)).Contains("--credits")) diff --git a/RombaSharp/RombaSharp.cs b/RombaSharp/RombaSharp.cs index 161dd429..5650c7ee 100644 --- a/RombaSharp/RombaSharp.cs +++ b/RombaSharp/RombaSharp.cs @@ -33,6 +33,7 @@ namespace SabreTools // Other private variables private string _config = "config.xml"; + private string _dbSchema = "rombasharp"; private string _connectionString; private Logger _logger; @@ -45,7 +46,7 @@ namespace SabreTools _logger = logger; InitializeConfiguration(); - InitializeDatabase(); + DBTools.EnsureDatabase(_dbSchema, _db, _connectionString); } public static void Main(string[] args) @@ -280,51 +281,6 @@ namespace SabreTools _port = port; } - /// - /// Initialize the Romba database - /// - private void InitializeDatabase() - { - // Make sure the db is set - if (String.IsNullOrEmpty(_db)) - { - _db = "db.sqlite"; - _connectionString = "Data Source=" + _db + ";Version = 3;"; - } - - // Make sure the file exists - if (!File.Exists(_db)) - { - SqliteConnection.CreateFile(_db); - } - - // Connect to the file - SqliteConnection dbc = new SqliteConnection(_connectionString); - dbc.Open(); - - // Initialize the database schema - try - { - string query = @" -CREATE TABLE IF NOT EXISTS data ( -'id' INTEGER NOT NULL -'key' TEXT NOT NULL -'value' TEXT NOT NULL -)"; - SqliteCommand slc = new SqliteCommand(query, dbc); - slc.ExecuteNonQuery(); - } - catch (Exception ex) - { - Console.WriteLine(ex); - } - finally - { - // Close the database connection - dbc.Close(); - } - } - /// /// Populate or refresh the database information /// diff --git a/SabreTools.Helper/Tools/DBTools.cs b/SabreTools.Helper/Tools/DBTools.cs index 20fb09aa..f15af457 100644 --- a/SabreTools.Helper/Tools/DBTools.cs +++ b/SabreTools.Helper/Tools/DBTools.cs @@ -12,19 +12,20 @@ namespace SabreTools.Helper /// /// Ensure that the databse exists and has the proper schema /// + /// Schema type to use /// Name of the databse /// Connection string for SQLite - public static void EnsureDatabase(string db, string connectionString) + public static void EnsureDatabase(string type, string db, string connectionString) { + // Set the type to lowercase + type = type.ToLowerInvariant(); + // Make sure the file exists if (!File.Exists(db)) { SqliteConnection.CreateFile(db); } - //Get "type" from the filename - string type = Path.GetFileNameWithoutExtension(db); - // Connect to the file SqliteConnection dbc = new SqliteConnection(connectionString); dbc.Open(); @@ -32,7 +33,18 @@ namespace SabreTools.Helper // Make sure the database has the correct schema try { - if (type == "Headerer") + if (type == "rombasharp") + { + string query = @" +CREATE TABLE IF NOT EXISTS data ( +'id' INTEGER NOT NULL +'key' TEXT NOT NULL +'value' TEXT NOT NULL +)"; + SqliteCommand slc = new SqliteCommand(query, dbc); + slc.ExecuteNonQuery(); + } + else if (type == "headerer") { string query = @" CREATE TABLE IF NOT EXISTS data ( diff --git a/SabreTools/Partials/SabreTools_Helpers.cs b/SabreTools/Partials/SabreTools_Helpers.cs index eccdb935..5e29abb9 100644 --- a/SabreTools/Partials/SabreTools_Helpers.cs +++ b/SabreTools/Partials/SabreTools_Helpers.cs @@ -25,7 +25,7 @@ namespace SabreTools { Directory.CreateDirectory(_outroot); } - DBTools.EnsureDatabase(_dbName, _connectionString); + DBTools.EnsureDatabase(_dbSchema, _dbName, _connectionString); using (SqliteConnection dbc = new SqliteConnection(_connectionString)) { diff --git a/SabreTools/SabreTools.cs b/SabreTools/SabreTools.cs index 6cf9693e..ab084438 100644 --- a/SabreTools/SabreTools.cs +++ b/SabreTools/SabreTools.cs @@ -26,7 +26,8 @@ namespace SabreTools // Private required variables private static string _datroot = "DATS"; private static string _outroot = "Output"; - private static string _dbName = "dats.sqlite"; + private static string _dbSchema = "dats"; + private static string _dbName = "dats.sqlite"; private static string _connectionString = "Data Source=" + _dbName + ";Version = 3;"; private static Logger _logger;