mods for sqlite
This commit is contained in:
parent
fb695098ea
commit
fe62e78c5b
|
@ -813,9 +813,11 @@ class Database:
|
||||||
self.fillDefaultData()
|
self.fillDefaultData()
|
||||||
self.commit()
|
self.commit()
|
||||||
except:
|
except:
|
||||||
print "Error creating tables: ", str(sys.exc_value)
|
#print "Error creating tables: ", str(sys.exc_value)
|
||||||
|
err = traceback.extract_tb(sys.exc_info()[2])[-1]
|
||||||
|
print "***Error creating tables: "+err[2]+"("+str(err[1])+"): "+str(sys.exc_info()[1])
|
||||||
self.rollback()
|
self.rollback()
|
||||||
raise fpdb_simple.FpdbError( "Error creating tables " + str(sys.exc_value) )
|
raise
|
||||||
#end def disconnect
|
#end def disconnect
|
||||||
|
|
||||||
def drop_tables(self):
|
def drop_tables(self):
|
||||||
|
@ -845,8 +847,9 @@ class Database:
|
||||||
|
|
||||||
self.commit()
|
self.commit()
|
||||||
except:
|
except:
|
||||||
print "Error dropping tables: " + str(sys.exc_value)
|
print "***Error dropping tables: "+err[2]+"("+str(err[1])+"): "+str(sys.exc_info()[1])
|
||||||
raise fpdb_simple.FpdbError( "Error dropping tables " + str(sys.exc_value) )
|
self.rollback()
|
||||||
|
raise
|
||||||
#end def drop_tables
|
#end def drop_tables
|
||||||
|
|
||||||
def createAllIndexes(self):
|
def createAllIndexes(self):
|
||||||
|
@ -917,7 +920,10 @@ class Database:
|
||||||
c.execute("INSERT INTO Sites (name,currency) VALUES ('PokerStars', 'USD')")
|
c.execute("INSERT INTO Sites (name,currency) VALUES ('PokerStars', 'USD')")
|
||||||
c.execute("INSERT INTO Sites (name,currency) VALUES ('Everleaf', 'USD')")
|
c.execute("INSERT INTO Sites (name,currency) VALUES ('Everleaf', 'USD')")
|
||||||
c.execute("INSERT INTO Sites (name,currency) VALUES ('Win2day', 'USD')")
|
c.execute("INSERT INTO Sites (name,currency) VALUES ('Win2day', 'USD')")
|
||||||
c.execute("INSERT INTO TourneyTypes VALUES (DEFAULT, 1, 0, 0, 0, False);")
|
if self.backend == self.SQLITE:
|
||||||
|
c.execute("INSERT INTO TourneyTypes VALUES (NULL, 1, 0, 0, 0, 0);")
|
||||||
|
else:
|
||||||
|
c.execute("INSERT INTO TourneyTypes VALUES (DEFAULT, 1, 0, 0, 0, False);")
|
||||||
#c.execute("""INSERT INTO TourneyTypes
|
#c.execute("""INSERT INTO TourneyTypes
|
||||||
# (siteId,buyin,fee,knockout,rebuyOrAddon) VALUES
|
# (siteId,buyin,fee,knockout,rebuyOrAddon) VALUES
|
||||||
# (1,0,0,0,?)""",(False,) )
|
# (1,0,0,0,?)""",(False,) )
|
||||||
|
@ -1794,6 +1800,8 @@ if __name__=="__main__":
|
||||||
print "database connection object = ", db_connection.connection
|
print "database connection object = ", db_connection.connection
|
||||||
print "database type = ", db_connection.type
|
print "database type = ", db_connection.type
|
||||||
|
|
||||||
|
db_connection.recreate_tables()
|
||||||
|
|
||||||
h = db_connection.get_last_hand()
|
h = db_connection.get_last_hand()
|
||||||
print "last hand = ", h
|
print "last hand = ", h
|
||||||
|
|
||||||
|
|
172
pyfpdb/SQL.py
172
pyfpdb/SQL.py
|
@ -22,6 +22,7 @@ Set up all of the SQL statements for a given game and database type.
|
||||||
########################################################################
|
########################################################################
|
||||||
|
|
||||||
# Standard Library modules
|
# Standard Library modules
|
||||||
|
import re
|
||||||
|
|
||||||
# pyGTK modules
|
# pyGTK modules
|
||||||
|
|
||||||
|
@ -290,7 +291,7 @@ class Sql:
|
||||||
name TEXT,
|
name TEXT,
|
||||||
siteId INTEGER,
|
siteId INTEGER,
|
||||||
comment TEXT,
|
comment TEXT,
|
||||||
commentTs BLOB,
|
commentTs REAL,
|
||||||
FOREIGN KEY(siteId) REFERENCES Sites(id) ON DELETE CASCADE)"""
|
FOREIGN KEY(siteId) REFERENCES Sites(id) ON DELETE CASCADE)"""
|
||||||
|
|
||||||
|
|
||||||
|
@ -400,12 +401,12 @@ class Sql:
|
||||||
tableName TEXT(20),
|
tableName TEXT(20),
|
||||||
siteHandNo INTEGER,
|
siteHandNo INTEGER,
|
||||||
gametypeId INTEGER,
|
gametypeId INTEGER,
|
||||||
handStart BLOB,
|
handStart REAL,
|
||||||
importTime BLOB,
|
importTime REAL,
|
||||||
seats INTEGER,
|
seats INTEGER,
|
||||||
maxSeats INTEGER,
|
maxSeats INTEGER,
|
||||||
comment TEXT,
|
comment TEXT,
|
||||||
commentTs BLOB,
|
commentTs REAL,
|
||||||
FOREIGN KEY(gametypeId) REFERENCES Gametypes(id) ON DELETE CASCADE)"""
|
FOREIGN KEY(gametypeId) REFERENCES Gametypes(id) ON DELETE CASCADE)"""
|
||||||
|
|
||||||
|
|
||||||
|
@ -425,14 +426,19 @@ class Sql:
|
||||||
elif db_server == 'postgresql':
|
elif db_server == 'postgresql':
|
||||||
self.query['createTourneyTypesTable'] = """CREATE TABLE TourneyTypes (
|
self.query['createTourneyTypesTable'] = """CREATE TABLE TourneyTypes (
|
||||||
id SERIAL, PRIMARY KEY (id),
|
id SERIAL, PRIMARY KEY (id),
|
||||||
siteId INT, FOREIGN KEY (siteId) REFERENCES Sites(id),
|
siteId INT NOT NULL, FOREIGN KEY (siteId) REFERENCES Sites(id),
|
||||||
buyin INT,
|
buyin INT NOT NULL,
|
||||||
fee INT,
|
fee INT NOT NULL,
|
||||||
knockout INT,
|
knockout INT NOT NULL,
|
||||||
rebuyOrAddon BOOLEAN)"""
|
rebuyOrAddon BOOLEAN NOT NULL)"""
|
||||||
elif db_server == 'sqlite':
|
elif db_server == 'sqlite':
|
||||||
self.query['createTourneyTypesTable'] = """ """
|
self.query['createTourneyTypesTable'] = """CREATE TABLE TourneyTypes (
|
||||||
|
id INTEGER PRIMARY KEY,
|
||||||
|
siteId INT NOT NULL,
|
||||||
|
buyin INT NOT NULL,
|
||||||
|
fee INT NOT NULL,
|
||||||
|
knockout INT NOT NULL,
|
||||||
|
rebuyOrAddon BOOLEAN NOT NULL)"""
|
||||||
|
|
||||||
################################
|
################################
|
||||||
# Create Tourneys
|
# Create Tourneys
|
||||||
|
@ -460,15 +466,15 @@ class Sql:
|
||||||
comment TEXT,
|
comment TEXT,
|
||||||
commentTs timestamp without time zone)"""
|
commentTs timestamp without time zone)"""
|
||||||
elif db_server == 'sqlite':
|
elif db_server == 'sqlite':
|
||||||
self.query['createTourneysTable'] = """CREATE TABLE TourneyTypes (
|
self.query['createTourneysTable'] = """CREATE TABLE Tourneys (
|
||||||
id INTEGER PRIMARY KEY,
|
id INTEGER PRIMARY KEY,
|
||||||
siteId INTEGER,
|
tourneyTypeId INT,
|
||||||
buyin INTEGER,
|
siteTourneyNo INT,
|
||||||
fee INTEGER,
|
entries INT,
|
||||||
knockout INTEGER,
|
prizepool INT,
|
||||||
rebuyOrAddon BOOL,
|
startTime REAL,
|
||||||
FOREIGN KEY(siteId) REFERENCES Sites(id) ON DELETE CASCADE)"""
|
comment TEXT,
|
||||||
|
commentTs REAL)"""
|
||||||
################################
|
################################
|
||||||
# Create HandsPlayers
|
# Create HandsPlayers
|
||||||
################################
|
################################
|
||||||
|
@ -709,7 +715,121 @@ class Sql:
|
||||||
|
|
||||||
FOREIGN KEY (tourneysPlayersId) REFERENCES TourneysPlayers(id))"""
|
FOREIGN KEY (tourneysPlayersId) REFERENCES TourneysPlayers(id))"""
|
||||||
elif db_server == 'sqlite':
|
elif db_server == 'sqlite':
|
||||||
self.query['createHandsPlayersTable'] = """ """
|
self.query['createHandsPlayersTable'] = """CREATE TABLE HandsPlayers (
|
||||||
|
id INTEGER PRIMARY KEY,
|
||||||
|
handId INT NOT NULL,
|
||||||
|
playerId INT NOT NULL,
|
||||||
|
startCash INT NOT NULL,
|
||||||
|
position TEXT,
|
||||||
|
seatNo INT NOT NULL,
|
||||||
|
|
||||||
|
card1 INT NOT NULL, /* 0=none, 1-13=2-Ah 14-26=2-Ad 27-39=2-Ac 40-52=2-As */
|
||||||
|
card2 INT NOT NULL,
|
||||||
|
card3 INT,
|
||||||
|
card4 INT,
|
||||||
|
card5 INT,
|
||||||
|
card6 INT,
|
||||||
|
card7 INT,
|
||||||
|
startCards INT,
|
||||||
|
|
||||||
|
ante INT,
|
||||||
|
winnings INT NOT NULL,
|
||||||
|
rake INT NOT NULL,
|
||||||
|
totalProfit INT,
|
||||||
|
comment TEXT,
|
||||||
|
commentTs REAL,
|
||||||
|
tourneysPlayersId INT,
|
||||||
|
tourneyTypeId INT NOT NULL,
|
||||||
|
|
||||||
|
wonWhenSeenStreet1 REAL,
|
||||||
|
wonWhenSeenStreet2 REAL,
|
||||||
|
wonWhenSeenStreet3 REAL,
|
||||||
|
wonWhenSeenStreet4 REAL,
|
||||||
|
wonAtSD REAL,
|
||||||
|
|
||||||
|
street0VPI INT,
|
||||||
|
street0Aggr INT,
|
||||||
|
street0_3BChance INT,
|
||||||
|
street0_3BDone INT,
|
||||||
|
street0_4BChance INT,
|
||||||
|
street0_4BDone INT,
|
||||||
|
other3BStreet0 INT,
|
||||||
|
other4BStreet0 INT,
|
||||||
|
|
||||||
|
street1Seen INT,
|
||||||
|
street2Seen INT,
|
||||||
|
street3Seen INT,
|
||||||
|
street4Seen INT,
|
||||||
|
sawShowdown INT,
|
||||||
|
|
||||||
|
street1Aggr INT,
|
||||||
|
street2Aggr INT,
|
||||||
|
street3Aggr INT,
|
||||||
|
street4Aggr INT,
|
||||||
|
|
||||||
|
otherRaisedStreet0 INT,
|
||||||
|
otherRaisedStreet1 INT,
|
||||||
|
otherRaisedStreet2 INT,
|
||||||
|
otherRaisedStreet3 INT,
|
||||||
|
otherRaisedStreet4 INT,
|
||||||
|
foldToOtherRaisedStreet0 INT,
|
||||||
|
foldToOtherRaisedStreet1 INT,
|
||||||
|
foldToOtherRaisedStreet2 INT,
|
||||||
|
foldToOtherRaisedStreet3 INT,
|
||||||
|
foldToOtherRaisedStreet4 INT,
|
||||||
|
|
||||||
|
stealAttemptChance INT,
|
||||||
|
stealAttempted INT,
|
||||||
|
foldBbToStealChance INT,
|
||||||
|
foldedBbToSteal INT,
|
||||||
|
foldSbToStealChance INT,
|
||||||
|
foldedSbToSteal INT,
|
||||||
|
|
||||||
|
street1CBChance INT,
|
||||||
|
street1CBDone INT,
|
||||||
|
street2CBChance INT,
|
||||||
|
street2CBDone INT,
|
||||||
|
street3CBChance INT,
|
||||||
|
street3CBDone INT,
|
||||||
|
street4CBChance INT,
|
||||||
|
street4CBDone INT,
|
||||||
|
|
||||||
|
foldToStreet1CBChance INT,
|
||||||
|
foldToStreet1CBDone INT,
|
||||||
|
foldToStreet2CBChance INT,
|
||||||
|
foldToStreet2CBDone INT,
|
||||||
|
foldToStreet3CBChance INT,
|
||||||
|
foldToStreet3CBDone INT,
|
||||||
|
foldToStreet4CBChance INT,
|
||||||
|
foldToStreet4CBDone INT,
|
||||||
|
|
||||||
|
street1CheckCallRaiseChance INT,
|
||||||
|
street1CheckCallRaiseDone INT,
|
||||||
|
street2CheckCallRaiseChance INT,
|
||||||
|
street2CheckCallRaiseDone INT,
|
||||||
|
street3CheckCallRaiseChance INT,
|
||||||
|
street3CheckCallRaiseDone INT,
|
||||||
|
street4CheckCallRaiseChance INT,
|
||||||
|
street4CheckCallRaiseDone INT,
|
||||||
|
|
||||||
|
street0Calls INT,
|
||||||
|
street1Calls INT,
|
||||||
|
street2Calls INT,
|
||||||
|
street3Calls INT,
|
||||||
|
street4Calls INT,
|
||||||
|
street0Bets INT,
|
||||||
|
street1Bets INT,
|
||||||
|
street2Bets INT,
|
||||||
|
street3Bets INT,
|
||||||
|
street4Bets INT,
|
||||||
|
street0Raises INT,
|
||||||
|
street1Raises INT,
|
||||||
|
street2Raises INT,
|
||||||
|
street3Raises INT,
|
||||||
|
street4Raises INT,
|
||||||
|
|
||||||
|
actionString REAL)
|
||||||
|
"""
|
||||||
|
|
||||||
|
|
||||||
################################
|
################################
|
||||||
|
@ -1081,7 +1201,7 @@ class Sql:
|
||||||
AND hc.styleKey > %s
|
AND hc.styleKey > %s
|
||||||
/* styleKey is currently 'd' (for date) followed by a yyyymmdd
|
/* styleKey is currently 'd' (for date) followed by a yyyymmdd
|
||||||
date key. Set it to 0000000 or similar to get all records */
|
date key. Set it to 0000000 or similar to get all records */
|
||||||
/* also check activeseats here? even if only 3 groups eg 2-3/4-6/7+ ??
|
/* also check activeseats here even if only 3 groups eg 2-3/4-6/7+
|
||||||
e.g. could use a multiplier:
|
e.g. could use a multiplier:
|
||||||
AND h.seats > X / 1.25 and hp.seats < X * 1.25
|
AND h.seats > X / 1.25 and hp.seats < X * 1.25
|
||||||
where X is the number of active players at the current table (and
|
where X is the number of active players at the current table (and
|
||||||
|
@ -1164,7 +1284,7 @@ class Sql:
|
||||||
date key. Set it to 0000000 or similar to get all records */
|
date key. Set it to 0000000 or similar to get all records */
|
||||||
/* Note: s means the placeholder 'percent's but we can't include that
|
/* Note: s means the placeholder 'percent's but we can't include that
|
||||||
in comments. (db api thinks they are actual arguments)
|
in comments. (db api thinks they are actual arguments)
|
||||||
Could also check activeseats here? even if only 3 groups eg 2-3/4-6/7+ ??
|
Could also check activeseats here even if only 3 groups eg 2-3/4-6/7+
|
||||||
e.g. could use a multiplier:
|
e.g. could use a multiplier:
|
||||||
AND h.seats > s / 1.25 and hp.seats < s * 1.25
|
AND h.seats > s / 1.25 and hp.seats < s * 1.25
|
||||||
where s is the number of active players at the current table (and
|
where s is the number of active players at the current table (and
|
||||||
|
@ -1252,7 +1372,7 @@ class Sql:
|
||||||
INNER JOIN HandsPlayers hp2 ON (hp2.playerId+0 = hp.playerId+0 AND (hp2.handId = h2.id+0)) /* other hands by these players */
|
INNER JOIN HandsPlayers hp2 ON (hp2.playerId+0 = hp.playerId+0 AND (hp2.handId = h2.id+0)) /* other hands by these players */
|
||||||
INNER JOIN Players p ON (p.id = hp2.PlayerId+0)
|
INNER JOIN Players p ON (p.id = hp2.PlayerId+0)
|
||||||
WHERE hp.handId = %s
|
WHERE hp.handId = %s
|
||||||
/* check activeseats once this data returned? (don't want to do that here as it might
|
/* check activeseats once this data returned (don't want to do that here as it might
|
||||||
assume a session ended just because the number of seats dipped for a few hands)
|
assume a session ended just because the number of seats dipped for a few hands)
|
||||||
*/
|
*/
|
||||||
ORDER BY h.handStart desc, hp2.PlayerId
|
ORDER BY h.handStart desc, hp2.PlayerId
|
||||||
|
@ -1331,7 +1451,7 @@ class Sql:
|
||||||
AND hp2.handId = h2.id) /* other hands by these players */
|
AND hp2.handId = h2.id) /* other hands by these players */
|
||||||
INNER JOIN Players p ON (p.id = hp2.PlayerId+0)
|
INNER JOIN Players p ON (p.id = hp2.PlayerId+0)
|
||||||
WHERE h.id = %s
|
WHERE h.id = %s
|
||||||
/* check activeseats once this data returned? (don't want to do that here as it might
|
/* check activeseats once this data returned (don't want to do that here as it might
|
||||||
assume a session ended just because the number of seats dipped for a few hands)
|
assume a session ended just because the number of seats dipped for a few hands)
|
||||||
*/
|
*/
|
||||||
ORDER BY h.handStart desc, hp2.PlayerId
|
ORDER BY h.handStart desc, hp2.PlayerId
|
||||||
|
@ -2450,6 +2570,10 @@ class Sql:
|
||||||
else: # assume postgres
|
else: # assume postgres
|
||||||
self.query['lockForInsert'] = ""
|
self.query['lockForInsert'] = ""
|
||||||
|
|
||||||
|
if db_server == 'sqlite':
|
||||||
|
for k,q in self.query.iteritems():
|
||||||
|
self.query[k] = re.sub('%s','?',q)
|
||||||
|
|
||||||
if __name__== "__main__":
|
if __name__== "__main__":
|
||||||
# just print the default queries and exit
|
# just print the default queries and exit
|
||||||
s = Sql(game = 'razz', type = 'ptracks')
|
s = Sql(game = 'razz', type = 'ptracks')
|
||||||
|
|
Loading…
Reference in New Issue
Block a user