Comment 2 for bug 594873

Revision history for this message
Joe Daly (skinny.moey) wrote :

This looks to be happening now and not before, because of the enum rework in val_int() adding the 1 to the return value.

int64_t Field_enum::val_int(void)
{
  ASSERT_COLUMN_MARKED_FOR_READ;

  switch (packlength) {
  case 1:
    return ((int64_t) ptr[0]) + 1; /* SQL is from 1, we store from 0 */
  case 2:
  {
    uint16_t tmp;
#ifdef WORDS_BIGENDIAN
    if (getTable()->s->db_low_byte_first)
      tmp=sint2korr(ptr);
    else
#endif
      shortget(tmp,ptr);
    return ((int64_t) tmp) + 1; /* SQL is from 1, we store from 0 */
  }
  default:
    assert(packlength <= 2);
  }
  return 0; // impossible
}

I think the correct fix for this probably is to rework the null handling in transaction_services.cc (again) from:

  while ((current_field= *table_fields++) != NULL)
  {
    string_value= current_field->val_str(string_value);
    record->add_is_null(current_field->is_null());
    record->add_insert_value(string_value->c_ptr(), string_value->length());
    string_value->free();
  }

to:

  while ((current_field= *table_fields++) != NULL)
  {
    if (current_field->is_null())
    {
      record->add_is_null(true);
      record->add_insert_value(NULL, 0);
    }
    else
    {
      string_value= current_field->val_str(string_value);
      record->add_is_null(false);
      record->add_insert_value(string_value->c_ptr(), string_value->length());
      string_value->free();
    }
  }