Skip to content

fix(typeCast): TINYINT(1) null handling - #279

Closed
airbon99 wants to merge 1 commit into
overextended:mainfrom
airbon99:fix-typecast-tiny-null
Closed

fix(typeCast): TINYINT(1) null handling#279
airbon99 wants to merge 1 commit into
overextended:mainfrom
airbon99:fix-typecast-tiny-null

Conversation

@airbon99

@airbon99 airbon99 commented May 7, 2026

Copy link
Copy Markdown

Problem reproduction

  • Left joining a tinyint(1) field which doesn't have a match returns false

Expected behaviour

  • Return null

@Kenshiin13

Copy link
Copy Markdown
Member

Confirmed on my end, nice catch 👍🏽

The old field.string() === '1' evaluates null === '1'false when the column is NULL (e.g. an unmatched LEFT JOIN), so a tinyint(1) that should be nil came back false. The change short-circuits NULL and only does the boolean compare when a value is present:

value before after
'1' true true
'0' false false
NULL false null
length ≠ 1 next() next()

Two things to note:

BIT(1) has the same bug in the case right below:

case 'BIT':
  return field.length === 1 ? field.buffer()?.[0] === 1 : field.buffer()?.[0];

A NULL bit(1) gives field.buffer()nullnull?.[0]undefinedundefined === 1false, identical to the TINY issue. Worth fixing in the same or a followup PR.

case 'BIT': {
  if (field.length !== 1) return field.buffer()?.[0] ?? null;
  const buf = field.buffer();
  return buf !== null ? buf[0] === 1 : null;
}

A regression test for "NULL tinyint(1) → null" would be good to have once #283 is merged.

@Kenshiin13
Kenshiin13 requested a review from thelindat June 6, 2026 22:46
@thelindat thelindat closed this in 887d841 Jun 7, 2026
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.

2 participants