move most stuff from fpdb_db.py to Database.py and simplify db connections in fpdb_import
This commit is contained in:
parent
3cc5ed8024
commit
298de5dc15
|
@ -29,6 +29,8 @@ import traceback
|
||||||
from datetime import datetime, date, time, timedelta
|
from datetime import datetime, date, time, timedelta
|
||||||
from time import time, strftime
|
from time import time, strftime
|
||||||
import string
|
import string
|
||||||
|
import re
|
||||||
|
import logging
|
||||||
|
|
||||||
# pyGTK modules
|
# pyGTK modules
|
||||||
|
|
||||||
|
@ -45,6 +47,112 @@ class Database:
|
||||||
PGSQL = 3
|
PGSQL = 3
|
||||||
SQLITE = 4
|
SQLITE = 4
|
||||||
|
|
||||||
|
# Data Structures for index and foreign key creation
|
||||||
|
# drop_code is an int with possible values: 0 - don't drop for bulk import
|
||||||
|
# 1 - drop during bulk import
|
||||||
|
# db differences:
|
||||||
|
# - note that mysql automatically creates indexes on constrained columns when
|
||||||
|
# foreign keys are created, while postgres does not. Hence the much longer list
|
||||||
|
# of indexes is required for postgres.
|
||||||
|
# all primary keys are left on all the time
|
||||||
|
#
|
||||||
|
# table column drop_code
|
||||||
|
|
||||||
|
indexes = [
|
||||||
|
[ ] # no db with index 0
|
||||||
|
, [ ] # no db with index 1
|
||||||
|
, [ # indexes for mysql (list index 2)
|
||||||
|
{'tab':'Players', 'col':'name', 'drop':0}
|
||||||
|
, {'tab':'Hands', 'col':'siteHandNo', 'drop':0}
|
||||||
|
, {'tab':'Tourneys', 'col':'siteTourneyNo', 'drop':0}
|
||||||
|
]
|
||||||
|
, [ # indexes for postgres (list index 3)
|
||||||
|
{'tab':'Boardcards', 'col':'handId', 'drop':0}
|
||||||
|
, {'tab':'Gametypes', 'col':'siteId', 'drop':0}
|
||||||
|
, {'tab':'Hands', 'col':'gametypeId', 'drop':0} # mct 22/3/09
|
||||||
|
, {'tab':'Hands', 'col':'siteHandNo', 'drop':0}
|
||||||
|
, {'tab':'HandsActions', 'col':'handsPlayerId', 'drop':0}
|
||||||
|
, {'tab':'HandsPlayers', 'col':'handId', 'drop':1}
|
||||||
|
, {'tab':'HandsPlayers', 'col':'playerId', 'drop':1}
|
||||||
|
, {'tab':'HandsPlayers', 'col':'tourneysPlayersId', 'drop':0}
|
||||||
|
, {'tab':'HudCache', 'col':'gametypeId', 'drop':1}
|
||||||
|
, {'tab':'HudCache', 'col':'playerId', 'drop':0}
|
||||||
|
, {'tab':'HudCache', 'col':'tourneyTypeId', 'drop':0}
|
||||||
|
, {'tab':'Players', 'col':'siteId', 'drop':1}
|
||||||
|
, {'tab':'Players', 'col':'name', 'drop':0}
|
||||||
|
, {'tab':'Tourneys', 'col':'tourneyTypeId', 'drop':1}
|
||||||
|
, {'tab':'Tourneys', 'col':'siteTourneyNo', 'drop':0}
|
||||||
|
, {'tab':'TourneysPlayers', 'col':'playerId', 'drop':0}
|
||||||
|
, {'tab':'TourneysPlayers', 'col':'tourneyId', 'drop':0}
|
||||||
|
, {'tab':'TourneyTypes', 'col':'siteId', 'drop':0}
|
||||||
|
]
|
||||||
|
, [ # indexes for sqlite (list index 4)
|
||||||
|
]
|
||||||
|
]
|
||||||
|
|
||||||
|
foreignKeys = [
|
||||||
|
[ ] # no db with index 0
|
||||||
|
, [ ] # no db with index 1
|
||||||
|
, [ # foreign keys for mysql
|
||||||
|
{'fktab':'Hands', 'fkcol':'gametypeId', 'rtab':'Gametypes', 'rcol':'id', 'drop':1}
|
||||||
|
, {'fktab':'HandsPlayers', 'fkcol':'handId', 'rtab':'Hands', 'rcol':'id', 'drop':1}
|
||||||
|
, {'fktab':'HandsPlayers', 'fkcol':'playerId', 'rtab':'Players', 'rcol':'id', 'drop':1}
|
||||||
|
, {'fktab':'HandsActions', 'fkcol':'handsPlayerId', 'rtab':'HandsPlayers', 'rcol':'id', 'drop':1}
|
||||||
|
, {'fktab':'HudCache', 'fkcol':'gametypeId', 'rtab':'Gametypes', 'rcol':'id', 'drop':1}
|
||||||
|
, {'fktab':'HudCache', 'fkcol':'playerId', 'rtab':'Players', 'rcol':'id', 'drop':0}
|
||||||
|
, {'fktab':'HudCache', 'fkcol':'tourneyTypeId', 'rtab':'TourneyTypes', 'rcol':'id', 'drop':1}
|
||||||
|
]
|
||||||
|
, [ # foreign keys for postgres
|
||||||
|
{'fktab':'Hands', 'fkcol':'gametypeId', 'rtab':'Gametypes', 'rcol':'id', 'drop':1}
|
||||||
|
, {'fktab':'HandsPlayers', 'fkcol':'handId', 'rtab':'Hands', 'rcol':'id', 'drop':1}
|
||||||
|
, {'fktab':'HandsPlayers', 'fkcol':'playerId', 'rtab':'Players', 'rcol':'id', 'drop':1}
|
||||||
|
, {'fktab':'HandsActions', 'fkcol':'handsPlayerId', 'rtab':'HandsPlayers', 'rcol':'id', 'drop':1}
|
||||||
|
, {'fktab':'HudCache', 'fkcol':'gametypeId', 'rtab':'Gametypes', 'rcol':'id', 'drop':1}
|
||||||
|
, {'fktab':'HudCache', 'fkcol':'playerId', 'rtab':'Players', 'rcol':'id', 'drop':0}
|
||||||
|
, {'fktab':'HudCache', 'fkcol':'tourneyTypeId', 'rtab':'TourneyTypes', 'rcol':'id', 'drop':1}
|
||||||
|
]
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
|
# MySQL Notes:
|
||||||
|
# "FOREIGN KEY (handId) REFERENCES Hands(id)" - requires index on Hands.id
|
||||||
|
# - creates index handId on <thistable>.handId
|
||||||
|
# alter table t drop foreign key fk
|
||||||
|
# alter table t add foreign key (fkcol) references tab(rcol)
|
||||||
|
# alter table t add constraint c foreign key (fkcol) references tab(rcol)
|
||||||
|
# (fkcol is used for foreigh key name)
|
||||||
|
|
||||||
|
# mysql to list indexes:
|
||||||
|
# SELECT table_name, index_name, non_unique, column_name
|
||||||
|
# FROM INFORMATION_SCHEMA.STATISTICS
|
||||||
|
# WHERE table_name = 'tbl_name'
|
||||||
|
# AND table_schema = 'db_name'
|
||||||
|
# ORDER BY table_name, index_name, seq_in_index
|
||||||
|
#
|
||||||
|
# ALTER TABLE Tourneys ADD INDEX siteTourneyNo(siteTourneyNo)
|
||||||
|
# ALTER TABLE tab DROP INDEX idx
|
||||||
|
|
||||||
|
# mysql to list fks:
|
||||||
|
# SELECT constraint_name, table_name, column_name, referenced_table_name, referenced_column_name
|
||||||
|
# FROM information_schema.KEY_COLUMN_USAGE
|
||||||
|
# WHERE REFERENCED_TABLE_SCHEMA = (your schema name here)
|
||||||
|
# AND REFERENCED_TABLE_NAME is not null
|
||||||
|
# ORDER BY TABLE_NAME, COLUMN_NAME;
|
||||||
|
|
||||||
|
# this may indicate missing object
|
||||||
|
# _mysql_exceptions.OperationalError: (1025, "Error on rename of '.\\fpdb\\hands' to '.\\fpdb\\#sql2-7f0-1b' (errno: 152)")
|
||||||
|
|
||||||
|
|
||||||
|
# PG notes:
|
||||||
|
|
||||||
|
# To add a foreign key constraint to a table:
|
||||||
|
# ALTER TABLE tab ADD CONSTRAINT c FOREIGN KEY (col) REFERENCES t2(col2) MATCH FULL;
|
||||||
|
# ALTER TABLE tab DROP CONSTRAINT zipchk
|
||||||
|
#
|
||||||
|
# Note: index names must be unique across a schema
|
||||||
|
# CREATE INDEX idx ON tab(col)
|
||||||
|
# DROP INDEX idx
|
||||||
|
|
||||||
def __init__(self, c, db_name = None, game = None, sql = None): # db_name and game not used any more
|
def __init__(self, c, db_name = None, game = None, sql = None): # db_name and game not used any more
|
||||||
print "\ncreating Database instance, sql =", sql
|
print "\ncreating Database instance, sql =", sql
|
||||||
self.fdb = fpdb_db.fpdb_db() # sets self.fdb.db self.fdb.cursor and self.fdb.sql
|
self.fdb = fpdb_db.fpdb_db() # sets self.fdb.db self.fdb.cursor and self.fdb.sql
|
||||||
|
@ -123,6 +231,7 @@ class Database:
|
||||||
self.saveActions = False if self.import_options['saveActions'] == False else True
|
self.saveActions = False if self.import_options['saveActions'] == False else True
|
||||||
|
|
||||||
self.connection.rollback() # make sure any locks taken so far are released
|
self.connection.rollback() # make sure any locks taken so far are released
|
||||||
|
#end def __init__
|
||||||
|
|
||||||
# could be used by hud to change hud style
|
# could be used by hud to change hud style
|
||||||
def set_hud_style(self, style):
|
def set_hud_style(self, style):
|
||||||
|
@ -336,6 +445,12 @@ class Database:
|
||||||
else:
|
else:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
def get_site_id(self, site):
|
||||||
|
c = self.get_cursor()
|
||||||
|
c.execute(self.sql.query['getSiteId'], (site,))
|
||||||
|
result = c.fetchall()
|
||||||
|
return result
|
||||||
|
|
||||||
def get_last_insert_id(self):
|
def get_last_insert_id(self):
|
||||||
try:
|
try:
|
||||||
ret = self.fdb.getLastInsertId()
|
ret = self.fdb.getLastInsertId()
|
||||||
|
@ -470,14 +585,358 @@ class Database:
|
||||||
return hands_id
|
return hands_id
|
||||||
#end def tourney_stud
|
#end def tourney_stud
|
||||||
|
|
||||||
|
def prepareBulkImport(self):
|
||||||
|
"""Drop some indexes/foreign keys to prepare for bulk import.
|
||||||
|
Currently keeping the standalone indexes as needed to import quickly"""
|
||||||
|
stime = time()
|
||||||
|
if self.backend == self.MYSQL_INNODB:
|
||||||
|
self.get_cursor().execute("SET foreign_key_checks=0")
|
||||||
|
self.get_cursor().execute("SET autocommit=0")
|
||||||
|
return
|
||||||
|
if self.backend == self.PGSQL:
|
||||||
|
self.connection.set_isolation_level(0) # allow table/index operations to work
|
||||||
|
for fk in self.foreignKeys[self.backend]:
|
||||||
|
if fk['drop'] == 1:
|
||||||
|
if self.backend == self.MYSQL_INNODB:
|
||||||
|
c = self.get_cursor()
|
||||||
|
c.execute("SELECT constraint_name " +
|
||||||
|
"FROM information_schema.KEY_COLUMN_USAGE " +
|
||||||
|
#"WHERE REFERENCED_TABLE_SCHEMA = 'fpdb'
|
||||||
|
"WHERE 1=1 " +
|
||||||
|
"AND table_name = %s AND column_name = %s " +
|
||||||
|
"AND referenced_table_name = %s " +
|
||||||
|
"AND referenced_column_name = %s ",
|
||||||
|
(fk['fktab'], fk['fkcol'], fk['rtab'], fk['rcol']) )
|
||||||
|
cons = c.fetchone()
|
||||||
|
#print "preparebulk: cons=", cons
|
||||||
|
if cons:
|
||||||
|
print "dropping mysql fk", cons[0], fk['fktab'], fk['fkcol']
|
||||||
|
try:
|
||||||
|
c.execute("alter table " + fk['fktab'] + " drop foreign key " + cons[0])
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
elif self.backend == self.PGSQL:
|
||||||
|
# DON'T FORGET TO RECREATE THEM!!
|
||||||
|
print "dropping pg fk", fk['fktab'], fk['fkcol']
|
||||||
|
try:
|
||||||
|
# try to lock table to see if index drop will work:
|
||||||
|
# hmmm, tested by commenting out rollback in grapher. lock seems to work but
|
||||||
|
# then drop still hangs :-( does work in some tests though??
|
||||||
|
# will leave code here for now pending further tests/enhancement ...
|
||||||
|
c.execute( "lock table %s in exclusive mode nowait" % (fk['fktab'],) )
|
||||||
|
#print "after lock, status:", c.statusmessage
|
||||||
|
#print "alter table %s drop constraint %s_%s_fkey" % (fk['fktab'], fk['fktab'], fk['fkcol'])
|
||||||
|
try:
|
||||||
|
c.execute("alter table %s drop constraint %s_%s_fkey" % (fk['fktab'], fk['fktab'], fk['fkcol']))
|
||||||
|
print "dropped pg fk pg fk %s_%s_fkey, continuing ..." % (fk['fktab'], fk['fkcol'])
|
||||||
|
except:
|
||||||
|
if "does not exist" not in str(sys.exc_value):
|
||||||
|
print "warning: drop pg fk %s_%s_fkey failed: %s, continuing ..." \
|
||||||
|
% (fk['fktab'], fk['fkcol'], str(sys.exc_value).rstrip('\n') )
|
||||||
|
except:
|
||||||
|
print "warning: constraint %s_%s_fkey not dropped: %s, continuing ..." \
|
||||||
|
% (fk['fktab'],fk['fkcol'], str(sys.exc_value).rstrip('\n'))
|
||||||
|
else:
|
||||||
|
print "Only MySQL and Postgres supported so far"
|
||||||
|
return -1
|
||||||
|
|
||||||
|
for idx in indexes[self.backend]:
|
||||||
|
if idx['drop'] == 1:
|
||||||
|
if self.backend == self.MYSQL_INNODB:
|
||||||
|
print "dropping mysql index ", idx['tab'], idx['col']
|
||||||
|
try:
|
||||||
|
# apparently nowait is not implemented in mysql so this just hands if there are locks
|
||||||
|
# preventing the index drop :-(
|
||||||
|
c.execute( "alter table %s drop index %s", (idx['tab'],idx['col']) )
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
elif self.backend == self.PGSQL:
|
||||||
|
# DON'T FORGET TO RECREATE THEM!!
|
||||||
|
print "dropping pg index ", idx['tab'], idx['col']
|
||||||
|
try:
|
||||||
|
# try to lock table to see if index drop will work:
|
||||||
|
c.execute( "lock table %s in exclusive mode nowait" % (idx['tab'],) )
|
||||||
|
#print "after lock, status:", c.statusmessage
|
||||||
|
try:
|
||||||
|
# table locked ok so index drop should work:
|
||||||
|
#print "drop index %s_%s_idx" % (idx['tab'],idx['col'])
|
||||||
|
c.execute( "drop index if exists %s_%s_idx" % (idx['tab'],idx['col']) )
|
||||||
|
#print "dropped pg index ", idx['tab'], idx['col']
|
||||||
|
except:
|
||||||
|
if "does not exist" not in str(sys.exc_value):
|
||||||
|
print "warning: drop index %s_%s_idx failed: %s, continuing ..." \
|
||||||
|
% (idx['tab'],idx['col'], str(sys.exc_value).rstrip('\n'))
|
||||||
|
except:
|
||||||
|
print "warning: index %s_%s_idx not dropped %s, continuing ..." \
|
||||||
|
% (idx['tab'],idx['col'], str(sys.exc_value).rstrip('\n'))
|
||||||
|
else:
|
||||||
|
print "Error: Only MySQL and Postgres supported so far"
|
||||||
|
return -1
|
||||||
|
|
||||||
|
if self.backend == self.PGSQL:
|
||||||
|
self.connection.set_isolation_level(1) # go back to normal isolation level
|
||||||
|
self.commit() # seems to clear up errors if there were any in postgres
|
||||||
|
ptime = time() - stime
|
||||||
|
print "prepare import took", ptime, "seconds"
|
||||||
|
#end def prepareBulkImport
|
||||||
|
|
||||||
|
def afterBulkImport(self):
|
||||||
|
"""Re-create any dropped indexes/foreign keys after bulk import"""
|
||||||
|
stime = time()
|
||||||
|
|
||||||
|
if self.backend == self.MYSQL_INNODB:
|
||||||
|
c = self.get_cursor()
|
||||||
|
c.execute("SET foreign_key_checks=1")
|
||||||
|
c.execute("SET autocommit=1")
|
||||||
|
return
|
||||||
|
|
||||||
|
if self.backend == self.PGSQL:
|
||||||
|
self.connection.set_isolation_level(0) # allow table/index operations to work
|
||||||
|
for fk in self.foreignKeys[self.backend]:
|
||||||
|
if fk['drop'] == 1:
|
||||||
|
if self.backend == self.MYSQL_INNODB:
|
||||||
|
c.execute("SELECT constraint_name " +
|
||||||
|
"FROM information_schema.KEY_COLUMN_USAGE " +
|
||||||
|
#"WHERE REFERENCED_TABLE_SCHEMA = 'fpdb'
|
||||||
|
"WHERE 1=1 " +
|
||||||
|
"AND table_name = %s AND column_name = %s " +
|
||||||
|
"AND referenced_table_name = %s " +
|
||||||
|
"AND referenced_column_name = %s ",
|
||||||
|
(fk['fktab'], fk['fkcol'], fk['rtab'], fk['rcol']) )
|
||||||
|
cons = c.fetchone()
|
||||||
|
#print "afterbulk: cons=", cons
|
||||||
|
if cons:
|
||||||
|
pass
|
||||||
|
else:
|
||||||
|
print "creating fk ", fk['fktab'], fk['fkcol'], "->", fk['rtab'], fk['rcol']
|
||||||
|
try:
|
||||||
|
c.execute("alter table " + fk['fktab'] + " add foreign key ("
|
||||||
|
+ fk['fkcol'] + ") references " + fk['rtab'] + "("
|
||||||
|
+ fk['rcol'] + ")")
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
elif self.backend == self.PGSQL:
|
||||||
|
print "creating fk ", fk['fktab'], fk['fkcol'], "->", fk['rtab'], fk['rcol']
|
||||||
|
try:
|
||||||
|
c.execute("alter table " + fk['fktab'] + " add constraint "
|
||||||
|
+ fk['fktab'] + '_' + fk['fkcol'] + '_fkey'
|
||||||
|
+ " foreign key (" + fk['fkcol']
|
||||||
|
+ ") references " + fk['rtab'] + "(" + fk['rcol'] + ")")
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
else:
|
||||||
|
print "Only MySQL and Postgres supported so far"
|
||||||
|
return -1
|
||||||
|
|
||||||
|
for idx in indexes[self.backend]:
|
||||||
|
if idx['drop'] == 1:
|
||||||
|
if self.backend == self.MYSQL_INNODB:
|
||||||
|
print "creating mysql index ", idx['tab'], idx['col']
|
||||||
|
try:
|
||||||
|
c.execute( "alter table %s add index %s(%s)"
|
||||||
|
, (idx['tab'],idx['col'],idx['col']) )
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
elif self.backend == self.PGSQL:
|
||||||
|
# pass
|
||||||
|
# mod to use tab_col for index name?
|
||||||
|
print "creating pg index ", idx['tab'], idx['col']
|
||||||
|
try:
|
||||||
|
print "create index %s_%s_idx on %s(%s)" % (idx['tab'], idx['col'], idx['tab'], idx['col'])
|
||||||
|
c.execute( "create index %s_%s_idx on %s(%s)"
|
||||||
|
% (idx['tab'], idx['col'], idx['tab'], idx['col']) )
|
||||||
|
except:
|
||||||
|
print " ERROR! :-("
|
||||||
|
pass
|
||||||
|
else:
|
||||||
|
print "Only MySQL and Postgres supported so far"
|
||||||
|
return -1
|
||||||
|
|
||||||
|
if self.backend == self.PGSQL:
|
||||||
|
self.connection.set_isolation_level(1) # go back to normal isolation level
|
||||||
|
self.commit() # seems to clear up errors if there were any in postgres
|
||||||
|
atime = time() - stime
|
||||||
|
print "After import took", atime, "seconds"
|
||||||
|
#end def afterBulkImport
|
||||||
|
|
||||||
|
def drop_referential_integrity(self):
|
||||||
|
"""Update all tables to remove foreign keys"""
|
||||||
|
|
||||||
|
c = self.get_cursor()
|
||||||
|
c.execute(self.sql.query['list_tables'])
|
||||||
|
result = c.fetchall()
|
||||||
|
|
||||||
|
for i in range(len(result)):
|
||||||
|
c.execute("SHOW CREATE TABLE " + result[i][0])
|
||||||
|
inner = c.fetchall()
|
||||||
|
|
||||||
|
for j in range(len(inner)):
|
||||||
|
# result[i][0] - Table name
|
||||||
|
# result[i][1] - CREATE TABLE parameters
|
||||||
|
#Searching for CONSTRAINT `tablename_ibfk_1`
|
||||||
|
for m in re.finditer('(ibfk_[0-9]+)', inner[j][1]):
|
||||||
|
key = "`" + inner[j][0] + "_" + m.group() + "`"
|
||||||
|
c.execute("ALTER TABLE " + inner[j][0] + " DROP FOREIGN KEY " + key)
|
||||||
|
self.commit()
|
||||||
|
#end drop_referential_inegrity
|
||||||
|
|
||||||
|
def recreate_tables(self):
|
||||||
|
"""(Re-)creates the tables of the current DB"""
|
||||||
|
|
||||||
|
self.drop_tables()
|
||||||
|
self.create_tables()
|
||||||
|
self.createAllIndexes()
|
||||||
|
self.commit()
|
||||||
|
print "Finished recreating tables"
|
||||||
|
#end def recreate_tables
|
||||||
|
|
||||||
|
def create_tables(self):
|
||||||
|
#todo: should detect and fail gracefully if tables already exist.
|
||||||
|
try:
|
||||||
|
logging.debug(self.sql.query['createSettingsTable'])
|
||||||
|
c = self.get_cursor()
|
||||||
|
c.execute(self.sql.query['createSettingsTable'])
|
||||||
|
logging.debug(self.sql.query['createSitesTable'])
|
||||||
|
c.execute(self.sql.query['createSitesTable'])
|
||||||
|
c.execute(self.sql.query['createGametypesTable'])
|
||||||
|
c.execute(self.sql.query['createPlayersTable'])
|
||||||
|
c.execute(self.sql.query['createAutoratesTable'])
|
||||||
|
c.execute(self.sql.query['createHandsTable'])
|
||||||
|
c.execute(self.sql.query['createTourneyTypesTable'])
|
||||||
|
c.execute(self.sql.query['createTourneysTable'])
|
||||||
|
c.execute(self.sql.query['createTourneysPlayersTable'])
|
||||||
|
c.execute(self.sql.query['createHandsPlayersTable'])
|
||||||
|
c.execute(self.sql.query['createHandsActionsTable'])
|
||||||
|
c.execute(self.sql.query['createHudCacheTable'])
|
||||||
|
#c.execute(self.sql.query['addTourneyIndex'])
|
||||||
|
#c.execute(self.sql.query['addHandsIndex'])
|
||||||
|
#c.execute(self.sql.query['addPlayersIndex'])
|
||||||
|
self.fillDefaultData()
|
||||||
|
self.commit()
|
||||||
|
except:
|
||||||
|
print "Error creating tables: ", str(sys.exc_value)
|
||||||
|
self.rollback()
|
||||||
|
raise fpdb_simple.FpdbError( "Error creating tables " + str(sys.exc_value) )
|
||||||
|
#end def disconnect
|
||||||
|
|
||||||
|
def drop_tables(self):
|
||||||
|
"""Drops the fpdb tables from the current db"""
|
||||||
|
|
||||||
|
try:
|
||||||
|
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 = self.get_cursor()
|
||||||
|
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():
|
||||||
|
logging.debug(self.sql.query['drop_table'] + table[0])
|
||||||
|
c.execute(self.sql.query['drop_table'] + table[0])
|
||||||
|
|
||||||
|
self.commit()
|
||||||
|
except:
|
||||||
|
print "Error dropping tables: " + str(sys.exc_value)
|
||||||
|
raise fpdb_simple.FpdbError( "Error dropping tables " + str(sys.exc_value) )
|
||||||
|
#end def drop_tables
|
||||||
|
|
||||||
|
def createAllIndexes(self):
|
||||||
|
"""Create new indexes"""
|
||||||
|
|
||||||
|
try:
|
||||||
|
if self.backend == self.PGSQL:
|
||||||
|
self.connection.set_isolation_level(0) # allow table/index operations to work
|
||||||
|
for idx in self.indexes[self.backend]:
|
||||||
|
if self.backend == self.MYSQL_INNODB:
|
||||||
|
print "creating mysql index ", idx['tab'], idx['col']
|
||||||
|
try:
|
||||||
|
self.get_cursor().execute( "alter table %s add index %s(%s)"
|
||||||
|
, (idx['tab'],idx['col'],idx['col']) )
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
elif self.backend == self.PGSQL:
|
||||||
|
# mod to use tab_col for index name?
|
||||||
|
print "creating pg index ", idx['tab'], idx['col']
|
||||||
|
try:
|
||||||
|
print "create index %s_%s_idx on %s(%s)" % (idx['tab'], idx['col'], idx['tab'], idx['col'])
|
||||||
|
self.get_cursor().execute( "create index %s_%s_idx on %s(%s)"
|
||||||
|
% (idx['tab'], idx['col'], idx['tab'], idx['col']) )
|
||||||
|
except:
|
||||||
|
print " ERROR! :-("
|
||||||
|
pass
|
||||||
|
else:
|
||||||
|
print "Only MySQL and Postgres supported so far"
|
||||||
|
return -1
|
||||||
|
if self.backend == self.PGSQL:
|
||||||
|
self.connection.set_isolation_level(1) # go back to normal isolation level
|
||||||
|
except:
|
||||||
|
print "Error creating indexes: " + str(sys.exc_value)
|
||||||
|
raise fpdb_simple.FpdbError( "Error creating indexes " + str(sys.exc_value) )
|
||||||
|
#end def createAllIndexes
|
||||||
|
|
||||||
|
def dropAllIndexes(self):
|
||||||
|
"""Drop all standalone indexes (i.e. not including primary keys or foreign keys)
|
||||||
|
using list of indexes in indexes data structure"""
|
||||||
|
# maybe upgrade to use data dictionary?? (but take care to exclude PK and FK)
|
||||||
|
if self.backend == self.PGSQL:
|
||||||
|
self.connection.set_isolation_level(0) # allow table/index operations to work
|
||||||
|
for idx in self.indexes[self.backend]:
|
||||||
|
if self.backend == self.MYSQL_INNODB:
|
||||||
|
print "dropping mysql index ", idx['tab'], idx['col']
|
||||||
|
try:
|
||||||
|
self.get_cursor().execute( "alter table %s drop index %s"
|
||||||
|
, (idx['tab'],idx['col']) )
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
elif self.backend == self.PGSQL:
|
||||||
|
print "dropping pg index ", idx['tab'], idx['col']
|
||||||
|
# mod to use tab_col for index name?
|
||||||
|
try:
|
||||||
|
self.get_cursor().execute( "drop index %s_%s_idx"
|
||||||
|
% (idx['tab'],idx['col']) )
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
else:
|
||||||
|
print "Only MySQL and Postgres supported so far"
|
||||||
|
return -1
|
||||||
|
if self.backend == self.PGSQL:
|
||||||
|
self.connection.set_isolation_level(1) # go back to normal isolation level
|
||||||
|
#end def dropAllIndexes
|
||||||
|
|
||||||
|
def fillDefaultData(self):
|
||||||
|
c = self.get_cursor()
|
||||||
|
c.execute("INSERT INTO Settings (version) VALUES (118);")
|
||||||
|
c.execute("INSERT INTO Sites (name,currency) VALUES ('Full Tilt Poker', '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 ('Win2day', 'USD')")
|
||||||
|
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,) )
|
||||||
|
#end def fillDefaultData
|
||||||
|
|
||||||
def rebuild_hudcache(self):
|
def rebuild_hudcache(self):
|
||||||
"""clears hudcache and rebuilds from the individual handsplayers records"""
|
"""clears hudcache and rebuilds from the individual handsplayers records"""
|
||||||
|
|
||||||
stime = time()
|
try:
|
||||||
self.connection.cursor().execute(self.sql.query['clearHudCache'])
|
stime = time()
|
||||||
self.connection.cursor().execute(self.sql.query['rebuildHudCache'])
|
self.connection.cursor().execute(self.sql.query['clearHudCache'])
|
||||||
self.commit()
|
self.connection.cursor().execute(self.sql.query['rebuildHudCache'])
|
||||||
print "Rebuild hudcache took %.1f seconds" % (time() - stime,)
|
self.commit()
|
||||||
|
print "Rebuild hudcache took %.1f seconds" % (time() - stime,)
|
||||||
|
except:
|
||||||
|
print "Error rebuilding hudcache:", str(sys.exc_value)
|
||||||
#end def rebuild_hudcache
|
#end def rebuild_hudcache
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -30,849 +30,6 @@ class FpdbSQLQueries:
|
||||||
self.query = {}
|
self.query = {}
|
||||||
self.dbname = db
|
self.dbname = db
|
||||||
|
|
||||||
################################
|
|
||||||
# List tables
|
|
||||||
################################
|
|
||||||
if(self.dbname == 'MySQL InnoDB'):
|
|
||||||
self.query['list_tables'] = """SHOW TABLES"""
|
|
||||||
elif(self.dbname == 'PostgreSQL'):
|
|
||||||
self.query['list_tables'] = """SELECT table_name FROM information_schema.tables WHERE table_schema = 'public'"""
|
|
||||||
elif(self.dbname == 'SQLite'):
|
|
||||||
self.query['list_tables'] = """SELECT name FROM sqlite_master
|
|
||||||
WHERE type='table'
|
|
||||||
ORDER BY name;"""
|
|
||||||
|
|
||||||
##################################################################
|
|
||||||
# Drop Tables - MySQL, PostgreSQL and SQLite all share same syntax
|
|
||||||
##################################################################
|
|
||||||
|
|
||||||
if(self.dbname == 'MySQL InnoDB') or (self.dbname == 'PostgreSQL') or (self.dbname == 'SQLite'):
|
|
||||||
self.query['drop_table'] = """DROP TABLE IF EXISTS """
|
|
||||||
|
|
||||||
|
|
||||||
################################
|
|
||||||
# Create Tables
|
|
||||||
################################
|
|
||||||
|
|
||||||
################################
|
|
||||||
# Create Settings
|
|
||||||
################################
|
|
||||||
if(self.dbname == 'MySQL InnoDB'):
|
|
||||||
self.query['createSettingsTable'] = """CREATE TABLE Settings (
|
|
||||||
version SMALLINT NOT NULL)
|
|
||||||
ENGINE=INNODB"""
|
|
||||||
elif(self.dbname == 'PostgreSQL'):
|
|
||||||
self.query['createSettingsTable'] = """CREATE TABLE Settings (version SMALLINT)"""
|
|
||||||
|
|
||||||
elif(self.dbname == 'SQLite'):
|
|
||||||
self.query['createSettingsTable'] = """CREATE TABLE Settings
|
|
||||||
(version INTEGER) """
|
|
||||||
|
|
||||||
|
|
||||||
################################
|
|
||||||
# Create Sites
|
|
||||||
################################
|
|
||||||
|
|
||||||
if(self.dbname == 'MySQL InnoDB'):
|
|
||||||
self.query['createSitesTable'] = """CREATE TABLE Sites (
|
|
||||||
id SMALLINT UNSIGNED AUTO_INCREMENT NOT NULL, PRIMARY KEY (id),
|
|
||||||
name varchar(32) NOT NULL,
|
|
||||||
currency char(3) NOT NULL)
|
|
||||||
ENGINE=INNODB"""
|
|
||||||
elif(self.dbname == 'PostgreSQL'):
|
|
||||||
self.query['createSitesTable'] = """CREATE TABLE Sites (
|
|
||||||
id SERIAL, PRIMARY KEY (id),
|
|
||||||
name varchar(32),
|
|
||||||
currency char(3))"""
|
|
||||||
elif(self.dbname == 'SQLite'):
|
|
||||||
self.query['createSitesTable'] = """CREATE TABLE Sites (
|
|
||||||
id INTEGER PRIMARY KEY,
|
|
||||||
name TEXT NOT NULL,
|
|
||||||
currency TEXT NOT NULL)"""
|
|
||||||
|
|
||||||
|
|
||||||
################################
|
|
||||||
# Create Gametypes
|
|
||||||
################################
|
|
||||||
|
|
||||||
if(self.dbname == 'MySQL InnoDB'):
|
|
||||||
self.query['createGametypesTable'] = """CREATE TABLE Gametypes (
|
|
||||||
id SMALLINT UNSIGNED AUTO_INCREMENT NOT NULL, PRIMARY KEY (id),
|
|
||||||
siteId SMALLINT UNSIGNED NOT NULL, FOREIGN KEY (siteId) REFERENCES Sites(id),
|
|
||||||
type char(4) NOT NULL,
|
|
||||||
base char(4) NOT NULL,
|
|
||||||
category varchar(9) NOT NULL,
|
|
||||||
limitType char(2) NOT NULL,
|
|
||||||
hiLo char(1) NOT NULL,
|
|
||||||
smallBlind int,
|
|
||||||
bigBlind int,
|
|
||||||
smallBet int NOT NULL,
|
|
||||||
bigBet int NOT NULL)
|
|
||||||
ENGINE=INNODB"""
|
|
||||||
elif(self.dbname == 'PostgreSQL'):
|
|
||||||
self.query['createGametypesTable'] = """CREATE TABLE Gametypes (
|
|
||||||
id SERIAL, PRIMARY KEY (id),
|
|
||||||
siteId INTEGER, FOREIGN KEY (siteId) REFERENCES Sites(id),
|
|
||||||
type char(4),
|
|
||||||
base char(4),
|
|
||||||
category varchar(9),
|
|
||||||
limitType char(2),
|
|
||||||
hiLo char(1),
|
|
||||||
smallBlind int,
|
|
||||||
bigBlind int,
|
|
||||||
smallBet int,
|
|
||||||
bigBet int)"""
|
|
||||||
elif(self.dbname == 'SQLite'):
|
|
||||||
self.query['createGametypesTable'] = """CREATE TABLE GameTypes (
|
|
||||||
id INTEGER PRIMARY KEY,
|
|
||||||
siteId INTEGER,
|
|
||||||
type TEXT,
|
|
||||||
base TEXT,
|
|
||||||
category TEXT,
|
|
||||||
limitType TEXT,
|
|
||||||
hiLo TEXT,
|
|
||||||
smallBlind INTEGER,
|
|
||||||
bigBlind INTEGER,
|
|
||||||
smallBet INTEGER,
|
|
||||||
bigBet INTEGER,
|
|
||||||
FOREIGN KEY(siteId) REFERENCES Sites(id) ON DELETE CASCADE)"""
|
|
||||||
|
|
||||||
|
|
||||||
################################
|
|
||||||
# Create Players
|
|
||||||
################################
|
|
||||||
|
|
||||||
if(self.dbname == 'MySQL InnoDB'):
|
|
||||||
self.query['createPlayersTable'] = """CREATE TABLE Players (
|
|
||||||
id INT UNSIGNED AUTO_INCREMENT NOT NULL, PRIMARY KEY (id),
|
|
||||||
name VARCHAR(32) CHARACTER SET utf8 NOT NULL,
|
|
||||||
siteId SMALLINT UNSIGNED NOT NULL, FOREIGN KEY (siteId) REFERENCES Sites(id),
|
|
||||||
comment text,
|
|
||||||
commentTs DATETIME)
|
|
||||||
ENGINE=INNODB"""
|
|
||||||
elif(self.dbname == 'PostgreSQL'):
|
|
||||||
self.query['createPlayersTable'] = """CREATE TABLE Players (
|
|
||||||
id SERIAL, PRIMARY KEY (id),
|
|
||||||
name VARCHAR(32),
|
|
||||||
siteId INTEGER, FOREIGN KEY (siteId) REFERENCES Sites(id),
|
|
||||||
comment text,
|
|
||||||
commentTs timestamp without time zone)"""
|
|
||||||
elif(self.dbname == 'SQLite'):
|
|
||||||
self.query['createPlayersTable'] = """CREATE TABLE Players (
|
|
||||||
id INTEGER PRIMARY KEY,
|
|
||||||
name TEXT,
|
|
||||||
siteId INTEGER,
|
|
||||||
comment TEXT,
|
|
||||||
commentTs BLOB,
|
|
||||||
FOREIGN KEY(siteId) REFERENCES Sites(id) ON DELETE CASCADE)"""
|
|
||||||
|
|
||||||
|
|
||||||
################################
|
|
||||||
# Create Autorates
|
|
||||||
################################
|
|
||||||
|
|
||||||
if(self.dbname == 'MySQL InnoDB'):
|
|
||||||
self.query['createAutoratesTable'] = """CREATE TABLE Autorates (
|
|
||||||
id BIGINT UNSIGNED AUTO_INCREMENT NOT NULL, PRIMARY KEY (id),
|
|
||||||
playerId INT UNSIGNED NOT NULL, FOREIGN KEY (playerId) REFERENCES Players(id),
|
|
||||||
gametypeId SMALLINT UNSIGNED NOT NULL, FOREIGN KEY (gametypeId) REFERENCES Gametypes(id),
|
|
||||||
description varchar(50) NOT NULL,
|
|
||||||
shortDesc char(8) NOT NULL,
|
|
||||||
ratingTime DATETIME NOT NULL,
|
|
||||||
handCount int NOT NULL)
|
|
||||||
ENGINE=INNODB"""
|
|
||||||
elif(self.dbname == 'PostgreSQL'):
|
|
||||||
self.query['createAutoratesTable'] = """CREATE TABLE Autorates (
|
|
||||||
id BIGSERIAL, PRIMARY KEY (id),
|
|
||||||
playerId INT, FOREIGN KEY (playerId) REFERENCES Players(id),
|
|
||||||
gametypeId INT, FOREIGN KEY (gametypeId) REFERENCES Gametypes(id),
|
|
||||||
description varchar(50),
|
|
||||||
shortDesc char(8),
|
|
||||||
ratingTime timestamp without time zone,
|
|
||||||
handCount int)"""
|
|
||||||
elif(self.dbname == 'SQLite'):
|
|
||||||
self.query['createAutoratesTable'] = """ """
|
|
||||||
|
|
||||||
|
|
||||||
################################
|
|
||||||
# Create Hands
|
|
||||||
################################
|
|
||||||
|
|
||||||
if(self.dbname == 'MySQL InnoDB'):
|
|
||||||
self.query['createHandsTable'] = """CREATE TABLE Hands (
|
|
||||||
id BIGINT UNSIGNED AUTO_INCREMENT NOT NULL, PRIMARY KEY (id),
|
|
||||||
tableName VARCHAR(20) NOT NULL,
|
|
||||||
siteHandNo BIGINT NOT NULL,
|
|
||||||
gametypeId SMALLINT UNSIGNED NOT NULL, FOREIGN KEY (gametypeId) REFERENCES Gametypes(id),
|
|
||||||
handStart DATETIME NOT NULL,
|
|
||||||
importTime DATETIME NOT NULL,
|
|
||||||
seats TINYINT NOT NULL,
|
|
||||||
maxSeats TINYINT NOT NULL,
|
|
||||||
boardcard1 smallint, /* 0=none, 1-13=2-Ah 14-26=2-Ad 27-39=2-Ac 40-52=2-As */
|
|
||||||
boardcard2 smallint,
|
|
||||||
boardcard3 smallint,
|
|
||||||
boardcard4 smallint,
|
|
||||||
boardcard5 smallint,
|
|
||||||
texture smallint,
|
|
||||||
playersVpi SMALLINT NOT NULL, /* num of players vpi */
|
|
||||||
playersAtStreet1 SMALLINT NOT NULL, /* num of players seeing flop/street4 */
|
|
||||||
playersAtStreet2 SMALLINT NOT NULL,
|
|
||||||
playersAtStreet3 SMALLINT NOT NULL,
|
|
||||||
playersAtStreet4 SMALLINT NOT NULL,
|
|
||||||
playersAtShowdown SMALLINT NOT NULL,
|
|
||||||
street0Raises TINYINT NOT NULL, /* num small bets paid to see flop/street4, including blind */
|
|
||||||
street1Raises TINYINT NOT NULL, /* num small bets paid to see turn/street5 */
|
|
||||||
street2Raises TINYINT NOT NULL, /* num big bets paid to see river/street6 */
|
|
||||||
street3Raises TINYINT NOT NULL, /* num big bets paid to see sd/street7 */
|
|
||||||
street4Raises TINYINT NOT NULL, /* num big bets paid to see showdown */
|
|
||||||
street1Pot INT, /* pot size at flop/street4 */
|
|
||||||
street2Pot INT, /* pot size at turn/street5 */
|
|
||||||
street3Pot INT, /* pot size at river/street6 */
|
|
||||||
street4Pot INT, /* pot size at sd/street7 */
|
|
||||||
showdownPot INT, /* pot size at sd/street7 */
|
|
||||||
comment TEXT,
|
|
||||||
commentTs DATETIME)
|
|
||||||
ENGINE=INNODB"""
|
|
||||||
elif(self.dbname == 'PostgreSQL'):
|
|
||||||
self.query['createHandsTable'] = """CREATE TABLE Hands (
|
|
||||||
id BIGSERIAL, PRIMARY KEY (id),
|
|
||||||
tableName VARCHAR(20) NOT NULL,
|
|
||||||
siteHandNo BIGINT NOT NULL,
|
|
||||||
gametypeId INT NOT NULL, FOREIGN KEY (gametypeId) REFERENCES Gametypes(id),
|
|
||||||
handStart timestamp without time zone NOT NULL,
|
|
||||||
importTime timestamp without time zone NOT NULL,
|
|
||||||
seats SMALLINT NOT NULL,
|
|
||||||
maxSeats SMALLINT NOT NULL,
|
|
||||||
boardcard1 smallint, /* 0=none, 1-13=2-Ah 14-26=2-Ad 27-39=2-Ac 40-52=2-As */
|
|
||||||
boardcard2 smallint,
|
|
||||||
boardcard3 smallint,
|
|
||||||
boardcard4 smallint,
|
|
||||||
boardcard5 smallint,
|
|
||||||
texture smallint,
|
|
||||||
playersVpi SMALLINT NOT NULL, /* num of players vpi */
|
|
||||||
playersAtStreet1 SMALLINT NOT NULL, /* num of players seeing flop/street4 */
|
|
||||||
playersAtStreet2 SMALLINT NOT NULL,
|
|
||||||
playersAtStreet3 SMALLINT NOT NULL,
|
|
||||||
playersAtStreet4 SMALLINT NOT NULL,
|
|
||||||
playersAtShowdown SMALLINT NOT NULL,
|
|
||||||
street0Raises SMALLINT NOT NULL, /* num small bets paid to see flop/street4, including blind */
|
|
||||||
street1Raises SMALLINT NOT NULL, /* num small bets paid to see turn/street5 */
|
|
||||||
street2Raises SMALLINT NOT NULL, /* num big bets paid to see river/street6 */
|
|
||||||
street3Raises SMALLINT NOT NULL, /* num big bets paid to see sd/street7 */
|
|
||||||
street4Raises SMALLINT NOT NULL, /* num big bets paid to see showdown */
|
|
||||||
street1Pot INT, /* pot size at flop/street4 */
|
|
||||||
street2Pot INT, /* pot size at turn/street5 */
|
|
||||||
street3Pot INT, /* pot size at river/street6 */
|
|
||||||
street4Pot INT, /* pot size at sd/street7 */
|
|
||||||
showdownPot INT, /* pot size at sd/street7 */
|
|
||||||
comment TEXT,
|
|
||||||
commentTs timestamp without time zone)"""
|
|
||||||
elif(self.dbname == 'SQLite'):
|
|
||||||
self.query['createHandsTable'] = """CREATE TABLE Hands (
|
|
||||||
id INTEGER PRIMARY KEY,
|
|
||||||
tableName TEXT(20),
|
|
||||||
siteHandNo INTEGER,
|
|
||||||
gametypeId INTEGER,
|
|
||||||
handStart BLOB,
|
|
||||||
importTime BLOB,
|
|
||||||
seats INTEGER,
|
|
||||||
maxSeats INTEGER,
|
|
||||||
comment TEXT,
|
|
||||||
commentTs BLOB,
|
|
||||||
FOREIGN KEY(gametypeId) REFERENCES Gametypes(id) ON DELETE CASCADE)"""
|
|
||||||
|
|
||||||
|
|
||||||
################################
|
|
||||||
# Create TourneyTypes
|
|
||||||
################################
|
|
||||||
|
|
||||||
if(self.dbname == 'MySQL InnoDB'):
|
|
||||||
self.query['createTourneyTypesTable'] = """CREATE TABLE TourneyTypes (
|
|
||||||
id SMALLINT UNSIGNED AUTO_INCREMENT NOT NULL, PRIMARY KEY (id),
|
|
||||||
siteId SMALLINT UNSIGNED NOT NULL, FOREIGN KEY (siteId) REFERENCES Sites(id),
|
|
||||||
buyin INT NOT NULL,
|
|
||||||
fee INT NOT NULL,
|
|
||||||
knockout INT NOT NULL,
|
|
||||||
rebuyOrAddon BOOLEAN NOT NULL)
|
|
||||||
ENGINE=INNODB"""
|
|
||||||
elif(self.dbname == '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)"""
|
|
||||||
elif(self.dbname == 'SQLite'):
|
|
||||||
self.query['createTourneyTypesTable'] = """ """
|
|
||||||
|
|
||||||
|
|
||||||
################################
|
|
||||||
# Create Tourneys
|
|
||||||
################################
|
|
||||||
|
|
||||||
if(self.dbname == 'MySQL InnoDB'):
|
|
||||||
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),
|
|
||||||
siteTourneyNo BIGINT NOT NULL,
|
|
||||||
entries INT NOT NULL,
|
|
||||||
prizepool INT NOT NULL,
|
|
||||||
startTime DATETIME NOT NULL,
|
|
||||||
comment TEXT,
|
|
||||||
commentTs DATETIME)
|
|
||||||
ENGINE=INNODB"""
|
|
||||||
elif(self.dbname == 'PostgreSQL'):
|
|
||||||
self.query['createTourneysTable'] = """CREATE TABLE Tourneys (
|
|
||||||
id SERIAL, PRIMARY KEY (id),
|
|
||||||
tourneyTypeId INT, FOREIGN KEY (tourneyTypeId) REFERENCES TourneyTypes(id),
|
|
||||||
siteTourneyNo BIGINT,
|
|
||||||
entries INT,
|
|
||||||
prizepool INT,
|
|
||||||
startTime timestamp without time zone,
|
|
||||||
comment TEXT,
|
|
||||||
commentTs timestamp without time zone)"""
|
|
||||||
elif(self.dbname == 'SQLite'):
|
|
||||||
self.query['createTourneysTable'] = """CREATE TABLE TourneyTypes (
|
|
||||||
id INTEGER PRIMARY KEY,
|
|
||||||
siteId INTEGER,
|
|
||||||
buyin INTEGER,
|
|
||||||
fee INTEGER,
|
|
||||||
knockout INTEGER,
|
|
||||||
rebuyOrAddon BOOL,
|
|
||||||
FOREIGN KEY(siteId) REFERENCES Sites(id) ON DELETE CASCADE)"""
|
|
||||||
|
|
||||||
################################
|
|
||||||
# Create HandsPlayers
|
|
||||||
################################
|
|
||||||
|
|
||||||
if(self.dbname == 'MySQL InnoDB'):
|
|
||||||
self.query['createHandsPlayersTable'] = """CREATE TABLE HandsPlayers (
|
|
||||||
id BIGINT UNSIGNED AUTO_INCREMENT NOT NULL, PRIMARY KEY (id),
|
|
||||||
handId BIGINT UNSIGNED NOT NULL, FOREIGN KEY (handId) REFERENCES Hands(id),
|
|
||||||
playerId INT UNSIGNED NOT NULL, FOREIGN KEY (playerId) REFERENCES Players(id),
|
|
||||||
startCash INT NOT NULL,
|
|
||||||
position CHAR(1),
|
|
||||||
seatNo SMALLINT NOT NULL,
|
|
||||||
|
|
||||||
card1 smallint NOT NULL, /* 0=none, 1-13=2-Ah 14-26=2-Ad 27-39=2-Ac 40-52=2-As */
|
|
||||||
card2 smallint NOT NULL,
|
|
||||||
card3 smallint,
|
|
||||||
card4 smallint,
|
|
||||||
card5 smallint,
|
|
||||||
card6 smallint,
|
|
||||||
card7 smallint,
|
|
||||||
startCards smallint,
|
|
||||||
|
|
||||||
ante INT,
|
|
||||||
winnings int NOT NULL,
|
|
||||||
rake int NOT NULL,
|
|
||||||
totalProfit INT NOT NULL,
|
|
||||||
comment text,
|
|
||||||
commentTs DATETIME,
|
|
||||||
tourneysPlayersId BIGINT UNSIGNED,
|
|
||||||
tourneyTypeId SMALLINT UNSIGNED NOT NULL, FOREIGN KEY (tourneyTypeId) REFERENCES TourneyTypes(id),
|
|
||||||
|
|
||||||
wonWhenSeenStreet1 FLOAT NOT NULL,
|
|
||||||
wonWhenSeenStreet2 FLOAT,
|
|
||||||
wonWhenSeenStreet3 FLOAT,
|
|
||||||
wonWhenSeenStreet4 FLOAT,
|
|
||||||
wonAtSD FLOAT NOT NULL,
|
|
||||||
|
|
||||||
street0VPI BOOLEAN NOT NULL,
|
|
||||||
street0Aggr BOOLEAN NOT NULL,
|
|
||||||
street0_3BChance BOOLEAN NOT NULL,
|
|
||||||
street0_3BDone BOOLEAN NOT NULL,
|
|
||||||
street0_4BChance BOOLEAN,
|
|
||||||
street0_4BDone BOOLEAN,
|
|
||||||
other3BStreet0 BOOLEAN,
|
|
||||||
other4BStreet0 BOOLEAN,
|
|
||||||
|
|
||||||
street1Seen BOOLEAN NOT NULL,
|
|
||||||
street2Seen BOOLEAN NOT NULL,
|
|
||||||
street3Seen BOOLEAN NOT NULL,
|
|
||||||
street4Seen BOOLEAN NOT NULL,
|
|
||||||
sawShowdown BOOLEAN NOT NULL,
|
|
||||||
|
|
||||||
street1Aggr BOOLEAN NOT NULL,
|
|
||||||
street2Aggr BOOLEAN NOT NULL,
|
|
||||||
street3Aggr BOOLEAN NOT NULL,
|
|
||||||
street4Aggr BOOLEAN NOT NULL,
|
|
||||||
|
|
||||||
otherRaisedStreet0 BOOLEAN,
|
|
||||||
otherRaisedStreet1 BOOLEAN NOT NULL,
|
|
||||||
otherRaisedStreet2 BOOLEAN NOT NULL,
|
|
||||||
otherRaisedStreet3 BOOLEAN NOT NULL,
|
|
||||||
otherRaisedStreet4 BOOLEAN NOT NULL,
|
|
||||||
foldToOtherRaisedStreet0 BOOLEAN,
|
|
||||||
foldToOtherRaisedStreet1 BOOLEAN NOT NULL,
|
|
||||||
foldToOtherRaisedStreet2 BOOLEAN NOT NULL,
|
|
||||||
foldToOtherRaisedStreet3 BOOLEAN NOT NULL,
|
|
||||||
foldToOtherRaisedStreet4 BOOLEAN NOT NULL,
|
|
||||||
|
|
||||||
stealAttemptChance BOOLEAN NOT NULL,
|
|
||||||
stealAttempted BOOLEAN NOT NULL,
|
|
||||||
foldBbToStealChance BOOLEAN NOT NULL,
|
|
||||||
foldedBbToSteal BOOLEAN NOT NULL,
|
|
||||||
foldSbToStealChance BOOLEAN NOT NULL,
|
|
||||||
foldedSbToSteal BOOLEAN NOT NULL,
|
|
||||||
|
|
||||||
street1CBChance BOOLEAN NOT NULL,
|
|
||||||
street1CBDone BOOLEAN NOT NULL,
|
|
||||||
street2CBChance BOOLEAN NOT NULL,
|
|
||||||
street2CBDone BOOLEAN NOT NULL,
|
|
||||||
street3CBChance BOOLEAN NOT NULL,
|
|
||||||
street3CBDone BOOLEAN NOT NULL,
|
|
||||||
street4CBChance BOOLEAN NOT NULL,
|
|
||||||
street4CBDone BOOLEAN NOT NULL,
|
|
||||||
|
|
||||||
foldToStreet1CBChance BOOLEAN NOT NULL,
|
|
||||||
foldToStreet1CBDone BOOLEAN NOT NULL,
|
|
||||||
foldToStreet2CBChance BOOLEAN NOT NULL,
|
|
||||||
foldToStreet2CBDone BOOLEAN NOT NULL,
|
|
||||||
foldToStreet3CBChance BOOLEAN NOT NULL,
|
|
||||||
foldToStreet3CBDone BOOLEAN NOT NULL,
|
|
||||||
foldToStreet4CBChance BOOLEAN NOT NULL,
|
|
||||||
foldToStreet4CBDone BOOLEAN NOT NULL,
|
|
||||||
|
|
||||||
street1CheckCallRaiseChance BOOLEAN NOT NULL,
|
|
||||||
street1CheckCallRaiseDone BOOLEAN NOT NULL,
|
|
||||||
street2CheckCallRaiseChance BOOLEAN NOT NULL,
|
|
||||||
street2CheckCallRaiseDone BOOLEAN NOT NULL,
|
|
||||||
street3CheckCallRaiseChance BOOLEAN NOT NULL,
|
|
||||||
street3CheckCallRaiseDone BOOLEAN NOT NULL,
|
|
||||||
street4CheckCallRaiseChance BOOLEAN NOT NULL,
|
|
||||||
street4CheckCallRaiseDone BOOLEAN NOT NULL,
|
|
||||||
|
|
||||||
street0Calls TINYINT,
|
|
||||||
street1Calls TINYINT,
|
|
||||||
street2Calls TINYINT,
|
|
||||||
street3Calls TINYINT,
|
|
||||||
street4Calls TINYINT,
|
|
||||||
street0Bets TINYINT,
|
|
||||||
street1Bets TINYINT,
|
|
||||||
street2Bets TINYINT,
|
|
||||||
street3Bets TINYINT,
|
|
||||||
street4Bets TINYINT,
|
|
||||||
street0Raises TINYINT,
|
|
||||||
street1Raises TINYINT,
|
|
||||||
street2Raises TINYINT,
|
|
||||||
street3Raises TINYINT,
|
|
||||||
street4Raises TINYINT,
|
|
||||||
|
|
||||||
actionString VARCHAR(15),
|
|
||||||
|
|
||||||
FOREIGN KEY (tourneysPlayersId) REFERENCES TourneysPlayers(id))
|
|
||||||
ENGINE=INNODB"""
|
|
||||||
elif(self.dbname == 'PostgreSQL'):
|
|
||||||
self.query['createHandsPlayersTable'] = """CREATE TABLE HandsPlayers (
|
|
||||||
id BIGSERIAL, PRIMARY KEY (id),
|
|
||||||
handId BIGINT NOT NULL, FOREIGN KEY (handId) REFERENCES Hands(id),
|
|
||||||
playerId INT NOT NULL, FOREIGN KEY (playerId) REFERENCES Players(id),
|
|
||||||
startCash INT NOT NULL,
|
|
||||||
position CHAR(1),
|
|
||||||
seatNo SMALLINT NOT NULL,
|
|
||||||
|
|
||||||
card1 smallint NOT NULL, /* 0=none, 1-13=2-Ah 14-26=2-Ad 27-39=2-Ac 40-52=2-As */
|
|
||||||
card2 smallint NOT NULL,
|
|
||||||
card3 smallint,
|
|
||||||
card4 smallint,
|
|
||||||
card5 smallint,
|
|
||||||
card6 smallint,
|
|
||||||
card7 smallint,
|
|
||||||
startCards smallint,
|
|
||||||
|
|
||||||
ante INT,
|
|
||||||
winnings int NOT NULL,
|
|
||||||
rake int NOT NULL,
|
|
||||||
totalProfit INT NOT NULL,
|
|
||||||
comment text,
|
|
||||||
commentTs timestamp without time zone,
|
|
||||||
tourneysPlayersId BIGINT,
|
|
||||||
tourneyTypeId INT NOT NULL, FOREIGN KEY (tourneyTypeId) REFERENCES TourneyTypes(id),
|
|
||||||
|
|
||||||
wonWhenSeenStreet1 FLOAT NOT NULL,
|
|
||||||
wonWhenSeenStreet2 FLOAT,
|
|
||||||
wonWhenSeenStreet3 FLOAT,
|
|
||||||
wonWhenSeenStreet4 FLOAT,
|
|
||||||
wonAtSD FLOAT NOT NULL,
|
|
||||||
|
|
||||||
street0VPI BOOLEAN NOT NULL,
|
|
||||||
street0Aggr BOOLEAN NOT NULL,
|
|
||||||
street0_3BChance BOOLEAN NOT NULL,
|
|
||||||
street0_3BDone BOOLEAN NOT NULL,
|
|
||||||
street0_4BChance BOOLEAN,
|
|
||||||
street0_4BDone BOOLEAN,
|
|
||||||
other3BStreet0 BOOLEAN,
|
|
||||||
other4BStreet0 BOOLEAN,
|
|
||||||
|
|
||||||
street1Seen BOOLEAN NOT NULL,
|
|
||||||
street2Seen BOOLEAN NOT NULL,
|
|
||||||
street3Seen BOOLEAN NOT NULL,
|
|
||||||
street4Seen BOOLEAN NOT NULL,
|
|
||||||
sawShowdown BOOLEAN NOT NULL,
|
|
||||||
|
|
||||||
street1Aggr BOOLEAN NOT NULL,
|
|
||||||
street2Aggr BOOLEAN NOT NULL,
|
|
||||||
street3Aggr BOOLEAN NOT NULL,
|
|
||||||
street4Aggr BOOLEAN NOT NULL,
|
|
||||||
|
|
||||||
otherRaisedStreet0 BOOLEAN,
|
|
||||||
otherRaisedStreet1 BOOLEAN NOT NULL,
|
|
||||||
otherRaisedStreet2 BOOLEAN NOT NULL,
|
|
||||||
otherRaisedStreet3 BOOLEAN NOT NULL,
|
|
||||||
otherRaisedStreet4 BOOLEAN NOT NULL,
|
|
||||||
foldToOtherRaisedStreet0 BOOLEAN,
|
|
||||||
foldToOtherRaisedStreet1 BOOLEAN NOT NULL,
|
|
||||||
foldToOtherRaisedStreet2 BOOLEAN NOT NULL,
|
|
||||||
foldToOtherRaisedStreet3 BOOLEAN NOT NULL,
|
|
||||||
foldToOtherRaisedStreet4 BOOLEAN NOT NULL,
|
|
||||||
|
|
||||||
stealAttemptChance BOOLEAN NOT NULL,
|
|
||||||
stealAttempted BOOLEAN NOT NULL,
|
|
||||||
foldBbToStealChance BOOLEAN NOT NULL,
|
|
||||||
foldedBbToSteal BOOLEAN NOT NULL,
|
|
||||||
foldSbToStealChance BOOLEAN NOT NULL,
|
|
||||||
foldedSbToSteal BOOLEAN NOT NULL,
|
|
||||||
|
|
||||||
street1CBChance BOOLEAN NOT NULL,
|
|
||||||
street1CBDone BOOLEAN NOT NULL,
|
|
||||||
street2CBChance BOOLEAN NOT NULL,
|
|
||||||
street2CBDone BOOLEAN NOT NULL,
|
|
||||||
street3CBChance BOOLEAN NOT NULL,
|
|
||||||
street3CBDone BOOLEAN NOT NULL,
|
|
||||||
street4CBChance BOOLEAN NOT NULL,
|
|
||||||
street4CBDone BOOLEAN NOT NULL,
|
|
||||||
|
|
||||||
foldToStreet1CBChance BOOLEAN NOT NULL,
|
|
||||||
foldToStreet1CBDone BOOLEAN NOT NULL,
|
|
||||||
foldToStreet2CBChance BOOLEAN NOT NULL,
|
|
||||||
foldToStreet2CBDone BOOLEAN NOT NULL,
|
|
||||||
foldToStreet3CBChance BOOLEAN NOT NULL,
|
|
||||||
foldToStreet3CBDone BOOLEAN NOT NULL,
|
|
||||||
foldToStreet4CBChance BOOLEAN NOT NULL,
|
|
||||||
foldToStreet4CBDone BOOLEAN NOT NULL,
|
|
||||||
|
|
||||||
street1CheckCallRaiseChance BOOLEAN NOT NULL,
|
|
||||||
street1CheckCallRaiseDone BOOLEAN NOT NULL,
|
|
||||||
street2CheckCallRaiseChance BOOLEAN NOT NULL,
|
|
||||||
street2CheckCallRaiseDone BOOLEAN NOT NULL,
|
|
||||||
street3CheckCallRaiseChance BOOLEAN NOT NULL,
|
|
||||||
street3CheckCallRaiseDone BOOLEAN NOT NULL,
|
|
||||||
street4CheckCallRaiseChance BOOLEAN NOT NULL,
|
|
||||||
street4CheckCallRaiseDone BOOLEAN NOT NULL,
|
|
||||||
|
|
||||||
street0Calls SMALLINT,
|
|
||||||
street1Calls SMALLINT,
|
|
||||||
street2Calls SMALLINT,
|
|
||||||
street3Calls SMALLINT,
|
|
||||||
street4Calls SMALLINT,
|
|
||||||
street0Bets SMALLINT,
|
|
||||||
street1Bets SMALLINT,
|
|
||||||
street2Bets SMALLINT,
|
|
||||||
street3Bets SMALLINT,
|
|
||||||
street4Bets SMALLINT,
|
|
||||||
street0Raises SMALLINT,
|
|
||||||
street1Raises SMALLINT,
|
|
||||||
street2Raises SMALLINT,
|
|
||||||
street3Raises SMALLINT,
|
|
||||||
street4Raises SMALLINT,
|
|
||||||
|
|
||||||
actionString VARCHAR(15),
|
|
||||||
|
|
||||||
FOREIGN KEY (tourneysPlayersId) REFERENCES TourneysPlayers(id))"""
|
|
||||||
elif(self.dbname == 'SQLite'):
|
|
||||||
self.query['createHandsPlayersTable'] = """ """
|
|
||||||
|
|
||||||
|
|
||||||
################################
|
|
||||||
# Create TourneysPlayers
|
|
||||||
################################
|
|
||||||
|
|
||||||
if(self.dbname == 'MySQL InnoDB'):
|
|
||||||
self.query['createTourneysPlayersTable'] = """CREATE TABLE TourneysPlayers (
|
|
||||||
id BIGINT UNSIGNED AUTO_INCREMENT NOT NULL, PRIMARY KEY (id),
|
|
||||||
tourneyId INT UNSIGNED NOT NULL, FOREIGN KEY (tourneyId) REFERENCES Tourneys(id),
|
|
||||||
playerId INT UNSIGNED NOT NULL, FOREIGN KEY (playerId) REFERENCES Players(id),
|
|
||||||
payinAmount INT NOT NULL,
|
|
||||||
rank INT NOT NULL,
|
|
||||||
winnings INT NOT NULL,
|
|
||||||
comment TEXT,
|
|
||||||
commentTs DATETIME)
|
|
||||||
ENGINE=INNODB"""
|
|
||||||
elif(self.dbname == 'PostgreSQL'):
|
|
||||||
self.query['createTourneysPlayersTable'] = """CREATE TABLE TourneysPlayers (
|
|
||||||
id BIGSERIAL, PRIMARY KEY (id),
|
|
||||||
tourneyId INT, FOREIGN KEY (tourneyId) REFERENCES Tourneys(id),
|
|
||||||
playerId INT, FOREIGN KEY (playerId) REFERENCES Players(id),
|
|
||||||
payinAmount INT,
|
|
||||||
rank INT,
|
|
||||||
winnings INT,
|
|
||||||
comment TEXT,
|
|
||||||
commentTs timestamp without time zone)"""
|
|
||||||
elif(self.dbname == 'SQLite'):
|
|
||||||
self.query['createTourneysPlayersTable'] = """ """
|
|
||||||
|
|
||||||
|
|
||||||
################################
|
|
||||||
# Create HandsActions
|
|
||||||
################################
|
|
||||||
|
|
||||||
if(self.dbname == 'MySQL InnoDB'):
|
|
||||||
self.query['createHandsActionsTable'] = """CREATE TABLE HandsActions (
|
|
||||||
id BIGINT UNSIGNED AUTO_INCREMENT NOT NULL, PRIMARY KEY (id),
|
|
||||||
handsPlayerId BIGINT UNSIGNED NOT NULL, FOREIGN KEY (handsPlayerId) REFERENCES HandsPlayers(id),
|
|
||||||
street SMALLINT NOT NULL,
|
|
||||||
actionNo SMALLINT NOT NULL,
|
|
||||||
action CHAR(5) NOT NULL,
|
|
||||||
allIn BOOLEAN NOT NULL,
|
|
||||||
amount INT NOT NULL,
|
|
||||||
comment TEXT,
|
|
||||||
commentTs DATETIME)
|
|
||||||
ENGINE=INNODB"""
|
|
||||||
elif(self.dbname == 'PostgreSQL'):
|
|
||||||
self.query['createHandsActionsTable'] = """CREATE TABLE HandsActions (
|
|
||||||
id BIGSERIAL, PRIMARY KEY (id),
|
|
||||||
handsPlayerId BIGINT, FOREIGN KEY (handsPlayerId) REFERENCES HandsPlayers(id),
|
|
||||||
street SMALLINT,
|
|
||||||
actionNo SMALLINT,
|
|
||||||
action CHAR(5),
|
|
||||||
allIn BOOLEAN,
|
|
||||||
amount INT,
|
|
||||||
comment TEXT,
|
|
||||||
commentTs timestamp without time zone)"""
|
|
||||||
elif(self.dbname == 'SQLite'):
|
|
||||||
self.query['createHandsActionsTable'] = """ """
|
|
||||||
|
|
||||||
|
|
||||||
################################
|
|
||||||
# Create HudCache
|
|
||||||
################################
|
|
||||||
|
|
||||||
if(self.dbname == 'MySQL InnoDB'):
|
|
||||||
self.query['createHudCacheTable'] = """CREATE TABLE HudCache (
|
|
||||||
id BIGINT UNSIGNED AUTO_INCREMENT NOT NULL, PRIMARY KEY (id),
|
|
||||||
gametypeId SMALLINT UNSIGNED NOT NULL, FOREIGN KEY (gametypeId) REFERENCES Gametypes(id),
|
|
||||||
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),
|
|
||||||
styleKey CHAR(7) NOT NULL, /* 1st char is style (A/T/H/S), other 6 are the key */
|
|
||||||
HDs INT NOT NULL,
|
|
||||||
|
|
||||||
wonWhenSeenStreet1 FLOAT NOT NULL,
|
|
||||||
wonWhenSeenStreet2 FLOAT,
|
|
||||||
wonWhenSeenStreet3 FLOAT,
|
|
||||||
wonWhenSeenStreet4 FLOAT,
|
|
||||||
wonAtSD FLOAT NOT NULL,
|
|
||||||
|
|
||||||
street0VPI INT NOT NULL,
|
|
||||||
street0Aggr INT NOT NULL,
|
|
||||||
street0_3BChance INT NOT NULL,
|
|
||||||
street0_3BDone INT NOT NULL,
|
|
||||||
street0_4BChance INT,
|
|
||||||
street0_4BDone INT,
|
|
||||||
other3BStreet0 INT,
|
|
||||||
other4BStreet0 INT,
|
|
||||||
|
|
||||||
street1Seen INT NOT NULL,
|
|
||||||
street2Seen INT NOT NULL,
|
|
||||||
street3Seen INT NOT NULL,
|
|
||||||
street4Seen INT NOT NULL,
|
|
||||||
sawShowdown INT NOT NULL,
|
|
||||||
|
|
||||||
street1Aggr INT NOT NULL,
|
|
||||||
street2Aggr INT NOT NULL,
|
|
||||||
street3Aggr INT NOT NULL,
|
|
||||||
street4Aggr INT NOT NULL,
|
|
||||||
|
|
||||||
otherRaisedStreet0 INT,
|
|
||||||
otherRaisedStreet1 INT NOT NULL,
|
|
||||||
otherRaisedStreet2 INT NOT NULL,
|
|
||||||
otherRaisedStreet3 INT NOT NULL,
|
|
||||||
otherRaisedStreet4 INT NOT NULL,
|
|
||||||
foldToOtherRaisedStreet0 INT,
|
|
||||||
foldToOtherRaisedStreet1 INT NOT NULL,
|
|
||||||
foldToOtherRaisedStreet2 INT NOT NULL,
|
|
||||||
foldToOtherRaisedStreet3 INT NOT NULL,
|
|
||||||
foldToOtherRaisedStreet4 INT NOT NULL,
|
|
||||||
|
|
||||||
stealAttemptChance INT NOT NULL,
|
|
||||||
stealAttempted INT NOT NULL,
|
|
||||||
foldBbToStealChance INT NOT NULL,
|
|
||||||
foldedBbToSteal INT NOT NULL,
|
|
||||||
foldSbToStealChance INT NOT NULL,
|
|
||||||
foldedSbToSteal INT NOT NULL,
|
|
||||||
|
|
||||||
street1CBChance INT NOT NULL,
|
|
||||||
street1CBDone INT NOT NULL,
|
|
||||||
street2CBChance INT NOT NULL,
|
|
||||||
street2CBDone INT NOT NULL,
|
|
||||||
street3CBChance INT NOT NULL,
|
|
||||||
street3CBDone INT NOT NULL,
|
|
||||||
street4CBChance INT NOT NULL,
|
|
||||||
street4CBDone INT NOT NULL,
|
|
||||||
|
|
||||||
foldToStreet1CBChance INT NOT NULL,
|
|
||||||
foldToStreet1CBDone INT NOT NULL,
|
|
||||||
foldToStreet2CBChance INT NOT NULL,
|
|
||||||
foldToStreet2CBDone INT NOT NULL,
|
|
||||||
foldToStreet3CBChance INT NOT NULL,
|
|
||||||
foldToStreet3CBDone INT NOT NULL,
|
|
||||||
foldToStreet4CBChance INT NOT NULL,
|
|
||||||
foldToStreet4CBDone INT NOT NULL,
|
|
||||||
|
|
||||||
totalProfit INT NOT NULL,
|
|
||||||
|
|
||||||
street1CheckCallRaiseChance INT NOT NULL,
|
|
||||||
street1CheckCallRaiseDone INT NOT NULL,
|
|
||||||
street2CheckCallRaiseChance INT NOT NULL,
|
|
||||||
street2CheckCallRaiseDone INT NOT NULL,
|
|
||||||
street3CheckCallRaiseChance INT NOT NULL,
|
|
||||||
street3CheckCallRaiseDone INT NOT NULL,
|
|
||||||
street4CheckCallRaiseChance INT NOT NULL,
|
|
||||||
street4CheckCallRaiseDone INT NOT NULL,
|
|
||||||
|
|
||||||
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)
|
|
||||||
|
|
||||||
ENGINE=INNODB"""
|
|
||||||
elif(self.dbname == 'PostgreSQL'):
|
|
||||||
self.query['createHudCacheTable'] = """CREATE TABLE HudCache (
|
|
||||||
id BIGSERIAL, PRIMARY KEY (id),
|
|
||||||
gametypeId INT, FOREIGN KEY (gametypeId) REFERENCES Gametypes(id),
|
|
||||||
playerId INT, FOREIGN KEY (playerId) REFERENCES Players(id),
|
|
||||||
activeSeats SMALLINT,
|
|
||||||
position CHAR(1),
|
|
||||||
tourneyTypeId INT, 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,
|
|
||||||
|
|
||||||
wonWhenSeenStreet1 FLOAT NOT NULL,
|
|
||||||
wonWhenSeenStreet2 FLOAT,
|
|
||||||
wonWhenSeenStreet3 FLOAT,
|
|
||||||
wonWhenSeenStreet4 FLOAT,
|
|
||||||
wonAtSD FLOAT NOT NULL,
|
|
||||||
|
|
||||||
street0VPI INT NOT NULL,
|
|
||||||
street0Aggr INT,
|
|
||||||
street0_3BChance INT NOT NULL,
|
|
||||||
street0_3BDone INT NOT NULL,
|
|
||||||
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,
|
|
||||||
|
|
||||||
totalProfit 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)
|
|
||||||
"""
|
|
||||||
elif(self.dbname == 'SQLite'):
|
|
||||||
self.query['createHudCacheTable'] = """ """
|
|
||||||
|
|
||||||
if(self.dbname == 'MySQL InnoDB'):
|
|
||||||
self.query['addTourneyIndex'] = """ALTER TABLE Tourneys ADD INDEX siteTourneyNo(siteTourneyNo)"""
|
|
||||||
elif(self.dbname == 'PostgreSQL'):
|
|
||||||
self.query['addTourneyIndex'] = """CREATE INDEX siteTourneyNo ON Tourneys (siteTourneyNo)"""
|
|
||||||
elif(self.dbname == 'SQLite'):
|
|
||||||
self.query['addHandsIndex'] = """ """
|
|
||||||
|
|
||||||
if(self.dbname == 'MySQL InnoDB'):
|
|
||||||
self.query['addHandsIndex'] = """ALTER TABLE Hands ADD INDEX siteHandNo(siteHandNo)"""
|
|
||||||
elif(self.dbname == 'PostgreSQL'):
|
|
||||||
self.query['addHandsIndex'] = """CREATE INDEX siteHandNo ON Hands (siteHandNo)"""
|
|
||||||
elif(self.dbname == 'SQLite'):
|
|
||||||
self.query['addHandsIndex'] = """ """
|
|
||||||
|
|
||||||
if(self.dbname == 'MySQL InnoDB'):
|
|
||||||
self.query['addPlayersIndex'] = """ALTER TABLE Players ADD INDEX name(name)"""
|
|
||||||
elif(self.dbname == 'PostgreSQL'):
|
|
||||||
self.query['addPlayersIndex'] = """CREATE INDEX name ON Players (name)"""
|
|
||||||
elif(self.dbname == 'SQLite'):
|
|
||||||
self.query['addPlayersIndex'] = """ """
|
|
||||||
|
|
||||||
|
|
||||||
if(self.dbname == 'MySQL InnoDB' or self.dbname == 'PostgreSQL'):
|
if(self.dbname == 'MySQL InnoDB' or self.dbname == 'PostgreSQL'):
|
||||||
self.query['set tx level'] = """SET SESSION TRANSACTION
|
self.query['set tx level'] = """SET SESSION TRANSACTION
|
||||||
|
|
|
@ -86,6 +86,7 @@ class GuiBulkImport():
|
||||||
|
|
||||||
self.lab_info.set_text("Import finished")
|
self.lab_info.set_text("Import finished")
|
||||||
except:
|
except:
|
||||||
|
print "bulkimport.loadclicked error: "+str(sys.exc_value)
|
||||||
pass
|
pass
|
||||||
self.settings['global_lock'].release()
|
self.settings['global_lock'].release()
|
||||||
else:
|
else:
|
||||||
|
|
855
pyfpdb/SQL.py
855
pyfpdb/SQL.py
|
@ -162,6 +162,845 @@ class Sql:
|
||||||
#
|
#
|
||||||
if type == 'fpdb':
|
if type == 'fpdb':
|
||||||
|
|
||||||
|
################################
|
||||||
|
# List tables
|
||||||
|
################################
|
||||||
|
if db_server == 'mysql':
|
||||||
|
self.query['list_tables'] = """SHOW TABLES"""
|
||||||
|
elif db_server == 'postgres': # what is the correct value here?
|
||||||
|
self.query['list_tables'] = """SELECT table_name FROM information_schema.tables WHERE table_schema = 'public'"""
|
||||||
|
elif db_server == 'sqlite': # what is the correct value here?
|
||||||
|
self.query['list_tables'] = """SELECT name FROM sqlite_master
|
||||||
|
WHERE type='table'
|
||||||
|
ORDER BY name;"""
|
||||||
|
|
||||||
|
##################################################################
|
||||||
|
# Drop Tables - MySQL, PostgreSQL and SQLite all share same syntax
|
||||||
|
##################################################################
|
||||||
|
|
||||||
|
self.query['drop_table'] = """DROP TABLE IF EXISTS """
|
||||||
|
|
||||||
|
|
||||||
|
################################
|
||||||
|
# Create Settings
|
||||||
|
################################
|
||||||
|
if db_server == 'mysql':
|
||||||
|
self.query['createSettingsTable'] = """CREATE TABLE Settings (
|
||||||
|
version SMALLINT NOT NULL)
|
||||||
|
ENGINE=INNODB"""
|
||||||
|
elif db_server == 'postgres': # what is the correct value here?
|
||||||
|
self.query['createSettingsTable'] = """CREATE TABLE Settings (version SMALLINT)"""
|
||||||
|
|
||||||
|
elif db_server == 'sqlite': # what is the correct value here?
|
||||||
|
self.query['createSettingsTable'] = """CREATE TABLE Settings
|
||||||
|
(version INTEGER) """
|
||||||
|
|
||||||
|
|
||||||
|
################################
|
||||||
|
# Create Sites
|
||||||
|
################################
|
||||||
|
|
||||||
|
if db_server == 'mysql':
|
||||||
|
self.query['createSitesTable'] = """CREATE TABLE Sites (
|
||||||
|
id SMALLINT UNSIGNED AUTO_INCREMENT NOT NULL, PRIMARY KEY (id),
|
||||||
|
name varchar(32) NOT NULL,
|
||||||
|
currency char(3) NOT NULL)
|
||||||
|
ENGINE=INNODB"""
|
||||||
|
elif db_server == 'postgres': # what is the correct value here?
|
||||||
|
self.query['createSitesTable'] = """CREATE TABLE Sites (
|
||||||
|
id SERIAL, PRIMARY KEY (id),
|
||||||
|
name varchar(32),
|
||||||
|
currency char(3))"""
|
||||||
|
elif db_server == 'sqlite': # what is the correct value here?
|
||||||
|
self.query['createSitesTable'] = """CREATE TABLE Sites (
|
||||||
|
id INTEGER PRIMARY KEY,
|
||||||
|
name TEXT NOT NULL,
|
||||||
|
currency TEXT NOT NULL)"""
|
||||||
|
|
||||||
|
|
||||||
|
################################
|
||||||
|
# Create Gametypes
|
||||||
|
################################
|
||||||
|
|
||||||
|
if db_server == 'mysql':
|
||||||
|
self.query['createGametypesTable'] = """CREATE TABLE Gametypes (
|
||||||
|
id SMALLINT UNSIGNED AUTO_INCREMENT NOT NULL, PRIMARY KEY (id),
|
||||||
|
siteId SMALLINT UNSIGNED NOT NULL, FOREIGN KEY (siteId) REFERENCES Sites(id),
|
||||||
|
type char(4) NOT NULL,
|
||||||
|
base char(4) NOT NULL,
|
||||||
|
category varchar(9) NOT NULL,
|
||||||
|
limitType char(2) NOT NULL,
|
||||||
|
hiLo char(1) NOT NULL,
|
||||||
|
smallBlind int,
|
||||||
|
bigBlind int,
|
||||||
|
smallBet int NOT NULL,
|
||||||
|
bigBet int NOT NULL)
|
||||||
|
ENGINE=INNODB"""
|
||||||
|
elif db_server == 'postgres': # what is the correct value here?
|
||||||
|
self.query['createGametypesTable'] = """CREATE TABLE Gametypes (
|
||||||
|
id SERIAL, PRIMARY KEY (id),
|
||||||
|
siteId INTEGER, FOREIGN KEY (siteId) REFERENCES Sites(id),
|
||||||
|
type char(4),
|
||||||
|
base char(4),
|
||||||
|
category varchar(9),
|
||||||
|
limitType char(2),
|
||||||
|
hiLo char(1),
|
||||||
|
smallBlind int,
|
||||||
|
bigBlind int,
|
||||||
|
smallBet int,
|
||||||
|
bigBet int)"""
|
||||||
|
elif db_server == 'sqlite': # what is the correct value here?
|
||||||
|
self.query['createGametypesTable'] = """CREATE TABLE GameTypes (
|
||||||
|
id INTEGER PRIMARY KEY,
|
||||||
|
siteId INTEGER,
|
||||||
|
type TEXT,
|
||||||
|
base TEXT,
|
||||||
|
category TEXT,
|
||||||
|
limitType TEXT,
|
||||||
|
hiLo TEXT,
|
||||||
|
smallBlind INTEGER,
|
||||||
|
bigBlind INTEGER,
|
||||||
|
smallBet INTEGER,
|
||||||
|
bigBet INTEGER,
|
||||||
|
FOREIGN KEY(siteId) REFERENCES Sites(id) ON DELETE CASCADE)"""
|
||||||
|
|
||||||
|
|
||||||
|
################################
|
||||||
|
# Create Players
|
||||||
|
################################
|
||||||
|
|
||||||
|
if db_server == 'mysql':
|
||||||
|
self.query['createPlayersTable'] = """CREATE TABLE Players (
|
||||||
|
id INT UNSIGNED AUTO_INCREMENT NOT NULL, PRIMARY KEY (id),
|
||||||
|
name VARCHAR(32) CHARACTER SET utf8 NOT NULL,
|
||||||
|
siteId SMALLINT UNSIGNED NOT NULL, FOREIGN KEY (siteId) REFERENCES Sites(id),
|
||||||
|
comment text,
|
||||||
|
commentTs DATETIME)
|
||||||
|
ENGINE=INNODB"""
|
||||||
|
elif db_server == 'postgres': # what is the correct value here?
|
||||||
|
self.query['createPlayersTable'] = """CREATE TABLE Players (
|
||||||
|
id SERIAL, PRIMARY KEY (id),
|
||||||
|
name VARCHAR(32),
|
||||||
|
siteId INTEGER, FOREIGN KEY (siteId) REFERENCES Sites(id),
|
||||||
|
comment text,
|
||||||
|
commentTs timestamp without time zone)"""
|
||||||
|
elif db_server == 'sqlite': # what is the correct value here?
|
||||||
|
self.query['createPlayersTable'] = """CREATE TABLE Players (
|
||||||
|
id INTEGER PRIMARY KEY,
|
||||||
|
name TEXT,
|
||||||
|
siteId INTEGER,
|
||||||
|
comment TEXT,
|
||||||
|
commentTs BLOB,
|
||||||
|
FOREIGN KEY(siteId) REFERENCES Sites(id) ON DELETE CASCADE)"""
|
||||||
|
|
||||||
|
|
||||||
|
################################
|
||||||
|
# Create Autorates
|
||||||
|
################################
|
||||||
|
|
||||||
|
if db_server == 'mysql':
|
||||||
|
self.query['createAutoratesTable'] = """CREATE TABLE Autorates (
|
||||||
|
id BIGINT UNSIGNED AUTO_INCREMENT NOT NULL, PRIMARY KEY (id),
|
||||||
|
playerId INT UNSIGNED NOT NULL, FOREIGN KEY (playerId) REFERENCES Players(id),
|
||||||
|
gametypeId SMALLINT UNSIGNED NOT NULL, FOREIGN KEY (gametypeId) REFERENCES Gametypes(id),
|
||||||
|
description varchar(50) NOT NULL,
|
||||||
|
shortDesc char(8) NOT NULL,
|
||||||
|
ratingTime DATETIME NOT NULL,
|
||||||
|
handCount int NOT NULL)
|
||||||
|
ENGINE=INNODB"""
|
||||||
|
elif db_server == 'postgres': # what is the correct value here?
|
||||||
|
self.query['createAutoratesTable'] = """CREATE TABLE Autorates (
|
||||||
|
id BIGSERIAL, PRIMARY KEY (id),
|
||||||
|
playerId INT, FOREIGN KEY (playerId) REFERENCES Players(id),
|
||||||
|
gametypeId INT, FOREIGN KEY (gametypeId) REFERENCES Gametypes(id),
|
||||||
|
description varchar(50),
|
||||||
|
shortDesc char(8),
|
||||||
|
ratingTime timestamp without time zone,
|
||||||
|
handCount int)"""
|
||||||
|
elif db_server == 'sqlite': # what is the correct value here?
|
||||||
|
self.query['createAutoratesTable'] = """ """
|
||||||
|
|
||||||
|
|
||||||
|
################################
|
||||||
|
# Create Hands
|
||||||
|
################################
|
||||||
|
|
||||||
|
if db_server == 'mysql':
|
||||||
|
self.query['createHandsTable'] = """CREATE TABLE Hands (
|
||||||
|
id BIGINT UNSIGNED AUTO_INCREMENT NOT NULL, PRIMARY KEY (id),
|
||||||
|
tableName VARCHAR(20) NOT NULL,
|
||||||
|
siteHandNo BIGINT NOT NULL,
|
||||||
|
gametypeId SMALLINT UNSIGNED NOT NULL, FOREIGN KEY (gametypeId) REFERENCES Gametypes(id),
|
||||||
|
handStart DATETIME NOT NULL,
|
||||||
|
importTime DATETIME NOT NULL,
|
||||||
|
seats TINYINT NOT NULL,
|
||||||
|
maxSeats TINYINT NOT NULL,
|
||||||
|
boardcard1 smallint, /* 0=none, 1-13=2-Ah 14-26=2-Ad 27-39=2-Ac 40-52=2-As */
|
||||||
|
boardcard2 smallint,
|
||||||
|
boardcard3 smallint,
|
||||||
|
boardcard4 smallint,
|
||||||
|
boardcard5 smallint,
|
||||||
|
texture smallint,
|
||||||
|
playersVpi SMALLINT NOT NULL, /* num of players vpi */
|
||||||
|
playersAtStreet1 SMALLINT NOT NULL, /* num of players seeing flop/street4 */
|
||||||
|
playersAtStreet2 SMALLINT NOT NULL,
|
||||||
|
playersAtStreet3 SMALLINT NOT NULL,
|
||||||
|
playersAtStreet4 SMALLINT NOT NULL,
|
||||||
|
playersAtShowdown SMALLINT NOT NULL,
|
||||||
|
street0Raises TINYINT NOT NULL, /* num small bets paid to see flop/street4, including blind */
|
||||||
|
street1Raises TINYINT NOT NULL, /* num small bets paid to see turn/street5 */
|
||||||
|
street2Raises TINYINT NOT NULL, /* num big bets paid to see river/street6 */
|
||||||
|
street3Raises TINYINT NOT NULL, /* num big bets paid to see sd/street7 */
|
||||||
|
street4Raises TINYINT NOT NULL, /* num big bets paid to see showdown */
|
||||||
|
street1Pot INT, /* pot size at flop/street4 */
|
||||||
|
street2Pot INT, /* pot size at turn/street5 */
|
||||||
|
street3Pot INT, /* pot size at river/street6 */
|
||||||
|
street4Pot INT, /* pot size at sd/street7 */
|
||||||
|
showdownPot INT, /* pot size at sd/street7 */
|
||||||
|
comment TEXT,
|
||||||
|
commentTs DATETIME)
|
||||||
|
ENGINE=INNODB"""
|
||||||
|
elif db_server == 'postgres': # what is the correct value here?
|
||||||
|
self.query['createHandsTable'] = """CREATE TABLE Hands (
|
||||||
|
id BIGSERIAL, PRIMARY KEY (id),
|
||||||
|
tableName VARCHAR(20) NOT NULL,
|
||||||
|
siteHandNo BIGINT NOT NULL,
|
||||||
|
gametypeId INT NOT NULL, FOREIGN KEY (gametypeId) REFERENCES Gametypes(id),
|
||||||
|
handStart timestamp without time zone NOT NULL,
|
||||||
|
importTime timestamp without time zone NOT NULL,
|
||||||
|
seats SMALLINT NOT NULL,
|
||||||
|
maxSeats SMALLINT NOT NULL,
|
||||||
|
boardcard1 smallint, /* 0=none, 1-13=2-Ah 14-26=2-Ad 27-39=2-Ac 40-52=2-As */
|
||||||
|
boardcard2 smallint,
|
||||||
|
boardcard3 smallint,
|
||||||
|
boardcard4 smallint,
|
||||||
|
boardcard5 smallint,
|
||||||
|
texture smallint,
|
||||||
|
playersVpi SMALLINT NOT NULL, /* num of players vpi */
|
||||||
|
playersAtStreet1 SMALLINT NOT NULL, /* num of players seeing flop/street4 */
|
||||||
|
playersAtStreet2 SMALLINT NOT NULL,
|
||||||
|
playersAtStreet3 SMALLINT NOT NULL,
|
||||||
|
playersAtStreet4 SMALLINT NOT NULL,
|
||||||
|
playersAtShowdown SMALLINT NOT NULL,
|
||||||
|
street0Raises SMALLINT NOT NULL, /* num small bets paid to see flop/street4, including blind */
|
||||||
|
street1Raises SMALLINT NOT NULL, /* num small bets paid to see turn/street5 */
|
||||||
|
street2Raises SMALLINT NOT NULL, /* num big bets paid to see river/street6 */
|
||||||
|
street3Raises SMALLINT NOT NULL, /* num big bets paid to see sd/street7 */
|
||||||
|
street4Raises SMALLINT NOT NULL, /* num big bets paid to see showdown */
|
||||||
|
street1Pot INT, /* pot size at flop/street4 */
|
||||||
|
street2Pot INT, /* pot size at turn/street5 */
|
||||||
|
street3Pot INT, /* pot size at river/street6 */
|
||||||
|
street4Pot INT, /* pot size at sd/street7 */
|
||||||
|
showdownPot INT, /* pot size at sd/street7 */
|
||||||
|
comment TEXT,
|
||||||
|
commentTs timestamp without time zone)"""
|
||||||
|
elif db_server == 'sqlite': # what is the correct value here?
|
||||||
|
self.query['createHandsTable'] = """CREATE TABLE Hands (
|
||||||
|
id INTEGER PRIMARY KEY,
|
||||||
|
tableName TEXT(20),
|
||||||
|
siteHandNo INTEGER,
|
||||||
|
gametypeId INTEGER,
|
||||||
|
handStart BLOB,
|
||||||
|
importTime BLOB,
|
||||||
|
seats INTEGER,
|
||||||
|
maxSeats INTEGER,
|
||||||
|
comment TEXT,
|
||||||
|
commentTs BLOB,
|
||||||
|
FOREIGN KEY(gametypeId) REFERENCES Gametypes(id) ON DELETE CASCADE)"""
|
||||||
|
|
||||||
|
|
||||||
|
################################
|
||||||
|
# Create TourneyTypes
|
||||||
|
################################
|
||||||
|
|
||||||
|
if db_server == 'mysql':
|
||||||
|
self.query['createTourneyTypesTable'] = """CREATE TABLE TourneyTypes (
|
||||||
|
id SMALLINT UNSIGNED AUTO_INCREMENT NOT NULL, PRIMARY KEY (id),
|
||||||
|
siteId SMALLINT UNSIGNED NOT NULL, FOREIGN KEY (siteId) REFERENCES Sites(id),
|
||||||
|
buyin INT NOT NULL,
|
||||||
|
fee INT NOT NULL,
|
||||||
|
knockout INT NOT NULL,
|
||||||
|
rebuyOrAddon BOOLEAN NOT NULL)
|
||||||
|
ENGINE=INNODB"""
|
||||||
|
elif db_server == 'postgres': # what is the correct value here?
|
||||||
|
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)"""
|
||||||
|
elif db_server == 'sqlite': # what is the correct value here?
|
||||||
|
self.query['createTourneyTypesTable'] = """ """
|
||||||
|
|
||||||
|
|
||||||
|
################################
|
||||||
|
# Create Tourneys
|
||||||
|
################################
|
||||||
|
|
||||||
|
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),
|
||||||
|
siteTourneyNo BIGINT NOT NULL,
|
||||||
|
entries INT NOT NULL,
|
||||||
|
prizepool INT NOT NULL,
|
||||||
|
startTime DATETIME NOT NULL,
|
||||||
|
comment TEXT,
|
||||||
|
commentTs DATETIME)
|
||||||
|
ENGINE=INNODB"""
|
||||||
|
elif db_server == 'postgres': # what is the correct value here?
|
||||||
|
self.query['createTourneysTable'] = """CREATE TABLE Tourneys (
|
||||||
|
id SERIAL, PRIMARY KEY (id),
|
||||||
|
tourneyTypeId INT, FOREIGN KEY (tourneyTypeId) REFERENCES TourneyTypes(id),
|
||||||
|
siteTourneyNo BIGINT,
|
||||||
|
entries INT,
|
||||||
|
prizepool INT,
|
||||||
|
startTime timestamp without time zone,
|
||||||
|
comment TEXT,
|
||||||
|
commentTs timestamp without time zone)"""
|
||||||
|
elif db_server == 'sqlite': # what is the correct value here?
|
||||||
|
self.query['createTourneysTable'] = """CREATE TABLE TourneyTypes (
|
||||||
|
id INTEGER PRIMARY KEY,
|
||||||
|
siteId INTEGER,
|
||||||
|
buyin INTEGER,
|
||||||
|
fee INTEGER,
|
||||||
|
knockout INTEGER,
|
||||||
|
rebuyOrAddon BOOL,
|
||||||
|
FOREIGN KEY(siteId) REFERENCES Sites(id) ON DELETE CASCADE)"""
|
||||||
|
|
||||||
|
################################
|
||||||
|
# Create HandsPlayers
|
||||||
|
################################
|
||||||
|
|
||||||
|
if db_server == 'mysql':
|
||||||
|
self.query['createHandsPlayersTable'] = """CREATE TABLE HandsPlayers (
|
||||||
|
id BIGINT UNSIGNED AUTO_INCREMENT NOT NULL, PRIMARY KEY (id),
|
||||||
|
handId BIGINT UNSIGNED NOT NULL, FOREIGN KEY (handId) REFERENCES Hands(id),
|
||||||
|
playerId INT UNSIGNED NOT NULL, FOREIGN KEY (playerId) REFERENCES Players(id),
|
||||||
|
startCash INT NOT NULL,
|
||||||
|
position CHAR(1),
|
||||||
|
seatNo SMALLINT NOT NULL,
|
||||||
|
|
||||||
|
card1 smallint NOT NULL, /* 0=none, 1-13=2-Ah 14-26=2-Ad 27-39=2-Ac 40-52=2-As */
|
||||||
|
card2 smallint NOT NULL,
|
||||||
|
card3 smallint,
|
||||||
|
card4 smallint,
|
||||||
|
card5 smallint,
|
||||||
|
card6 smallint,
|
||||||
|
card7 smallint,
|
||||||
|
startCards smallint,
|
||||||
|
|
||||||
|
ante INT,
|
||||||
|
winnings int NOT NULL,
|
||||||
|
rake int NOT NULL,
|
||||||
|
totalProfit INT NOT NULL,
|
||||||
|
comment text,
|
||||||
|
commentTs DATETIME,
|
||||||
|
tourneysPlayersId BIGINT UNSIGNED,
|
||||||
|
tourneyTypeId SMALLINT UNSIGNED NOT NULL, FOREIGN KEY (tourneyTypeId) REFERENCES TourneyTypes(id),
|
||||||
|
|
||||||
|
wonWhenSeenStreet1 FLOAT NOT NULL,
|
||||||
|
wonWhenSeenStreet2 FLOAT,
|
||||||
|
wonWhenSeenStreet3 FLOAT,
|
||||||
|
wonWhenSeenStreet4 FLOAT,
|
||||||
|
wonAtSD FLOAT NOT NULL,
|
||||||
|
|
||||||
|
street0VPI BOOLEAN NOT NULL,
|
||||||
|
street0Aggr BOOLEAN NOT NULL,
|
||||||
|
street0_3BChance BOOLEAN NOT NULL,
|
||||||
|
street0_3BDone BOOLEAN NOT NULL,
|
||||||
|
street0_4BChance BOOLEAN,
|
||||||
|
street0_4BDone BOOLEAN,
|
||||||
|
other3BStreet0 BOOLEAN,
|
||||||
|
other4BStreet0 BOOLEAN,
|
||||||
|
|
||||||
|
street1Seen BOOLEAN NOT NULL,
|
||||||
|
street2Seen BOOLEAN NOT NULL,
|
||||||
|
street3Seen BOOLEAN NOT NULL,
|
||||||
|
street4Seen BOOLEAN NOT NULL,
|
||||||
|
sawShowdown BOOLEAN NOT NULL,
|
||||||
|
|
||||||
|
street1Aggr BOOLEAN NOT NULL,
|
||||||
|
street2Aggr BOOLEAN NOT NULL,
|
||||||
|
street3Aggr BOOLEAN NOT NULL,
|
||||||
|
street4Aggr BOOLEAN NOT NULL,
|
||||||
|
|
||||||
|
otherRaisedStreet0 BOOLEAN,
|
||||||
|
otherRaisedStreet1 BOOLEAN NOT NULL,
|
||||||
|
otherRaisedStreet2 BOOLEAN NOT NULL,
|
||||||
|
otherRaisedStreet3 BOOLEAN NOT NULL,
|
||||||
|
otherRaisedStreet4 BOOLEAN NOT NULL,
|
||||||
|
foldToOtherRaisedStreet0 BOOLEAN,
|
||||||
|
foldToOtherRaisedStreet1 BOOLEAN NOT NULL,
|
||||||
|
foldToOtherRaisedStreet2 BOOLEAN NOT NULL,
|
||||||
|
foldToOtherRaisedStreet3 BOOLEAN NOT NULL,
|
||||||
|
foldToOtherRaisedStreet4 BOOLEAN NOT NULL,
|
||||||
|
|
||||||
|
stealAttemptChance BOOLEAN NOT NULL,
|
||||||
|
stealAttempted BOOLEAN NOT NULL,
|
||||||
|
foldBbToStealChance BOOLEAN NOT NULL,
|
||||||
|
foldedBbToSteal BOOLEAN NOT NULL,
|
||||||
|
foldSbToStealChance BOOLEAN NOT NULL,
|
||||||
|
foldedSbToSteal BOOLEAN NOT NULL,
|
||||||
|
|
||||||
|
street1CBChance BOOLEAN NOT NULL,
|
||||||
|
street1CBDone BOOLEAN NOT NULL,
|
||||||
|
street2CBChance BOOLEAN NOT NULL,
|
||||||
|
street2CBDone BOOLEAN NOT NULL,
|
||||||
|
street3CBChance BOOLEAN NOT NULL,
|
||||||
|
street3CBDone BOOLEAN NOT NULL,
|
||||||
|
street4CBChance BOOLEAN NOT NULL,
|
||||||
|
street4CBDone BOOLEAN NOT NULL,
|
||||||
|
|
||||||
|
foldToStreet1CBChance BOOLEAN NOT NULL,
|
||||||
|
foldToStreet1CBDone BOOLEAN NOT NULL,
|
||||||
|
foldToStreet2CBChance BOOLEAN NOT NULL,
|
||||||
|
foldToStreet2CBDone BOOLEAN NOT NULL,
|
||||||
|
foldToStreet3CBChance BOOLEAN NOT NULL,
|
||||||
|
foldToStreet3CBDone BOOLEAN NOT NULL,
|
||||||
|
foldToStreet4CBChance BOOLEAN NOT NULL,
|
||||||
|
foldToStreet4CBDone BOOLEAN NOT NULL,
|
||||||
|
|
||||||
|
street1CheckCallRaiseChance BOOLEAN NOT NULL,
|
||||||
|
street1CheckCallRaiseDone BOOLEAN NOT NULL,
|
||||||
|
street2CheckCallRaiseChance BOOLEAN NOT NULL,
|
||||||
|
street2CheckCallRaiseDone BOOLEAN NOT NULL,
|
||||||
|
street3CheckCallRaiseChance BOOLEAN NOT NULL,
|
||||||
|
street3CheckCallRaiseDone BOOLEAN NOT NULL,
|
||||||
|
street4CheckCallRaiseChance BOOLEAN NOT NULL,
|
||||||
|
street4CheckCallRaiseDone BOOLEAN NOT NULL,
|
||||||
|
|
||||||
|
street0Calls TINYINT,
|
||||||
|
street1Calls TINYINT,
|
||||||
|
street2Calls TINYINT,
|
||||||
|
street3Calls TINYINT,
|
||||||
|
street4Calls TINYINT,
|
||||||
|
street0Bets TINYINT,
|
||||||
|
street1Bets TINYINT,
|
||||||
|
street2Bets TINYINT,
|
||||||
|
street3Bets TINYINT,
|
||||||
|
street4Bets TINYINT,
|
||||||
|
street0Raises TINYINT,
|
||||||
|
street1Raises TINYINT,
|
||||||
|
street2Raises TINYINT,
|
||||||
|
street3Raises TINYINT,
|
||||||
|
street4Raises TINYINT,
|
||||||
|
|
||||||
|
actionString VARCHAR(15),
|
||||||
|
|
||||||
|
FOREIGN KEY (tourneysPlayersId) REFERENCES TourneysPlayers(id))
|
||||||
|
ENGINE=INNODB"""
|
||||||
|
elif db_server == 'postgres': # what is the correct value here?
|
||||||
|
self.query['createHandsPlayersTable'] = """CREATE TABLE HandsPlayers (
|
||||||
|
id BIGSERIAL, PRIMARY KEY (id),
|
||||||
|
handId BIGINT NOT NULL, FOREIGN KEY (handId) REFERENCES Hands(id),
|
||||||
|
playerId INT NOT NULL, FOREIGN KEY (playerId) REFERENCES Players(id),
|
||||||
|
startCash INT NOT NULL,
|
||||||
|
position CHAR(1),
|
||||||
|
seatNo SMALLINT NOT NULL,
|
||||||
|
|
||||||
|
card1 smallint NOT NULL, /* 0=none, 1-13=2-Ah 14-26=2-Ad 27-39=2-Ac 40-52=2-As */
|
||||||
|
card2 smallint NOT NULL,
|
||||||
|
card3 smallint,
|
||||||
|
card4 smallint,
|
||||||
|
card5 smallint,
|
||||||
|
card6 smallint,
|
||||||
|
card7 smallint,
|
||||||
|
startCards smallint,
|
||||||
|
|
||||||
|
ante INT,
|
||||||
|
winnings int NOT NULL,
|
||||||
|
rake int NOT NULL,
|
||||||
|
totalProfit INT NOT NULL,
|
||||||
|
comment text,
|
||||||
|
commentTs timestamp without time zone,
|
||||||
|
tourneysPlayersId BIGINT,
|
||||||
|
tourneyTypeId INT NOT NULL, FOREIGN KEY (tourneyTypeId) REFERENCES TourneyTypes(id),
|
||||||
|
|
||||||
|
wonWhenSeenStreet1 FLOAT NOT NULL,
|
||||||
|
wonWhenSeenStreet2 FLOAT,
|
||||||
|
wonWhenSeenStreet3 FLOAT,
|
||||||
|
wonWhenSeenStreet4 FLOAT,
|
||||||
|
wonAtSD FLOAT NOT NULL,
|
||||||
|
|
||||||
|
street0VPI BOOLEAN NOT NULL,
|
||||||
|
street0Aggr BOOLEAN NOT NULL,
|
||||||
|
street0_3BChance BOOLEAN NOT NULL,
|
||||||
|
street0_3BDone BOOLEAN NOT NULL,
|
||||||
|
street0_4BChance BOOLEAN,
|
||||||
|
street0_4BDone BOOLEAN,
|
||||||
|
other3BStreet0 BOOLEAN,
|
||||||
|
other4BStreet0 BOOLEAN,
|
||||||
|
|
||||||
|
street1Seen BOOLEAN NOT NULL,
|
||||||
|
street2Seen BOOLEAN NOT NULL,
|
||||||
|
street3Seen BOOLEAN NOT NULL,
|
||||||
|
street4Seen BOOLEAN NOT NULL,
|
||||||
|
sawShowdown BOOLEAN NOT NULL,
|
||||||
|
|
||||||
|
street1Aggr BOOLEAN NOT NULL,
|
||||||
|
street2Aggr BOOLEAN NOT NULL,
|
||||||
|
street3Aggr BOOLEAN NOT NULL,
|
||||||
|
street4Aggr BOOLEAN NOT NULL,
|
||||||
|
|
||||||
|
otherRaisedStreet0 BOOLEAN,
|
||||||
|
otherRaisedStreet1 BOOLEAN NOT NULL,
|
||||||
|
otherRaisedStreet2 BOOLEAN NOT NULL,
|
||||||
|
otherRaisedStreet3 BOOLEAN NOT NULL,
|
||||||
|
otherRaisedStreet4 BOOLEAN NOT NULL,
|
||||||
|
foldToOtherRaisedStreet0 BOOLEAN,
|
||||||
|
foldToOtherRaisedStreet1 BOOLEAN NOT NULL,
|
||||||
|
foldToOtherRaisedStreet2 BOOLEAN NOT NULL,
|
||||||
|
foldToOtherRaisedStreet3 BOOLEAN NOT NULL,
|
||||||
|
foldToOtherRaisedStreet4 BOOLEAN NOT NULL,
|
||||||
|
|
||||||
|
stealAttemptChance BOOLEAN NOT NULL,
|
||||||
|
stealAttempted BOOLEAN NOT NULL,
|
||||||
|
foldBbToStealChance BOOLEAN NOT NULL,
|
||||||
|
foldedBbToSteal BOOLEAN NOT NULL,
|
||||||
|
foldSbToStealChance BOOLEAN NOT NULL,
|
||||||
|
foldedSbToSteal BOOLEAN NOT NULL,
|
||||||
|
|
||||||
|
street1CBChance BOOLEAN NOT NULL,
|
||||||
|
street1CBDone BOOLEAN NOT NULL,
|
||||||
|
street2CBChance BOOLEAN NOT NULL,
|
||||||
|
street2CBDone BOOLEAN NOT NULL,
|
||||||
|
street3CBChance BOOLEAN NOT NULL,
|
||||||
|
street3CBDone BOOLEAN NOT NULL,
|
||||||
|
street4CBChance BOOLEAN NOT NULL,
|
||||||
|
street4CBDone BOOLEAN NOT NULL,
|
||||||
|
|
||||||
|
foldToStreet1CBChance BOOLEAN NOT NULL,
|
||||||
|
foldToStreet1CBDone BOOLEAN NOT NULL,
|
||||||
|
foldToStreet2CBChance BOOLEAN NOT NULL,
|
||||||
|
foldToStreet2CBDone BOOLEAN NOT NULL,
|
||||||
|
foldToStreet3CBChance BOOLEAN NOT NULL,
|
||||||
|
foldToStreet3CBDone BOOLEAN NOT NULL,
|
||||||
|
foldToStreet4CBChance BOOLEAN NOT NULL,
|
||||||
|
foldToStreet4CBDone BOOLEAN NOT NULL,
|
||||||
|
|
||||||
|
street1CheckCallRaiseChance BOOLEAN NOT NULL,
|
||||||
|
street1CheckCallRaiseDone BOOLEAN NOT NULL,
|
||||||
|
street2CheckCallRaiseChance BOOLEAN NOT NULL,
|
||||||
|
street2CheckCallRaiseDone BOOLEAN NOT NULL,
|
||||||
|
street3CheckCallRaiseChance BOOLEAN NOT NULL,
|
||||||
|
street3CheckCallRaiseDone BOOLEAN NOT NULL,
|
||||||
|
street4CheckCallRaiseChance BOOLEAN NOT NULL,
|
||||||
|
street4CheckCallRaiseDone BOOLEAN NOT NULL,
|
||||||
|
|
||||||
|
street0Calls SMALLINT,
|
||||||
|
street1Calls SMALLINT,
|
||||||
|
street2Calls SMALLINT,
|
||||||
|
street3Calls SMALLINT,
|
||||||
|
street4Calls SMALLINT,
|
||||||
|
street0Bets SMALLINT,
|
||||||
|
street1Bets SMALLINT,
|
||||||
|
street2Bets SMALLINT,
|
||||||
|
street3Bets SMALLINT,
|
||||||
|
street4Bets SMALLINT,
|
||||||
|
street0Raises SMALLINT,
|
||||||
|
street1Raises SMALLINT,
|
||||||
|
street2Raises SMALLINT,
|
||||||
|
street3Raises SMALLINT,
|
||||||
|
street4Raises SMALLINT,
|
||||||
|
|
||||||
|
actionString VARCHAR(15),
|
||||||
|
|
||||||
|
FOREIGN KEY (tourneysPlayersId) REFERENCES TourneysPlayers(id))"""
|
||||||
|
elif db_server == 'sqlite': # what is the correct value here?
|
||||||
|
self.query['createHandsPlayersTable'] = """ """
|
||||||
|
|
||||||
|
|
||||||
|
################################
|
||||||
|
# Create TourneysPlayers
|
||||||
|
################################
|
||||||
|
|
||||||
|
if db_server == 'mysql':
|
||||||
|
self.query['createTourneysPlayersTable'] = """CREATE TABLE TourneysPlayers (
|
||||||
|
id BIGINT UNSIGNED AUTO_INCREMENT NOT NULL, PRIMARY KEY (id),
|
||||||
|
tourneyId INT UNSIGNED NOT NULL, FOREIGN KEY (tourneyId) REFERENCES Tourneys(id),
|
||||||
|
playerId INT UNSIGNED NOT NULL, FOREIGN KEY (playerId) REFERENCES Players(id),
|
||||||
|
payinAmount INT NOT NULL,
|
||||||
|
rank INT NOT NULL,
|
||||||
|
winnings INT NOT NULL,
|
||||||
|
comment TEXT,
|
||||||
|
commentTs DATETIME)
|
||||||
|
ENGINE=INNODB"""
|
||||||
|
elif db_server == 'postgres': # what is the correct value here?
|
||||||
|
self.query['createTourneysPlayersTable'] = """CREATE TABLE TourneysPlayers (
|
||||||
|
id BIGSERIAL, PRIMARY KEY (id),
|
||||||
|
tourneyId INT, FOREIGN KEY (tourneyId) REFERENCES Tourneys(id),
|
||||||
|
playerId INT, FOREIGN KEY (playerId) REFERENCES Players(id),
|
||||||
|
payinAmount INT,
|
||||||
|
rank INT,
|
||||||
|
winnings INT,
|
||||||
|
comment TEXT,
|
||||||
|
commentTs timestamp without time zone)"""
|
||||||
|
elif db_server == 'sqlite': # what is the correct value here?
|
||||||
|
self.query['createTourneysPlayersTable'] = """ """
|
||||||
|
|
||||||
|
|
||||||
|
################################
|
||||||
|
# Create HandsActions
|
||||||
|
################################
|
||||||
|
|
||||||
|
if db_server == 'mysql':
|
||||||
|
self.query['createHandsActionsTable'] = """CREATE TABLE HandsActions (
|
||||||
|
id BIGINT UNSIGNED AUTO_INCREMENT NOT NULL, PRIMARY KEY (id),
|
||||||
|
handsPlayerId BIGINT UNSIGNED NOT NULL, FOREIGN KEY (handsPlayerId) REFERENCES HandsPlayers(id),
|
||||||
|
street SMALLINT NOT NULL,
|
||||||
|
actionNo SMALLINT NOT NULL,
|
||||||
|
action CHAR(5) NOT NULL,
|
||||||
|
allIn BOOLEAN NOT NULL,
|
||||||
|
amount INT NOT NULL,
|
||||||
|
comment TEXT,
|
||||||
|
commentTs DATETIME)
|
||||||
|
ENGINE=INNODB"""
|
||||||
|
elif db_server == 'postgres': # what is the correct value here?
|
||||||
|
self.query['createHandsActionsTable'] = """CREATE TABLE HandsActions (
|
||||||
|
id BIGSERIAL, PRIMARY KEY (id),
|
||||||
|
handsPlayerId BIGINT, FOREIGN KEY (handsPlayerId) REFERENCES HandsPlayers(id),
|
||||||
|
street SMALLINT,
|
||||||
|
actionNo SMALLINT,
|
||||||
|
action CHAR(5),
|
||||||
|
allIn BOOLEAN,
|
||||||
|
amount INT,
|
||||||
|
comment TEXT,
|
||||||
|
commentTs timestamp without time zone)"""
|
||||||
|
elif db_server == 'sqlite': # what is the correct value here?
|
||||||
|
self.query['createHandsActionsTable'] = """ """
|
||||||
|
|
||||||
|
|
||||||
|
################################
|
||||||
|
# Create HudCache
|
||||||
|
################################
|
||||||
|
|
||||||
|
if db_server == 'mysql':
|
||||||
|
self.query['createHudCacheTable'] = """CREATE TABLE HudCache (
|
||||||
|
id BIGINT UNSIGNED AUTO_INCREMENT NOT NULL, PRIMARY KEY (id),
|
||||||
|
gametypeId SMALLINT UNSIGNED NOT NULL, FOREIGN KEY (gametypeId) REFERENCES Gametypes(id),
|
||||||
|
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),
|
||||||
|
styleKey CHAR(7) NOT NULL, /* 1st char is style (A/T/H/S), other 6 are the key */
|
||||||
|
HDs INT NOT NULL,
|
||||||
|
|
||||||
|
wonWhenSeenStreet1 FLOAT NOT NULL,
|
||||||
|
wonWhenSeenStreet2 FLOAT,
|
||||||
|
wonWhenSeenStreet3 FLOAT,
|
||||||
|
wonWhenSeenStreet4 FLOAT,
|
||||||
|
wonAtSD FLOAT NOT NULL,
|
||||||
|
|
||||||
|
street0VPI INT NOT NULL,
|
||||||
|
street0Aggr INT NOT NULL,
|
||||||
|
street0_3BChance INT NOT NULL,
|
||||||
|
street0_3BDone INT NOT NULL,
|
||||||
|
street0_4BChance INT,
|
||||||
|
street0_4BDone INT,
|
||||||
|
other3BStreet0 INT,
|
||||||
|
other4BStreet0 INT,
|
||||||
|
|
||||||
|
street1Seen INT NOT NULL,
|
||||||
|
street2Seen INT NOT NULL,
|
||||||
|
street3Seen INT NOT NULL,
|
||||||
|
street4Seen INT NOT NULL,
|
||||||
|
sawShowdown INT NOT NULL,
|
||||||
|
|
||||||
|
street1Aggr INT NOT NULL,
|
||||||
|
street2Aggr INT NOT NULL,
|
||||||
|
street3Aggr INT NOT NULL,
|
||||||
|
street4Aggr INT NOT NULL,
|
||||||
|
|
||||||
|
otherRaisedStreet0 INT,
|
||||||
|
otherRaisedStreet1 INT NOT NULL,
|
||||||
|
otherRaisedStreet2 INT NOT NULL,
|
||||||
|
otherRaisedStreet3 INT NOT NULL,
|
||||||
|
otherRaisedStreet4 INT NOT NULL,
|
||||||
|
foldToOtherRaisedStreet0 INT,
|
||||||
|
foldToOtherRaisedStreet1 INT NOT NULL,
|
||||||
|
foldToOtherRaisedStreet2 INT NOT NULL,
|
||||||
|
foldToOtherRaisedStreet3 INT NOT NULL,
|
||||||
|
foldToOtherRaisedStreet4 INT NOT NULL,
|
||||||
|
|
||||||
|
stealAttemptChance INT NOT NULL,
|
||||||
|
stealAttempted INT NOT NULL,
|
||||||
|
foldBbToStealChance INT NOT NULL,
|
||||||
|
foldedBbToSteal INT NOT NULL,
|
||||||
|
foldSbToStealChance INT NOT NULL,
|
||||||
|
foldedSbToSteal INT NOT NULL,
|
||||||
|
|
||||||
|
street1CBChance INT NOT NULL,
|
||||||
|
street1CBDone INT NOT NULL,
|
||||||
|
street2CBChance INT NOT NULL,
|
||||||
|
street2CBDone INT NOT NULL,
|
||||||
|
street3CBChance INT NOT NULL,
|
||||||
|
street3CBDone INT NOT NULL,
|
||||||
|
street4CBChance INT NOT NULL,
|
||||||
|
street4CBDone INT NOT NULL,
|
||||||
|
|
||||||
|
foldToStreet1CBChance INT NOT NULL,
|
||||||
|
foldToStreet1CBDone INT NOT NULL,
|
||||||
|
foldToStreet2CBChance INT NOT NULL,
|
||||||
|
foldToStreet2CBDone INT NOT NULL,
|
||||||
|
foldToStreet3CBChance INT NOT NULL,
|
||||||
|
foldToStreet3CBDone INT NOT NULL,
|
||||||
|
foldToStreet4CBChance INT NOT NULL,
|
||||||
|
foldToStreet4CBDone INT NOT NULL,
|
||||||
|
|
||||||
|
totalProfit INT NOT NULL,
|
||||||
|
|
||||||
|
street1CheckCallRaiseChance INT NOT NULL,
|
||||||
|
street1CheckCallRaiseDone INT NOT NULL,
|
||||||
|
street2CheckCallRaiseChance INT NOT NULL,
|
||||||
|
street2CheckCallRaiseDone INT NOT NULL,
|
||||||
|
street3CheckCallRaiseChance INT NOT NULL,
|
||||||
|
street3CheckCallRaiseDone INT NOT NULL,
|
||||||
|
street4CheckCallRaiseChance INT NOT NULL,
|
||||||
|
street4CheckCallRaiseDone INT NOT NULL,
|
||||||
|
|
||||||
|
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)
|
||||||
|
|
||||||
|
ENGINE=INNODB"""
|
||||||
|
elif db_server == 'postgres': # what is the correct value here?
|
||||||
|
self.query['createHudCacheTable'] = """CREATE TABLE HudCache (
|
||||||
|
id BIGSERIAL, PRIMARY KEY (id),
|
||||||
|
gametypeId INT, FOREIGN KEY (gametypeId) REFERENCES Gametypes(id),
|
||||||
|
playerId INT, FOREIGN KEY (playerId) REFERENCES Players(id),
|
||||||
|
activeSeats SMALLINT,
|
||||||
|
position CHAR(1),
|
||||||
|
tourneyTypeId INT, 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,
|
||||||
|
|
||||||
|
wonWhenSeenStreet1 FLOAT NOT NULL,
|
||||||
|
wonWhenSeenStreet2 FLOAT,
|
||||||
|
wonWhenSeenStreet3 FLOAT,
|
||||||
|
wonWhenSeenStreet4 FLOAT,
|
||||||
|
wonAtSD FLOAT NOT NULL,
|
||||||
|
|
||||||
|
street0VPI INT NOT NULL,
|
||||||
|
street0Aggr INT,
|
||||||
|
street0_3BChance INT NOT NULL,
|
||||||
|
street0_3BDone INT NOT NULL,
|
||||||
|
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,
|
||||||
|
|
||||||
|
totalProfit 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)
|
||||||
|
"""
|
||||||
|
elif db_server == 'sqlite': # what is the correct value here?
|
||||||
|
self.query['createHudCacheTable'] = """ """
|
||||||
|
|
||||||
|
if db_server == 'mysql':
|
||||||
|
self.query['addTourneyIndex'] = """ALTER TABLE Tourneys ADD INDEX siteTourneyNo(siteTourneyNo)"""
|
||||||
|
elif db_server == 'postgres': # what is the correct value here?
|
||||||
|
self.query['addTourneyIndex'] = """CREATE INDEX siteTourneyNo ON Tourneys (siteTourneyNo)"""
|
||||||
|
elif db_server == 'sqlite': # what is the correct value here?
|
||||||
|
self.query['addHandsIndex'] = """ """
|
||||||
|
|
||||||
|
if db_server == 'mysql':
|
||||||
|
self.query['addHandsIndex'] = """ALTER TABLE Hands ADD INDEX siteHandNo(siteHandNo)"""
|
||||||
|
elif db_server == 'postgres': # what is the correct value here?
|
||||||
|
self.query['addHandsIndex'] = """CREATE INDEX siteHandNo ON Hands (siteHandNo)"""
|
||||||
|
elif db_server == 'sqlite': # what is the correct value here?
|
||||||
|
self.query['addHandsIndex'] = """ """
|
||||||
|
|
||||||
|
if db_server == 'mysql':
|
||||||
|
self.query['addPlayersIndex'] = """ALTER TABLE Players ADD INDEX name(name)"""
|
||||||
|
elif db_server == 'postgres': # what is the correct value here?
|
||||||
|
self.query['addPlayersIndex'] = """CREATE INDEX name ON Players (name)"""
|
||||||
|
elif db_server == 'sqlite': # what is the correct value here?
|
||||||
|
self.query['addPlayersIndex'] = """ """
|
||||||
|
|
||||||
|
|
||||||
self.query['get_last_hand'] = "select max(id) from Hands"
|
self.query['get_last_hand'] = "select max(id) from Hands"
|
||||||
|
|
||||||
self.query['get_player_id'] = """
|
self.query['get_player_id'] = """
|
||||||
|
@ -171,6 +1010,8 @@ class Sql:
|
||||||
and Players.SiteId = Sites.id
|
and Players.SiteId = Sites.id
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
self.query['getSiteId'] = """SELECT id from Sites where name = %s"""
|
||||||
|
|
||||||
self.query['get_stats_from_hand'] = """
|
self.query['get_stats_from_hand'] = """
|
||||||
SELECT hc.playerId AS player_id,
|
SELECT hc.playerId AS player_id,
|
||||||
hp.seatNo AS seat,
|
hp.seatNo AS seat,
|
||||||
|
@ -745,7 +1586,7 @@ class Sql:
|
||||||
,upper(gt.limitType)
|
,upper(gt.limitType)
|
||||||
,s.name
|
,s.name
|
||||||
"""
|
"""
|
||||||
#elif(self.dbname == 'SQLite'):
|
#elif db_server == 'sqlite': # what is the correct value here?
|
||||||
# self.query['playerDetailedStats'] = """ """
|
# self.query['playerDetailedStats'] = """ """
|
||||||
|
|
||||||
if db_server == 'mysql':
|
if db_server == 'mysql':
|
||||||
|
@ -957,7 +1798,7 @@ class Sql:
|
||||||
) hprof2
|
) hprof2
|
||||||
on hprof2.gtId = stats.gtId
|
on hprof2.gtId = stats.gtId
|
||||||
order by stats.base, stats.limittype, stats.bigBlindDesc desc <orderbyseats>"""
|
order by stats.base, stats.limittype, stats.bigBlindDesc desc <orderbyseats>"""
|
||||||
#elif(self.dbname == 'SQLite'):
|
#elif db_server == 'sqlite': # what is the correct value here?
|
||||||
# self.query['playerStats'] = """ """
|
# self.query['playerStats'] = """ """
|
||||||
|
|
||||||
if db_server == 'mysql':
|
if db_server == 'mysql':
|
||||||
|
@ -1232,7 +2073,7 @@ class Sql:
|
||||||
order by stats.category, stats.limitType, stats.bigBlindDesc desc
|
order by stats.category, stats.limitType, stats.bigBlindDesc desc
|
||||||
<orderbyseats>, cast(stats.PlPosition as smallint)
|
<orderbyseats>, cast(stats.PlPosition as smallint)
|
||||||
"""
|
"""
|
||||||
#elif(self.dbname == 'SQLite'):
|
#elif db_server == 'sqlite': # what is the correct value here?
|
||||||
# self.query['playerStatsByPosition'] = """ """
|
# self.query['playerStatsByPosition'] = """ """
|
||||||
|
|
||||||
self.query['getRingProfitAllHandsPlayerIdSite'] = """
|
self.query['getRingProfitAllHandsPlayerIdSite'] = """
|
||||||
|
@ -1556,15 +2397,17 @@ class Sql:
|
||||||
|
|
||||||
if db_server == 'mysql':
|
if db_server == 'mysql':
|
||||||
self.query['analyze'] = """
|
self.query['analyze'] = """
|
||||||
analyze table autorates, gametypes, hands, handsplayers, hudcache, players
|
analyze table Autorates, GameTypes, Hands, HandsPlayers, Hudcache, Players
|
||||||
, settings, sites, tourneys, tourneysplayers, tourneytypes
|
, Settings, Sites, Tourneys, TourneysPlayers, TourneyTypes
|
||||||
"""
|
"""
|
||||||
else: # assume postgres
|
else: # assume postgres
|
||||||
self.query['analyze'] = "vacuum analyze"
|
self.query['analyze'] = "vacuum analyze"
|
||||||
|
|
||||||
if db_server == 'mysql':
|
if db_server == 'mysql':
|
||||||
self.query['lockForInsert'] = """
|
self.query['lockForInsert'] = """
|
||||||
lock tables hands write, handsplayers write, handsactions write, players write, hudcache write
|
lock tables Hands write, HandsPlayers write, HandsActions write, Players write
|
||||||
|
, HudCache write, GameTypes write, Sites write, Tourneys write
|
||||||
|
, TourneysPlayers write, TourneyTypes write, Autorates write
|
||||||
"""
|
"""
|
||||||
else: # assume postgres
|
else: # assume postgres
|
||||||
self.query['lockForInsert'] = ""
|
self.query['lockForInsert'] = ""
|
||||||
|
|
|
@ -232,7 +232,7 @@ class fpdb:
|
||||||
# ToDo: lock all other tables so that lock doesn't have to be released
|
# ToDo: lock all other tables so that lock doesn't have to be released
|
||||||
# self.release_global_lock()
|
# self.release_global_lock()
|
||||||
# lock_released = True
|
# lock_released = True
|
||||||
self.db.fdb.recreate_tables()
|
self.db.recreate_tables()
|
||||||
#else:
|
#else:
|
||||||
# for other dbs use same connection as holds global lock
|
# for other dbs use same connection as holds global lock
|
||||||
# self.fdb_lock.fdb.recreate_tables()
|
# self.fdb_lock.fdb.recreate_tables()
|
||||||
|
|
|
@ -33,112 +33,6 @@ class fpdb_db:
|
||||||
self.db = None
|
self.db = None
|
||||||
self.cursor = None
|
self.cursor = None
|
||||||
self.sql = {}
|
self.sql = {}
|
||||||
|
|
||||||
# Data Structures for index and foreign key creation
|
|
||||||
# drop_code is an int with possible values: 0 - don't drop for bulk import
|
|
||||||
# 1 - drop during bulk import
|
|
||||||
# db differences:
|
|
||||||
# - note that mysql automatically creates indexes on constrained columns when
|
|
||||||
# foreign keys are created, while postgres does not. Hence the much longer list
|
|
||||||
# of indexes is required for postgres.
|
|
||||||
# all primary keys are left on all the time
|
|
||||||
#
|
|
||||||
# table column drop_code
|
|
||||||
|
|
||||||
self.indexes = [
|
|
||||||
[ ] # no db with index 0
|
|
||||||
, [ ] # no db with index 1
|
|
||||||
, [ # indexes for mysql (list index 2)
|
|
||||||
{'tab':'Players', 'col':'name', 'drop':0}
|
|
||||||
, {'tab':'Hands', 'col':'siteHandNo', 'drop':0}
|
|
||||||
, {'tab':'Tourneys', 'col':'siteTourneyNo', 'drop':0}
|
|
||||||
]
|
|
||||||
, [ # indexes for postgres (list index 3)
|
|
||||||
{'tab':'Boardcards', 'col':'handId', 'drop':0}
|
|
||||||
, {'tab':'Gametypes', 'col':'siteId', 'drop':0}
|
|
||||||
, {'tab':'Hands', 'col':'gametypeId', 'drop':0} # mct 22/3/09
|
|
||||||
, {'tab':'Hands', 'col':'siteHandNo', 'drop':0}
|
|
||||||
, {'tab':'HandsActions', 'col':'handsPlayerId', 'drop':0}
|
|
||||||
, {'tab':'HandsPlayers', 'col':'handId', 'drop':1}
|
|
||||||
, {'tab':'HandsPlayers', 'col':'playerId', 'drop':1}
|
|
||||||
, {'tab':'HandsPlayers', 'col':'tourneysPlayersId', 'drop':0}
|
|
||||||
, {'tab':'HudCache', 'col':'gametypeId', 'drop':1}
|
|
||||||
, {'tab':'HudCache', 'col':'playerId', 'drop':0}
|
|
||||||
, {'tab':'HudCache', 'col':'tourneyTypeId', 'drop':0}
|
|
||||||
, {'tab':'Players', 'col':'siteId', 'drop':1}
|
|
||||||
, {'tab':'Players', 'col':'name', 'drop':0}
|
|
||||||
, {'tab':'Tourneys', 'col':'tourneyTypeId', 'drop':1}
|
|
||||||
, {'tab':'Tourneys', 'col':'siteTourneyNo', 'drop':0}
|
|
||||||
, {'tab':'TourneysPlayers', 'col':'playerId', 'drop':0}
|
|
||||||
, {'tab':'TourneysPlayers', 'col':'tourneyId', 'drop':0}
|
|
||||||
, {'tab':'TourneyTypes', 'col':'siteId', 'drop':0}
|
|
||||||
]
|
|
||||||
, [ # indexes for sqlite (list index 4)
|
|
||||||
]
|
|
||||||
]
|
|
||||||
|
|
||||||
self.foreignKeys = [
|
|
||||||
[ ] # no db with index 0
|
|
||||||
, [ ] # no db with index 1
|
|
||||||
, [ # foreign keys for mysql
|
|
||||||
{'fktab':'Hands', 'fkcol':'gametypeId', 'rtab':'Gametypes', 'rcol':'id', 'drop':1}
|
|
||||||
, {'fktab':'HandsPlayers', 'fkcol':'handId', 'rtab':'Hands', 'rcol':'id', 'drop':1}
|
|
||||||
, {'fktab':'HandsPlayers', 'fkcol':'playerId', 'rtab':'Players', 'rcol':'id', 'drop':1}
|
|
||||||
, {'fktab':'HandsActions', 'fkcol':'handsPlayerId', 'rtab':'HandsPlayers', 'rcol':'id', 'drop':1}
|
|
||||||
, {'fktab':'HudCache', 'fkcol':'gametypeId', 'rtab':'Gametypes', 'rcol':'id', 'drop':1}
|
|
||||||
, {'fktab':'HudCache', 'fkcol':'playerId', 'rtab':'Players', 'rcol':'id', 'drop':0}
|
|
||||||
, {'fktab':'HudCache', 'fkcol':'tourneyTypeId', 'rtab':'TourneyTypes', 'rcol':'id', 'drop':1}
|
|
||||||
]
|
|
||||||
, [ # foreign keys for postgres
|
|
||||||
{'fktab':'Hands', 'fkcol':'gametypeId', 'rtab':'Gametypes', 'rcol':'id', 'drop':1}
|
|
||||||
, {'fktab':'HandsPlayers', 'fkcol':'handId', 'rtab':'Hands', 'rcol':'id', 'drop':1}
|
|
||||||
, {'fktab':'HandsPlayers', 'fkcol':'playerId', 'rtab':'Players', 'rcol':'id', 'drop':1}
|
|
||||||
, {'fktab':'HandsActions', 'fkcol':'handsPlayerId', 'rtab':'HandsPlayers', 'rcol':'id', 'drop':1}
|
|
||||||
, {'fktab':'HudCache', 'fkcol':'gametypeId', 'rtab':'Gametypes', 'rcol':'id', 'drop':1}
|
|
||||||
, {'fktab':'HudCache', 'fkcol':'playerId', 'rtab':'Players', 'rcol':'id', 'drop':0}
|
|
||||||
, {'fktab':'HudCache', 'fkcol':'tourneyTypeId', 'rtab':'TourneyTypes', 'rcol':'id', 'drop':1}
|
|
||||||
]
|
|
||||||
]
|
|
||||||
|
|
||||||
|
|
||||||
# MySQL Notes:
|
|
||||||
# "FOREIGN KEY (handId) REFERENCES Hands(id)" - requires index on Hands.id
|
|
||||||
# - creates index handId on <thistable>.handId
|
|
||||||
# alter table t drop foreign key fk
|
|
||||||
# alter table t add foreign key (fkcol) references tab(rcol)
|
|
||||||
# alter table t add constraint c foreign key (fkcol) references tab(rcol)
|
|
||||||
# (fkcol is used for foreigh key name)
|
|
||||||
|
|
||||||
# mysql to list indexes:
|
|
||||||
# SELECT table_name, index_name, non_unique, column_name
|
|
||||||
# FROM INFORMATION_SCHEMA.STATISTICS
|
|
||||||
# WHERE table_name = 'tbl_name'
|
|
||||||
# AND table_schema = 'db_name'
|
|
||||||
# ORDER BY table_name, index_name, seq_in_index
|
|
||||||
#
|
|
||||||
# ALTER TABLE Tourneys ADD INDEX siteTourneyNo(siteTourneyNo)
|
|
||||||
# ALTER TABLE tab DROP INDEX idx
|
|
||||||
|
|
||||||
# mysql to list fks:
|
|
||||||
# SELECT constraint_name, table_name, column_name, referenced_table_name, referenced_column_name
|
|
||||||
# FROM information_schema.KEY_COLUMN_USAGE
|
|
||||||
# WHERE REFERENCED_TABLE_SCHEMA = (your schema name here)
|
|
||||||
# AND REFERENCED_TABLE_NAME is not null
|
|
||||||
# ORDER BY TABLE_NAME, COLUMN_NAME;
|
|
||||||
|
|
||||||
# this may indicate missing object
|
|
||||||
# _mysql_exceptions.OperationalError: (1025, "Error on rename of '.\\fpdb\\hands' to '.\\fpdb\\#sql2-7f0-1b' (errno: 152)")
|
|
||||||
|
|
||||||
|
|
||||||
# PG notes:
|
|
||||||
|
|
||||||
# To add a foreign key constraint to a table:
|
|
||||||
# ALTER TABLE tab ADD CONSTRAINT c FOREIGN KEY (col) REFERENCES t2(col2) MATCH FULL;
|
|
||||||
# ALTER TABLE tab DROP CONSTRAINT zipchk
|
|
||||||
#
|
|
||||||
# Note: index names must be unique across a schema
|
|
||||||
# CREATE INDEX idx ON tab(col)
|
|
||||||
# DROP INDEX idx
|
|
||||||
#end def __init__
|
#end def __init__
|
||||||
|
|
||||||
def do_connect(self, config=None):
|
def do_connect(self, config=None):
|
||||||
|
@ -245,80 +139,6 @@ class fpdb_db:
|
||||||
self.disconnect(due_to_error)
|
self.disconnect(due_to_error)
|
||||||
self.connect(self.backend, self.host, self.database, self.user, self.password)
|
self.connect(self.backend, self.host, self.database, self.user, self.password)
|
||||||
|
|
||||||
def create_tables(self):
|
|
||||||
#todo: should detect and fail gracefully if tables already exist.
|
|
||||||
try:
|
|
||||||
logging.debug(self.sql.query['createSettingsTable'])
|
|
||||||
self.cursor.execute(self.sql.query['createSettingsTable'])
|
|
||||||
logging.debug(self.sql.query['createSitesTable'])
|
|
||||||
self.cursor.execute(self.sql.query['createSitesTable'])
|
|
||||||
self.cursor.execute(self.sql.query['createGametypesTable'])
|
|
||||||
self.cursor.execute(self.sql.query['createPlayersTable'])
|
|
||||||
self.cursor.execute(self.sql.query['createAutoratesTable'])
|
|
||||||
self.cursor.execute(self.sql.query['createHandsTable'])
|
|
||||||
self.cursor.execute(self.sql.query['createTourneyTypesTable'])
|
|
||||||
self.cursor.execute(self.sql.query['createTourneysTable'])
|
|
||||||
self.cursor.execute(self.sql.query['createTourneysPlayersTable'])
|
|
||||||
self.cursor.execute(self.sql.query['createHandsPlayersTable'])
|
|
||||||
#self.cursor.execute(self.sql.query['createHandsActionsTable'])
|
|
||||||
self.cursor.execute(self.sql.query['createHudCacheTable'])
|
|
||||||
#self.cursor.execute(self.sql.query['addTourneyIndex'])
|
|
||||||
#self.cursor.execute(self.sql.query['addHandsIndex'])
|
|
||||||
#self.cursor.execute(self.sql.query['addPlayersIndex'])
|
|
||||||
self.fillDefaultData()
|
|
||||||
self.db.commit()
|
|
||||||
except:
|
|
||||||
print "err: ", str(sys.exc_value)
|
|
||||||
self.db.rollback()
|
|
||||||
raise fpdb_simple.FpdbError( "Error creating tables " + str(sys.exc_value) )
|
|
||||||
#end def disconnect
|
|
||||||
|
|
||||||
def drop_tables(self):
|
|
||||||
"""Drops the fpdb tables from the current db"""
|
|
||||||
|
|
||||||
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
|
|
||||||
self.cursor.execute(self.sql.query['list_tables'])
|
|
||||||
for table in self.cursor:
|
|
||||||
self.cursor.execute(self.sql.query['drop_table'] + table[0])
|
|
||||||
elif(self.get_backend_name() == 'PostgreSQL'):
|
|
||||||
self.db.commit()# I have no idea why this makes the query work--REB 07OCT2008
|
|
||||||
self.cursor.execute(self.sql.query['list_tables'])
|
|
||||||
tables = self.cursor.fetchall()
|
|
||||||
for table in tables:
|
|
||||||
self.cursor.execute(self.sql.query['drop_table'] + table[0] + ' cascade')
|
|
||||||
elif(self.get_backend_name() == 'SQLite'):
|
|
||||||
self.cursor.execute(self.sql.query['list_tables'])
|
|
||||||
for table in self.cursor.fetchall():
|
|
||||||
logging.debug(self.sql.query['drop_table'] + table[0])
|
|
||||||
self.cursor.execute(self.sql.query['drop_table'] + table[0])
|
|
||||||
|
|
||||||
self.db.commit()
|
|
||||||
#end def drop_tables
|
|
||||||
|
|
||||||
def drop_referential_integrity(self):
|
|
||||||
"""Update all tables to remove foreign keys"""
|
|
||||||
|
|
||||||
self.cursor.execute(self.sql.query['list_tables'])
|
|
||||||
result = self.cursor.fetchall()
|
|
||||||
|
|
||||||
for i in range(len(result)):
|
|
||||||
self.cursor.execute("SHOW CREATE TABLE " + result[i][0])
|
|
||||||
inner = self.cursor.fetchall()
|
|
||||||
|
|
||||||
for j in range(len(inner)):
|
|
||||||
# result[i][0] - Table name
|
|
||||||
# result[i][1] - CREATE TABLE parameters
|
|
||||||
#Searching for CONSTRAINT `tablename_ibfk_1`
|
|
||||||
for m in re.finditer('(ibfk_[0-9]+)', inner[j][1]):
|
|
||||||
key = "`" + inner[j][0] + "_" + m.group() + "`"
|
|
||||||
self.cursor.execute("ALTER TABLE " + inner[j][0] + " DROP FOREIGN KEY " + key)
|
|
||||||
self.db.commit()
|
|
||||||
#end drop_referential_inegrity
|
|
||||||
|
|
||||||
def get_backend_name(self):
|
def get_backend_name(self):
|
||||||
"""Returns the name of the currently used backend"""
|
"""Returns the name of the currently used backend"""
|
||||||
if self.backend==2:
|
if self.backend==2:
|
||||||
|
@ -335,258 +155,6 @@ class fpdb_db:
|
||||||
return (self.host, self.database, self.user, self.password)
|
return (self.host, self.database, self.user, self.password)
|
||||||
#end def get_db_info
|
#end def get_db_info
|
||||||
|
|
||||||
def fillDefaultData(self):
|
|
||||||
self.cursor.execute("INSERT INTO Settings (version) VALUES (118);")
|
|
||||||
self.cursor.execute("INSERT INTO Sites (name,currency) VALUES ('Full Tilt Poker', 'USD')")
|
|
||||||
self.cursor.execute("INSERT INTO Sites (name,currency) VALUES ('PokerStars', 'USD')")
|
|
||||||
self.cursor.execute("INSERT INTO Sites (name,currency) VALUES ('Everleaf', 'USD')")
|
|
||||||
self.cursor.execute("INSERT INTO Sites (name,currency) VALUES ('Win2day', 'USD')")
|
|
||||||
self.cursor.execute("INSERT INTO TourneyTypes VALUES (DEFAULT, 1, 0, 0, 0, False);")
|
|
||||||
#self.cursor.execute("""INSERT INTO TourneyTypes
|
|
||||||
# (siteId,buyin,fee,knockout,rebuyOrAddon) VALUES
|
|
||||||
# (1,0,0,0,?)""",(False,) )
|
|
||||||
#end def fillDefaultData
|
|
||||||
|
|
||||||
def recreate_tables(self):
|
|
||||||
"""(Re-)creates the tables of the current DB"""
|
|
||||||
|
|
||||||
self.drop_tables()
|
|
||||||
self.create_tables()
|
|
||||||
self.createAllIndexes()
|
|
||||||
self.db.commit()
|
|
||||||
print "Finished recreating tables"
|
|
||||||
#end def recreate_tables
|
|
||||||
|
|
||||||
def prepareBulkImport(self):
|
|
||||||
"""Drop some indexes/foreign keys to prepare for bulk import.
|
|
||||||
Currently keeping the standalone indexes as needed to import quickly"""
|
|
||||||
stime = time()
|
|
||||||
if self.backend == self.MYSQL_INNODB:
|
|
||||||
self.cursor.execute("SET foreign_key_checks=0")
|
|
||||||
self.cursor.execute("SET autocommit=0")
|
|
||||||
return
|
|
||||||
if self.backend == self.PGSQL:
|
|
||||||
self.db.set_isolation_level(0) # allow table/index operations to work
|
|
||||||
for fk in self.foreignKeys[self.backend]:
|
|
||||||
if fk['drop'] == 1:
|
|
||||||
if self.backend == self.MYSQL_INNODB:
|
|
||||||
self.cursor.execute("SELECT constraint_name " +
|
|
||||||
"FROM information_schema.KEY_COLUMN_USAGE " +
|
|
||||||
#"WHERE REFERENCED_TABLE_SCHEMA = 'fpdb'
|
|
||||||
"WHERE 1=1 " +
|
|
||||||
"AND table_name = %s AND column_name = %s " +
|
|
||||||
"AND referenced_table_name = %s " +
|
|
||||||
"AND referenced_column_name = %s ",
|
|
||||||
(fk['fktab'], fk['fkcol'], fk['rtab'], fk['rcol']) )
|
|
||||||
cons = self.cursor.fetchone()
|
|
||||||
#print "preparebulk: cons=", cons
|
|
||||||
if cons:
|
|
||||||
print "dropping mysql fk", cons[0], fk['fktab'], fk['fkcol']
|
|
||||||
try:
|
|
||||||
self.cursor.execute("alter table " + fk['fktab'] + " drop foreign key " + cons[0])
|
|
||||||
except:
|
|
||||||
pass
|
|
||||||
elif self.backend == self.PGSQL:
|
|
||||||
# DON'T FORGET TO RECREATE THEM!!
|
|
||||||
print "dropping pg fk", fk['fktab'], fk['fkcol']
|
|
||||||
try:
|
|
||||||
# try to lock table to see if index drop will work:
|
|
||||||
# hmmm, tested by commenting out rollback in grapher. lock seems to work but
|
|
||||||
# then drop still hangs :-( does work in some tests though??
|
|
||||||
# will leave code here for now pending further tests/enhancement ...
|
|
||||||
self.cursor.execute( "lock table %s in exclusive mode nowait" % (fk['fktab'],) )
|
|
||||||
#print "after lock, status:", self.cursor.statusmessage
|
|
||||||
#print "alter table %s drop constraint %s_%s_fkey" % (fk['fktab'], fk['fktab'], fk['fkcol'])
|
|
||||||
try:
|
|
||||||
self.cursor.execute("alter table %s drop constraint %s_%s_fkey" % (fk['fktab'], fk['fktab'], fk['fkcol']))
|
|
||||||
print "dropped pg fk pg fk %s_%s_fkey, continuing ..." % (fk['fktab'], fk['fkcol'])
|
|
||||||
except:
|
|
||||||
if "does not exist" not in str(sys.exc_value):
|
|
||||||
print "warning: drop pg fk %s_%s_fkey failed: %s, continuing ..." \
|
|
||||||
% (fk['fktab'], fk['fkcol'], str(sys.exc_value).rstrip('\n') )
|
|
||||||
except:
|
|
||||||
print "warning: constraint %s_%s_fkey not dropped: %s, continuing ..." \
|
|
||||||
% (fk['fktab'],fk['fkcol'], str(sys.exc_value).rstrip('\n'))
|
|
||||||
else:
|
|
||||||
print "Only MySQL and Postgres supported so far"
|
|
||||||
return -1
|
|
||||||
|
|
||||||
for idx in self.indexes[self.backend]:
|
|
||||||
if idx['drop'] == 1:
|
|
||||||
if self.backend == self.MYSQL_INNODB:
|
|
||||||
print "dropping mysql index ", idx['tab'], idx['col']
|
|
||||||
try:
|
|
||||||
# apparently nowait is not implemented in mysql so this just hands if there are locks
|
|
||||||
# preventing the index drop :-(
|
|
||||||
self.cursor.execute( "alter table %s drop index %s", (idx['tab'],idx['col']) )
|
|
||||||
except:
|
|
||||||
pass
|
|
||||||
elif self.backend == self.PGSQL:
|
|
||||||
# DON'T FORGET TO RECREATE THEM!!
|
|
||||||
print "dropping pg index ", idx['tab'], idx['col']
|
|
||||||
try:
|
|
||||||
# try to lock table to see if index drop will work:
|
|
||||||
self.cursor.execute( "lock table %s in exclusive mode nowait" % (idx['tab'],) )
|
|
||||||
#print "after lock, status:", self.cursor.statusmessage
|
|
||||||
try:
|
|
||||||
# table locked ok so index drop should work:
|
|
||||||
#print "drop index %s_%s_idx" % (idx['tab'],idx['col'])
|
|
||||||
self.cursor.execute( "drop index if exists %s_%s_idx" % (idx['tab'],idx['col']) )
|
|
||||||
#print "dropped pg index ", idx['tab'], idx['col']
|
|
||||||
except:
|
|
||||||
if "does not exist" not in str(sys.exc_value):
|
|
||||||
print "warning: drop index %s_%s_idx failed: %s, continuing ..." \
|
|
||||||
% (idx['tab'],idx['col'], str(sys.exc_value).rstrip('\n'))
|
|
||||||
except:
|
|
||||||
print "warning: index %s_%s_idx not dropped %s, continuing ..." \
|
|
||||||
% (idx['tab'],idx['col'], str(sys.exc_value).rstrip('\n'))
|
|
||||||
else:
|
|
||||||
print "Error: Only MySQL and Postgres supported so far"
|
|
||||||
return -1
|
|
||||||
|
|
||||||
if self.backend == self.PGSQL:
|
|
||||||
self.db.set_isolation_level(1) # go back to normal isolation level
|
|
||||||
self.db.commit() # seems to clear up errors if there were any in postgres
|
|
||||||
ptime = time() - stime
|
|
||||||
print "prepare import took", ptime, "seconds"
|
|
||||||
#end def prepareBulkImport
|
|
||||||
|
|
||||||
def afterBulkImport(self):
|
|
||||||
"""Re-create any dropped indexes/foreign keys after bulk import"""
|
|
||||||
stime = time()
|
|
||||||
|
|
||||||
if self.backend == self.MYSQL_INNODB:
|
|
||||||
self.cursor.execute("SET foreign_key_checks=1")
|
|
||||||
self.cursor.execute("SET autocommit=1")
|
|
||||||
return
|
|
||||||
|
|
||||||
if self.backend == self.PGSQL:
|
|
||||||
self.db.set_isolation_level(0) # allow table/index operations to work
|
|
||||||
for fk in self.foreignKeys[self.backend]:
|
|
||||||
if fk['drop'] == 1:
|
|
||||||
if self.backend == self.MYSQL_INNODB:
|
|
||||||
self.cursor.execute("SELECT constraint_name " +
|
|
||||||
"FROM information_schema.KEY_COLUMN_USAGE " +
|
|
||||||
#"WHERE REFERENCED_TABLE_SCHEMA = 'fpdb'
|
|
||||||
"WHERE 1=1 " +
|
|
||||||
"AND table_name = %s AND column_name = %s " +
|
|
||||||
"AND referenced_table_name = %s " +
|
|
||||||
"AND referenced_column_name = %s ",
|
|
||||||
(fk['fktab'], fk['fkcol'], fk['rtab'], fk['rcol']) )
|
|
||||||
cons = self.cursor.fetchone()
|
|
||||||
#print "afterbulk: cons=", cons
|
|
||||||
if cons:
|
|
||||||
pass
|
|
||||||
else:
|
|
||||||
print "creating fk ", fk['fktab'], fk['fkcol'], "->", fk['rtab'], fk['rcol']
|
|
||||||
try:
|
|
||||||
self.cursor.execute("alter table " + fk['fktab'] + " add foreign key ("
|
|
||||||
+ fk['fkcol'] + ") references " + fk['rtab'] + "("
|
|
||||||
+ fk['rcol'] + ")")
|
|
||||||
except:
|
|
||||||
pass
|
|
||||||
elif self.backend == self.PGSQL:
|
|
||||||
print "creating fk ", fk['fktab'], fk['fkcol'], "->", fk['rtab'], fk['rcol']
|
|
||||||
try:
|
|
||||||
self.cursor.execute("alter table " + fk['fktab'] + " add constraint "
|
|
||||||
+ fk['fktab'] + '_' + fk['fkcol'] + '_fkey'
|
|
||||||
+ " foreign key (" + fk['fkcol']
|
|
||||||
+ ") references " + fk['rtab'] + "(" + fk['rcol'] + ")")
|
|
||||||
except:
|
|
||||||
pass
|
|
||||||
else:
|
|
||||||
print "Only MySQL and Postgres supported so far"
|
|
||||||
return -1
|
|
||||||
|
|
||||||
for idx in self.indexes[self.backend]:
|
|
||||||
if idx['drop'] == 1:
|
|
||||||
if self.backend == self.MYSQL_INNODB:
|
|
||||||
print "creating mysql index ", idx['tab'], idx['col']
|
|
||||||
try:
|
|
||||||
self.cursor.execute( "alter table %s add index %s(%s)"
|
|
||||||
, (idx['tab'],idx['col'],idx['col']) )
|
|
||||||
except:
|
|
||||||
pass
|
|
||||||
elif self.backend == self.PGSQL:
|
|
||||||
# pass
|
|
||||||
# mod to use tab_col for index name?
|
|
||||||
print "creating pg index ", idx['tab'], idx['col']
|
|
||||||
try:
|
|
||||||
print "create index %s_%s_idx on %s(%s)" % (idx['tab'], idx['col'], idx['tab'], idx['col'])
|
|
||||||
self.cursor.execute( "create index %s_%s_idx on %s(%s)"
|
|
||||||
% (idx['tab'], idx['col'], idx['tab'], idx['col']) )
|
|
||||||
except:
|
|
||||||
print " ERROR! :-("
|
|
||||||
pass
|
|
||||||
else:
|
|
||||||
print "Only MySQL and Postgres supported so far"
|
|
||||||
return -1
|
|
||||||
|
|
||||||
if self.backend == self.PGSQL:
|
|
||||||
self.db.set_isolation_level(1) # go back to normal isolation level
|
|
||||||
self.db.commit() # seems to clear up errors if there were any in postgres
|
|
||||||
atime = time() - stime
|
|
||||||
print "After import took", atime, "seconds"
|
|
||||||
#end def afterBulkImport
|
|
||||||
|
|
||||||
def createAllIndexes(self):
|
|
||||||
"""Create new indexes"""
|
|
||||||
if self.backend == self.PGSQL:
|
|
||||||
self.db.set_isolation_level(0) # allow table/index operations to work
|
|
||||||
for idx in self.indexes[self.backend]:
|
|
||||||
if self.backend == self.MYSQL_INNODB:
|
|
||||||
print "creating mysql index ", idx['tab'], idx['col']
|
|
||||||
try:
|
|
||||||
self.cursor.execute( "alter table %s add index %s(%s)"
|
|
||||||
, (idx['tab'],idx['col'],idx['col']) )
|
|
||||||
except:
|
|
||||||
pass
|
|
||||||
elif self.backend == self.PGSQL:
|
|
||||||
# mod to use tab_col for index name?
|
|
||||||
print "creating pg index ", idx['tab'], idx['col']
|
|
||||||
try:
|
|
||||||
print "create index %s_%s_idx on %s(%s)" % (idx['tab'], idx['col'], idx['tab'], idx['col'])
|
|
||||||
self.cursor.execute( "create index %s_%s_idx on %s(%s)"
|
|
||||||
% (idx['tab'], idx['col'], idx['tab'], idx['col']) )
|
|
||||||
except:
|
|
||||||
print " ERROR! :-("
|
|
||||||
pass
|
|
||||||
else:
|
|
||||||
print "Only MySQL and Postgres supported so far"
|
|
||||||
return -1
|
|
||||||
if self.backend == self.PGSQL:
|
|
||||||
self.db.set_isolation_level(1) # go back to normal isolation level
|
|
||||||
#end def createAllIndexes
|
|
||||||
|
|
||||||
def dropAllIndexes(self):
|
|
||||||
"""Drop all standalone indexes (i.e. not including primary keys or foreign keys)
|
|
||||||
using list of indexes in indexes data structure"""
|
|
||||||
# maybe upgrade to use data dictionary?? (but take care to exclude PK and FK)
|
|
||||||
if self.backend == self.PGSQL:
|
|
||||||
self.db.set_isolation_level(0) # allow table/index operations to work
|
|
||||||
for idx in self.indexes[self.backend]:
|
|
||||||
if self.backend == self.MYSQL_INNODB:
|
|
||||||
print "dropping mysql index ", idx['tab'], idx['col']
|
|
||||||
try:
|
|
||||||
self.cursor.execute( "alter table %s drop index %s"
|
|
||||||
, (idx['tab'],idx['col']) )
|
|
||||||
except:
|
|
||||||
pass
|
|
||||||
elif self.backend == self.PGSQL:
|
|
||||||
print "dropping pg index ", idx['tab'], idx['col']
|
|
||||||
# mod to use tab_col for index name?
|
|
||||||
try:
|
|
||||||
self.cursor.execute( "drop index %s_%s_idx"
|
|
||||||
% (idx['tab'],idx['col']) )
|
|
||||||
except:
|
|
||||||
pass
|
|
||||||
else:
|
|
||||||
print "Only MySQL and Postgres supported so far"
|
|
||||||
return -1
|
|
||||||
if self.backend == self.PGSQL:
|
|
||||||
self.db.set_isolation_level(1) # go back to normal isolation level
|
|
||||||
#end def dropAllIndexes
|
|
||||||
|
|
||||||
def getLastInsertId(self):
|
def getLastInsertId(self):
|
||||||
try:
|
try:
|
||||||
if self.backend == self.MYSQL_INNODB:
|
if self.backend == self.MYSQL_INNODB:
|
||||||
|
|
|
@ -60,8 +60,6 @@ class Importer:
|
||||||
self.caller = caller
|
self.caller = caller
|
||||||
self.config = config
|
self.config = config
|
||||||
self.database = None # database will be the main db interface eventually
|
self.database = None # database will be the main db interface eventually
|
||||||
self.fdb = None # fdb may disappear or just hold the simple db connection
|
|
||||||
self.cursor = None
|
|
||||||
self.filelist = {}
|
self.filelist = {}
|
||||||
self.dirlist = {}
|
self.dirlist = {}
|
||||||
self.siteIds = {}
|
self.siteIds = {}
|
||||||
|
@ -79,12 +77,9 @@ class Importer:
|
||||||
self.settings.setdefault("handCount", 0)
|
self.settings.setdefault("handCount", 0)
|
||||||
|
|
||||||
self.database = Database.Database(self.config) # includes .connection and .sql variables
|
self.database = Database.Database(self.config) # includes .connection and .sql variables
|
||||||
self.fdb = fpdb_db.fpdb_db() # sets self.fdb.db self.fdb.cursor and self.fdb.sql
|
|
||||||
self.fdb.do_connect(self.config)
|
|
||||||
self.fdb.db.rollback() # make sure all locks are released
|
|
||||||
|
|
||||||
self.NEWIMPORT = False
|
self.NEWIMPORT = False
|
||||||
self.allow_hudcache_rebuild = False;
|
self.allow_hudcache_rebuild = False
|
||||||
|
|
||||||
#Set functions
|
#Set functions
|
||||||
def setCallHud(self, value):
|
def setCallHud(self, value):
|
||||||
|
@ -123,8 +118,7 @@ class Importer:
|
||||||
self.filelist[filename] = [site] + [filter]
|
self.filelist[filename] = [site] + [filter]
|
||||||
if site not in self.siteIds:
|
if site not in self.siteIds:
|
||||||
# Get id from Sites table in DB
|
# Get id from Sites table in DB
|
||||||
self.fdb.cursor.execute(self.fdb.sql.query['getSiteId'], (site,))
|
result = self.database.get_site_id(site)
|
||||||
result = self.fdb.cursor.fetchall()
|
|
||||||
if len(result) == 1:
|
if len(result) == 1:
|
||||||
self.siteIds[site] = result[0][0]
|
self.siteIds[site] = result[0][0]
|
||||||
else:
|
else:
|
||||||
|
@ -178,7 +172,7 @@ class Importer:
|
||||||
self.settings['dropHudCache'] = self.calculate_auto2(25.0, 500.0) # returns "drop"/"don't drop"
|
self.settings['dropHudCache'] = self.calculate_auto2(25.0, 500.0) # returns "drop"/"don't drop"
|
||||||
|
|
||||||
if self.settings['dropIndexes'] == 'drop':
|
if self.settings['dropIndexes'] == 'drop':
|
||||||
self.fdb.prepareBulkImport()
|
self.database.prepareBulkImport()
|
||||||
else:
|
else:
|
||||||
print "No need to drop indexes."
|
print "No need to drop indexes."
|
||||||
#print "dropInd =", self.settings['dropIndexes'], " dropHudCache =", self.settings['dropHudCache']
|
#print "dropInd =", self.settings['dropIndexes'], " dropHudCache =", self.settings['dropHudCache']
|
||||||
|
@ -196,7 +190,7 @@ class Importer:
|
||||||
toterrors += errors
|
toterrors += errors
|
||||||
tottime += ttime
|
tottime += ttime
|
||||||
if self.settings['dropIndexes'] == 'drop':
|
if self.settings['dropIndexes'] == 'drop':
|
||||||
self.fdb.afterBulkImport()
|
self.database.afterBulkImport()
|
||||||
else:
|
else:
|
||||||
print "No need to rebuild indexes."
|
print "No need to rebuild indexes."
|
||||||
if self.allow_hudcache_rebuild and self.settings['dropHudCache'] == 'drop':
|
if self.allow_hudcache_rebuild and self.settings['dropHudCache'] == 'drop':
|
||||||
|
@ -212,7 +206,7 @@ class Importer:
|
||||||
if len(self.filelist) == 1: return "don't drop"
|
if len(self.filelist) == 1: return "don't drop"
|
||||||
if 'handsInDB' not in self.settings:
|
if 'handsInDB' not in self.settings:
|
||||||
try:
|
try:
|
||||||
tmpcursor = self.fdb.db.cursor()
|
tmpcursor = self.database.get_cursor()
|
||||||
tmpcursor.execute("Select count(1) from Hands;")
|
tmpcursor.execute("Select count(1) from Hands;")
|
||||||
self.settings['handsInDB'] = tmpcursor.fetchone()[0]
|
self.settings['handsInDB'] = tmpcursor.fetchone()[0]
|
||||||
except:
|
except:
|
||||||
|
@ -235,7 +229,7 @@ class Importer:
|
||||||
# get number of hands in db
|
# get number of hands in db
|
||||||
if 'handsInDB' not in self.settings:
|
if 'handsInDB' not in self.settings:
|
||||||
try:
|
try:
|
||||||
tmpcursor = self.fdb.db.cursor()
|
tmpcursor = self.database.get_cursor()
|
||||||
tmpcursor.execute("Select count(1) from Hands;")
|
tmpcursor.execute("Select count(1) from Hands;")
|
||||||
self.settings['handsInDB'] = tmpcursor.fetchone()[0]
|
self.settings['handsInDB'] = tmpcursor.fetchone()[0]
|
||||||
except:
|
except:
|
||||||
|
@ -299,12 +293,13 @@ class Importer:
|
||||||
|
|
||||||
self.addToDirList = {}
|
self.addToDirList = {}
|
||||||
self.removeFromFileList = {}
|
self.removeFromFileList = {}
|
||||||
self.fdb.db.rollback()
|
self.database.rollback()
|
||||||
#rulog.writelines(" finished\n")
|
#rulog.writelines(" finished\n")
|
||||||
#rulog.close()
|
#rulog.close()
|
||||||
|
|
||||||
# This is now an internal function that should not be called directly.
|
# This is now an internal function that should not be called directly.
|
||||||
def import_file_dict(self, file, site, filter):
|
def import_file_dict(self, file, site, filter):
|
||||||
|
#print "import_file_dict"
|
||||||
if os.path.isdir(file):
|
if os.path.isdir(file):
|
||||||
self.addToDirList[file] = [site] + [filter]
|
self.addToDirList[file] = [site] + [filter]
|
||||||
return
|
return
|
||||||
|
@ -350,6 +345,7 @@ class Importer:
|
||||||
|
|
||||||
|
|
||||||
def import_fpdb_file(self, file, site):
|
def import_fpdb_file(self, file, site):
|
||||||
|
#print "import_fpdb_file"
|
||||||
starttime = time()
|
starttime = time()
|
||||||
last_read_hand = 0
|
last_read_hand = 0
|
||||||
loc = 0
|
loc = 0
|
||||||
|
@ -379,8 +375,7 @@ class Importer:
|
||||||
self.pos_in_file[file] = inputFile.tell()
|
self.pos_in_file[file] = inputFile.tell()
|
||||||
inputFile.close()
|
inputFile.close()
|
||||||
|
|
||||||
# fix fdb and database cursors before using this:
|
#self.database.lock_for_insert() # should be ok when using one thread
|
||||||
#self.database.lock_for_insert() # ok when using one thread
|
|
||||||
|
|
||||||
try: # sometimes we seem to be getting an empty self.lines, in which case, we just want to return.
|
try: # sometimes we seem to be getting an empty self.lines, in which case, we just want to return.
|
||||||
firstline = self.lines[0]
|
firstline = self.lines[0]
|
||||||
|
@ -423,10 +418,10 @@ class Importer:
|
||||||
self.hand=hand
|
self.hand=hand
|
||||||
|
|
||||||
try:
|
try:
|
||||||
handsId = fpdb_parse_logic.mainParser( self.settings, self.fdb
|
handsId = fpdb_parse_logic.mainParser( self.settings
|
||||||
, self.siteIds[site], category, hand
|
, self.siteIds[site], category, hand
|
||||||
, self.config, self.database )
|
, self.config, self.database )
|
||||||
self.fdb.db.commit()
|
self.database.commit()
|
||||||
|
|
||||||
stored += 1
|
stored += 1
|
||||||
if self.callHud:
|
if self.callHud:
|
||||||
|
@ -436,23 +431,23 @@ class Importer:
|
||||||
self.caller.pipe_to_hud.stdin.write("%s" % (handsId) + os.linesep)
|
self.caller.pipe_to_hud.stdin.write("%s" % (handsId) + os.linesep)
|
||||||
except fpdb_simple.DuplicateError:
|
except fpdb_simple.DuplicateError:
|
||||||
duplicates += 1
|
duplicates += 1
|
||||||
self.fdb.db.rollback()
|
self.database.rollback()
|
||||||
except (ValueError), fe:
|
except (ValueError), fe:
|
||||||
errors += 1
|
errors += 1
|
||||||
self.printEmailErrorMessage(errors, file, hand)
|
self.printEmailErrorMessage(errors, file, hand)
|
||||||
|
|
||||||
if (self.settings['failOnError']):
|
if (self.settings['failOnError']):
|
||||||
self.fdb.db.commit() #dont remove this, in case hand processing was cancelled.
|
self.database.commit() #dont remove this, in case hand processing was cancelled.
|
||||||
raise
|
raise
|
||||||
else:
|
else:
|
||||||
self.fdb.db.rollback()
|
self.database.rollback()
|
||||||
except (fpdb_simple.FpdbError), fe:
|
except (fpdb_simple.FpdbError), fe:
|
||||||
errors += 1
|
errors += 1
|
||||||
self.printEmailErrorMessage(errors, file, hand)
|
self.printEmailErrorMessage(errors, file, hand)
|
||||||
self.fdb.db.rollback()
|
self.database.rollback()
|
||||||
|
|
||||||
if self.settings['failOnError']:
|
if self.settings['failOnError']:
|
||||||
self.fdb.db.commit() #dont remove this, in case hand processing was cancelled.
|
self.database.commit() #dont remove this, in case hand processing was cancelled.
|
||||||
raise
|
raise
|
||||||
|
|
||||||
if self.settings['minPrint']:
|
if self.settings['minPrint']:
|
||||||
|
@ -479,7 +474,7 @@ class Importer:
|
||||||
print "failed to read a single hand from file:", inputFile
|
print "failed to read a single hand from file:", inputFile
|
||||||
handsId=0
|
handsId=0
|
||||||
#todo: this will cause return of an unstored hand number if the last hand was error
|
#todo: this will cause return of an unstored hand number if the last hand was error
|
||||||
self.fdb.db.commit()
|
self.database.commit()
|
||||||
self.handsId=handsId
|
self.handsId=handsId
|
||||||
return (stored, duplicates, partial, errors, ttime)
|
return (stored, duplicates, partial, errors, ttime)
|
||||||
|
|
||||||
|
|
|
@ -22,14 +22,13 @@ import Database
|
||||||
from time import time, strftime
|
from time import time, strftime
|
||||||
|
|
||||||
#parses a holdem hand
|
#parses a holdem hand
|
||||||
def mainParser(settings, fdb, siteID, category, hand, config, db = None):
|
def mainParser(settings, siteID, category, hand, config, db = None):
|
||||||
|
# fdb is not used now - to be removed ...
|
||||||
t0 = time()
|
t0 = time()
|
||||||
|
#print "mainparser"
|
||||||
backend = settings['db-backend']
|
backend = settings['db-backend']
|
||||||
if db == None:
|
if db == None:
|
||||||
#This is redundant - hopefully fdb will be a Database object in an iteration soon
|
|
||||||
db = Database.Database(c = config, sql = None)
|
db = Database.Database(c = config, sql = None)
|
||||||
else:
|
|
||||||
db = db
|
|
||||||
category = fpdb_simple.recogniseCategory(hand[0])
|
category = fpdb_simple.recogniseCategory(hand[0])
|
||||||
|
|
||||||
base = "hold" if category == "holdem" or category == "omahahi" or category == "omahahilo" else "stud"
|
base = "hold" if category == "holdem" or category == "omahahi" or category == "omahahilo" else "stud"
|
||||||
|
@ -54,7 +53,7 @@ def mainParser(settings, fdb, siteID, category, hand, config, db = None):
|
||||||
break
|
break
|
||||||
#print "small blind line:",smallBlindLine
|
#print "small blind line:",smallBlindLine
|
||||||
|
|
||||||
gametypeID = fpdb_simple.recogniseGametypeID(backend, fdb.db, fdb.cursor, hand[0], hand[smallBlindLine], siteID, category, isTourney)
|
gametypeID = fpdb_simple.recogniseGametypeID(backend, db, db.get_cursor(), hand[0], hand[smallBlindLine], siteID, category, isTourney)
|
||||||
if isTourney:
|
if isTourney:
|
||||||
siteTourneyNo = fpdb_simple.parseTourneyNo(hand[0])
|
siteTourneyNo = fpdb_simple.parseTourneyNo(hand[0])
|
||||||
buyin = fpdb_simple.parseBuyin(hand[0])
|
buyin = fpdb_simple.parseBuyin(hand[0])
|
||||||
|
@ -65,9 +64,9 @@ def mainParser(settings, fdb, siteID, category, hand, config, db = None):
|
||||||
tourneyStartTime= handStartTime #todo: read tourney start time
|
tourneyStartTime= handStartTime #todo: read tourney start time
|
||||||
rebuyOrAddon = fpdb_simple.isRebuyOrAddon(hand[0])
|
rebuyOrAddon = fpdb_simple.isRebuyOrAddon(hand[0])
|
||||||
|
|
||||||
tourneyTypeId = fpdb_simple.recogniseTourneyTypeId(fdb.cursor, siteID, buyin, fee, knockout, rebuyOrAddon)
|
tourneyTypeId = fpdb_simple.recogniseTourneyTypeId(db.get_cursor(), siteID, buyin, fee, knockout, rebuyOrAddon)
|
||||||
|
|
||||||
fpdb_simple.isAlreadyInDB(fdb.cursor, gametypeID, siteHandNo)
|
fpdb_simple.isAlreadyInDB(db.get_cursor(), gametypeID, siteHandNo)
|
||||||
|
|
||||||
hand = fpdb_simple.filterCrap(hand, isTourney)
|
hand = fpdb_simple.filterCrap(hand, isTourney)
|
||||||
|
|
||||||
|
@ -81,7 +80,7 @@ def mainParser(settings, fdb, siteID, category, hand, config, db = None):
|
||||||
seatLines.append(line)
|
seatLines.append(line)
|
||||||
|
|
||||||
names = fpdb_simple.parseNames(seatLines)
|
names = fpdb_simple.parseNames(seatLines)
|
||||||
playerIDs = fpdb_simple.recognisePlayerIDs(fdb.cursor, names, siteID) # inserts players as needed
|
playerIDs = fpdb_simple.recognisePlayerIDs(db.get_cursor(), names, siteID) # inserts players as needed
|
||||||
tmp = fpdb_simple.parseCashesAndSeatNos(seatLines)
|
tmp = fpdb_simple.parseCashesAndSeatNos(seatLines)
|
||||||
startCashes = tmp['startCashes']
|
startCashes = tmp['startCashes']
|
||||||
seatNos = tmp['seatNos']
|
seatNos = tmp['seatNos']
|
||||||
|
@ -128,8 +127,9 @@ def mainParser(settings, fdb, siteID, category, hand, config, db = None):
|
||||||
fpdb_simple.convertBlindBet(actionTypes, actionAmounts)
|
fpdb_simple.convertBlindBet(actionTypes, actionAmounts)
|
||||||
fpdb_simple.checkPositions(positions)
|
fpdb_simple.checkPositions(positions)
|
||||||
|
|
||||||
fdb.cursor.execute("SELECT limitType FROM Gametypes WHERE id=%s",(gametypeID, ))
|
c = db.get_cursor()
|
||||||
limit_type = fdb.cursor.fetchone()[0]
|
c.execute("SELECT limitType FROM Gametypes WHERE id=%s",(gametypeID, ))
|
||||||
|
limit_type = c.fetchone()[0]
|
||||||
fpdb_simple.convert3B4B(category, limit_type, actionTypes, actionAmounts)
|
fpdb_simple.convert3B4B(category, limit_type, actionTypes, actionAmounts)
|
||||||
|
|
||||||
totalWinnings = sum(winnings)
|
totalWinnings = sum(winnings)
|
||||||
|
@ -148,7 +148,7 @@ def mainParser(settings, fdb, siteID, category, hand, config, db = None):
|
||||||
|
|
||||||
#print "parse: hand data prepared" # only reads up to here apart from inserting new players
|
#print "parse: hand data prepared" # only reads up to here apart from inserting new players
|
||||||
try:
|
try:
|
||||||
fdb.db.commit() # need to commit new players as different db connection used
|
db.commit() # need to commit new players as different db connection used
|
||||||
# for other writes. maybe this will change maybe not ...
|
# for other writes. maybe this will change maybe not ...
|
||||||
except:
|
except:
|
||||||
print "parse: error during rollback: " + str(sys.exc_value)
|
print "parse: error during rollback: " + str(sys.exc_value)
|
||||||
|
|
|
@ -983,7 +983,7 @@ def recogniseGametypeID(backend, db, cursor, topline, smallBlindLine, site_id, c
|
||||||
#AND limitType=%s AND smallBlind=%s AND bigBlind=%s", (site_id, type, category, limit_type, small_bet, big_bet))
|
#AND limitType=%s AND smallBlind=%s AND bigBlind=%s", (site_id, type, category, limit_type, small_bet, big_bet))
|
||||||
|
|
||||||
#result=(db.insert_id(),)
|
#result=(db.insert_id(),)
|
||||||
result=(getLastInsertId(backend,db,cursor),)
|
result=(db.get_last_insert_id(),)
|
||||||
|
|
||||||
return result[0]
|
return result[0]
|
||||||
#end def recogniseGametypeID
|
#end def recogniseGametypeID
|
||||||
|
|
Loading…
Reference in New Issue
Block a user