From 2813bb7fe67358634d9107872891db2e6113fedb Mon Sep 17 00:00:00 2001 From: Steffen Schaumburg Date: Sat, 25 Dec 2010 20:38:18 +0100 Subject: [PATCH] prevent crasher when connecting to empty mysql (presumably this bug also applied to postgres) --- pyfpdb/Database.py | 5 +++-- pyfpdb/fpdb.pyw | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/pyfpdb/Database.py b/pyfpdb/Database.py index b9786b16..7caeaae8 100644 --- a/pyfpdb/Database.py +++ b/pyfpdb/Database.py @@ -244,8 +244,9 @@ class Database: # create index indexname on tablename (col); - def __init__(self, c, sql = None, autoconnect = True): + def __init__(self, c, sql = None, autoconnect = True, create_db=False): #log = Configuration.get_logger("logging.conf", "db", log_dir=c.dir_log) + print "create DB=",create_db log.debug(_("Creating Database instance, sql = %s") % sql) self.config = c self.__connected = False @@ -307,7 +308,7 @@ class Database: self.saveActions = False if self.import_options['saveActions'] == False else True - if self.is_connected(): + if self.is_connected() and not create_db: self.get_sites() self.connection.rollback() # make sure any locks taken so far are released #end def __init__ diff --git a/pyfpdb/fpdb.pyw b/pyfpdb/fpdb.pyw index fe6e1124..ff9e7c45 100755 --- a/pyfpdb/fpdb.pyw +++ b/pyfpdb/fpdb.pyw @@ -880,7 +880,7 @@ class fpdb: self.sql = SQL.Sql(db_server = self.settings['db-server']) err_msg = None try: - self.db = Database.Database(self.config, sql = self.sql) + self.db = Database.Database(self.config, sql = self.sql, create_db=create_db) if self.db.get_backend_name() == 'SQLite': # tell sqlite users where the db file is print (_("Connected to SQLite: %s") % self.db.db_path)