Add exception for not being able to connect to MySQL, make use of it to pop up an error box

This commit is contained in:
Eric Blade 2009-10-09 07:31:25 -04:00
parent 971a282383
commit ee864033ee
3 changed files with 11 additions and 3 deletions

View File

@ -17,5 +17,8 @@ class FpdbParseError(FpdbError):
class FpdbDatabaseError(FpdbError):
pass
class FpdbMySQLFailedError(FpdbDatabaseError):
pass
class DuplicateError(FpdbError):
pass

View File

@ -76,7 +76,7 @@ import SQL
import Database
import FpdbSQLQueries
import Configuration
from Exceptions import *
import Exceptions
VERSION = "0.11"
@ -453,7 +453,12 @@ class fpdb:
self.db.disconnect()
self.sql = SQL.Sql(type = self.settings['db-type'], db_server = self.settings['db-server'])
self.db = Database.Database(self.config, sql = self.sql)
try:
self.db = Database.Database(self.config, sql = self.sql)
except Exceptions.FpdbMySQLFailedError:
self.warning_box("Unable to connect to MySQL! Is the MySQL server running?!", "FPDB ERROR")
exit()
if self.db.fdb.wrongDbVersion:
diaDbVersionWarning = gtk.Dialog(title="Strong Warning - Invalid database version", parent=None, flags=0, buttons=(gtk.STOCK_OK,gtk.RESPONSE_OK))

View File

@ -80,7 +80,7 @@ class fpdb_db:
try:
self.db = MySQLdb.connect(host = host, user = user, passwd = password, db = database, use_unicode=True)
except:
raise FpdbError("MySQL connection failed")
raise FpdbMySQLFailedError("MySQL connection failed")
elif backend==fpdb_db.PGSQL:
import psycopg2
import psycopg2.extensions