Skip to content

fix: normalize key column name when CASESENSITIV is off#33

Draft
toddr-bot wants to merge 2 commits into
cpan-authors:mainfrom
toddr-bot:koan.toddr.bot/fix-casesensitiv-key-normalization
Draft

fix: normalize key column name when CASESENSITIV is off#33
toddr-bot wants to merge 2 commits into
cpan-authors:mainfrom
toddr-bot:koan.toddr.bot/fix-casesensitiv-key-normalization

Conversation

@toddr-bot

@toddr-bot toddr-bot commented Apr 3, 2026

Copy link
Copy Markdown
Contributor

What

Normalize $self->{key} to lowercase at TIEHASH time when CASESENSITIV=0 (the default).

Why

_fields() lowercases stored column names when case-insensitive, but the key column name was stored as-is from the tie() call. When a mixed-case key name was used (e.g. Produce_ID), the key-field guard in STORE failed to match, allowing the key column into INSERT/UPDATE statements — potential data corruption.

This also affected Record::CLEAR, which builds a hash from the lowercased _fields() keys but tried to delete the original-case key name — a no-op that left the key column in the update set.

How

One-line fix in TIEHASH: $self->{key} = lc $self->{key} unless $self->{CASESENSITIV}. This ensures consistency with _fields() across all downstream comparisons and SQL generation.

Complementary to PR #25 (field lookup normalization) — this PR fixes the key-side normalization that PR #25 doesn't address.

Testing

  • 4 new tests: STORE key-field guard with mixed-case key, Record::CLEAR with mixed-case key
  • All 40 DBI.t tests pass, all 23 RDBM.t tests pass

🤖 Generated with Claude Code


Quality Report

Changes: 2 files changed, 52 insertions(+), 1 deletion(-)

Code scan: clean

Tests: passed (OK)

Branch hygiene: clean

Generated by Kōan post-mission quality pipeline

toddr-bot and others added 2 commits April 3, 2026 02:37
When the key column is passed with mixed case (e.g. 'Produce_ID')
and CASESENSITIV=0 (default), the key-field guard in STORE fails
to match the lowercased field names from _fields(), allowing
the key column to be included in INSERT/UPDATE statements.

Tests verify:
- STORE key-field guard fires with mixed-case key names
- Record::CLEAR exclusion works with mixed-case key names

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
When CASESENSITIV=0 (the default), _fields() lowercases all stored
column names, but $self->{key} was stored as-is from the tie() call.
This caused the key-field guard in STORE to miss when the user passed
a mixed-case key name (e.g. 'Produce_ID'), allowing the key column
to be included in INSERT/UPDATE statements — potential data corruption.

Fix: lowercase $self->{key} at TIEHASH time when CASESENSITIV=0.
This ensures all downstream comparisons against $self->{key}
(STORE guard, Record::CLEAR exclusion, SQL WHERE clauses) are
consistent with the lowercased names from _fields().

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant