p82 - made import of SQL interface libraries into try-except loop to facilitate choosing between mysql and pgsql

This commit is contained in:
steffen123
2008-09-16 22:19:50 +01:00
parent 092f68e259
commit cd212af029
5 changed files with 50 additions and 21 deletions
+5 -3
View File
@@ -32,12 +32,14 @@ import sys
import Configuration
import SQL
try:
# pgdb database module for posgres via DB-API
import psycopg2
import psycopg2
# pgdb uses pyformat. is that fixed or an option?
# mysql bindings
import MySQLdb
import MySQLdb
except:
pass
class Database:
def __init__(self, c, db_name, game):
+17 -1
View File
@@ -20,7 +20,23 @@ import pygtk
pygtk.require('2.0')
import gtk
import os
import MySQLdb
try:
import MySQLdb
except:
diaSQLLibMissing = gtk.Dialog(title="Fatal Error - SQL interface library missing", parent=None, flags=0, buttons=(gtk.STOCK_QUIT,gtk.RESPONSE_OK))
label = gtk.Label("Please note that the table viewer only works with MySQL, if you use PostgreSQL this error is expected.")
diaSQLLibMissing.vbox.add(label)
label.show()
label = gtk.Label("Since the HUD now runs on all supported plattforms I do not see any point in table viewer anymore, if you disagree please send a message to steffen@sycamoretest.info")
diaSQLLibMissing.vbox.add(label)
label.show()
response = diaSQLLibMissing.run()
#sys.exit(1)
import fpdb_import
import fpdb_db
-3
View File
@@ -35,13 +35,10 @@ class fpdb_db:
self.database=database
self.user=user
self.password=password
#print "fpdb_db.connect, database:",database
if backend==self.MYSQL_INNODB:
import MySQLdb
self.db=MySQLdb.connect(host = host, user = user, passwd = password, db = database)
elif backend==self.PGSQL:
# import pgdb
# self.db = pgdb.connect(dsn=host+":"+database, user='postgres', password=password)
import psycopg2
self.db = psycopg2.connect(host = host, user = user, password = password, database = database)
else:
+17 -3
View File
@@ -18,9 +18,19 @@
#see status.txt for site/games support info
import sys
import MySQLdb
import psycopg2
#import pgdb
try:
import MySQLdb
mysqlLibFound=True
except:
pass
try:
import psycopg2
pgsqlLibFound=True
except:
pass
import math
import os
import datetime
@@ -47,9 +57,13 @@ def import_file_dict(options, settings, callHud=False):
#connect to DB
if options.settings['db-backend'] == 2:
if not mysqlLibFound:
raise fpdb_simple.FpdbError("interface library MySQLdb not found but MySQL selected as backend - please install the library or change the config file")
db = MySQLdb.connect(host = options.server, user = options.user,
passwd = options.password, db = options.database)
elif options.settings['db-backend'] == 3:
if not pgsqlLibFound:
raise fpdb_simple.FpdbError("interface library psycopg2 not found but PostgreSQL selected as backend - please install the library or change the config file")
db = psycopg2.connect(host = options.server, user = options.user,
password = options.password, database = options.database)
elif options.settings['db-backend'] == 4: