-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathSQL.py
14450 lines (13752 loc) · 783 KB
/
SQL.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""Returns a dict of SQL statements used in fpdb.
"""
# Copyright 2008-2011, Ray E. Barker
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
# NOTES: The sql statements use the placeholder %s for bind variables
# which is then replaced by ? for sqlite. Comments can be included
# within sql statements using C style /* ... */ comments, BUT
# THE COMMENTS MUST NOT INCLUDE %s OR ?.
########################################################################
# Standard Library modules
import re
# pyGTK modules
# FreePokerTools modules
class Sql:
def __init__(self, game='holdem', db_server='mysql'):
self.query = {}
###############################################################################3
# Support for the Free Poker DataBase = fpdb http://fpdb.sourceforge.net/
#
################################
# List tables
################################
if db_server == 'mysql':
self.query['list_tables'] = """SHOW TABLES"""
elif db_server == 'postgresql':
self.query['list_tables'] = """SELECT table_name FROM information_schema.tables WHERE table_schema = 'public'"""
elif db_server == 'sqlite':
self.query['list_tables'] = """SELECT name FROM sqlite_master
WHERE type='table'
ORDER BY name;"""
################################
# List indexes
################################
if db_server == 'mysql':
self.query['list_indexes'] = """SHOW INDEXES"""
elif db_server == 'postgresql':
self.query['list_indexes'] = """SELECT tablename, indexname FROM PG_INDEXES"""
elif db_server == 'sqlite':
self.query['list_indexes'] = """SELECT name FROM sqlite_master
WHERE type='index'
ORDER BY name;"""
##################################################################
# Drop Tables - MySQL, PostgreSQL and SQLite all share same syntax
##################################################################
self.query['drop_table'] = """DROP TABLE IF EXISTS """
##################################################################
# Set transaction isolation level
##################################################################
if db_server == 'mysql' or db_server == 'postgresql':
self.query['set tx level'] = """SET SESSION TRANSACTION
ISOLATION LEVEL READ COMMITTED"""
elif db_server == 'sqlite':
self.query['set tx level'] = """ """
################################
# Select basic info
################################
self.query['getSiteId'] = """SELECT id from Sites where name = %s"""
self.query['getGames'] = """SELECT DISTINCT category from Gametypes"""
self.query['getCurrencies'] = """SELECT DISTINCT currency from Gametypes ORDER BY currency"""
self.query['getLimits'] = """SELECT DISTINCT bigBlind from Gametypes ORDER by bigBlind DESC"""
self.query['getTourneyTypesIds'] = "SELECT id FROM TourneyTypes"
################################
# Create Settings
################################
if db_server == 'mysql':
self.query['createSettingsTable'] = """CREATE TABLE Settings (
version SMALLINT NOT NULL)
ENGINE=INNODB"""
elif db_server == 'postgresql':
self.query['createSettingsTable'] = """CREATE TABLE Settings (version SMALLINT NOT NULL)"""
elif db_server == 'sqlite':
self.query['createSettingsTable'] = """CREATE TABLE Settings
(version INTEGER NOT NULL) """
################################
# Create InsertLock
################################
if db_server == 'mysql':
self.query['createLockTable'] = """CREATE TABLE InsertLock (
id BIGINT UNSIGNED AUTO_INCREMENT NOT NULL, PRIMARY KEY (id),
locked BOOLEAN NOT NULL DEFAULT FALSE)
ENGINE=INNODB"""
################################
# Create RawHands (this table is all but identical with RawTourneys)
################################
if db_server == 'mysql':
self.query['createRawHands'] = """CREATE TABLE RawHands (
id BIGINT UNSIGNED AUTO_INCREMENT NOT NULL, PRIMARY KEY (id),
handId BIGINT NOT NULL,
rawHand TEXT NOT NULL,
complain BOOLEAN NOT NULL DEFAULT FALSE)
ENGINE=INNODB"""
elif db_server == 'postgresql':
self.query['createRawHands'] = """CREATE TABLE RawHands (
id BIGSERIAL, PRIMARY KEY (id),
handId BIGINT NOT NULL,
rawHand TEXT NOT NULL,
complain BOOLEAN NOT NULL DEFAULT FALSE)"""
elif db_server == 'sqlite':
self.query['createRawHands'] = """CREATE TABLE RawHands (
id INTEGER PRIMARY KEY,
handId BIGINT NOT NULL,
rawHand TEXT NOT NULL,
complain BOOLEAN NOT NULL DEFAULT FALSE)"""
################################
# Create RawTourneys (this table is all but identical with RawHands)
################################
if db_server == 'mysql':
self.query['createRawTourneys'] = """CREATE TABLE RawTourneys (
id BIGINT UNSIGNED AUTO_INCREMENT NOT NULL, PRIMARY KEY (id),
tourneyId BIGINT NOT NULL,
rawTourney TEXT NOT NULL,
complain BOOLEAN NOT NULL DEFAULT FALSE)
ENGINE=INNODB"""
elif db_server == 'postgresql':
self.query['createRawTourneys'] = """CREATE TABLE RawTourneys (
id BIGSERIAL, PRIMARY KEY (id),
tourneyId BIGINT NOT NULL,
rawTourney TEXT NOT NULL,
complain BOOLEAN NOT NULL DEFAULT FALSE)"""
elif db_server == 'sqlite':
self.query['createRawTourneys'] = """CREATE TABLE RawTourneys (
id INTEGER PRIMARY KEY,
tourneyId BIGINT NOT NULL,
rawTourney TEXT NOT NULL,
complain BOOLEAN NOT NULL DEFAULT FALSE)"""
################################
# Create Actions
################################
if db_server == 'mysql':
self.query['createActionsTable'] = """CREATE TABLE Actions (
id SMALLINT UNSIGNED AUTO_INCREMENT NOT NULL, PRIMARY KEY (id),
name varchar(32) NOT NULL,
code char(4) NOT NULL)
ENGINE=INNODB"""
elif db_server == 'postgresql':
self.query['createActionsTable'] = """CREATE TABLE Actions (
id SERIAL, PRIMARY KEY (id),
name varchar(32),
code char(4))"""
elif db_server == 'sqlite':
self.query['createActionsTable'] = """CREATE TABLE Actions (
id INTEGER PRIMARY KEY,
name TEXT NOT NULL,
code TEXT NOT NULL)"""
################################
# Create Rank
################################
if db_server == 'mysql':
self.query['createRankTable'] = """CREATE TABLE Rank (
id SMALLINT UNSIGNED AUTO_INCREMENT NOT NULL, PRIMARY KEY (id),
name varchar(8) NOT NULL)
ENGINE=INNODB"""
elif db_server == 'postgresql':
self.query['createRankTable'] = """CREATE TABLE Rank (
id SERIAL, PRIMARY KEY (id),
name varchar(8))"""
elif db_server == 'sqlite':
self.query['createRankTable'] = """CREATE TABLE Rank (
id INTEGER PRIMARY KEY,
name TEXT NOT NULL)"""
################################
# Create StartCards
################################
if db_server == 'mysql':
self.query['createStartCardsTable'] = """CREATE TABLE StartCards (
id SMALLINT UNSIGNED AUTO_INCREMENT NOT NULL, PRIMARY KEY (id),
category varchar(9) NOT NULL,
name varchar(32) NOT NULL,
rank SMALLINT NOT NULL,
combinations SMALLINT NOT NULL)
ENGINE=INNODB"""
elif db_server == 'postgresql':
self.query['createStartCardsTable'] = """CREATE TABLE StartCards (
id SERIAL, PRIMARY KEY (id),
category varchar(9) NOT NULL,
name varchar(32),
rank SMALLINT NOT NULL,
combinations SMALLINT NOT NULL)"""
elif db_server == 'sqlite':
self.query['createStartCardsTable'] = """CREATE TABLE StartCards (
id INTEGER PRIMARY KEY,
category TEXT NOT NULL,
name TEXT NOT NULL,
rank SMALLINT NOT NULL,
combinations SMALLINT NOT NULL)"""
################################
# 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,
code char(2) NOT NULL)
ENGINE=INNODB"""
elif db_server == 'postgresql':
self.query['createSitesTable'] = """CREATE TABLE Sites (
id SERIAL, PRIMARY KEY (id),
name varchar(32),
code char(2))"""
elif db_server == 'sqlite':
self.query['createSitesTable'] = """CREATE TABLE Sites (
id INTEGER PRIMARY KEY,
name TEXT NOT NULL,
code TEXT NOT NULL)"""
################################
# Create Backings
################################
if db_server == 'mysql':
self.query['createBackingsTable'] = """CREATE TABLE Backings (
id SMALLINT UNSIGNED AUTO_INCREMENT NOT NULL, PRIMARY KEY (id),
tourneysPlayersId BIGINT UNSIGNED NOT NULL, FOREIGN KEY (tourneysPlayersId) REFERENCES TourneysPlayers(id),
playerId INT UNSIGNED NOT NULL, FOREIGN KEY (playerId) REFERENCES Players(id),
buyInPercentage FLOAT UNSIGNED NOT NULL,
payOffPercentage FLOAT UNSIGNED NOT NULL) ENGINE=INNODB"""
elif db_server == 'postgresql':
self.query['createBackingsTable'] = """CREATE TABLE Backings (
id BIGSERIAL, PRIMARY KEY (id),
tourneysPlayersId INT NOT NULL, FOREIGN KEY (tourneysPlayersId) REFERENCES TourneysPlayers(id),
playerId INT NOT NULL, FOREIGN KEY (playerId) REFERENCES Players(id),
buyInPercentage FLOAT NOT NULL,
payOffPercentage FLOAT NOT NULL)"""
elif db_server == 'sqlite':
self.query['createBackingsTable'] = """CREATE TABLE Backings (
id INTEGER PRIMARY KEY,
tourneysPlayersId INT NOT NULL,
playerId INT NOT NULL,
buyInPercentage REAL UNSIGNED NOT NULL,
payOffPercentage REAL UNSIGNED 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),
currency varchar(4) NOT NULL,
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,
mix varchar(9) NOT NULL,
smallBlind bigint,
bigBlind bigint,
smallBet bigint NOT NULL,
bigBet bigint NOT NULL,
maxSeats TINYINT NOT NULL,
ante INT NOT NULL,
buyinType varchar(9) NOT NULL,
fast BOOLEAN,
newToGame BOOLEAN,
homeGame BOOLEAN,
split BOOLEAN)
ENGINE=INNODB"""
elif db_server == 'postgresql':
self.query['createGametypesTable'] = """CREATE TABLE Gametypes (
id SERIAL NOT NULL, PRIMARY KEY (id),
siteId INTEGER NOT NULL, FOREIGN KEY (siteId) REFERENCES Sites(id),
currency varchar(4) NOT NULL,
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,
mix varchar(9) NOT NULL,
smallBlind bigint,
bigBlind bigint,
smallBet bigint NOT NULL,
bigBet bigint NOT NULL,
maxSeats SMALLINT NOT NULL,
ante INT NOT NULL,
buyinType varchar(9) NOT NULL,
fast BOOLEAN,
newToGame BOOLEAN,
homeGame BOOLEAN,
split BOOLEAN)"""
elif db_server == 'sqlite':
self.query['createGametypesTable'] = """CREATE TABLE Gametypes (
id INTEGER PRIMARY KEY NOT NULL,
siteId INTEGER NOT NULL,
currency TEXT NOT NULL,
type TEXT NOT NULL,
base TEXT NOT NULL,
category TEXT NOT NULL,
limitType TEXT NOT NULL,
hiLo TEXT NOT NULL,
mix TEXT NOT NULL,
smallBlind INTEGER,
bigBlind INTEGER,
smallBet INTEGER NOT NULL,
bigBet INTEGER NOT NULL,
maxSeats INT NOT NULL,
ante INT NOT NULL,
buyinType TEXT NOT NULL,
fast INT,
newToGame INT,
homeGame INT,
split INT,
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) NOT NULL,
siteId SMALLINT UNSIGNED NOT NULL, FOREIGN KEY (siteId) REFERENCES Sites(id),
hero BOOLEAN,
chars char(3),
comment text,
commentTs DATETIME)
ENGINE=INNODB"""
elif db_server == 'postgresql':
self.query['createPlayersTable'] = """CREATE TABLE Players (
id SERIAL, PRIMARY KEY (id),
name VARCHAR(32),
siteId INTEGER, FOREIGN KEY (siteId) REFERENCES Sites(id),
hero BOOLEAN,
chars char(3),
comment text,
commentTs timestamp without time zone)"""
elif db_server == 'sqlite':
self.query['createPlayersTable'] = """CREATE TABLE Players (
id INTEGER PRIMARY KEY,
name TEXT,
siteId INTEGER,
hero BOOLEAN,
chars TEXT,
comment TEXT,
commentTs timestamp,
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 == '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 db_server == 'sqlite':
self.query['createAutoratesTable'] = """CREATE TABLE Autorates (
id INTEGER PRIMARY KEY,
playerId INT,
gametypeId INT,
description TEXT,
shortDesc TEXT,
ratingTime timestamp,
handCount int)"""
################################
# Create Hands
################################
if db_server == 'mysql':
self.query['createHandsTable'] = """CREATE TABLE Hands (
id BIGINT UNSIGNED AUTO_INCREMENT NOT NULL, PRIMARY KEY (id),
tableName VARCHAR(50) NOT NULL,
siteHandNo BIGINT NOT NULL,
tourneyId INT UNSIGNED, FOREIGN KEY (tourneyId) REFERENCES Tourneys(id),
gametypeId SMALLINT UNSIGNED NOT NULL, FOREIGN KEY (gametypeId) REFERENCES Gametypes(id),
sessionId INT UNSIGNED, FOREIGN KEY (sessionId) REFERENCES Sessions(id),
fileId INT(10) UNSIGNED NOT NULL, FOREIGN KEY (fileId) REFERENCES Files(id),
startTime DATETIME NOT NULL,
importTime DATETIME NOT NULL,
seats TINYINT NOT NULL,
heroSeat TINYINT NOT NULL,
maxPosition 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,
runItTwice BOOLEAN,
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,
street0Callers TINYINT NOT NULL,
street1Callers TINYINT NOT NULL,
street2Callers TINYINT NOT NULL,
street3Callers TINYINT NOT NULL,
street4Callers TINYINT NOT NULL,
street0Aggressors TINYINT NOT NULL,
street1Aggressors TINYINT NOT NULL,
street2Aggressors TINYINT NOT NULL,
street3Aggressors TINYINT NOT NULL,
street4Aggressors TINYINT NOT NULL,
street0Calls TINYINT NOT NULL,
street1Calls TINYINT NOT NULL,
street2Calls TINYINT NOT NULL,
street3Calls TINYINT NOT NULL,
street4Calls TINYINT 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 */
street0Pot BIGINT, /* pot size at pre-flop/street2 */
street1Pot BIGINT, /* pot size at flop/street4 */
street2Pot BIGINT, /* pot size at turn/street5 */
street3Pot BIGINT, /* pot size at river/street6 */
street4Pot BIGINT, /* pot size at sd/street7 */
finalPot BIGINT, /* final pot size */
comment TEXT,
commentTs DATETIME)
ENGINE=INNODB"""
elif db_server == 'postgresql':
self.query['createHandsTable'] = """CREATE TABLE Hands (
id BIGSERIAL, PRIMARY KEY (id),
tableName VARCHAR(50) NOT NULL,
siteHandNo BIGINT NOT NULL,
tourneyId INT, FOREIGN KEY (tourneyId) REFERENCES Tourneys(id),
gametypeId INT NOT NULL, FOREIGN KEY (gametypeId) REFERENCES Gametypes(id),
sessionId INT, FOREIGN KEY (sessionId) REFERENCES Sessions(id),
fileId BIGINT NOT NULL, FOREIGN KEY (fileId) REFERENCES Files(id),
startTime timestamp without time zone NOT NULL,
importTime timestamp without time zone NOT NULL,
seats SMALLINT NOT NULL,
heroSeat SMALLINT NOT NULL,
maxPosition 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,
runItTwice BOOLEAN,
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,
street0Callers SMALLINT NOT NULL,
street1Callers SMALLINT NOT NULL,
street2Callers SMALLINT NOT NULL,
street3Callers SMALLINT NOT NULL,
street4Callers SMALLINT NOT NULL,
street0Aggressors SMALLINT NOT NULL,
street1Aggressors SMALLINT NOT NULL,
street2Aggressors SMALLINT NOT NULL,
street3Aggressors SMALLINT NOT NULL,
street4Aggressors SMALLINT NOT NULL,
street0Calls SMALLINT NOT NULL,
street1Calls SMALLINT NOT NULL,
street2Calls SMALLINT NOT NULL,
street3Calls SMALLINT NOT NULL,
street4Calls 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 */
street0Pot BIGINT, /* pot size at preflop/street3 */
street1Pot BIGINT, /* pot size at flop/street4 */
street2Pot BIGINT, /* pot size at turn/street5 */
street3Pot BIGINT, /* pot size at river/street6 */
street4Pot BIGINT, /* pot size at sd/street7 */
finalPot BIGINT, /* final pot size */
comment TEXT,
commentTs timestamp without time zone)"""
elif db_server == 'sqlite':
self.query['createHandsTable'] = """CREATE TABLE Hands (
id INTEGER PRIMARY KEY,
tableName TEXT(50) NOT NULL,
siteHandNo INT NOT NULL,
tourneyId INT,
gametypeId INT NOT NULL,
sessionId INT,
fileId INT NOT NULL,
startTime timestamp NOT NULL,
importTime timestamp NOT NULL,
seats INT NOT NULL,
heroSeat INT NOT NULL,
maxPosition INT NOT NULL,
boardcard1 INT, /* 0=none, 1-13=2-Ah 14-26=2-Ad 27-39=2-Ac 40-52=2-As */
boardcard2 INT,
boardcard3 INT,
boardcard4 INT,
boardcard5 INT,
texture INT,
runItTwice BOOLEAN,
playersVpi INT NOT NULL, /* num of players vpi */
playersAtStreet1 INT NOT NULL, /* num of players seeing flop/street4 */
playersAtStreet2 INT NOT NULL,
playersAtStreet3 INT NOT NULL,
playersAtStreet4 INT NOT NULL,
playersAtShowdown INT NOT NULL,
street0Callers INT NOT NULL,
street1Callers INT NOT NULL,
street2Callers INT NOT NULL,
street3Callers INT NOT NULL,
street4Callers INT NOT NULL,
street0Aggressors INT NOT NULL,
street1Aggressors INT NOT NULL,
street2Aggressors INT NOT NULL,
street3Aggressors INT NOT NULL,
street4Aggressors INT NOT NULL,
street0Calls INT NOT NULL,
street1Calls INT NOT NULL,
street2Calls INT NOT NULL,
street3Calls INT NOT NULL,
street4Calls INT NOT NULL,
street0Raises INT NOT NULL, /* num small bets paid to see flop/street4, including blind */
street1Raises INT NOT NULL, /* num small bets paid to see turn/street5 */
street2Raises INT NOT NULL, /* num big bets paid to see river/street6 */
street3Raises INT NOT NULL, /* num big bets paid to see sd/street7 */
street4Raises INT NOT NULL, /* num big bets paid to see showdown */
street0Pot INT, /* pot size at preflop/street3 */
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 */
finalPot INT, /* final pot size */
comment TEXT,
commentTs timestamp)"""
################################
# Create Boards
################################
if db_server == 'mysql':
self.query['createBoardsTable'] = """CREATE TABLE Boards (
id BIGINT UNSIGNED AUTO_INCREMENT NOT NULL, PRIMARY KEY (id),
handId BIGINT UNSIGNED NOT NULL, FOREIGN KEY (handId) REFERENCES Hands(id),
boardId smallint,
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)
ENGINE=INNODB"""
elif db_server == 'postgresql':
self.query['createBoardsTable'] = """CREATE TABLE Boards (
id BIGSERIAL, PRIMARY KEY (id),
handId BIGINT NOT NULL, FOREIGN KEY (handId) REFERENCES Hands(id),
boardId smallint,
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)"""
elif db_server == 'sqlite':
self.query['createBoardsTable'] = """CREATE TABLE Boards (
id INTEGER PRIMARY KEY,
handId INT NOT NULL,
boardId INT,
boardcard1 INT, /* 0=none, 1-13=2-Ah 14-26=2-Ad 27-39=2-Ac 40-52=2-As */
boardcard2 INT,
boardcard3 INT,
boardcard4 INT,
boardcard5 INT)"""
################################
# 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),
currency varchar(4),
buyIn BIGINT,
fee BIGINT,
category varchar(9) NOT NULL,
limitType char(2) NOT NULL,
buyInChips BIGINT,
stack varchar(8),
maxSeats INT,
rebuy BOOLEAN,
rebuyCost BIGINT,
rebuyFee BIGINT,
rebuyChips BIGINT,
addOn BOOLEAN,
addOnCost BIGINT,
addOnFee BIGINT,
addOnChips BIGINT,
knockout BOOLEAN,
koBounty BIGINT,
progressive BOOLEAN,
step BOOLEAN,
stepNo INT,
chance BOOLEAN,
chanceCount INT,
speed varchar(10),
shootout BOOLEAN,
matrix BOOLEAN,
multiEntry BOOLEAN,
reEntry BOOLEAN,
fast BOOLEAN,
newToGame BOOLEAN,
homeGame BOOLEAN,
split BOOLEAN,
sng BOOLEAN,
fifty50 BOOLEAN,
time BOOLEAN,
timeAmt INT,
satellite BOOLEAN,
doubleOrNothing BOOLEAN,
cashOut BOOLEAN,
onDemand BOOLEAN,
flighted BOOLEAN,
guarantee BOOLEAN,
guaranteeAmt BIGINT)
ENGINE=INNODB"""
elif db_server == 'postgresql':
self.query['createTourneyTypesTable'] = """CREATE TABLE TourneyTypes (
id SERIAL, PRIMARY KEY (id),
siteId INT NOT NULL, FOREIGN KEY (siteId) REFERENCES Sites(id),
currency varchar(4),
buyin BIGINT,
fee BIGINT,
category varchar(9),
limitType char(2),
buyInChips BIGINT,
stack varchar(8),
maxSeats INT,
rebuy BOOLEAN,
rebuyCost BIGINT,
rebuyFee BIGINT,
rebuyChips BIGINT,
addOn BOOLEAN,
addOnCost BIGINT,
addOnFee BIGINT,
addOnChips BIGINT,
knockout BOOLEAN,
koBounty BIGINT,
progressive BOOLEAN,
step BOOLEAN,
stepNo INT,
chance BOOLEAN,
chanceCount INT,
speed varchar(10),
shootout BOOLEAN,
matrix BOOLEAN,
multiEntry BOOLEAN,
reEntry BOOLEAN,
fast BOOLEAN,
newToGame BOOLEAN,
homeGame BOOLEAN,
split BOOLEAN,
sng BOOLEAN,
fifty50 BOOLEAN,
time BOOLEAN,
timeAmt INT,
satellite BOOLEAN,
doubleOrNothing BOOLEAN,
cashOut BOOLEAN,
onDemand BOOLEAN,
flighted BOOLEAN,
guarantee BOOLEAN,
guaranteeAmt BIGINT)"""
elif db_server == 'sqlite':
self.query['createTourneyTypesTable'] = """CREATE TABLE TourneyTypes (
id INTEGER PRIMARY KEY,
siteId INT NOT NULL,
currency VARCHAR(4),
buyin INT,
fee INT,
category TEXT,
limitType TEXT,
buyInChips INT,
stack VARCHAR(8),
maxSeats INT,
rebuy BOOLEAN,
rebuyCost INT,
rebuyFee INT,
rebuyChips INT,
addOn BOOLEAN,
addOnCost INT,
addOnFee INT,
addOnChips INT,
knockout BOOLEAN,
koBounty INT,
progressive BOOLEAN,
step BOOLEAN,
stepNo INT,
chance BOOLEAN,
chanceCount INT,
speed TEXT,
shootout BOOLEAN,
matrix BOOLEAN,
multiEntry BOOLEAN,
reEntry BOOLEAN,
fast BOOLEAN,
newToGame BOOLEAN,
homeGame BOOLEAN,
split BOOLEAN,
sng BOOLEAN,
fifty50 BOOLEAN,
time BOOLEAN,
timeAmt INT,
satellite BOOLEAN,
doubleOrNothing BOOLEAN,
cashOut BOOLEAN,
onDemand BOOLEAN,
flighted BOOLEAN,
guarantee BOOLEAN,
guaranteeAmt INT)"""
################################
# 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),
sessionId INT UNSIGNED, FOREIGN KEY (sessionId) REFERENCES Sessions(id),
siteTourneyNo BIGINT NOT NULL,
entries INT,
prizepool BIGINT,
startTime DATETIME,
endTime DATETIME,
tourneyName TEXT,
totalRebuyCount INT,
totalAddOnCount INT,
added BIGINT,
addedCurrency VARCHAR(4),
comment TEXT,
commentTs DATETIME)
ENGINE=INNODB"""
elif db_server == 'postgresql':
self.query['createTourneysTable'] = """CREATE TABLE Tourneys (
id SERIAL, PRIMARY KEY (id),
tourneyTypeId INT, FOREIGN KEY (tourneyTypeId) REFERENCES TourneyTypes(id),
sessionId INT, FOREIGN KEY (sessionId) REFERENCES Sessions(id),
siteTourneyNo BIGINT,
entries INT,
prizepool BIGINT,
startTime timestamp without time zone,
endTime timestamp without time zone,
tourneyName TEXT,
totalRebuyCount INT,
totalAddOnCount INT,
added BIGINT,
addedCurrency VARCHAR(4),
comment TEXT,
commentTs timestamp without time zone)"""
elif db_server == 'sqlite':
self.query['createTourneysTable'] = """CREATE TABLE Tourneys (
id INTEGER PRIMARY KEY,
tourneyTypeId INT,
sessionId INT,
siteTourneyNo INT,
entries INT,
prizepool INT,
startTime timestamp,
endTime timestamp,
tourneyName TEXT,
totalRebuyCount INT,
totalAddOnCount INT,
added INT,
addedCurrency VARCHAR(4),
comment TEXT,
commentTs timestamp)"""
################################
# 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 BIGINT NOT NULL,
bigblind BIGINT NOT NULL,
effStack BIGINT NOT NULL,
effActiveStack BIGINT NOT NULL,
effMzone FLOAT NOT NULL,
effActiveMzone FLOAT NOT NULL,
tableMzone FLOAT NOT NULL,
startBounty BIGINT,
endBounty BIGINT,
position CHAR(1),
seatNo SMALLINT NOT NULL,
sitout BOOLEAN 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,
card8 smallint, /* cards 8-20 for draw hands */
card9 smallint,
card10 smallint,
card11 smallint,
card12 smallint,
card13 smallint,
card14 smallint,
card15 smallint,
card16 smallint,
card17 smallint,
card18 smallint,
card19 smallint,
card20 smallint,
startCards SMALLINT UNSIGNED, FOREIGN KEY (startCards) REFERENCES StartCards(id),
common BIGINT NOT NULL,
committed BIGINT NOT NULL,
winnings BIGINT NOT NULL,
rake BIGINT NOT NULL,
rakeDealt NUMERIC NOT NULL,
rakeContributed NUMERIC NOT NULL,
rakeWeighted NUMERIC NOT NULL,
totalProfit BIGINT,
allInEV NUMERIC,
comment text,
commentTs DATETIME,
tourneysPlayersId BIGINT UNSIGNED, FOREIGN KEY (tourneysPlayersId) REFERENCES TourneysPlayers(id),
wonWhenSeenStreet1 BOOLEAN,
wonWhenSeenStreet2 BOOLEAN,
wonWhenSeenStreet3 BOOLEAN,
wonWhenSeenStreet4 BOOLEAN,
wonAtSD BOOLEAN,
street0VPIChance BOOLEAN,
street0VPI BOOLEAN,
street0AggrChance BOOLEAN,
street0Aggr BOOLEAN,
street0CalledRaiseChance TINYINT,
street0CalledRaiseDone TINYINT,
street0_2BChance BOOLEAN,
street0_2BDone BOOLEAN,
street0_3BChance BOOLEAN,
street0_3BDone BOOLEAN,
street0_4BChance BOOLEAN,
street0_4BDone BOOLEAN,
street0_C4BChance BOOLEAN,
street0_C4BDone BOOLEAN,
street0_FoldTo2BChance BOOLEAN,
street0_FoldTo2BDone BOOLEAN,
street0_FoldTo3BChance BOOLEAN,
street0_FoldTo3BDone BOOLEAN,
street0_FoldTo4BChance BOOLEAN,
street0_FoldTo4BDone BOOLEAN,
street0_SqueezeChance BOOLEAN,
street0_SqueezeDone BOOLEAN,
street0_FoldToSqueezeChance BOOLEAN,
street0_FoldToSqueezeDone BOOLEAN,
street1_2BChance BOOLEAN,
street1_2BDone BOOLEAN,
street1_3BChance BOOLEAN,
street1_3BDone BOOLEAN,
street1_4BChance BOOLEAN,
street1_4BDone BOOLEAN,
street1_C4BChance BOOLEAN,
street1_C4BDone BOOLEAN,
street1_FoldTo2BChance BOOLEAN,
street1_FoldTo2BDone BOOLEAN,
street1_FoldTo3BChance BOOLEAN,
street1_FoldTo3BDone BOOLEAN,
street1_FoldTo4BChance BOOLEAN,
street1_FoldTo4BDone BOOLEAN,
street1_SqueezeChance BOOLEAN,
street1_SqueezeDone BOOLEAN,
street1_FoldToSqueezeChance BOOLEAN,
street1_FoldToSqueezeDone BOOLEAN,
street2_2BChance BOOLEAN,
street2_2BDone BOOLEAN,
street2_3BChance BOOLEAN,
street2_3BDone BOOLEAN,
street2_4BChance BOOLEAN,
street2_4BDone BOOLEAN,
street2_C4BChance BOOLEAN,
street2_C4BDone BOOLEAN,
street2_FoldTo2BChance BOOLEAN,
street2_FoldTo2BDone BOOLEAN,
street2_FoldTo3BChance BOOLEAN,
street2_FoldTo3BDone BOOLEAN,
street2_FoldTo4BChance BOOLEAN,
street2_FoldTo4BDone BOOLEAN,
street2_SqueezeChance BOOLEAN,
street2_SqueezeDone BOOLEAN,
street2_FoldToSqueezeChance BOOLEAN,
street2_FoldToSqueezeDone BOOLEAN,
street3_2BChance BOOLEAN,
street3_2BDone BOOLEAN,
street3_3BChance BOOLEAN,
street3_3BDone BOOLEAN,
street3_4BChance BOOLEAN,
street3_4BDone BOOLEAN,
street3_C4BChance BOOLEAN,
street3_C4BDone BOOLEAN,
street3_FoldTo2BChance BOOLEAN,
street3_FoldTo2BDone BOOLEAN,
street3_FoldTo3BChance BOOLEAN,
street3_FoldTo3BDone BOOLEAN,
street3_FoldTo4BChance BOOLEAN,
street3_FoldTo4BDone BOOLEAN,
street3_SqueezeChance BOOLEAN,
street3_SqueezeDone BOOLEAN,
street3_FoldToSqueezeChance BOOLEAN,
street3_FoldToSqueezeDone BOOLEAN,
raiseToStealChance BOOLEAN,
raiseToStealDone BOOLEAN,
stealChance BOOLEAN,
stealDone BOOLEAN,
success_Steal BOOLEAN,