示例#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()
示例#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()
示例#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()
示例#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()
示例#5
0
def drop(table="lastrow"):
    # solved
    CURSOR.execute(f"DROP TABLE {table}")
    CONN.commit()
示例#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()
示例#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]
示例#8
0
def create(table):
    # solved
    request = f"CREATE TABLE {table} {table_header(table)}"
    CURSOR.execute(request)
    CONN.commit()