Summary
In VirtualResultGrid._handleDuplicateRow:
void _handleDuplicateRow(int row) {
if (widget.stagingBuffer == null || row >= _sortedRows.length) return;
final rowData = _sortedRows[row];
widget.stagingBuffer!.addRow(List<String>.from(rowData));
}
When a user triggers "Duplicate Row" (via row context menu or keyboard shortcut), the row is cloned verbatim into the staging buffer, including the primary key value (e.g. id = 42).
When the user clicks Save, TableMutationEngine constructs an INSERT query containing the duplicate primary key:
INSERT INTO users (id, name, email) VALUES (42, 'Alice', ...);
This causes an immediate database error (duplicate key value violates unique constraint / PRIMARY KEY must be unique), failing the save operation.
Repro
- Open Table Browser on a table with a primary key.
- Right-click any row and select "Duplicate Row".
- A new row appears at the bottom with all identical values, including the PK.
- Click Save.
- Save fails with a unique constraint violation error.
Scope
• When duplicating a row, identify primary key columns (using primaryKeys / columnMeta).
• Reset primary key cell values to empty string or default sentinel so the database can generate a fresh unique key.
• Alternatively, provide a duplicateRow(int index, {Set<String> primaryKeys}) helper on DataGridStagingBuffer that blanks PK columns automatically.
• Add tests in test/features/workspace/data_grid_staging_buffer_test.dart.
Out of scope
• Natural composite keys where the user is required to manually input distinct key components (the user can still edit the blank cell before saving).
Summary
In
VirtualResultGrid._handleDuplicateRow:When a user triggers "Duplicate Row" (via row context menu or keyboard shortcut), the row is cloned verbatim into the staging buffer, including the primary key value (e.g.
id = 42).When the user clicks Save,
TableMutationEngineconstructs anINSERTquery containing the duplicate primary key:INSERT INTO users (id, name, email) VALUES (42, 'Alice', ...);This causes an immediate database error (
duplicate key value violates unique constraint/PRIMARY KEY must be unique), failing the save operation.Repro
Scope
• When duplicating a row, identify primary key columns (using
primaryKeys/columnMeta).• Reset primary key cell values to empty string or default sentinel so the database can generate a fresh unique key.
• Alternatively, provide a
duplicateRow(int index, {Set<String> primaryKeys})helper onDataGridStagingBufferthat blanks PK columns automatically.• Add tests in
test/features/workspace/data_grid_staging_buffer_test.dart.Out of scope
• Natural composite keys where the user is required to manually input distinct key components (the user can still edit the blank cell before saving).