mirror of
https://github.com/simonw/sqlite-utils.git
synced 2026-10-02 06:44:29 +02:00
Update _defaults["strict"] when necessary
Refs https://github.com/simonw/sqlite-utils/pull/788#issuecomment-4948505824
This commit is contained in:
parent
7a01dd94f3
commit
5b9898ed9b
2 changed files with 15 additions and 0 deletions
|
|
@ -2591,6 +2591,8 @@ class Table(Queryable):
|
||||||
self.db.execute("PRAGMA defer_foreign_keys=OFF;")
|
self.db.execute("PRAGMA defer_foreign_keys=OFF;")
|
||||||
if should_disable_foreign_keys:
|
if should_disable_foreign_keys:
|
||||||
self.db.execute("PRAGMA foreign_keys=1;")
|
self.db.execute("PRAGMA foreign_keys=1;")
|
||||||
|
if strict is not None:
|
||||||
|
self._defaults["strict"] = strict
|
||||||
return self
|
return self
|
||||||
|
|
||||||
def transform_sql(
|
def transform_sql(
|
||||||
|
|
|
||||||
|
|
@ -602,6 +602,19 @@ def test_transform_to_strict_with_invalid_data(fresh_db):
|
||||||
assert fresh_db.table_names() == ["dogs"]
|
assert fresh_db.table_names() == ["dogs"]
|
||||||
|
|
||||||
|
|
||||||
|
def test_transform_strict_updates_default(fresh_db):
|
||||||
|
if not fresh_db.supports_strict:
|
||||||
|
pytest.skip("SQLite version does not support strict tables")
|
||||||
|
table = fresh_db.table("items", strict=True)
|
||||||
|
table.create({"id": int})
|
||||||
|
|
||||||
|
table.transform(strict=False)
|
||||||
|
assert table.strict is False
|
||||||
|
|
||||||
|
table.create({"id": int}, replace=True)
|
||||||
|
assert table.strict is False
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
"indexes, transform_params",
|
"indexes, transform_params",
|
||||||
[
|
[
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue