コード例 #1
0
        private bool UpgradeSystemsDB()
        {
            try
            {
                ExecuteNonQuery("CREATE TABLE IF NOT EXISTS Register (ID TEXT PRIMARY KEY NOT NULL, ValueInt INTEGER, ValueDouble DOUBLE, ValueString TEXT, ValueBlob BLOB)");

                // BE VERY careful with connections when creating/deleting tables - you end up with SQL Schema errors or it not seeing the table

                SQLExtRegister reg   = new SQLExtRegister(this);
                int            dbver = reg.GetSettingInt("DBVer", 0); // use reg, don't use the built in func as they create new connections and confuse the schema

                ExecuteNonQueries(new string[]                        // always kill these old tables and make EDDB new table
                {
                    "DROP TABLE IF EXISTS EddbSystems",
                    "DROP TABLE IF EXISTS Distances",
                    "DROP TABLE IF EXISTS Stations",
                    "DROP TABLE IF EXISTS SystemAliases",
                    "DROP TABLE IF EXISTS station_commodities",
                    "CREATE TABLE IF NOT EXISTS EDDB (edsmid INTEGER PRIMARY KEY NOT NULL, eddbid INTEGER, eddbupdatedat INTEGER, population INTEGER, faction TEXT, government INTEGER, allegiance INTEGER, state INTEGER, security INTEGER, primaryeconomy INTEGER, needspermit INTEGER, power TEXT, powerstate TEXT, properties TEXT)",
                    "CREATE TABLE IF NOT EXISTS Aliases (edsmid INTEGER PRIMARY KEY NOT NULL, edsmid_mergedto INTEGER, name TEXT COLLATE NOCASE)"
                });

                if (dbver < 102)                   // is it older than 102, its unusable
                {
                    ExecuteNonQueries(new string[] // older than 102, not supporting, remove
                    {
                        "DROP TABLE IF EXISTS EdsmSystems",
                        "DROP TABLE IF EXISTS SystemNames",
                    });

                    reg.DeleteKey("EDSMLastSystems");       // no EDSM system time
                }

                CreateStarTables();                   // ensure we have
                CreateSystemDBTableIndexes();         // ensure they are there
                DropStarTables(tablepostfix);         // clean out any temp tables half prepared

                //    conn.Vacuum();  // debug

                if (dbver < 200)
                {
                    reg.PutSettingInt("DBVer", 200);
                    reg.DeleteKey("EDDBSystemsTime");       // force a reload of EDDB
                }

                return(true);
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine("UpgradeSystemsDB error: " + ex.Message + Environment.NewLine + ex.StackTrace);
                return(false);
            }
        }
コード例 #2
0
        const string tablepostfix = "temp"; // postfix for temp tables

        public bool UpgradeSystemsDB()
        {
            try
            {
                ExecuteNonQuery("CREATE TABLE IF NOT EXISTS Register (ID TEXT PRIMARY KEY NOT NULL, ValueInt INTEGER, ValueDouble DOUBLE, ValueString TEXT, ValueBlob BLOB)");

                // BE VERY careful with connections when creating/deleting tables - you end up with SQL Schema errors or it not seeing the table

                SQLExtRegister reg   = new SQLExtRegister(this);
                int            dbver = reg.GetSettingInt("DBVer", 0); // use reg, don't use the built in func as they create new connections and confuse the schema

                ExecuteNonQueries(new string[]                        // always kill these old tables and make EDDB new table
                {
                    "DROP TABLE IF EXISTS EDDB",                      // New Dec 20 - no more EDDB
                    "DROP TABLE IF EXISTS Distances",
                    "DROP TABLE IF EXISTS EddbSystems",
                    // keep edsmsystems
                    "DROP TABLE IF EXISTS Stations",
                    "DROP TABLE IF EXISTS SystemAliases",
                    // don't drop Systemnames
                    "DROP TABLE IF EXISTS station_commodities",
                    "CREATE TABLE IF NOT EXISTS Aliases (edsmid INTEGER PRIMARY KEY NOT NULL, edsmid_mergedto INTEGER, name TEXT COLLATE NOCASE)"
                });

                var  tablesql   = this.SQLMasterQuery("table");
                int  index      = tablesql.FindIndex(x => x.TableName == "Systems");
                bool oldsystems = index >= 0 && tablesql[index].SQL.Contains("commandercreate");

                if (dbver < 200 || oldsystems)
                {
                    ExecuteNonQueries(new string[]      // always kill these old tables and make EDDB new table
                    {
                        "DROP TABLE IF EXISTS Systems", // New! this is an hold over which never got deleted when we moved to the 102 schema
                    });
                }

                if (dbver < 102)                   // is it older than 102, its unusable
                {
                    ExecuteNonQueries(new string[] // older than 102, not supporting, remove
                    {
                        "DROP TABLE IF EXISTS EdsmSystems",
                        "DROP TABLE IF EXISTS SystemNames",
                    });

                    reg.DeleteKey("EDSMLastSystems");       // no EDSM system time
                }

                CreateStarTables();                   // ensure we have
                CreateSystemDBTableIndexes();         // ensure they are there
                DropStarTables(tablepostfix);         // clean out any temp tables half prepared

                //    conn.Vacuum();  // debug

                if (dbver < 200)
                {
                    reg.PutSettingInt("DBVer", 200);
                    reg.DeleteKey("EDDBSystemsTime");       // force a reload of EDDB
                }

                return(true);
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine("UpgradeSystemsDB error: " + ex.Message + Environment.NewLine + ex.StackTrace);
                return(false);
            }
        }