+ // retrieve list of active tournaments
+ $trn_sql = sprintf("SELECT * FROM %sbin5_tournaments WHERE active = 1;", $G_dbpfx);
+ if (($trn_pg = pg_query($bdb->dbconn->db(), $trn_sql)) == FALSE) {
+ log_crit("stat-day: select from tournaments failed");
+ break;
+ }
+
+ $trn_n = pg_numrows($trn_pg);
+ printf("Number of tournaments: %d\n", $trn_n);
+
+ for ($t = 0 ; $t < $trn_n ; $t++) {
+ $trn_obj = pg_fetch_object($trn_pg, $t);
+
+ $tmt_sql = sprintf("SELECT m.code AS code, m.mazzo_next as minus_one_is_old FROM %sbin5_matches AS m, %sbin5_games AS g, %sbin5_tournaments as t WHERE t.code = m.tcode AND m.code = g.mcode AND t.code = %d AND g.tstamp >= '%s' AND g.tstamp < '%s' GROUP BY m.code, minus_one_is_old ORDER BY m.code, minus_one_is_old DESC;",
+ $G_dbpfx, $G_dbpfx, $G_dbpfx, $trn_obj->code, $from, $to);
+
+ // if deletable old matches exists then ...
+ if (($tmt_pg = pg_query($bdb->dbconn->db(), $tmt_sql)) == FALSE) {
+ log_crit("stat-day: select from matches failed");
+ break;
+ }
+