mirror of
https://github.com/simonw/sqlite-utils.git
synced 2026-07-23 01:14:31 +02:00
db.supports_strict and table.strict properties, refs #344
This commit is contained in:
parent
126703706e
commit
e3f108e0f3
3 changed files with 65 additions and 14 deletions
|
|
@ -18,6 +18,7 @@ import json
|
|||
import os
|
||||
import pathlib
|
||||
import re
|
||||
import secrets
|
||||
from sqlite_fts4 import rank_bm25 # type: ignore
|
||||
import sys
|
||||
import textwrap
|
||||
|
|
@ -521,6 +522,19 @@ class Database:
|
|||
sqls.append(sql)
|
||||
return "\n".join(sqls)
|
||||
|
||||
@property
|
||||
def supports_strict(self):
|
||||
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 as e:
|
||||
return False
|
||||
|
||||
@property
|
||||
def journal_mode(self) -> str:
|
||||
"Current ``journal_mode`` of this database."
|
||||
|
|
@ -1219,6 +1233,13 @@ class Table(Queryable):
|
|||
"``{trigger_name: sql}`` dictionary of triggers defined on this table."
|
||||
return {trigger.name: trigger.sql for trigger in self.triggers}
|
||||
|
||||
@property
|
||||
def strict(self) -> bool:
|
||||
"Is this a STRICT table?"
|
||||
table_suffix = self.schema.split(")")[-1].strip().upper()
|
||||
table_options = [bit.strip() for bit in table_suffix.split(",")]
|
||||
return "STRICT" in table_options
|
||||
|
||||
def create(
|
||||
self,
|
||||
columns: Dict[str, Any],
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue