From c1ead5fe27eda8be9f15c4c9f3133ff9ec5e37e4 Mon Sep 17 00:00:00 2001 From: Ebag333 Date: Mon, 2 Jan 2017 00:29:44 -0800 Subject: [PATCH] change method for retreiving count --- eos/db/saveddata/databaseRepair.py | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/eos/db/saveddata/databaseRepair.py b/eos/db/saveddata/databaseRepair.py index 5561b41a1..bfc6e8569 100644 --- a/eos/db/saveddata/databaseRepair.py +++ b/eos/db/saveddata/databaseRepair.py @@ -40,7 +40,13 @@ class DatabaseCleanup: results = saveddata_engine.execute("SELECT COUNT(*) AS num FROM characterSkills " "WHERE characterID NOT IN (SELECT ID from characters)") - if results.fetchone()['num'] > 0: + count_results = 0 + for result in results: + count_results = result[0] + break + + # Count how many records exist. This is ugly, but SQLAlchemy doesn't return a count from a select query. + if count_results > 0: delete = saveddata_engine.execute("DELETE FROM characterSkills WHERE characterID NOT IN (SELECT ID from characters)") logger.error("Database corruption found. Cleaning up %d records.", delete.rowcount) @@ -56,7 +62,13 @@ class DatabaseCleanup: logger.debug("Running database cleanup for orphaned damage patterns attached to fits.") results = saveddata_engine.execute("SELECT COUNT(*) AS num FROM fits WHERE damagePatternID not in (select ID from damagePatterns)") - if results.fetchone()['num'] > 0: + count_results = 0 + for result in results: + count_results = result[0] + break + + # Count how many records exist. This is ugly, but SQLAlchemy doesn't return a count from a select query. + if count_results > 0: # Get Uniform damage pattern ID uniform_results = saveddata_engine.execute("select ID from damagePatterns WHERE name = 'Uniform'") @@ -80,13 +92,18 @@ class DatabaseCleanup: @staticmethod def OrphanedFitCharacterIDs(saveddata_engine): - # Find orphaned character IDs. This solves an issue where the chaaracter doesn't exist, but fits reference the pattern. + # Find orphaned character IDs. This solves an issue where the character doesn't exist, but fits reference the pattern. try: logger.debug("Running database cleanup for orphaned characters attached to fits.") results = saveddata_engine.execute("SELECT COUNT(*) AS num FROM fits WHERE characterID NOT IN (SELECT ID FROM characters)") + count_results = 0 + for result in results: + count_results = result[0] + break + # Count how many records exist. This is ugly, but SQLAlchemy doesn't return a count from a select query. - if results.fetchone()['num'] > 0: + if count_results > 0: # Get All 5 character ID all5_results = saveddata_engine.execute("SELECT ID FROM characters WHERE name = 'All 5'")