Skip to content

Commit 55047db

Browse files
committed
supports_strict now caches on self._supports_strict
1 parent 72f6c82 commit 55047db

File tree

1 file changed

+12
-10
lines changed

1 file changed

+12
-10
lines changed

sqlite_utils/db.py

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -671,16 +671,18 @@ def schema(self) -> str:
671671
@property
672672
def supports_strict(self) -> bool:
673673
"Does this database support STRICT mode?"
674-
try:
675-
table_name = "t{}".format(secrets.token_hex(16))
676-
with self.conn:
677-
self.conn.execute(
678-
"create table {} (name text) strict".format(table_name)
679-
)
680-
self.conn.execute("drop table {}".format(table_name))
681-
return True
682-
except Exception:
683-
return False
674+
if not hasattr(self, "_supports_strict"):
675+
try:
676+
table_name = "t{}".format(secrets.token_hex(16))
677+
with self.conn:
678+
self.conn.execute(
679+
"create table {} (name text) strict".format(table_name)
680+
)
681+
self.conn.execute("drop table {}".format(table_name))
682+
self._supports_strict = True
683+
except Exception:
684+
self._supports_strict = False
685+
return self._supports_strict
684686

685687
@property
686688
def sqlite_version(self) -> Tuple[int, ...]:

0 commit comments

Comments
 (0)