From 9b50987d0cf05d9e8cbe0c5cc97d288770e882e0 Mon Sep 17 00:00:00 2001 From: sqlcoder Date: Tue, 23 Jun 2009 23:44:37 +0100 Subject: [PATCH] add sql param to Database constructor - aim is to have just one SQL instance passed around and to use Database for db connections and methods --- pyfpdb/Database.py | 9 +++++++-- pyfpdb/fpdb.py | 2 +- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/pyfpdb/Database.py b/pyfpdb/Database.py index f652d9a7..392681eb 100755 --- a/pyfpdb/Database.py +++ b/pyfpdb/Database.py @@ -39,7 +39,8 @@ import SQL import Card class Database: - def __init__(self, c, db_name = None, game = None): # db_name and game not used any more + def __init__(self, c, db_name = None, game = None, sql = None): # db_name and game not used any more + print "creating Database instance, sql =", sql self.fdb = fpdb_db.fpdb_db() # sets self.fdb.db self.fdb.cursor and self.fdb.sql self.fdb.do_connect(c) self.connection = self.fdb.db @@ -48,7 +49,11 @@ class Database: self.import_options = c.get_import_parameters() self.type = db_params['db-type'] self.backend = db_params['db-backend'] - self.sql = SQL.Sql(type = self.type, db_server = db_params['db-server']) + # where possible avoid creating new SQL instance by using the global one passed in + if sql == None: + self.sql = SQL.Sql(type = self.type, db_server = db_params['db-server']) + else: + self.sql = sql self.connection.rollback() # To add to config: diff --git a/pyfpdb/fpdb.py b/pyfpdb/fpdb.py index a6d4cb3c..6c982002 100755 --- a/pyfpdb/fpdb.py +++ b/pyfpdb/fpdb.py @@ -396,7 +396,7 @@ class fpdb: # Database connected to successfully, load queries to pass on to other classes self.querydict = FpdbSQLQueries.FpdbSQLQueries(self.db.get_backend_name()) self.sql = SQL.Sql(type = self.settings['db-type'], db_server = self.settings['db-server']) - #self.dbi = Database.Database(self.config, sql = self.sql) # dbi for db interface and to avoid clashes with db/database/etc + self.dbi = Database.Database(self.config, sql = self.sql) # dbi for db interface and to avoid clashes with db/database/etc # can rename later if required self.db.db.rollback() #end def load_profile