Use REAL for floating point columns if table is strict, closes #644

Refs #645
This commit is contained in:
Simon Willison 2024-11-23 14:27:21 -08:00
commit 4dc2e2e9c8
4 changed files with 17 additions and 3 deletions

View file

@ -2416,11 +2416,13 @@ def test_create_table_strict(strict):
db = Database("test.db")
result = runner.invoke(
cli.cli,
["create-table", "test.db", "items", "id", "integer"]
["create-table", "test.db", "items", "id", "integer", "w", "float"]
+ (["--strict"] if strict else []),
)
assert result.exit_code == 0
assert db["items"].strict == strict or not db.supports_strict
# Should have a floating point column
assert db["items"].columns_dict == {"id": int, "w": float}
@pytest.mark.parametrize("method", ("insert", "upsert"))

View file

@ -1350,8 +1350,12 @@ def test_insert_upsert_strict(fresh_db, method_name, strict):
@pytest.mark.parametrize("strict", (False, True))
def test_create_table_strict(fresh_db, strict):
table = fresh_db.create_table("t", {"id": int}, strict=strict)
table = fresh_db.create_table("t", {"id": int, "f": float}, strict=strict)
assert table.strict == strict or not fresh_db.supports_strict
expected_schema = "CREATE TABLE [t] (\n" " [id] INTEGER,\n" " [f] FLOAT\n" ")"
if strict:
expected_schema = "CREATE TABLE [t] (\n [id] INTEGER,\n [f] REAL\n) STRICT"
assert table.schema == expected_schema
@pytest.mark.parametrize("strict", (False, True))