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

This commit is contained in:
sqlcoder 2009-06-23 23:44:37 +01:00
parent 84cc951045
commit 9b50987d0c
2 changed files with 8 additions and 3 deletions

View File

@ -39,7 +39,8 @@ import SQL
import Card import Card
class Database: 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 = fpdb_db.fpdb_db() # sets self.fdb.db self.fdb.cursor and self.fdb.sql
self.fdb.do_connect(c) self.fdb.do_connect(c)
self.connection = self.fdb.db self.connection = self.fdb.db
@ -48,7 +49,11 @@ class Database:
self.import_options = c.get_import_parameters() self.import_options = c.get_import_parameters()
self.type = db_params['db-type'] self.type = db_params['db-type']
self.backend = db_params['db-backend'] self.backend = db_params['db-backend']
# 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']) self.sql = SQL.Sql(type = self.type, db_server = db_params['db-server'])
else:
self.sql = sql
self.connection.rollback() self.connection.rollback()
# To add to config: # To add to config:

View File

@ -396,7 +396,7 @@ class fpdb:
# Database connected to successfully, load queries to pass on to other classes # Database connected to successfully, load queries to pass on to other classes
self.querydict = FpdbSQLQueries.FpdbSQLQueries(self.db.get_backend_name()) 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.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 # can rename later if required
self.db.db.rollback() self.db.db.rollback()
#end def load_profile #end def load_profile