mirror of
https://github.com/simonw/sqlite-utils.git
synced 2026-09-12 03:24:23 +02:00
supports_strict now caches on self._supports_strict
This commit is contained in:
parent
72f6c820f6
commit
55047db798
1 changed files with 12 additions and 10 deletions
|
|
@ -671,16 +671,18 @@ class Database:
|
|||
@property
|
||||
def supports_strict(self) -> bool:
|
||||
"Does this database support STRICT mode?"
|
||||
try:
|
||||
table_name = "t{}".format(secrets.token_hex(16))
|
||||
with self.conn:
|
||||
self.conn.execute(
|
||||
"create table {} (name text) strict".format(table_name)
|
||||
)
|
||||
self.conn.execute("drop table {}".format(table_name))
|
||||
return True
|
||||
except Exception:
|
||||
return False
|
||||
if not hasattr(self, "_supports_strict"):
|
||||
try:
|
||||
table_name = "t{}".format(secrets.token_hex(16))
|
||||
with self.conn:
|
||||
self.conn.execute(
|
||||
"create table {} (name text) strict".format(table_name)
|
||||
)
|
||||
self.conn.execute("drop table {}".format(table_name))
|
||||
self._supports_strict = True
|
||||
except Exception:
|
||||
self._supports_strict = False
|
||||
return self._supports_strict
|
||||
|
||||
@property
|
||||
def sqlite_version(self) -> Tuple[int, ...]:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue