Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions sqlite_utils/db.py
Original file line number Diff line number Diff line change
Expand Up @@ -5212,8 +5212,8 @@ def resolve_extracts(

def _decode_default_value(value: str) -> object:
if value.startswith("'") and value.endswith("'"):
# It's a string
return value[1:-1]
# It's a string; unescape doubled single quotes
return value[1:-1].replace("''", "'")
if value.isdigit():
# It's an integer
return int(value)
Expand Down
11 changes: 11 additions & 0 deletions tests/test_introspect.py
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,7 @@ def test_table_strict(fresh_db, create_table, expected_strict):
1,
1.3,
"foo",
"O'Brien",
True,
b"binary",
),
Expand All @@ -323,6 +324,16 @@ def test_table_default_values(fresh_db, value):
assert default_values == {"value": value}


def test_table_default_values_escaped_quotes(fresh_db):
# SQLite stores string defaults with single quotes doubled, so
# introspection needs to unescape them again
fresh_db.execute(
"create table t (id integer primary key, name text default 'O''Brien')"
)
assert "default 'O''Brien'" in fresh_db["t"].schema
assert fresh_db["t"].default_values == {"name": "O'Brien"}


def test_pks_use_primary_key_declaration_order(fresh_db):
# PRIMARY KEY (a, b) declared against columns stored in order (b, a) -
# pks must follow the declaration order, which is what SQLite uses to
Expand Down
Loading