void GameIdUpgrade(DbConnection connection) { //player.game_id was nullable prior to r348, should have been not null all along bool isAffected = false; using (var pragma = new DatabaseCommand("pragma table_info(player)", connection)) { using (var reader = pragma.ExecuteReader()) { while (reader.Read()) { string name = (string)reader.Get("name"); if (name != "game_id") { continue; } object notNullObject = reader.Get("notnull"); bool isNotNull = (int)(long)notNullObject == 1; if (!isNotNull) { isAffected = true; break; } } } } if (isAffected) { WriteLine("This database is affected by the pre-348 player.game_id bug. Attempting to upgrade it."); CopyTableTransaction(connection, "player", Properties.Resources.CreateTablePlayer); } }
void InitialiseSummonerCache() { SummonerCache = new Dictionary <RegionType, Dictionary <int, Summoner> >(); foreach (RegionType regionType in Enum.GetValues(typeof(RegionType))) { SummonerCache[regionType] = new Dictionary <int, Summoner>(); } using (var connection = Provider.GetConnection()) { using (var select = new DatabaseCommand("select {0} from summoner", connection, null, Summoner.GetFields())) { using (var reader = select.ExecuteReader()) { while (reader.Read()) { Summoner summoner = new Summoner(reader); SummonerCache[summoner.Region][summoner.AccountId] = summoner; } } } } }
void UnknownPlayerUpgrade(DbConnection connection) { //This is required for the r248 fix in the unknown_player table //The field "account_id" had to be renamed to "summoner_id" in that version //First check if this database is actually affected by that bug bool isAffected = false; using (var pragma = new DatabaseCommand("pragma table_info(unknown_player)", connection)) { using (var reader = pragma.ExecuteReader()) { while (reader.Read()) { string name = (string)reader.Get("name"); if (name == "account_id") { isAffected = true; break; } } } } if (isAffected) { WriteLine("This database is affected by the pre-r248 unknown_player bug. Attempting to upgrade it."); CopyTableTransaction(connection, "unknown_player", Properties.Resources.CreateTableUnknownPlayer); } }
//This function is required to upgrade old database formats to newer ones void UpgradeDatabase() { using (var connection = Provider.GetConnection()) { //This is required for the r248 fix in the unknown_player table //The field "account_id" had to be renamed to "summoner_id" in that version //First check if this database is actually affected by that bug bool isAffected = false; using (var pragma = new DatabaseCommand("pragma table_info(unknown_player)", connection)) { using (var reader = pragma.ExecuteReader()) { while (reader.Read()) { string name = (string)reader.Get("name"); if (name == "account_id") { isAffected = true; break; } } } } if (isAffected) { const string createTableQuery = "create table unknown_player(team_id integer not null, champion_id integer not null, summoner_id integer not null, foreign key (team_id) references team(id))"; WriteLine("This database is affected by the pre-r248 unknown_player bug. Attempting to upgrade it."); using (var transaction = connection.BeginTransaction()) { //Rename the old table to a temporary name using (var renameTable = new DatabaseCommand("alter table unknown_player rename to broken_unknown_player", connection)) renameTable.Execute(); //Create the new table using (var createTable = new DatabaseCommand(createTableQuery, connection)) createTable.Execute(); //Insert the data from the old table into the new table using (var insert = new DatabaseCommand("insert into unknown_player (team_id, champion_id, summoner_id) select team_id, champion_id, account_id from broken_unknown_player", connection)) insert.Execute(); //Remove the old table using (var dropTable = new DatabaseCommand("drop table broken_unknown_player", connection)) dropTable.Execute(); //Commit the transaction transaction.Commit(); //Vacuum using (var vacuum = new DatabaseCommand("vacuum", connection)) vacuum.Execute(); } WriteLine("Upgrade succeeded."); } } }
void GameIdUpgrade(DbConnection connection) { //player.game_id was nullable prior to r348, should have been not null all along bool isAffected = false; using (var pragma = new DatabaseCommand("pragma table_info(player)", connection)) { using (var reader = pragma.ExecuteReader()) { while (reader.Read()) { string name = (string)reader.Get("name"); if (name != "game_id") continue; object notNullObject = reader.Get("notnull"); bool isNotNull = (int)(long)notNullObject == 1; if (!isNotNull) { isAffected = true; break; } } } } if (isAffected) { WriteLine("This database is affected by the pre-348 player.game_id bug. Attempting to upgrade it."); using (var transaction = connection.BeginTransaction()) { //Rename the old table to a temporary name using (var renameTable = new DatabaseCommand("alter table player rename to broken_player", connection)) renameTable.Execute(); //Create the new table using (var createTable = new DatabaseCommand(Properties.Resources.CreateTablePlayer, connection)) createTable.Execute(); //Insert the data from the old table into the new table string fieldString = Properties.Resources.PlayerFields.Replace("\n", " "); using (var insert = new DatabaseCommand(string.Format("insert into player ({0}) select {0} from broken_player", fieldString), connection)) insert.Execute(); //Remove the old table using (var dropTable = new DatabaseCommand("drop table broken_player", connection)) dropTable.Execute(); //Commit the transaction transaction.Commit(); //Vacuum using (var vacuum = new DatabaseCommand("vacuum", connection)) vacuum.Execute(); } WriteLine("Upgrade succeeded."); } }
void AccountIdUpgrade(DbConnection connection) { //In pre-r375 databases the account_id was marked as unique even though it shouldn't have been bool isAffected = false; using (var pragma = new DatabaseCommand("select sql from sqlite_master where tbl_name = 'summoner'", connection)) { using (var reader = pragma.ExecuteReader()) { if (reader.Read()) { string query = reader.String(); if (query.IndexOf("account_id integer unique not null") >= 0) { isAffected = true; } } else { throw new Exception("Unable to locate summoner table for upgrade check"); } } } if (isAffected) { WriteLine("This database is affected by the pre-375 summoner.account_id bug. Attempting to upgrade it."); using (var transaction = connection.BeginTransaction()) { CopyTable(connection, "summoner", Properties.Resources.CreateTableSummoner); CopyTable(connection, "summoner_rating", Properties.Resources.CreateTableSummonerRating); CopyTable(connection, "summoner_ranked_statistics", Properties.Resources.CreateTableSummonerRankedStatistics); CopyTable(connection, "player", Properties.Resources.CreateTablePlayer); CopyTable(connection, "rune_page", Properties.Resources.CreateTableRunePage); CopyTable(connection, "rune_slot", Properties.Resources.CreateTableRuneSlot); DropOldTable(connection, "rune_slot"); DropOldTable(connection, "rune_page"); DropOldTable(connection, "player"); DropOldTable(connection, "summoner_ranked_statistics"); DropOldTable(connection, "summoner_rating"); DropOldTable(connection, "summoner"); transaction.Commit(); } Vacuum(connection); WriteLine("Upgrade succeeded."); } }
void AccountIdUpgrade(DbConnection connection) { //In pre-r375 databases the account_id was marked as unique even though it shouldn't have been bool isAffected = false; using (var pragma = new DatabaseCommand("select sql from sqlite_master where tbl_name = 'summoner'", connection)) { using (var reader = pragma.ExecuteReader()) { if (reader.Read()) { string query = reader.String(); if (query.IndexOf("account_id integer unique not null") >= 0) isAffected = true; } else throw new Exception("Unable to locate summoner table for upgrade check"); } } if (isAffected) { WriteLine("This database is affected by the pre-375 summoner.account_id bug. Attempting to upgrade it."); using (var transaction = connection.BeginTransaction()) { CopyTable(connection, "summoner", Properties.Resources.CreateTableSummoner); CopyTable(connection, "summoner_rating", Properties.Resources.CreateTableSummonerRating); CopyTable(connection, "summoner_ranked_statistics", Properties.Resources.CreateTableSummonerRankedStatistics); CopyTable(connection, "player", Properties.Resources.CreateTablePlayer); CopyTable(connection, "rune_page", Properties.Resources.CreateTableRunePage); CopyTable(connection, "rune_slot", Properties.Resources.CreateTableRuneSlot); DropOldTable(connection, "rune_slot"); DropOldTable(connection, "rune_page"); DropOldTable(connection, "player"); DropOldTable(connection, "summoner_ranked_statistics"); DropOldTable(connection, "summoner_rating"); DropOldTable(connection, "summoner"); transaction.Commit(); } Vacuum(connection); WriteLine("Upgrade succeeded."); } }
void InitialiseSummonerCache() { SummonerCache = new Dictionary<RegionType, Dictionary<int, Summoner>>(); foreach (RegionType regionType in Enum.GetValues(typeof(RegionType))) SummonerCache[regionType] = new Dictionary<int, Summoner>(); using (var connection = Provider.GetConnection()) { using (var select = new DatabaseCommand("select {0} from summoner", connection, null, Summoner.GetFields())) { using (var reader = select.ExecuteReader()) { while (reader.Read()) { Summoner summoner = new Summoner(reader); SummonerCache[summoner.Region][summoner.AccountId] = summoner; } } } } }
void UnknownPlayerUpgrade(DbConnection connection) { //This is required for the r248 fix in the unknown_player table //The field "account_id" had to be renamed to "summoner_id" in that version //First check if this database is actually affected by that bug bool isAffected = false; using (var pragma = new DatabaseCommand("pragma table_info(unknown_player)", connection)) { using (var reader = pragma.ExecuteReader()) { while (reader.Read()) { string name = (string)reader.Get("name"); if (name == "account_id") { isAffected = true; break; } } } } if (isAffected) { WriteLine("This database is affected by the pre-r248 unknown_player bug. Attempting to upgrade it."); CopyTableTransaction(connection, "unknown_player", Properties.Resources.CreateTableUnknownPlayer); } }
void GameIdUpgrade(DbConnection connection) { //player.game_id was nullable prior to r348, should have been not null all along bool isAffected = false; using (var pragma = new DatabaseCommand("pragma table_info(player)", connection)) { using (var reader = pragma.ExecuteReader()) { while (reader.Read()) { string name = (string)reader.Get("name"); if (name != "game_id") continue; object notNullObject = reader.Get("notnull"); bool isNotNull = (int)(long)notNullObject == 1; if (!isNotNull) { isAffected = true; break; } } } } if (isAffected) { WriteLine("This database is affected by the pre-348 player.game_id bug. Attempting to upgrade it."); CopyTableTransaction(connection, "player", Properties.Resources.CreateTablePlayer); } }
void TierSystemUpgrade(DbConnection connection) { //Pre-r431 databases were still designed for season 1/2 style stats where losses and Elo were visible bool isAffected = false; using (var pragma = new DatabaseCommand("select sql from sqlite_master where tbl_name = 'summoner_rating'", connection)) { using (var reader = pragma.ExecuteReader()) { if (reader.Read()) { string query = reader.String(); if (query.IndexOf("current_rating") >= 0) isAffected = true; } else throw new Exception("Unable to locate summoner rating table for upgrade check"); } } if (isAffected) { WriteLine("This database is still using the pre-r431 season 1/2 rating system. Attempting to upgrade it."); using (var transaction = connection.BeginTransaction()) { string tableName = "summoner_rating"; string oldTableName = "old_summoner_rating"; // Rename the old table so it can be copied to the new one RenameTable(connection, tableName, oldTableName); // Remove the old indices RemoveIndicesBasedOnQuery(connection, Properties.Resources.CreateTableSummonerRating); // Create the new table and copy the old data ExecuteScript(connection, Properties.Resources.CreateAndCopySummonerRatingSeason3); // Remove the old table DropTable(connection, oldTableName); transaction.Commit(); } Vacuum(connection); WriteLine("Upgrade succeeded."); } }