Skip to content

Commit 13b71fd

Browse files
committed
hotfix
1 parent e33c668 commit 13b71fd

File tree

2 files changed

+13
-9
lines changed

2 files changed

+13
-9
lines changed

CHANGELOG.MD

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,4 +47,9 @@ All notable changes to this project will be documented in this file.
4747

4848
### Fixed
4949
- A bug with `CircularChecker` class where the database connection would be closed after a while and would report 20 new circulars
50-
- Minor improvements
50+
- Minor improvements
51+
52+
## v1.2.1 - 17/1/2023
53+
54+
### Fixed
55+
- SQL syntax error

pybpsapi.py

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -141,10 +141,9 @@ def __init__(self, category, url: str = "https://bpsapi.rajtech.me/v1/", cache_m
141141
self._con = sqlite3.connect(self.db_path + f"/{self.db_name}.db")
142142
self._cur = self._con.cursor()
143143

144-
self._cur.execute("CREATE TABLE IF NOT EXISTS ? (title TEXT, category TEXT, data BLOB)",
145-
(self.db_table,))
146-
self._cur.execute("INSERT INTO ? VALUES (?, ?, ?)",
147-
(self.db_table, "circular_list", self.category, pickle.dumps([])))
144+
self._cur.execute(f"CREATE TABLE IF NOT EXISTS {self.db_table} (title TEXT, category TEXT, data BLOB)")
145+
self._cur.execute(f"INSERT INTO {self.db_table} VALUES (?, ?, ?)",
146+
("circular_list", self.category, pickle.dumps([])))
148147
self._con.commit()
149148

150149
elif cache_method == "pickle":
@@ -180,7 +179,7 @@ def refresh_db_con(self):
180179
def get_cache(self) -> list[list]:
181180
if self.cache_method == "database":
182181
self.refresh_db_con()
183-
self._cur.execute("SELECT * FROM ? WHERE category = ?", (self.db_table, self.category))
182+
self._cur.execute(f"SELECT * FROM {self.db_table} WHERE category = ?", (self.category,))
184183
res = self._cur.fetchone()
185184
if res is None:
186185
return []
@@ -198,9 +197,9 @@ def get_cache(self) -> list[list]:
198197
def _set_cache(self, data, title: str = "circular_list"):
199198
if self.cache_method == "database":
200199
self.refresh_db_con()
201-
self._cur.execute("DELETE FROM ? WHERE category = ?", (self.db_table, self.category,))
202-
self._cur.execute("INSERT INTO ? VALUES (?, ?, ?)",
203-
(self.db_table, title, self.category, pickle.dumps(data)))
200+
self._cur.execute(f"DELETE FROM {self.db_table} WHERE category = ?", (self.category,))
201+
self._cur.execute(f"INSERT INTO {self.db_table} VALUES (?, ?, ?)",
202+
(title, self.category, pickle.dumps(data)))
204203
self._con.commit()
205204

206205
elif self.cache_method == "pickle":

0 commit comments

Comments
 (0)