fix: _exec must return cursor for both PG and SQLite
Browse files- backend/database.py +9 -13
backend/database.py
CHANGED
|
@@ -244,20 +244,17 @@ def get_db():
|
|
| 244 |
conn.close()
|
| 245 |
|
| 246 |
|
| 247 |
-
def _cur(conn):
|
| 248 |
-
if _is_pg():
|
| 249 |
-
return conn.cursor()
|
| 250 |
-
return conn
|
| 251 |
-
|
| 252 |
-
|
| 253 |
def _exec(conn, sql: str, params=()):
|
| 254 |
-
|
| 255 |
-
|
|
|
|
|
|
|
|
|
|
| 256 |
|
| 257 |
|
| 258 |
def _exec_lastid(conn, sql: str, params=()):
|
| 259 |
-
c = _cur(conn)
|
| 260 |
if _is_pg():
|
|
|
|
| 261 |
c.execute(_fix_sql(sql) + " RETURNING id", params)
|
| 262 |
row = c.fetchone()
|
| 263 |
return row["id"] if row else None
|
|
@@ -501,14 +498,13 @@ def save_global_jobs(jobs: list[dict]) -> int:
|
|
| 501 |
has_full_info,
|
| 502 |
is_graduate,
|
| 503 |
)
|
| 504 |
-
c = _cur(conn)
|
| 505 |
if _is_pg():
|
| 506 |
-
|
| 507 |
-
c.execute(
|
| 508 |
if c.rowcount > 0:
|
| 509 |
saved += 1
|
| 510 |
else:
|
| 511 |
-
|
| 512 |
if conn.total_changes > 0:
|
| 513 |
saved += 1
|
| 514 |
except Exception:
|
|
|
|
| 244 |
conn.close()
|
| 245 |
|
| 246 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 247 |
def _exec(conn, sql: str, params=()):
|
| 248 |
+
if _is_pg():
|
| 249 |
+
c = conn.cursor()
|
| 250 |
+
c.execute(_fix_sql(sql), params)
|
| 251 |
+
return c
|
| 252 |
+
return conn.execute(sql, params)
|
| 253 |
|
| 254 |
|
| 255 |
def _exec_lastid(conn, sql: str, params=()):
|
|
|
|
| 256 |
if _is_pg():
|
| 257 |
+
c = conn.cursor()
|
| 258 |
c.execute(_fix_sql(sql) + " RETURNING id", params)
|
| 259 |
row = c.fetchone()
|
| 260 |
return row["id"] if row else None
|
|
|
|
| 498 |
has_full_info,
|
| 499 |
is_graduate,
|
| 500 |
)
|
|
|
|
| 501 |
if _is_pg():
|
| 502 |
+
c = conn.cursor()
|
| 503 |
+
c.execute("INSERT INTO global_jobs (title, company, location, description, url, source, board_category, job_category, posted_date, has_full_info, is_graduate) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s) ON CONFLICT (url) DO NOTHING", p)
|
| 504 |
if c.rowcount > 0:
|
| 505 |
saved += 1
|
| 506 |
else:
|
| 507 |
+
conn.execute(sql, p)
|
| 508 |
if conn.total_changes > 0:
|
| 509 |
saved += 1
|
| 510 |
except Exception:
|