~jlukas79/+junk/mysql-server

« back to all changes in this revision

Viewing changes to sql/item.cc

manual merge 6.0-main --> 6.0-bka-review

Show diffs side-by-side

added added

removed removed

Lines of Context:
255
255
my_decimal *Item::val_decimal_from_string(my_decimal *decimal_value)
256
256
{
257
257
  String *res;
258
 
  char *end_ptr;
259
258
  if (!(res= val_str(&str_value)))
260
259
    return 0;                                   // NULL or EOM
261
260
 
262
 
  end_ptr= (char*) res->ptr()+ res->length();
263
261
  if (str2my_decimal(E_DEC_FATAL_ERROR & ~E_DEC_BAD_NUM,
264
262
                     res->ptr(), res->length(), res->charset(),
265
263
                     decimal_value) & E_DEC_BAD_NUM)
383
381
  maybe_null=null_value=with_sum_func=unsigned_flag=0;
384
382
  decimals= 0; max_length= 0;
385
383
  with_subselect= 0;
386
 
  cmp_context= (Item_result)-1;
 
384
  cmp_context= IMPOSSIBLE_RESULT;
387
385
 
388
386
  /* Put item in free list so that we can free all items at end */
389
387
  THD *thd= current_thd;
857
855
    cnvitem->max_length= cnvitem->str_value.numchars() * tocs->mbmaxlen;
858
856
    return cnvitem;
859
857
  }
860
 
  return NULL;
 
858
  return Item::safe_charset_converter(tocs);
861
859
}
862
860
 
863
861
 
1199
1197
{
1200
1198
  if (str->reserve(MAX_INT_WIDTH + sizeof("case_expr@")))
1201
1199
    return;                                    /* purecov: inspected */
1202
 
  VOID(str->append(STRING_WITH_LEN("case_expr@")));
 
1200
  (void) str->append(STRING_WITH_LEN("case_expr@"));
1203
1201
  str->qs_append(m_case_expr_id);
1204
1202
}
1205
1203
 
1481
1479
    if (collation == &my_charset_bin)
1482
1480
    {
1483
1481
      if (derivation <= dt.derivation)
1484
 
        ; // Do nothing
 
1482
      {
 
1483
        /* Do nothing */
 
1484
      }
1485
1485
      else
1486
1486
      {
1487
1487
        set(dt); 
1493
1493
      {
1494
1494
        set(dt);
1495
1495
      }
1496
 
      else
1497
 
      {
1498
 
        // Do nothing
1499
 
      }
1500
1496
    }
1501
1497
    else if ((flags & MY_COLL_ALLOW_SUPERSET_CONV) &&
1502
1498
             left_is_superset(this, &dt))
1503
1499
    {
1504
 
      // Do nothing
 
1500
      /* Do nothing */
1505
1501
    }
1506
1502
    else if ((flags & MY_COLL_ALLOW_SUPERSET_CONV) &&
1507
1503
             left_is_superset(&dt, this))
1512
1508
             derivation < dt.derivation &&
1513
1509
             dt.derivation >= DERIVATION_SYSCONST)
1514
1510
    {
1515
 
      // Do nothing;
 
1511
      /* Do nothing */
1516
1512
    }
1517
1513
    else if ((flags & MY_COLL_ALLOW_COERCIBLE_CONV) &&
1518
1514
             dt.derivation < derivation &&
1529
1525
  }
1530
1526
  else if (derivation < dt.derivation)
1531
1527
  {
1532
 
    // Do nothing
 
1528
    /* Do nothing */
1533
1529
  }
1534
1530
  else if (dt.derivation < derivation)
1535
1531
  {
1539
1535
  { 
1540
1536
    if (collation == dt.collation)
1541
1537
    {
1542
 
      // Do nothing
 
1538
      /* Do nothing */
1543
1539
    }
1544
1540
    else 
1545
1541
    {
1705
1701
  {
1706
1702
    Item* conv;
1707
1703
    uint32 dummy_offset;
1708
 
    if (!String::needs_conversion(0, (*arg)->collation.collation,
 
1704
    if (!String::needs_conversion(1, (*arg)->collation.collation,
1709
1705
                                  coll.collation,
1710
1706
                                  &dummy_offset))
1711
1707
      continue;
3185
3181
}
3186
3182
 
3187
3183
 
 
3184
/**
 
3185
  Preserve the original parameter types and values
 
3186
  when re-preparing a prepared statement.
 
3187
 
 
3188
  @details Copy parameter type information and conversion
 
3189
  function pointers from a parameter of the old statement
 
3190
  to the corresponding parameter of the new one.
 
3191
 
 
3192
  Move parameter values from the old parameters to the new
 
3193
  one. We simply "exchange" the values, which allows
 
3194
  to save on allocation and character set conversion in
 
3195
  case a parameter is a string or a blob/clob.
 
3196
 
 
3197
  The old parameter gets the value of this one, which
 
3198
  ensures that all memory of this parameter is freed
 
3199
  correctly.
 
3200
 
 
3201
  @param[in]  src   parameter item of the original
 
3202
                    prepared statement
 
3203
*/
 
3204
 
 
3205
void
 
3206
Item_param::set_param_type_and_swap_value(Item_param *src)
 
3207
{
 
3208
  unsigned_flag= src->unsigned_flag;
 
3209
  param_type= src->param_type;
 
3210
  set_param_func= src->set_param_func;
 
3211
  item_type= src->item_type;
 
3212
  item_result_type= src->item_result_type;
 
3213
 
 
3214
  collation.set(src->collation);
 
3215
  maybe_null= src->maybe_null;
 
3216
  null_value= src->null_value;
 
3217
  max_length= src->max_length;
 
3218
  decimals= src->decimals;
 
3219
  state= src->state;
 
3220
  value= src->value;
 
3221
 
 
3222
  decimal_value.swap(src->decimal_value);
 
3223
  str_value.swap(src->str_value);
 
3224
  str_value_ptr.swap(src->str_value_ptr);
 
3225
}
 
3226
 
3188
3227
/****************************************************************************
3189
3228
  Item_copy_string
3190
3229
****************************************************************************/
4027
4066
      }
4028
4067
      if ((ret= fix_outer_field(thd, &from_field, reference)) < 0)
4029
4068
        goto error;
4030
 
      else if (!ret)
4031
 
        return FALSE;
4032
4069
      outer_fixed= TRUE;
 
4070
      if (!ret)
 
4071
        goto mark_non_agg_field;
4033
4072
    }
4034
4073
    else if (!from_field)
4035
4074
      goto error;
4041
4080
      int ret;
4042
4081
      if ((ret= fix_outer_field(thd, &from_field, reference)) < 0)
4043
4082
        goto error;
4044
 
      if (!ret)
4045
 
        return FALSE;
4046
4083
      outer_fixed= 1;
 
4084
      if (!ret)
 
4085
        goto mark_non_agg_field;
4047
4086
    }
4048
4087
 
4049
4088
    /*
4127
4166
    thd->lex->current_select->non_agg_fields.push_back(this);
4128
4167
    marker= thd->lex->current_select->cur_pos_in_select_list;
4129
4168
  }
 
4169
mark_non_agg_field:
 
4170
  if (fixed && thd->variables.sql_mode & MODE_ONLY_FULL_GROUP_BY)
 
4171
  {
 
4172
    /*
 
4173
      Mark selects according to presence of non aggregated fields.
 
4174
      Fields from outer selects added to the aggregate function
 
4175
      outer_fields list as its unknown at the moment whether it's
 
4176
      aggregated or not.
 
4177
    */
 
4178
    if (!thd->lex->in_sum_func)
 
4179
      cached_table->select_lex->full_group_by_flag|= NON_AGG_FIELD_USED;
 
4180
    else
 
4181
    {
 
4182
      if (outer_fixed)
 
4183
        thd->lex->in_sum_func->outer_fields.push_back(this);
 
4184
      else if (thd->lex->in_sum_func->nest_level !=
 
4185
          thd->lex->current_select->nest_level)
 
4186
        cached_table->select_lex->full_group_by_flag|= NON_AGG_FIELD_USED;
 
4187
    }
 
4188
  }
4130
4189
  return FALSE;
4131
4190
 
4132
4191
error:
4248
4307
  String tmp(buff,sizeof(buff), field->charset()), *res;
4249
4308
 
4250
4309
  res= (*item)->val_str(&tmp);
4251
 
  field->prepend_zeros(res);
4252
 
  pos= (char *) sql_strmake (res->ptr(), res->length());
4253
 
  *item= new Item_string(pos, res->length(), field->charset());
 
4310
  if ((*item)->is_null())
 
4311
    *item= new Item_null();
 
4312
  else
 
4313
  {
 
4314
    field->prepend_zeros(res);
 
4315
    pos= (char *) sql_strmake (res->ptr(), res->length());
 
4316
    *item= new Item_string(pos, res->length(), field->charset());
 
4317
  }
4254
4318
}
4255
4319
 
4256
4320
 
4298
4362
    DATE/TIME represented as an int and as a string.
4299
4363
  */
4300
4364
  if (!item ||
4301
 
      (cmp_context != (Item_result)-1 && item->cmp_context != cmp_context))
 
4365
      (cmp_context != IMPOSSIBLE_RESULT && item->cmp_context != cmp_context))
4302
4366
    item= this;
4303
4367
  else if (field && (field->flags & ZEROFILL_FLAG) && IS_NUM(field->type()))
4304
4368
  {
4357
4421
    Item *const_item= item_equal->get_const();
4358
4422
    if (const_item)
4359
4423
    {
4360
 
      if (cmp_context != (Item_result)-1 &&
 
4424
      if (cmp_context != IMPOSSIBLE_RESULT &&
4361
4425
          const_item->cmp_context != cmp_context)
4362
4426
        return this;
4363
4427
      return const_item;
4543
4607
  DBUG_ASSERT(collation.collation);
4544
4608
  if (max_length/collation.collation->mbmaxlen > CONVERT_IF_BIGGER_TO_BLOB)
4545
4609
    field= new Field_blob(max_length, maybe_null, name,
4546
 
                          collation.collation);
 
4610
                          collation.collation, TRUE);
4547
4611
  /* Item_type_holder holds the exact type, do not change it */
4548
4612
  else if (max_length > 0 &&
4549
4613
      (type() != Item::TYPE_HOLDER || field_type() != MYSQL_TYPE_STRING))
5136
5200
  if (!ptr)
5137
5201
    return;
5138
5202
  str_value.set(ptr, max_length, &my_charset_bin);
5139
 
  ptr+= max_length - 1;
5140
 
  ptr[1]= 0;                     // Set end null for string
5141
 
  for (; end >= str; end--)
 
5203
 
 
5204
  if (max_length > 0)
5142
5205
  {
5143
 
    if (power == 256)
 
5206
    ptr+= max_length - 1;
 
5207
    ptr[1]= 0;                     // Set end null for string
 
5208
    for (; end >= str; end--)
5144
5209
    {
5145
 
      power= 1;
5146
 
      *ptr--= bits;
5147
 
      bits= 0;     
 
5210
      if (power == 256)
 
5211
      {
 
5212
        power= 1;
 
5213
        *ptr--= bits;
 
5214
        bits= 0;
 
5215
      }
 
5216
      if (*end == '1')
 
5217
        bits|= power;
 
5218
      power<<= 1;
5148
5219
    }
5149
 
    if (*end == '1')
5150
 
      bits|= power; 
5151
 
    power<<= 1;
 
5220
    *ptr= (char) bits;
5152
5221
  }
5153
 
  *ptr= (char) bits;
 
5222
  else
 
5223
    ptr[0]= 0;
 
5224
 
5154
5225
  collation.set(&my_charset_bin, DERIVATION_COERCIBLE);
5155
5226
  fixed= 1;
5156
5227
}