Correctly hand remote and local postgres dbs. Use get_db_parmeters().
This commit is contained in:
parent
441b300cff
commit
9826138744
|
@ -26,6 +26,7 @@ Create and manage the database objects.
|
||||||
# Standard Library modules
|
# Standard Library modules
|
||||||
import sys
|
import sys
|
||||||
import traceback
|
import traceback
|
||||||
|
import string
|
||||||
|
|
||||||
# pyGTK modules
|
# pyGTK modules
|
||||||
|
|
||||||
|
@ -35,18 +36,21 @@ import SQL
|
||||||
|
|
||||||
class Database:
|
class Database:
|
||||||
def __init__(self, c, db_name, game):
|
def __init__(self, c, db_name, game):
|
||||||
if c.supported_databases[db_name].db_server == 'postgresql':
|
db_params = c.get_db_parameters()
|
||||||
# psycopg2 database module for posgres via DB-API
|
if (string.lower(db_params['db-server']) == 'postgresql' or
|
||||||
import psycopg2
|
string.lower(db_params['db-server']) == 'postgres'):
|
||||||
|
import psycopg2 # posgres via DB-API
|
||||||
import psycopg2.extensions
|
import psycopg2.extensions
|
||||||
psycopg2.extensions.register_type(psycopg2.extensions.UNICODE)
|
psycopg2.extensions.register_type(psycopg2.extensions.UNICODE)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
# self.connection = psycopg2.connect(host = c.supported_databases[db_name].db_ip,
|
if db_params['db-host'] == 'localhost' or db_params['db-host'] == '127.0.0.1':
|
||||||
# user = c.supported_databases[db_name].db_user,
|
self.connection = psycopg2.connect(database = db_params['db-databaseName'])
|
||||||
# password = c.supported_databases[db_name].db_pass,
|
else:
|
||||||
# database = c.supported_databases[db_name].db_name)
|
self.connection = psycopg2.connect(host = db_params['db-host'],
|
||||||
self.connection = psycopg2.connect(database = c.supported_databases[db_name].db_name)
|
user = db_params['db-user'],
|
||||||
|
password = db_params['db-password'],
|
||||||
|
database = db_params['db-databaseName'])
|
||||||
except:
|
except:
|
||||||
print "Error opening database connection %s. See error log file." % (file)
|
print "Error opening database connection %s. See error log file." % (file)
|
||||||
traceback.print_exc(file=sys.stderr)
|
traceback.print_exc(file=sys.stderr)
|
||||||
|
@ -54,14 +58,13 @@ class Database:
|
||||||
sys.stdin.readline()
|
sys.stdin.readline()
|
||||||
sys.exit()
|
sys.exit()
|
||||||
|
|
||||||
elif c.supported_databases[db_name].db_server == 'mysql':
|
elif string.lower(db_params['db-server']) == 'mysql':
|
||||||
# mysql bindings
|
import MySQLdb # mysql bindings
|
||||||
import MySQLdb
|
|
||||||
try:
|
try:
|
||||||
self.connection = MySQLdb.connect(host = c.supported_databases[db_name].db_ip,
|
self.connection = MySQLdb.connect(host = db_params['db-host'],
|
||||||
user = c.supported_databases[db_name].db_user,
|
user = db_params['db-user'],
|
||||||
passwd = c.supported_databases[db_name].db_pass,
|
passwd = db_params['db-password'],
|
||||||
db = c.supported_databases[db_name].db_name)
|
db = db_params['db-databaseName'])
|
||||||
cur_iso = self.connection.cursor()
|
cur_iso = self.connection.cursor()
|
||||||
cur_iso.execute('SET SESSION TRANSACTION ISOLATION LEVEL READ COMMITTED')
|
cur_iso.execute('SET SESSION TRANSACTION ISOLATION LEVEL READ COMMITTED')
|
||||||
cur_iso.close()
|
cur_iso.close()
|
||||||
|
@ -79,7 +82,7 @@ class Database:
|
||||||
print "press enter to continue"
|
print "press enter to continue"
|
||||||
sys.exit()
|
sys.exit()
|
||||||
|
|
||||||
self.type = c.supported_databases[db_name].db_type
|
self.type = db_params['db-type']
|
||||||
self.sql = SQL.Sql(game = game, type = self.type)
|
self.sql = SQL.Sql(game = game, type = self.type)
|
||||||
|
|
||||||
def close_connection(self):
|
def close_connection(self):
|
||||||
|
|
Loading…
Reference in New Issue
Block a user