From 94aa5f3d0c043547f9bac6f0046b64898cf277e7 Mon Sep 17 00:00:00 2001 From: Sol Jerome Date: Fri, 11 May 2012 09:22:45 -0500 Subject: reports: Fix traceback reported by Rodney Young Previously left out a check for whether the column exists when using MySQL. We will probably eventually need checks for other db types as well. Signed-off-by: Sol Jerome --- src/lib/Bcfg2/Server/Reports/updatefix.py | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) (limited to 'src/lib/Bcfg2/Server/Reports') diff --git a/src/lib/Bcfg2/Server/Reports/updatefix.py b/src/lib/Bcfg2/Server/Reports/updatefix.py index b5e41b8f9..192b94b61 100644 --- a/src/lib/Bcfg2/Server/Reports/updatefix.py +++ b/src/lib/Bcfg2/Server/Reports/updatefix.py @@ -63,10 +63,20 @@ def _interactions_constraint_or_idx(): def _remove_table_column(tbl, col): """sqlite doesn't support deleting a column via alter table""" cursor = connection.cursor() - try: + db_engine = Bcfg2.Server.Reports.settings.DATABASES['default']['ENGINE'] + if db_engine == 'django.db.backends.mysql': + db_name = Bcfg2.Server.Reports.settings.DATABASES['default']['NAME'] + column_exists = cursor.execute('select * from information_schema.columns ' + 'where table_schema="%s" and ' + 'table_name="%s" ' + 'and column_name="%s";' % (db_name, tbl, col)) + if not column_exists: + # column doesn't exist + return + # if column exists from previous database, remove it cursor.execute('alter table %s ' 'drop column %s;' % (tbl, col)) - except DatabaseError: + elif db_engine == 'django.db.backends.sqlite3': # check if table exists try: cursor.execute('select * from sqlite_master where name=%s and type="table";' % tbl) -- cgit v1.2.3-1-g7c22