Exemplo n.º 1
0
def update(rows, table):
    # solved
    table_header, position = (
        [result, -2] if table in ["win_loss", "overall"] else [fractions, 3]
    )
    _update = defaultdict(lambda: defaultdict(int))
    for col in rows:
        _update[col[1]][table_header[col[position]]] += 1
    for fraction in _update.keys():
        select_where = _update[fraction]
        if table in ["win_loss", "versus"]:
            select = read(table, {fraction: select_where})
            _select = map(sum, zip(*select, select_where.values()))
            _set = settostr(zip(select_where.keys(), _select))
            _where = wheretostr([("Fraction", fraction)])
        elif table == "overall":
            if select_where["Win"] == 0:
                continue
            select = read("overall", fraction)
            _select = map(sum, zip(*select, [select_where["Win"]] * 2))
            _set = settostr(zip(["Overall", fractions[fraction]], _select))
            _where = "rowid = 1"
        request = f"UPDATE {table} SET {_set} WHERE {_where}"
        CURSOR.execute(request)
        CONN.commit()
Exemplo n.º 2
0
def write(rows, table="games"):
    # solved
    if type(rows) == tuple:
        request = f"INSERT INTO {table} {request_header(table)} VALUES {rows}"
        CURSOR.execute(request, rows)
    else:
        request = f"INSERT INTO {table} VALUES (?, ?, ?, ?, ?, ?)"
        CURSOR.executemany(request, rows)
    CONN.commit()
Exemplo n.º 3
0
def read(table="lastrow", _where={}):
    # solved
    column_list = "*"
    for fraction in _where.keys():
        column_list = ", ".join(_where[fraction].keys())
        _where = f" WHERE Fraction = '{fraction}'"
    request = f"SELECT {column_list} FROM {table}{_where if _where != {} else ''}"
    return CURSOR.execute(request).fetchall()
Exemplo n.º 4
0
def read(table, _where={}):
    # solved
    if table in ["win_loss", "versus"]:
        return tb.read(table, _where)
    elif table in ["overall"]:
        fraction = ("Overall, " + fractions[_where]) if _where != {} else "*"
        request = f"SELECT {fraction} FROM overall"
    return CURSOR.execute(request).fetchall()
Exemplo n.º 5
0
def drop(table="lastrow"):
    # solved
    CURSOR.execute(f"DROP TABLE {table}")
    CONN.commit()
Exemplo n.º 6
0
def update(row):
    # solved
    _set = settostr(zip(games_title, row))
    request = f"UPDATE lastrow SET {_set} WHERE rowid = 1"
    CURSOR.execute(request)
    CONN.commit()
Exemplo n.º 7
0
def count(table, _where=[]):
    # solved 50/50
    _where = f" WHERE {wheretostr(_where, ' AND ')}" if _where != [] else ""
    request = f"SELECT count(*) FROM {table}{_where}"
    return CURSOR.execute(request).fetchall()[0][0]
Exemplo n.º 8
0
def create(table):
    # solved
    request = f"CREATE TABLE {table} {table_header(table)}"
    CURSOR.execute(request)
    CONN.commit()