mods for sqlite
This commit is contained in:
parent
fb695098ea
commit
fe62e78c5b
|
@ -813,9 +813,11 @@ class Database:
|
|||
self.fillDefaultData()
|
||||
self.commit()
|
||||
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()
|
||||
raise fpdb_simple.FpdbError( "Error creating tables " + str(sys.exc_value) )
|
||||
raise
|
||||
#end def disconnect
|
||||
|
||||
def drop_tables(self):
|
||||
|
@ -845,8 +847,9 @@ class Database:
|
|||
|
||||
self.commit()
|
||||
except:
|
||||
print "Error dropping tables: " + str(sys.exc_value)
|
||||
raise fpdb_simple.FpdbError( "Error dropping tables " + str(sys.exc_value) )
|
||||
print "***Error dropping tables: "+err[2]+"("+str(err[1])+"): "+str(sys.exc_info()[1])
|
||||
self.rollback()
|
||||
raise
|
||||
#end def drop_tables
|
||||
|
||||
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 ('Everleaf', '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
|
||||
# (siteId,buyin,fee,knockout,rebuyOrAddon) VALUES
|
||||
# (1,0,0,0,?)""",(False,) )
|
||||
|
@ -1794,6 +1800,8 @@ if __name__=="__main__":
|
|||
print "database connection object = ", db_connection.connection
|
||||
print "database type = ", db_connection.type
|
||||
|
||||
db_connection.recreate_tables()
|
||||
|
||||
h = db_connection.get_last_hand()
|
||||
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
|
||||
import re
|
||||
|
||||
# pyGTK modules
|
||||
|
||||
|
@ -290,7 +291,7 @@ class Sql:
|
|||
name TEXT,
|
||||
siteId INTEGER,
|
||||
comment TEXT,
|
||||
commentTs BLOB,
|
||||
commentTs REAL,
|
||||
FOREIGN KEY(siteId) REFERENCES Sites(id) ON DELETE CASCADE)"""
|
||||
|
||||
|
||||
|
@ -400,12 +401,12 @@ class Sql:
|
|||
tableName TEXT(20),
|
||||
siteHandNo INTEGER,
|
||||
gametypeId INTEGER,
|
||||
handStart BLOB,
|
||||
importTime BLOB,
|
||||
handStart REAL,
|
||||
importTime REAL,
|
||||
seats INTEGER,
|
||||
maxSeats INTEGER,
|
||||
comment TEXT,
|
||||
commentTs BLOB,
|
||||
commentTs REAL,
|
||||
FOREIGN KEY(gametypeId) REFERENCES Gametypes(id) ON DELETE CASCADE)"""
|
||||
|
||||
|
||||
|
@ -425,14 +426,19 @@ class Sql:
|
|||
elif db_server == 'postgresql':
|
||||
self.query['createTourneyTypesTable'] = """CREATE TABLE TourneyTypes (
|
||||
id SERIAL, PRIMARY KEY (id),
|
||||
siteId INT, FOREIGN KEY (siteId) REFERENCES Sites(id),
|
||||
buyin INT,
|
||||
fee INT,
|
||||
knockout INT,
|
||||
rebuyOrAddon BOOLEAN)"""
|
||||
siteId INT NOT NULL, FOREIGN KEY (siteId) REFERENCES Sites(id),
|
||||
buyin INT NOT NULL,
|
||||
fee INT NOT NULL,
|
||||
knockout INT NOT NULL,
|
||||
rebuyOrAddon BOOLEAN NOT NULL)"""
|
||||
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
|
||||
|
@ -460,15 +466,15 @@ class Sql:
|
|||
comment TEXT,
|
||||
commentTs timestamp without time zone)"""
|
||||
elif db_server == 'sqlite':
|
||||
self.query['createTourneysTable'] = """CREATE TABLE TourneyTypes (
|
||||
self.query['createTourneysTable'] = """CREATE TABLE Tourneys (
|
||||
id INTEGER PRIMARY KEY,
|
||||
siteId INTEGER,
|
||||
buyin INTEGER,
|
||||
fee INTEGER,
|
||||
knockout INTEGER,
|
||||
rebuyOrAddon BOOL,
|
||||
FOREIGN KEY(siteId) REFERENCES Sites(id) ON DELETE CASCADE)"""
|
||||
|
||||
tourneyTypeId INT,
|
||||
siteTourneyNo INT,
|
||||
entries INT,
|
||||
prizepool INT,
|
||||
startTime REAL,
|
||||
comment TEXT,
|
||||
commentTs REAL)"""
|
||||
################################
|
||||
# Create HandsPlayers
|
||||
################################
|
||||
|
@ -709,7 +715,121 @@ class Sql:
|
|||
|
||||
FOREIGN KEY (tourneysPlayersId) REFERENCES TourneysPlayers(id))"""
|
||||
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
|
||||
/* styleKey is currently 'd' (for date) followed by a yyyymmdd
|
||||
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:
|
||||
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
|
||||
|
@ -1164,7 +1284,7 @@ class Sql:
|
|||
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
|
||||
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:
|
||||
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
|
||||
|
@ -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 Players p ON (p.id = hp2.PlayerId+0)
|
||||
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)
|
||||
*/
|
||||
ORDER BY h.handStart desc, hp2.PlayerId
|
||||
|
@ -1331,7 +1451,7 @@ class Sql:
|
|||
AND hp2.handId = h2.id) /* other hands by these players */
|
||||
INNER JOIN Players p ON (p.id = hp2.PlayerId+0)
|
||||
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)
|
||||
*/
|
||||
ORDER BY h.handStart desc, hp2.PlayerId
|
||||
|
@ -2450,6 +2570,10 @@ class Sql:
|
|||
else: # assume postgres
|
||||
self.query['lockForInsert'] = ""
|
||||
|
||||
if db_server == 'sqlite':
|
||||
for k,q in self.query.iteritems():
|
||||
self.query[k] = re.sub('%s','?',q)
|
||||
|
||||
if __name__== "__main__":
|
||||
# just print the default queries and exit
|
||||
s = Sql(game = 'razz', type = 'ptracks')
|
||||
|
|
Loading…
Reference in New Issue
Block a user