mirror of
https://github.com/simonw/sqlite-utils.git
synced 2026-09-12 03:24:23 +02:00
Drop table in finally
Refs https://github.com/simonw/sqlite-utils/pull/653#issuecomment-2864963011
This commit is contained in:
parent
41497c3210
commit
494075584f
1 changed files with 4 additions and 3 deletions
|
|
@ -692,8 +692,8 @@ class Database:
|
|||
def supports_on_conflict(self) -> bool:
|
||||
# SQLite's upsert is implemented as INSERT INTO ... ON CONFLICT DO ...
|
||||
if not hasattr(self, "_supports_on_conflict"):
|
||||
table_name = "t{}".format(secrets.token_hex(16))
|
||||
try:
|
||||
table_name = "t{}".format(secrets.token_hex(16))
|
||||
with self.conn:
|
||||
self.conn.execute(
|
||||
"create table {} (id integer primary key, name text)".format(
|
||||
|
|
@ -709,10 +709,11 @@ class Database:
|
|||
"on conflict do update set name = 'two'"
|
||||
).format(table_name)
|
||||
)
|
||||
self.conn.execute("drop table {}".format(table_name))
|
||||
self._supports_on_conflict = True
|
||||
self._supports_on_conflict = True
|
||||
except Exception:
|
||||
self._supports_on_conflict = False
|
||||
finally:
|
||||
self.conn.execute("drop table {}".format(table_name))
|
||||
return self._supports_on_conflict
|
||||
|
||||
@property
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue