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
8 changes: 3 additions & 5 deletions dissect/database/sqlite3/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,11 +134,9 @@ def get_primary_key_from_constraint(column_type_constraint: str, column_def: str
)
matched_group = primary_key_sql.groups()[0]
primary_key_defs = list(split_sql_list(matched_group))
# We only handle single primary keys, no compound keys or
# expressions, so a single entry in the list consisting of a single
# part.
# We only handle single primary keys, no compound keys or expressions, so a single entry in the list consisting of
# a single part. For example we parse ``id`` as a primary_key in the constraint ``PRIMARY KEY("id" AUTOINCREMENT)``.
if len(primary_key_defs) == 1:
primary_key_parts = primary_key_defs[0].split(maxsplit=1)
if len(primary_key_parts) == 1:
primary_key = primary_key_parts[0]
primary_key = primary_key_parts[0].strip("'\"")
return primary_key
15 changes: 15 additions & 0 deletions tests/sqlite3/test_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,21 @@
),
id="create-table-firefox-foreign-in-column-name",
),
# Primary key constraint with multiple parts, but not a compound/composite constraint.
pytest.param(
'CREATE TABLE "example"("foo" INTEGER, "bar" TEXT NOT NULL, PRIMARY KEY("foo" AUTOINCREMENT))',
(
"foo",
[
("foo", "INTEGER"),
("bar", "TEXT NOT NULL"),
],
[
'PRIMARY KEY("foo" AUTOINCREMENT)',
],
),
id="primary-key-constraint-multiple-parts",
),
]


Expand Down