Selaa lähdekoodia

Fixes for pymysql

pull/62/head
Ben Kurtovic 5 kuukautta sitten
vanhempi
commit
344d13832a
1 muutettua tiedostoa jossa 14 lisäystä ja 9 poistoa
  1. +14
    -9
      src/copyvios/checker.py

+ 14
- 9
src/copyvios/checker.py Näytä tiedosto

@@ -203,15 +203,20 @@ def _get_cache_id(page: Page, mode: str) -> bytes:
return hashlib.sha256((mode + page.get()).encode("utf8")).digest() return hashlib.sha256((mode + page.get()).encode("utf8")).digest()




def _sql_param() -> str:
# This is terrible!
return sql_dialect(mysql="%s", sqlite="?")


def _get_cached_results( def _get_cached_results(
page: Page, conn: PoolProxiedConnection, mode: str, noskip: bool page: Page, conn: PoolProxiedConnection, mode: str, noskip: bool
) -> CopyvioCheckResult | None: ) -> CopyvioCheckResult | None:
cache_id = _get_cache_id(page, mode) cache_id = _get_cache_id(page, mode)
cursor = conn.cursor() cursor = conn.cursor()
cursor.execute( cursor.execute(
"""SELECT cache_time, cache_queries, cache_process_time, cache_possible_miss
f"""SELECT cache_time, cache_queries, cache_process_time, cache_possible_miss
FROM cache FROM cache
WHERE cache_id = ?""",
WHERE cache_id = {_sql_param()}""",
(cache_id,), (cache_id,),
) )
results = cursor.fetchall() results = cursor.fetchall()
@@ -230,9 +235,9 @@ def _get_cached_results(
return None return None


cursor.execute( cursor.execute(
"""SELECT cdata_url, cdata_confidence, cdata_skipped, cdata_excluded
f"""SELECT cdata_url, cdata_confidence, cdata_skipped, cdata_excluded
FROM cache_data FROM cache_data
WHERE cdata_cache_id = ?""",
WHERE cdata_cache_id = {_sql_param()}""",
(cache_id,), (cache_id,),
) )
data = cursor.fetchall() data = cursor.fetchall()
@@ -307,19 +312,19 @@ def _cache_result(
# TODO: Switch to proper SQLAlchemy # TODO: Switch to proper SQLAlchemy
cur = conn.cursor() cur = conn.cursor()
try: try:
cur.execute("DELETE FROM cache WHERE cache_id = ?", (cache_id,))
cur.execute(f"DELETE FROM cache WHERE cache_id = {_sql_param()}", (cache_id,))
cur.execute(f"DELETE FROM cache WHERE cache_time < {expiry}") cur.execute(f"DELETE FROM cache WHERE cache_time < {expiry}")
cur.execute( cur.execute(
"""INSERT INTO cache (
f"""INSERT INTO cache (
cache_id, cache_queries, cache_process_time, cache_possible_miss cache_id, cache_queries, cache_process_time, cache_possible_miss
) VALUES (?, ?, ?, ?)""",
) VALUES ({_sql_param()}, {_sql_param()}, {_sql_param()}, {_sql_param()})""",
(cache_id, result.queries, result.time, result.possible_miss), (cache_id, result.queries, result.time, result.possible_miss),
) )
cur.executemany( cur.executemany(
"""INSERT INTO cache_data (
f"""INSERT INTO cache_data (
cdata_cache_id, cdata_url, cdata_confidence, cdata_skipped, cdata_cache_id, cdata_url, cdata_confidence, cdata_skipped,
cdata_excluded cdata_excluded
) VALUES (?, ?, ?, ?, ?)""",
) VALUES ({_sql_param()}, {_sql_param()}, {_sql_param()}, {_sql_param()}, {_sql_param()})""",
data, data,
) )
except Exception: except Exception:


Ladataan…
Peruuta
Tallenna