Skip to content

fix(data-grid): distinguish literal string 'NULL' from SQL NULL in TableMutationEngine WHERE clause #1368

Closed

Description

@ZhuchkaTriplesix

Summary

In TableMutationEngine._buildWhereClause (lib/core/database/table_mutation_engine.dart, lines 487 and 504):

final val = row[colIdx];
if (val == 'NULL' || val == 'null') {
  clauses.add('$colName IS NULL');
} else {
  final colType = _lookupDataType(columnDataTypes, matchedCol) ??
      _lookupDataType(columnDataTypes, pk);
  clauses.add('$colName = ${formatLiteral(val, dialect, dataTypeName: colType)}');
}

When building WHERE clauses for UPDATE and DELETE statements, _buildWhereClause unconditionally converts any column value equal to 'NULL' or 'null' to $colName IS NULL, ignoring whether the column is text-based (_isTextType) and bypassing TableMutationEngine.kNullSentinel.

Impact (Data Corruption / Data Loss Risk)

If a table contains a text column (e.g. code, status, notes, or a text primary key) with the literal string value "NULL":

  1. Modifying that row in the Virtual Data Grid generates:
    UPDATE "users" SET "name" = 'Bob' WHERE "code" IS NULL;
    instead of:
    UPDATE "users" SET "name" = 'Bob' WHERE "code" = 'NULL';
  2. If another row in the database has an actual NULL in that column, that other row is silently modified!
  3. If the user deletes the row, DELETE FROM "users" WHERE "code" IS NULL; deletes the wrong row(s).
  4. If no row has NULL, the mutation silently affects 0 rows.

Scope

  • In TableMutationEngine._buildWhereClause, check _isTextType(colType) before treating 'NULL' / 'null' as SQL NULL.
  • Ensure kNullSentinel (\u0000__QUERYA_NULL__\u0000) is used to unambiguously identify genuine SQL NULL values across staging buffers and mutation generation.
  • Add regression tests in test/core/database/table_mutation_engine_test.dart for rows containing literal 'NULL' strings in text columns and primary keys.

Out of scope

  • UI cell editor styling for NULL vs empty string (already handled).

Activity

  1. added
    bugSomething isn't working
    stabilityTheme parser epic label: stability
    data-gridInteractive data grid, cell editor, filtering, groupings
    backendBackend database driver execution and queries
    P1High priority / Core capability
    on Oct 10, 2026
  2. ZhuchkaTriplesix commented on Oct 11, 2026

    @ZhuchkaTriplesix
    MemberAuthor

    Done in #1385 (merged into dev).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    P1High priority / Core capabilitybackendBackend database driver execution and queriesbugSomething isn't workingdata-gridInteractive data grid, cell editor, filtering, groupingsstabilityTheme parser epic label: stability

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions