Database: re-write and fix drop_tables
Exceptions: add FpdbDatabaseError SQL: default all tourneytypeids to 1 fpdb_import: import error tuples set to right size
This commit is contained in:
parent
9a44a2efef
commit
9fa57b6014
|
@ -884,35 +884,51 @@ class Database:
|
|||
|
||||
def drop_tables(self):
|
||||
"""Drops the fpdb tables from the current db"""
|
||||
|
||||
try:
|
||||
c = self.get_cursor()
|
||||
if(self.get_backend_name() == 'MySQL InnoDB'):
|
||||
#Databases with FOREIGN KEY support need this switched of before you can drop tables
|
||||
self.drop_referential_integrity()
|
||||
|
||||
# Query the DB to see what tables exist
|
||||
c.execute(self.sql.query['list_tables'])
|
||||
for table in c:
|
||||
c.execute(self.sql.query['drop_table'] + table[0])
|
||||
elif(self.get_backend_name() == 'PostgreSQL'):
|
||||
self.commit()# I have no idea why this makes the query work--REB 07OCT2008
|
||||
c.execute(self.sql.query['list_tables'])
|
||||
tables = c.fetchall()
|
||||
for table in tables:
|
||||
c.execute(self.sql.query['drop_table'] + table[0] + ' cascade')
|
||||
elif(self.get_backend_name() == 'SQLite'):
|
||||
c.execute(self.sql.query['list_tables'])
|
||||
for table in c.fetchall():
|
||||
log.debug(self.sql.query['drop_table'] + table[0])
|
||||
c.execute(self.sql.query['drop_table'] + table[0])
|
||||
|
||||
self.commit()
|
||||
except:
|
||||
err = traceback.extract_tb(sys.exc_info()[2])[-1]
|
||||
print "***Error dropping tables: "+err[2]+"("+str(err[1])+"): "+str(sys.exc_info()[1])
|
||||
self.rollback()
|
||||
raise
|
||||
print "*** Error unable to get cursor"
|
||||
else:
|
||||
backend = self.get_backend_name()
|
||||
if backend == 'MySQL InnoDB': # what happens if someone is using MyISAM?
|
||||
try:
|
||||
self.drop_referential_integrity() # needed to drop tables with foreign keys
|
||||
c.execute(self.sql.query['list_tables'])
|
||||
tables = c.fetchall()
|
||||
for table in tables:
|
||||
c.execute(self.sql.query['drop_table'] + table[0])
|
||||
except:
|
||||
err = traceback.extract_tb(sys.exc_info()[2])[-1]
|
||||
print "***Error dropping tables: "+err[2]+"("+str(err[1])+"): "+str(sys.exc_info()[1])
|
||||
self.rollback()
|
||||
elif backend == 'PostgreSQL':
|
||||
try:
|
||||
self.commit()
|
||||
c.execute(self.sql.query['list_tables'])
|
||||
tables = c.fetchall()
|
||||
for table in tables:
|
||||
c.execute(self.sql.query['drop_table'] + table[0] + ' cascade')
|
||||
except:
|
||||
err = traceback.extract_tb(sys.exc_info()[2])[-1]
|
||||
print "***Error dropping tables: "+err[2]+"("+str(err[1])+"): "+str(sys.exc_info()[1])
|
||||
self.rollback()
|
||||
elif backend == 'SQLite':
|
||||
try:
|
||||
c.execute(self.sql.query['list_tables'])
|
||||
for table in c.fetchall():
|
||||
log.debug(self.sql.query['drop_table'] + table[0])
|
||||
c.execute(self.sql.query['drop_table'] + table[0])
|
||||
except:
|
||||
err = traceback.extract_tb(sys.exc_info()[2])[-1]
|
||||
print "***Error dropping tables: "+err[2]+"("+str(err[1])+"): "+str(sys.exc_info()[1])
|
||||
self.rollback()
|
||||
try:
|
||||
self.commit()
|
||||
except:
|
||||
print "*** Error in committing table drop"
|
||||
err = traceback.extract_tb(sys.exc_info()[2])[-1]
|
||||
print "***Error dropping tables: "+err[2]+"("+str(err[1])+"): "+str(sys.exc_info()[1])
|
||||
self.rollback()
|
||||
#end def drop_tables
|
||||
|
||||
def createAllIndexes(self):
|
||||
|
@ -998,7 +1014,7 @@ class Database:
|
|||
if self.backend == self.SQLITE:
|
||||
c.execute("INSERT INTO TourneyTypes (id, siteId, buyin, fee) VALUES (NULL, 1, 0, 0);")
|
||||
else:
|
||||
c.execute("INSERT INTO TourneyTypes (siteId, buyin, fee) VALUES (1, 0, 0);")
|
||||
c.execute("insert into tourneytypes values (0,1,0,0,0,0,0,null,0,0,0);")
|
||||
|
||||
#end def fillDefaultData
|
||||
|
||||
|
|
|
@ -14,5 +14,8 @@ class FpdbParseError(FpdbError):
|
|||
else:
|
||||
return repr(self.value)
|
||||
|
||||
class FpdbDatabaseError(FpdbError):
|
||||
pass
|
||||
|
||||
class DuplicateError(FpdbError):
|
||||
pass
|
||||
|
|
|
@ -370,7 +370,7 @@ class Sql:
|
|||
if db_server == 'mysql':
|
||||
self.query['createTourneysTable'] = """CREATE TABLE Tourneys (
|
||||
id INT UNSIGNED AUTO_INCREMENT NOT NULL, PRIMARY KEY (id),
|
||||
tourneyTypeId SMALLINT UNSIGNED NOT NULL, FOREIGN KEY (tourneyTypeId) REFERENCES TourneyTypes(id),
|
||||
tourneyTypeId SMALLINT UNSIGNED NOT NULL DEFAULT 1, FOREIGN KEY (tourneyTypeId) REFERENCES TourneyTypes(id),
|
||||
siteTourneyNo BIGINT NOT NULL,
|
||||
entries INT NOT NULL,
|
||||
prizepool INT NOT NULL,
|
||||
|
@ -392,7 +392,7 @@ class Sql:
|
|||
elif db_server == 'postgresql':
|
||||
self.query['createTourneysTable'] = """CREATE TABLE Tourneys (
|
||||
id SERIAL, PRIMARY KEY (id),
|
||||
tourneyTypeId INT, FOREIGN KEY (tourneyTypeId) REFERENCES TourneyTypes(id),
|
||||
tourneyTypeId INT DEFAULT 1, FOREIGN KEY (tourneyTypeId) REFERENCES TourneyTypes(id),
|
||||
siteTourneyNo BIGINT,
|
||||
entries INT,
|
||||
prizepool INT,
|
||||
|
@ -413,7 +413,7 @@ class Sql:
|
|||
elif db_server == 'sqlite':
|
||||
self.query['createTourneysTable'] = """CREATE TABLE Tourneys (
|
||||
id INTEGER PRIMARY KEY,
|
||||
tourneyTypeId INT,
|
||||
tourneyTypeId INT DEFAULT 1,
|
||||
siteTourneyNo INT,
|
||||
entries INT,
|
||||
prizepool INT,
|
||||
|
@ -460,7 +460,7 @@ class Sql:
|
|||
comment text,
|
||||
commentTs DATETIME,
|
||||
tourneysPlayersId BIGINT UNSIGNED,
|
||||
tourneyTypeId SMALLINT UNSIGNED NOT NULL, FOREIGN KEY (tourneyTypeId) REFERENCES TourneyTypes(id),
|
||||
tourneyTypeId SMALLINT UNSIGNED NOT NULL DEFAULT 1, FOREIGN KEY (tourneyTypeId) REFERENCES TourneyTypes(id),
|
||||
|
||||
wonWhenSeenStreet1 FLOAT,
|
||||
wonWhenSeenStreet2 FLOAT,
|
||||
|
@ -578,7 +578,7 @@ class Sql:
|
|||
comment text,
|
||||
commentTs timestamp without time zone,
|
||||
tourneysPlayersId BIGINT,
|
||||
tourneyTypeId INT NOT NULL, FOREIGN KEY (tourneyTypeId) REFERENCES TourneyTypes(id),
|
||||
tourneyTypeId INT NOT NULL DEFAULT 1, FOREIGN KEY (tourneyTypeId) REFERENCES TourneyTypes(id),
|
||||
|
||||
wonWhenSeenStreet1 FLOAT,
|
||||
wonWhenSeenStreet2 FLOAT,
|
||||
|
@ -695,7 +695,7 @@ class Sql:
|
|||
comment TEXT,
|
||||
commentTs REAL,
|
||||
tourneysPlayersId INT,
|
||||
tourneyTypeId INT NOT NULL,
|
||||
tourneyTypeId INT NOT NULL DEFAULT 1,
|
||||
|
||||
wonWhenSeenStreet1 REAL,
|
||||
wonWhenSeenStreet2 REAL,
|
||||
|
@ -865,7 +865,7 @@ class Sql:
|
|||
playerId INT UNSIGNED NOT NULL, FOREIGN KEY (playerId) REFERENCES Players(id),
|
||||
activeSeats SMALLINT NOT NULL,
|
||||
position CHAR(1),
|
||||
tourneyTypeId SMALLINT UNSIGNED NOT NULL, FOREIGN KEY (tourneyTypeId) REFERENCES TourneyTypes(id),
|
||||
tourneyTypeId SMALLINT UNSIGNED NOT NULL DEFAULT 1, FOREIGN KEY (tourneyTypeId) REFERENCES TourneyTypes(id),
|
||||
styleKey CHAR(7) NOT NULL, /* 1st char is style (A/T/H/S), other 6 are the key */
|
||||
HDs INT NOT NULL,
|
||||
|
||||
|
@ -966,7 +966,7 @@ class Sql:
|
|||
playerId INT, FOREIGN KEY (playerId) REFERENCES Players(id),
|
||||
activeSeats SMALLINT,
|
||||
position CHAR(1),
|
||||
tourneyTypeId INT, FOREIGN KEY (tourneyTypeId) REFERENCES TourneyTypes(id),
|
||||
tourneyTypeId INT DEFAULT 1, FOREIGN KEY (tourneyTypeId) REFERENCES TourneyTypes(id),
|
||||
styleKey CHAR(7) NOT NULL, /* 1st char is style (A/T/H/S), other 6 are the key */
|
||||
HDs INT,
|
||||
|
||||
|
@ -1065,7 +1065,7 @@ class Sql:
|
|||
playerId INT,
|
||||
activeSeats INT,
|
||||
position TEXT,
|
||||
tourneyTypeId INT,
|
||||
tourneyTypeId INT DEFAULT 1,
|
||||
styleKey TEXT NOT NULL, /* 1st char is style (A/T/H/S), other 6 are the key */
|
||||
HDs INT,
|
||||
|
||||
|
|
|
@ -418,10 +418,10 @@ class Importer:
|
|||
else:
|
||||
# conversion didn't work
|
||||
# TODO: appropriate response?
|
||||
return (0, 0, 0, 1, 0, -1)
|
||||
return (0, 0, 0, 1, 0)
|
||||
else:
|
||||
log.warning("Unknown filter filter_name:'%s' in filter:'%s'" %(filter_name, filter))
|
||||
return (0, 0, 0, 1, 0, -1)
|
||||
return (0, 0, 0, 1, 0)
|
||||
|
||||
#This will barf if conv.getStatus != True
|
||||
return (stored, duplicates, partial, errors, ttime)
|
||||
|
|
Loading…
Reference in New Issue
Block a user