mirror of
https://github.com/simonw/sqlite-utils.git
synced 2026-09-27 12:24:11 +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:
|
def supports_on_conflict(self) -> bool:
|
||||||
# SQLite's upsert is implemented as INSERT INTO ... ON CONFLICT DO ...
|
# SQLite's upsert is implemented as INSERT INTO ... ON CONFLICT DO ...
|
||||||
if not hasattr(self, "_supports_on_conflict"):
|
if not hasattr(self, "_supports_on_conflict"):
|
||||||
|
table_name = "t{}".format(secrets.token_hex(16))
|
||||||
try:
|
try:
|
||||||
table_name = "t{}".format(secrets.token_hex(16))
|
|
||||||
with self.conn:
|
with self.conn:
|
||||||
self.conn.execute(
|
self.conn.execute(
|
||||||
"create table {} (id integer primary key, name text)".format(
|
"create table {} (id integer primary key, name text)".format(
|
||||||
|
|
@ -709,10 +709,11 @@ class Database:
|
||||||
"on conflict do update set name = 'two'"
|
"on conflict do update set name = 'two'"
|
||||||
).format(table_name)
|
).format(table_name)
|
||||||
)
|
)
|
||||||
self.conn.execute("drop table {}".format(table_name))
|
self._supports_on_conflict = True
|
||||||
self._supports_on_conflict = True
|
|
||||||
except Exception:
|
except Exception:
|
||||||
self._supports_on_conflict = False
|
self._supports_on_conflict = False
|
||||||
|
finally:
|
||||||
|
self.conn.execute("drop table {}".format(table_name))
|
||||||
return self._supports_on_conflict
|
return self._supports_on_conflict
|
||||||
|
|
||||||
@property
|
@property
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue