~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to server/item.cc

  • Committer: Brian Aker
  • Date: 2008-07-10 19:37:55 UTC
  • mfrom: (51.1.67 remove-dbug)
  • Revision ID: brian@tangent.org-20080710193755-f5g761uieqa3wxmt
Merge.

Show diffs side-by-side

added added

removed removed

Lines of Context:
192
192
    return val_real() != 0.0;
193
193
  case ROW_RESULT:
194
194
  default:
195
 
    DBUG_ASSERT(0);
 
195
    assert(0);
196
196
    return 0;                                   // Wrong (but safe)
197
197
  }
198
198
}
272
272
 
273
273
my_decimal *Item::val_decimal_from_date(my_decimal *decimal_value)
274
274
{
275
 
  DBUG_ASSERT(fixed == 1);
 
275
  assert(fixed == 1);
276
276
  MYSQL_TIME ltime;
277
277
  if (get_date(&ltime, TIME_FUZZY_DATE))
278
278
  {
286
286
 
287
287
my_decimal *Item::val_decimal_from_time(my_decimal *decimal_value)
288
288
{
289
 
  DBUG_ASSERT(fixed == 1);
 
289
  assert(fixed == 1);
290
290
  MYSQL_TIME ltime;
291
291
  if (get_time(&ltime))
292
292
  {
456
456
 
457
457
void Item::cleanup()
458
458
{
459
 
  DBUG_ENTER("Item::cleanup");
460
459
  fixed=0;
461
460
  marker= 0;
462
461
  if (orig_name)
463
462
    name= orig_name;
464
 
  DBUG_VOID_RETURN;
 
463
  return;
465
464
}
466
465
 
467
466
 
567
566
 
568
567
void Item_ident::cleanup()
569
568
{
570
 
  DBUG_ENTER("Item_ident::cleanup");
571
569
#ifdef CANT_BE_USED_AS_MEMORY_IS_FREED
572
570
                       db_name ? db_name : "(null)",
573
571
                       orig_db_name ? orig_db_name : "(null)",
581
579
  table_name= orig_table_name;
582
580
  field_name= orig_field_name;
583
581
  depended_from= 0;
584
 
  DBUG_VOID_RETURN;
 
582
  return;
585
583
}
586
584
 
587
585
bool Item_ident::remove_dependence_processor(uchar * arg)
588
586
{
589
 
  DBUG_ENTER("Item_ident::remove_dependence_processor");
590
587
  if (depended_from == (st_select_lex *) arg)
591
588
    depended_from= 0;
592
 
  DBUG_RETURN(0);
 
589
  return(0);
593
590
}
594
591
 
595
592
 
613
610
 
614
611
bool Item_field::collect_item_field_processor(uchar *arg)
615
612
{
616
 
  DBUG_ENTER("Item_field::collect_item_field_processor");
617
 
  DBUG_PRINT("info", ("%s", field->field_name ? field->field_name : "noname"));
618
613
  List<Item_field> *item_list= (List<Item_field>*) arg;
619
614
  List_iterator<Item_field> item_list_it(*item_list);
620
615
  Item_field *curr_item;
621
616
  while ((curr_item= item_list_it++))
622
617
  {
623
618
    if (curr_item->eq(this, 1))
624
 
      DBUG_RETURN(false); /* Already in the set. */
 
619
      return(false); /* Already in the set. */
625
620
  }
626
621
  item_list->push_back(this);
627
 
  DBUG_RETURN(false);
 
622
  return(false);
628
623
}
629
624
 
630
625
 
1584
1579
/* ARGSUSED */
1585
1580
String *Item_field::val_str(String *str)
1586
1581
{
1587
 
  DBUG_ASSERT(fixed == 1);
 
1582
  assert(fixed == 1);
1588
1583
  if ((null_value=field->is_null()))
1589
1584
    return 0;
1590
1585
  str->set_charset(str_value.charset());
1594
1589
 
1595
1590
double Item_field::val_real()
1596
1591
{
1597
 
  DBUG_ASSERT(fixed == 1);
 
1592
  assert(fixed == 1);
1598
1593
  if ((null_value=field->is_null()))
1599
1594
    return 0.0;
1600
1595
  return field->val_real();
1603
1598
 
1604
1599
longlong Item_field::val_int()
1605
1600
{
1606
 
  DBUG_ASSERT(fixed == 1);
 
1601
  assert(fixed == 1);
1607
1602
  if ((null_value=field->is_null()))
1608
1603
    return 0;
1609
1604
  return field->val_int();
1700
1695
    return result_field->val_real() != 0.0;
1701
1696
  case ROW_RESULT:
1702
1697
  default:
1703
 
    DBUG_ASSERT(0);
 
1698
    assert(0);
1704
1699
    return 0;                                   // Shut up compiler
1705
1700
  }
1706
1701
}
1800
1795
String *Item_int::val_str(String *str)
1801
1796
{
1802
1797
  // following assert is redundant, because fixed=1 assigned in constructor
1803
 
  DBUG_ASSERT(fixed == 1);
 
1798
  assert(fixed == 1);
1804
1799
  str->set(value, &my_charset_bin);
1805
1800
  return str;
1806
1801
}
1831
1826
String *Item_uint::val_str(String *str)
1832
1827
{
1833
1828
  // following assert is redundant, because fixed=1 assigned in constructor
1834
 
  DBUG_ASSERT(fixed == 1);
 
1829
  assert(fixed == 1);
1835
1830
  str->set((ulonglong) value, &my_charset_bin);
1836
1831
  return str;
1837
1832
}
1972
1967
String *Item_float::val_str(String *str)
1973
1968
{
1974
1969
  // following assert is redundant, because fixed=1 assigned in constructor
1975
 
  DBUG_ASSERT(fixed == 1);
 
1970
  assert(fixed == 1);
1976
1971
  str->set_real(value,decimals,&my_charset_bin);
1977
1972
  return str;
1978
1973
}
1981
1976
my_decimal *Item_float::val_decimal(my_decimal *decimal_value)
1982
1977
{
1983
1978
  // following assert is redundant, because fixed=1 assigned in constructor
1984
 
  DBUG_ASSERT(fixed == 1);
 
1979
  assert(fixed == 1);
1985
1980
  double2my_decimal(E_DEC_FATAL_ERROR, value, decimal_value);
1986
1981
  return (decimal_value);
1987
1982
}
2026
2021
 
2027
2022
double Item_string::val_real()
2028
2023
{
2029
 
  DBUG_ASSERT(fixed == 1);
 
2024
  assert(fixed == 1);
2030
2025
  int error;
2031
2026
  char *end, *org_end;
2032
2027
  double tmp;
2056
2051
*/
2057
2052
longlong Item_string::val_int()
2058
2053
{
2059
 
  DBUG_ASSERT(fixed == 1);
 
2054
  assert(fixed == 1);
2060
2055
  int err;
2061
2056
  longlong tmp;
2062
2057
  char *end= (char*) str_value.ptr()+ str_value.length();
2094
2089
double Item_null::val_real()
2095
2090
{
2096
2091
  // following assert is redundant, because fixed=1 assigned in constructor
2097
 
  DBUG_ASSERT(fixed == 1);
 
2092
  assert(fixed == 1);
2098
2093
  null_value=1;
2099
2094
  return 0.0;
2100
2095
}
2101
2096
longlong Item_null::val_int()
2102
2097
{
2103
2098
  // following assert is redundant, because fixed=1 assigned in constructor
2104
 
  DBUG_ASSERT(fixed == 1);
 
2099
  assert(fixed == 1);
2105
2100
  null_value=1;
2106
2101
  return 0;
2107
2102
}
2109
2104
String *Item_null::val_str(String *str __attribute__((__unused__)))
2110
2105
{
2111
2106
  // following assert is redundant, because fixed=1 assigned in constructor
2112
 
  DBUG_ASSERT(fixed == 1);
 
2107
  assert(fixed == 1);
2113
2108
  null_value=1;
2114
2109
  return 0;
2115
2110
}
2166
2161
 
2167
2162
void Item_param::set_null()
2168
2163
{
2169
 
  DBUG_ENTER("Item_param::set_null");
2170
2164
  /* These are cleared after each execution by reset() method */
2171
2165
  null_value= 1;
2172
2166
  /* 
2178
2172
  decimals= 0;
2179
2173
  state= NULL_VALUE;
2180
2174
  item_type= Item::NULL_ITEM;
2181
 
  DBUG_VOID_RETURN;
 
2175
  return;
2182
2176
}
2183
2177
 
2184
2178
void Item_param::set_int(longlong i, uint32 max_length_arg)
2185
2179
{
2186
 
  DBUG_ENTER("Item_param::set_int");
2187
2180
  value.integer= (longlong) i;
2188
2181
  state= INT_VALUE;
2189
2182
  max_length= max_length_arg;
2190
2183
  decimals= 0;
2191
2184
  maybe_null= 0;
2192
 
  DBUG_VOID_RETURN;
 
2185
  return;
2193
2186
}
2194
2187
 
2195
2188
void Item_param::set_double(double d)
2196
2189
{
2197
 
  DBUG_ENTER("Item_param::set_double");
2198
2190
  value.real= d;
2199
2191
  state= REAL_VALUE;
2200
2192
  max_length= DBL_DIG + 8;
2201
2193
  decimals= NOT_FIXED_DEC;
2202
2194
  maybe_null= 0;
2203
 
  DBUG_VOID_RETURN;
 
2195
  return;
2204
2196
}
2205
2197
 
2206
2198
 
2219
2211
void Item_param::set_decimal(const char *str, ulong length)
2220
2212
{
2221
2213
  char *end;
2222
 
  DBUG_ENTER("Item_param::set_decimal");
2223
2214
 
2224
2215
  end= (char*) str+length;
2225
2216
  str2my_decimal(E_DEC_FATAL_ERROR, str, &decimal_value, &end);
2228
2219
  max_length= my_decimal_precision_to_length(decimal_value.precision(),
2229
2220
                                             decimals, unsigned_flag);
2230
2221
  maybe_null= 0;
2231
 
  DBUG_VOID_RETURN;
 
2222
  return;
2232
2223
}
2233
2224
 
2234
2225
 
2248
2239
void Item_param::set_time(MYSQL_TIME *tm, timestamp_type time_type,
2249
2240
                          uint32 max_length_arg)
2250
2241
2251
 
  DBUG_ENTER("Item_param::set_time");
2252
 
 
2253
2242
  value.time= *tm;
2254
2243
  value.time.time_type= time_type;
2255
2244
 
2269
2258
  maybe_null= 0;
2270
2259
  max_length= max_length_arg;
2271
2260
  decimals= 0;
2272
 
  DBUG_VOID_RETURN;
 
2261
  return;
2273
2262
}
2274
2263
 
2275
2264
 
2276
2265
bool Item_param::set_str(const char *str, ulong length)
2277
2266
{
2278
 
  DBUG_ENTER("Item_param::set_str");
2279
2267
  /*
2280
2268
    Assign string with no conversion: data is converted only after it's
2281
2269
    been written to the binary log.
2283
2271
  uint dummy_errors;
2284
2272
  if (str_value.copy(str, length, &my_charset_bin, &my_charset_bin,
2285
2273
                     &dummy_errors))
2286
 
    DBUG_RETURN(true);
 
2274
    return(true);
2287
2275
  state= STRING_VALUE;
2288
2276
  max_length= length;
2289
2277
  maybe_null= 0;
2290
2278
  /* max_length and decimals are set after charset conversion */
2291
2279
  /* sic: str may be not null-terminated, don't add DBUG_PRINT here */
2292
 
  DBUG_RETURN(false);
 
2280
  return(false);
2293
2281
}
2294
2282
 
2295
2283
 
2296
2284
bool Item_param::set_longdata(const char *str, ulong length)
2297
2285
{
2298
 
  DBUG_ENTER("Item_param::set_longdata");
2299
 
 
2300
2286
  /*
2301
2287
    If client character set is multibyte, end of long data packet
2302
2288
    may hit at the middle of a multibyte character.  Additionally,
2307
2293
    write query to the binary log and only then perform conversion.
2308
2294
  */
2309
2295
  if (str_value.append(str, length, &my_charset_bin))
2310
 
    DBUG_RETURN(true);
 
2296
    return(true);
2311
2297
  state= LONG_DATA_VALUE;
2312
2298
  maybe_null= 0;
2313
2299
 
2314
 
  DBUG_RETURN(false);
 
2300
  return(false);
2315
2301
}
2316
2302
 
2317
2303
 
2329
2315
 
2330
2316
bool Item_param::set_from_user_var(THD *thd, const user_var_entry *entry)
2331
2317
{
2332
 
  DBUG_ENTER("Item_param::set_from_user_var");
2333
2318
  if (entry && entry->value)
2334
2319
  {
2335
2320
    item_result_type= entry->type;
2339
2324
      my_bool unused;
2340
2325
      set_int(entry->val_int(&unused), MY_INT64_NUM_DECIMAL_DIGITS);
2341
2326
      item_type= Item::INT_ITEM;
2342
 
      DBUG_RETURN(!unsigned_flag && value.integer < 0 ? 1 : 0);
 
2327
      return(!unsigned_flag && value.integer < 0 ? 1 : 0);
2343
2328
    }
2344
2329
    switch (item_result_type) {
2345
2330
    case REAL_RESULT:
2373
2358
      item_type= Item::STRING_ITEM;
2374
2359
 
2375
2360
      if (set_str((const char *)entry->value, entry->length))
2376
 
        DBUG_RETURN(1);
 
2361
        return(1);
2377
2362
      break;
2378
2363
    }
2379
2364
    case DECIMAL_RESULT:
2388
2373
      break;
2389
2374
    }
2390
2375
    default:
2391
 
      DBUG_ASSERT(0);
 
2376
      assert(0);
2392
2377
      set_null();
2393
2378
    }
2394
2379
  }
2395
2380
  else
2396
2381
    set_null();
2397
2382
 
2398
 
  DBUG_RETURN(0);
 
2383
  return(0);
2399
2384
}
2400
2385
 
2401
2386
/**
2408
2393
 
2409
2394
void Item_param::reset()
2410
2395
{
2411
 
  DBUG_ENTER("Item_param::reset");
2412
2396
  /* Shrink string buffer if it's bigger than max possible CHAR column */
2413
2397
  if (str_value.alloced_length() > MAX_CHAR_WIDTH)
2414
2398
    str_value.free();
2430
2414
    contain a literal of some kind.
2431
2415
    In all other cases when this object is accessed its value is
2432
2416
    set (this assumption is guarded by 'state' and
2433
 
    DBUG_ASSERTS(state != NO_VALUE) in all Item_param::get_*
 
2417
    assertS(state != NO_VALUE) in all Item_param::get_*
2434
2418
    methods).
2435
2419
  */
2436
 
  DBUG_VOID_RETURN;
 
2420
  return;
2437
2421
}
2438
2422
 
2439
2423
 
2459
2443
    return set_field_to_null_with_conversions(field, no_conversions);
2460
2444
  case NO_VALUE:
2461
2445
  default:
2462
 
    DBUG_ASSERT(0);
 
2446
    assert(0);
2463
2447
  }
2464
2448
  return 1;
2465
2449
}
2521
2505
  case NULL_VALUE:
2522
2506
    return 0.0;
2523
2507
  default:
2524
 
    DBUG_ASSERT(0);
 
2508
    assert(0);
2525
2509
  }
2526
2510
  return 0.0;
2527
2511
2552
2536
  case NULL_VALUE:
2553
2537
    return 0; 
2554
2538
  default:
2555
 
    DBUG_ASSERT(0);
 
2539
    assert(0);
2556
2540
  }
2557
2541
  return 0;
2558
2542
}
2582
2566
  case NULL_VALUE:
2583
2567
    return 0; 
2584
2568
  default:
2585
 
    DBUG_ASSERT(0);
 
2569
    assert(0);
2586
2570
  }
2587
2571
  return 0;
2588
2572
}
2616
2600
  case NULL_VALUE:
2617
2601
    return NULL; 
2618
2602
  default:
2619
 
    DBUG_ASSERT(0);
 
2603
    assert(0);
2620
2604
  }
2621
2605
  return str;
2622
2606
}
2676
2660
  case NULL_VALUE:
2677
2661
    return &my_null_string;
2678
2662
  default:
2679
 
    DBUG_ASSERT(0);
 
2663
    assert(0);
2680
2664
  }
2681
2665
  return str;
2682
2666
}
2753
2737
    break;
2754
2738
  case NO_VALUE:
2755
2739
  default:
2756
 
    DBUG_ASSERT(0);
 
2740
    assert(0);
2757
2741
  };
2758
2742
  return 0;
2759
2743
}
2852
2836
{
2853
2837
 
2854
2838
  // We do not check fields which are fixed during construction
2855
 
  DBUG_ASSERT(fixed == 0 || basic_const_item());
 
2839
  assert(fixed == 0 || basic_const_item());
2856
2840
  fixed= 1;
2857
2841
  return false;
2858
2842
}
2859
2843
 
2860
2844
double Item_ref_null_helper::val_real()
2861
2845
{
2862
 
  DBUG_ASSERT(fixed == 1);
 
2846
  assert(fixed == 1);
2863
2847
  double tmp= (*ref)->val_result();
2864
2848
  owner->was_null|= null_value= (*ref)->null_value;
2865
2849
  return tmp;
2868
2852
 
2869
2853
longlong Item_ref_null_helper::val_int()
2870
2854
{
2871
 
  DBUG_ASSERT(fixed == 1);
 
2855
  assert(fixed == 1);
2872
2856
  longlong tmp= (*ref)->val_int_result();
2873
2857
  owner->was_null|= null_value= (*ref)->null_value;
2874
2858
  return tmp;
2877
2861
 
2878
2862
my_decimal *Item_ref_null_helper::val_decimal(my_decimal *decimal_value)
2879
2863
{
2880
 
  DBUG_ASSERT(fixed == 1);
 
2864
  assert(fixed == 1);
2881
2865
  my_decimal *val= (*ref)->val_decimal_result(decimal_value);
2882
2866
  owner->was_null|= null_value= (*ref)->null_value;
2883
2867
  return val;
2886
2870
 
2887
2871
bool Item_ref_null_helper::val_bool()
2888
2872
{
2889
 
  DBUG_ASSERT(fixed == 1);
 
2873
  assert(fixed == 1);
2890
2874
  bool val= (*ref)->val_bool_result();
2891
2875
  owner->was_null|= null_value= (*ref)->null_value;
2892
2876
  return val;
2895
2879
 
2896
2880
String* Item_ref_null_helper::val_str(String* s)
2897
2881
{
2898
 
  DBUG_ASSERT(fixed == 1);
 
2882
  assert(fixed == 1);
2899
2883
  String* tmp= (*ref)->str_result(s);
2900
2884
  owner->was_null|= null_value= (*ref)->null_value;
2901
2885
  return tmp;
3054
3038
    db_name= name_buff;
3055
3039
  }
3056
3040
 
3057
 
  DBUG_ASSERT(field_name != 0);
 
3041
  assert(field_name != 0);
3058
3042
 
3059
3043
  for (ORDER *cur_group= group_list ; cur_group ; cur_group= cur_group->next)
3060
3044
  {
3063
3047
      cur_field= (Item_ident*) *cur_group->item;
3064
3048
      cur_match_degree= 0;
3065
3049
      
3066
 
      DBUG_ASSERT(cur_field->field_name != 0);
 
3050
      assert(cur_field->field_name != 0);
3067
3051
 
3068
3052
      if (!my_strcasecmp(system_charset_info,
3069
3053
                         cur_field->field_name, field_name))
3194
3178
  {
3195
3179
    if (select_ref != not_found_item && !ambiguous_fields)
3196
3180
    {
3197
 
      DBUG_ASSERT(*select_ref != 0);
 
3181
      assert(*select_ref != 0);
3198
3182
      if (!select->ref_pointer_array[counter])
3199
3183
      {
3200
3184
        my_error(ER_ILLEGAL_REFERENCE, MYF(0),
3201
3185
                 ref->name, "forward reference in item list");
3202
3186
        return NULL;
3203
3187
      }
3204
 
      DBUG_ASSERT((*select_ref)->fixed);
 
3188
      assert((*select_ref)->fixed);
3205
3189
      return (select->ref_pointer_array + counter);
3206
3190
    }
3207
3191
    if (group_by_ref)
3208
3192
      return group_by_ref;
3209
 
    DBUG_ASSERT(false);
 
3193
    assert(false);
3210
3194
    return NULL; /* So there is no compiler warning. */
3211
3195
  }
3212
3196
 
3391
3375
        return -1; /* Some error occurred (e.g. ambiguous names). */
3392
3376
      if (ref != not_found_item)
3393
3377
      {
3394
 
        DBUG_ASSERT(*ref && (*ref)->fixed);
 
3378
        assert(*ref && (*ref)->fixed);
3395
3379
        prev_subselect_item->used_tables_cache|= (*ref)->used_tables();
3396
3380
        prev_subselect_item->const_item_cache&= (*ref)->const_item();
3397
3381
        break;
3407
3391
    prev_subselect_item->const_item_cache= 0;
3408
3392
  }
3409
3393
 
3410
 
  DBUG_ASSERT(ref != 0);
 
3394
  assert(ref != 0);
3411
3395
  if (!*from_field)
3412
3396
    return -1;
3413
3397
  if (ref == not_found_item && *from_field == not_found_field)
3435
3419
    Item_ref *rf;
3436
3420
 
3437
3421
    /* Should have been checked in resolve_ref_in_select_and_group(). */
3438
 
    DBUG_ASSERT(*ref && (*ref)->fixed);
 
3422
    assert(*ref && (*ref)->fixed);
3439
3423
    /*
3440
3424
      Here, a subset of actions performed by Item_ref::set_properties
3441
3425
      is not enough. So we pass ptr to NULL into Item_[direct]_ref
3466
3450
      rf is Item_ref => never substitute other items (in this case)
3467
3451
      during fix_fields() => we can use rf after fix_fields()
3468
3452
    */
3469
 
    DBUG_ASSERT(!rf->fixed);                // Assured by Item_ref()
 
3453
    assert(!rf->fixed);                // Assured by Item_ref()
3470
3454
    if (rf->fix_fields(thd, reference) || rf->check_cols(1))
3471
3455
      return -1;
3472
3456
 
3493
3477
        rf is Item_ref => never substitute other items (in this case)
3494
3478
        during fix_fields() => we can use rf after fix_fields()
3495
3479
      */
3496
 
      DBUG_ASSERT(!rf->fixed);                // Assured by Item_ref()
 
3480
      assert(!rf->fixed);                // Assured by Item_ref()
3497
3481
      if (rf->fix_fields(thd, reference) || rf->check_cols(1))
3498
3482
        return -1;
3499
3483
      return 0;
3550
3534
 
3551
3535
bool Item_field::fix_fields(THD *thd, Item **reference)
3552
3536
{
3553
 
  DBUG_ASSERT(fixed == 0);
 
3537
  assert(fixed == 0);
3554
3538
  Field *from_field= (Field *)not_found_field;
3555
3539
  bool outer_fixed= false;
3556
3540
 
3716
3700
 
3717
3701
void Item_field::cleanup()
3718
3702
{
3719
 
  DBUG_ENTER("Item_field::cleanup");
3720
3703
  Item_ident::cleanup();
3721
3704
  /*
3722
3705
    Even if this object was created by direct link to field in setup_wild()
3725
3708
   */
3726
3709
  field= result_field= 0;
3727
3710
  null_value= false;
3728
 
  DBUG_VOID_RETURN;
 
3711
  return;
3729
3712
}
3730
3713
 
3731
3714
/**
3993
3976
  case REAL_RESULT:    return MYSQL_TYPE_DOUBLE;
3994
3977
  case ROW_RESULT:
3995
3978
  default:
3996
 
    DBUG_ASSERT(0);
 
3979
    assert(0);
3997
3980
    return MYSQL_TYPE_VARCHAR;
3998
3981
  }
3999
3982
}
4104
4087
Field *Item::make_string_field(TABLE *table)
4105
4088
{
4106
4089
  Field *field;
4107
 
  DBUG_ASSERT(collation.collation);
 
4090
  assert(collation.collation);
4108
4091
  if (max_length/collation.collation->mbmaxlen > CONVERT_IF_BIGGER_TO_BLOB)
4109
4092
    field= new Field_blob(max_length, maybe_null, name,
4110
4093
                          collation.collation);
4194
4177
    break;
4195
4178
  default:
4196
4179
    /* This case should never be chosen */
4197
 
    DBUG_ASSERT(0);
 
4180
    assert(0);
4198
4181
    /* If something goes awfully wrong, it's better to get a string than die */
4199
4182
  case MYSQL_TYPE_STRING:
4200
4183
    if (fixed_length && max_length < CONVERT_IF_BIGGER_TO_BLOB)
4227
4210
void Item_field::make_field(Send_field *tmp_field)
4228
4211
{
4229
4212
  field->make_field(tmp_field);
4230
 
  DBUG_ASSERT(tmp_field->table_name != 0);
 
4213
  assert(tmp_field->table_name != 0);
4231
4214
  if (name)
4232
4215
    tmp_field->col_name=name;                   // Use user supplied name
4233
4216
  if (table_name)
4259
4242
int Item_field::save_in_field(Field *to, bool no_conversions)
4260
4243
{
4261
4244
  int res;
4262
 
  DBUG_ENTER("Item_field::save_in_field");
4263
4245
  if (result_field->is_null())
4264
4246
  {
4265
4247
    null_value=1;
4268
4250
  else
4269
4251
  {
4270
4252
    to->set_notnull();
4271
 
    DBUG_EXECUTE("info", dbug_print(););
4272
4253
    res= field_conv(to,result_field);
4273
4254
    null_value=0;
4274
4255
  }
4275
 
  DBUG_RETURN(res);
 
4256
  return(res);
4276
4257
}
4277
4258
 
4278
4259
 
4433
4414
 
4434
4415
Item *Item_int_with_ref::clone_item()
4435
4416
{
4436
 
  DBUG_ASSERT(ref->const_item());
 
4417
  assert(ref->const_item());
4437
4418
  /*
4438
4419
    We need to evaluate the constant to make sure it works with
4439
4420
    parameter markers.
4491
4472
      Note that we depend on that str_arg is null terminated, which is true
4492
4473
      when we are in the parser
4493
4474
    */
4494
 
    DBUG_ASSERT(str_arg[length] == 0);
 
4475
    assert(str_arg[length] == 0);
4495
4476
    my_error(ER_ILLEGAL_VALUE_FOR_TYPE, MYF(0), "double", (char*) str_arg);
4496
4477
  }
4497
4478
  presentation= name=(char*) str_arg;
4581
4562
longlong Item_hex_string::val_int()
4582
4563
{
4583
4564
  // following assert is redundant, because fixed=1 assigned in constructor
4584
 
  DBUG_ASSERT(fixed == 1);
 
4565
  assert(fixed == 1);
4585
4566
  char *end=(char*) str_value.ptr()+str_value.length(),
4586
4567
       *ptr=end-min(str_value.length(),sizeof(longlong));
4587
4568
 
4595
4576
my_decimal *Item_hex_string::val_decimal(my_decimal *decimal_value)
4596
4577
{
4597
4578
  // following assert is redundant, because fixed=1 assigned in constructor
4598
 
  DBUG_ASSERT(fixed == 1);
 
4579
  assert(fixed == 1);
4599
4580
  ulonglong value= (ulonglong)val_int();
4600
4581
  int2my_decimal(E_DEC_FATAL_ERROR, value, true, decimal_value);
4601
4582
  return (decimal_value);
4869
4850
Item *Item_field::update_value_transformer(uchar *select_arg)
4870
4851
{
4871
4852
  SELECT_LEX *select= (SELECT_LEX*)select_arg;
4872
 
  DBUG_ASSERT(fixed);
 
4853
  assert(fixed);
4873
4854
 
4874
4855
  if (field->table != select->context.table_list->table &&
4875
4856
      type() != Item::TRIGGER_FIELD_ITEM)
4988
4969
bool Item_ref::fix_fields(THD *thd, Item **reference)
4989
4970
{
4990
4971
  enum_parsing_place place= NO_MATTER;
4991
 
  DBUG_ASSERT(fixed == 0);
 
4972
  assert(fixed == 0);
4992
4973
  SELECT_LEX *current_sel= thd->lex->current_select;
4993
4974
 
4994
4975
  if (!ref || ref == not_found_item)
5037
5018
            goto error; /* Some error occurred (e.g. ambiguous names). */
5038
5019
          if (ref != not_found_item)
5039
5020
          {
5040
 
            DBUG_ASSERT(*ref && (*ref)->fixed);
 
5021
            assert(*ref && (*ref)->fixed);
5041
5022
            prev_subselect_item->used_tables_cache|= (*ref)->used_tables();
5042
5023
            prev_subselect_item->const_item_cache&= (*ref)->const_item();
5043
5024
            break;
5087
5068
              (*reference)->used_tables();
5088
5069
            prev_subselect_item->const_item_cache&=
5089
5070
              (*reference)->const_item();
5090
 
            DBUG_ASSERT((*reference)->type() == REF_ITEM);
 
5071
            assert((*reference)->type() == REF_ITEM);
5091
5072
            mark_as_dependent(thd, last_checked_context->select_lex,
5092
5073
                              context->select_lex, this,
5093
5074
                              ((refer_type == REF_ITEM ||
5126
5107
            break;
5127
5108
          }
5128
5109
        }
5129
 
        DBUG_ASSERT(from_field == not_found_field);
 
5110
        assert(from_field == not_found_field);
5130
5111
 
5131
5112
        /* Reference is not found => depend on outer (or just error). */
5132
5113
        prev_subselect_item->used_tables_cache|= OUTER_REF_TABLE_BIT;
5135
5116
        outer_context= outer_context->outer_context;
5136
5117
      } while (outer_context);
5137
5118
 
5138
 
      DBUG_ASSERT(from_field != 0 && from_field != view_ref_found);
 
5119
      assert(from_field != 0 && from_field != view_ref_found);
5139
5120
      if (from_field != not_found_field)
5140
5121
      {
5141
5122
        Item_field* fld;
5164
5145
        goto error;
5165
5146
      }
5166
5147
      /* Should be checked in resolve_ref_in_select_and_group(). */
5167
 
      DBUG_ASSERT(*ref && (*ref)->fixed);
 
5148
      assert(*ref && (*ref)->fixed);
5168
5149
      mark_as_dependent(thd, last_checked_context->select_lex,
5169
5150
                        context->select_lex, this, this);
5170
5151
      /*
5180
5161
    }
5181
5162
  }
5182
5163
 
5183
 
  DBUG_ASSERT(*ref);
 
5164
  assert(*ref);
5184
5165
  /*
5185
5166
    Check if this is an incorrect reference in a group function or forward
5186
5167
    reference. Do not issue an error if this is:
5237
5218
 
5238
5219
void Item_ref::cleanup()
5239
5220
{
5240
 
  DBUG_ENTER("Item_ref::cleanup");
5241
5221
  Item_ident::cleanup();
5242
5222
  result_field= 0;
5243
 
  DBUG_VOID_RETURN;
 
5223
  return;
5244
5224
}
5245
5225
 
5246
5226
 
5341
5321
      return result_field->val_real() != 0.0;
5342
5322
    case ROW_RESULT:
5343
5323
    default:
5344
 
      DBUG_ASSERT(0);
 
5324
      assert(0);
5345
5325
    }
5346
5326
  }
5347
5327
  return val_bool();
5350
5330
 
5351
5331
double Item_ref::val_real()
5352
5332
{
5353
 
  DBUG_ASSERT(fixed);
 
5333
  assert(fixed);
5354
5334
  double tmp=(*ref)->val_result();
5355
5335
  null_value=(*ref)->null_value;
5356
5336
  return tmp;
5359
5339
 
5360
5340
longlong Item_ref::val_int()
5361
5341
{
5362
 
  DBUG_ASSERT(fixed);
 
5342
  assert(fixed);
5363
5343
  longlong tmp=(*ref)->val_int_result();
5364
5344
  null_value=(*ref)->null_value;
5365
5345
  return tmp;
5368
5348
 
5369
5349
bool Item_ref::val_bool()
5370
5350
{
5371
 
  DBUG_ASSERT(fixed);
 
5351
  assert(fixed);
5372
5352
  bool tmp= (*ref)->val_bool_result();
5373
5353
  null_value= (*ref)->null_value;
5374
5354
  return tmp;
5377
5357
 
5378
5358
String *Item_ref::val_str(String* tmp)
5379
5359
{
5380
 
  DBUG_ASSERT(fixed);
 
5360
  assert(fixed);
5381
5361
  tmp=(*ref)->str_result(tmp);
5382
5362
  null_value=(*ref)->null_value;
5383
5363
  return tmp;
5386
5366
 
5387
5367
bool Item_ref::is_null()
5388
5368
{
5389
 
  DBUG_ASSERT(fixed);
 
5369
  assert(fixed);
5390
5370
  return (*ref)->is_null();
5391
5371
}
5392
5372
 
5407
5387
int Item_ref::save_in_field(Field *to, bool no_conversions)
5408
5388
{
5409
5389
  int res;
5410
 
  DBUG_ASSERT(!result_field);
 
5390
  assert(!result_field);
5411
5391
  res= (*ref)->save_in_field(to, no_conversions);
5412
5392
  null_value= (*ref)->null_value;
5413
5393
  return res;
5526
5506
bool Item_direct_view_ref::fix_fields(THD *thd, Item **reference)
5527
5507
{
5528
5508
  /* view fild reference must be defined */
5529
 
  DBUG_ASSERT(*ref);
 
5509
  assert(*ref);
5530
5510
  /* (*ref)->check_cols() will be made in Item_direct_ref::fix_fields */
5531
5511
  if (!(*ref)->fixed &&
5532
5512
      ((*ref)->fix_fields(thd, ref)))
5625
5605
  Item *real_arg;
5626
5606
  Item_field *field_arg;
5627
5607
  Field *def_field;
5628
 
  DBUG_ASSERT(fixed == 0);
 
5608
  assert(fixed == 0);
5629
5609
 
5630
5610
  if (!arg)
5631
5611
  {
5739
5719
bool Item_insert_value::fix_fields(THD *thd,
5740
5720
                                   Item **items __attribute__((__unused__)))
5741
5721
{
5742
 
  DBUG_ASSERT(fixed == 0);
 
5722
  assert(fixed == 0);
5743
5723
  /* We should only check that arg is in first table */
5744
5724
  if (!arg->fixed)
5745
5725
  {
5766
5746
    According to our SQL grammar, VALUES() function can reference
5767
5747
    only to a column.
5768
5748
  */
5769
 
  DBUG_ASSERT(arg->type() == FIELD_ITEM);
 
5749
  assert(arg->type() == FIELD_ITEM);
5770
5750
 
5771
5751
  Item_field *field_arg= (Item_field *)arg;
5772
5752
 
5875
5855
      We can't ignore NULL values here as this item may be used with <=>, in
5876
5856
      which case NULL's are significant.
5877
5857
    */
5878
 
    DBUG_ASSERT(item->result_type() == comp_item->result_type());
5879
 
    DBUG_ASSERT(item_row->cols() == comp_item_row->cols());
 
5858
    assert(item->result_type() == comp_item->result_type());
 
5859
    assert(item_row->cols() == comp_item_row->cols());
5880
5860
    col= item_row->cols();
5881
5861
    while (col-- > 0)
5882
5862
      resolve_const_item(thd, item_row->addr(col),
5905
5885
    break;
5906
5886
  }
5907
5887
  default:
5908
 
    DBUG_ASSERT(0);
 
5888
    assert(0);
5909
5889
  }
5910
5890
  if (new_item)
5911
5891
    thd->change_item_tree(ref, new_item);
5969
5949
    return new Item_cache_row();
5970
5950
  default:
5971
5951
    // should never be in real life
5972
 
    DBUG_ASSERT(0);
 
5952
    assert(0);
5973
5953
    return 0;
5974
5954
  }
5975
5955
}
6004
5984
 
6005
5985
String *Item_cache_int::val_str(String *str)
6006
5986
{
6007
 
  DBUG_ASSERT(fixed == 1);
 
5987
  assert(fixed == 1);
6008
5988
  str->set(value, default_charset());
6009
5989
  return str;
6010
5990
}
6012
5992
 
6013
5993
my_decimal *Item_cache_int::val_decimal(my_decimal *decimal_val)
6014
5994
{
6015
 
  DBUG_ASSERT(fixed == 1);
 
5995
  assert(fixed == 1);
6016
5996
  int2my_decimal(E_DEC_FATAL_ERROR, value, unsigned_flag, decimal_val);
6017
5997
  return decimal_val;
6018
5998
}
6027
6007
 
6028
6008
longlong Item_cache_real::val_int()
6029
6009
{
6030
 
  DBUG_ASSERT(fixed == 1);
 
6010
  assert(fixed == 1);
6031
6011
  return (longlong) rint(value);
6032
6012
}
6033
6013
 
6034
6014
 
6035
6015
String* Item_cache_real::val_str(String *str)
6036
6016
{
6037
 
  DBUG_ASSERT(fixed == 1);
 
6017
  assert(fixed == 1);
6038
6018
  str->set_real(value, decimals, default_charset());
6039
6019
  return str;
6040
6020
}
6042
6022
 
6043
6023
my_decimal *Item_cache_real::val_decimal(my_decimal *decimal_val)
6044
6024
{
6045
 
  DBUG_ASSERT(fixed == 1);
 
6025
  assert(fixed == 1);
6046
6026
  double2my_decimal(E_DEC_FATAL_ERROR, value, decimal_val);
6047
6027
  return decimal_val;
6048
6028
}
6057
6037
 
6058
6038
double Item_cache_decimal::val_real()
6059
6039
{
6060
 
  DBUG_ASSERT(fixed);
 
6040
  assert(fixed);
6061
6041
  double res;
6062
6042
  my_decimal2double(E_DEC_FATAL_ERROR, &decimal_value, &res);
6063
6043
  return res;
6065
6045
 
6066
6046
longlong Item_cache_decimal::val_int()
6067
6047
{
6068
 
  DBUG_ASSERT(fixed);
 
6048
  assert(fixed);
6069
6049
  longlong res;
6070
6050
  my_decimal2int(E_DEC_FATAL_ERROR, &decimal_value, unsigned_flag, &res);
6071
6051
  return res;
6073
6053
 
6074
6054
String* Item_cache_decimal::val_str(String *str)
6075
6055
{
6076
 
  DBUG_ASSERT(fixed);
 
6056
  assert(fixed);
6077
6057
  my_decimal_round(E_DEC_FATAL_ERROR, &decimal_value, decimals, false,
6078
6058
                   &decimal_value);
6079
6059
  my_decimal2string(E_DEC_FATAL_ERROR, &decimal_value, 0, 0, 0, str);
6082
6062
 
6083
6063
my_decimal *Item_cache_decimal::val_decimal(my_decimal *val __attribute__((__unused__)))
6084
6064
{
6085
 
  DBUG_ASSERT(fixed);
 
6065
  assert(fixed);
6086
6066
  return &decimal_value;
6087
6067
}
6088
6068
 
6110
6090
 
6111
6091
double Item_cache_str::val_real()
6112
6092
{
6113
 
  DBUG_ASSERT(fixed == 1);
 
6093
  assert(fixed == 1);
6114
6094
  int err_not_used;
6115
6095
  char *end_not_used;
6116
6096
  if (value)
6122
6102
 
6123
6103
longlong Item_cache_str::val_int()
6124
6104
{
6125
 
  DBUG_ASSERT(fixed == 1);
 
6105
  assert(fixed == 1);
6126
6106
  int err;
6127
6107
  if (value)
6128
6108
    return my_strntoll(value->charset(), value->ptr(),
6133
6113
 
6134
6114
my_decimal *Item_cache_str::val_decimal(my_decimal *decimal_val)
6135
6115
{
6136
 
  DBUG_ASSERT(fixed == 1);
 
6116
  assert(fixed == 1);
6137
6117
  if (value)
6138
6118
    string2my_decimal(E_DEC_FATAL_ERROR, value, decimal_val);
6139
6119
  else
6190
6170
 
6191
6171
void Item_cache_row::illegal_method_call(const char *method __attribute__((__unused__)))
6192
6172
{
6193
 
  DBUG_ENTER("Item_cache_row::illegal_method_call");
6194
 
  DBUG_PRINT("error", ("!!! %s method was called for row item", method));
6195
 
  DBUG_ASSERT(0);
 
6173
  assert(0);
6196
6174
  my_error(ER_OPERAND_COLUMNS, MYF(0), 1);
6197
 
  DBUG_VOID_RETURN;
 
6175
  return;
6198
6176
}
6199
6177
 
6200
6178
 
6240
6218
Item_type_holder::Item_type_holder(THD *thd, Item *item)
6241
6219
  :Item(thd, item), enum_set_typelib(0), fld_type(get_real_type(item))
6242
6220
{
6243
 
  DBUG_ASSERT(item->fixed);
 
6221
  assert(item->fixed);
6244
6222
  maybe_null= item->maybe_null;
6245
6223
  collation.set(item->collation);
6246
6224
  get_full_info(item);
6321
6299
        return MYSQL_TYPE_NEWDECIMAL;
6322
6300
      case ROW_RESULT:
6323
6301
      default:
6324
 
        DBUG_ASSERT(0);
 
6302
        assert(0);
6325
6303
        return MYSQL_TYPE_VAR_STRING;
6326
6304
      }
6327
6305
    }
6350
6328
{
6351
6329
  uint max_length_orig= max_length;
6352
6330
  uint decimals_orig= decimals;
6353
 
  DBUG_ENTER("Item_type_holder::join_types");
6354
 
  DBUG_PRINT("info:", ("was type %d len %d, dec %d name %s",
6355
 
                       fld_type, max_length, decimals,
6356
 
                       (name ? name : "<NULL>")));
6357
 
  DBUG_PRINT("info:", ("in type %d len %d, dec %d",
6358
 
                       get_real_type(item),
6359
 
                       item->max_length, item->decimals));
6360
6331
  fld_type= Field::field_type_merge(fld_type, get_real_type(item));
6361
6332
  {
6362
6333
    int item_decimals= item->decimals;
6390
6361
               item->collation.collation->name,
6391
6362
               item->collation.derivation_name(),
6392
6363
               "UNION");
6393
 
      DBUG_RETURN(true);
 
6364
      return(true);
6394
6365
    }
6395
6366
    /*
6396
6367
      To figure out max_length, we have to take into account possible
6438
6409
 
6439
6410
  /* Remember decimal integer part to be used in DECIMAL_RESULT handleng */
6440
6411
  prev_decimal_int_part= decimal_int_part();
6441
 
  DBUG_PRINT("info", ("become type: %d  len: %u  dec: %u",
6442
 
                      (int) fld_type, max_length, (uint) decimals));
6443
 
  DBUG_RETURN(false);
 
6412
  return(false);
6444
6413
}
6445
6414
 
6446
6415
/**
6486
6455
  case MYSQL_TYPE_LONGLONG:
6487
6456
    return 20;
6488
6457
  default:
6489
 
    DBUG_ASSERT(0); // we should never go there
 
6458
    assert(0); // we should never go there
6490
6459
    return 0;
6491
6460
  }
6492
6461
}
6512
6481
 
6513
6482
  switch (fld_type) {
6514
6483
  case MYSQL_TYPE_ENUM:
6515
 
    DBUG_ASSERT(enum_set_typelib);
 
6484
    assert(enum_set_typelib);
6516
6485
    field= new Field_enum((uchar *) 0, max_length, null_ptr, 0,
6517
6486
                          Field::NONE, name,
6518
6487
                          get_enum_pack_length(enum_set_typelib->count),
6521
6490
      field->init(table);
6522
6491
    return field;
6523
6492
  case MYSQL_TYPE_SET:
6524
 
    DBUG_ASSERT(enum_set_typelib);
 
6493
    assert(enum_set_typelib);
6525
6494
    field= new Field_set((uchar *) 0, max_length, null_ptr, 0,
6526
6495
                         Field::NONE, name,
6527
6496
                         get_set_pack_length(enum_set_typelib->count),
6557
6526
      We can have enum/set type after merging only if we have one enum|set
6558
6527
      field (or MIN|MAX(enum|set field)) and number of NULL fields
6559
6528
    */
6560
 
    DBUG_ASSERT((enum_set_typelib &&
 
6529
    assert((enum_set_typelib &&
6561
6530
                 get_real_type(item) == MYSQL_TYPE_NULL) ||
6562
6531
                (!enum_set_typelib &&
6563
6532
                 item->type() == Item::FIELD_ITEM &&
6574
6543
 
6575
6544
double Item_type_holder::val_real()
6576
6545
{
6577
 
  DBUG_ASSERT(0); // should never be called
 
6546
  assert(0); // should never be called
6578
6547
  return 0.0;
6579
6548
}
6580
6549
 
6581
6550
 
6582
6551
longlong Item_type_holder::val_int()
6583
6552
{
6584
 
  DBUG_ASSERT(0); // should never be called
 
6553
  assert(0); // should never be called
6585
6554
  return 0;
6586
6555
}
6587
6556
 
6588
6557
my_decimal *Item_type_holder::val_decimal(my_decimal *)
6589
6558
{
6590
 
  DBUG_ASSERT(0); // should never be called
 
6559
  assert(0); // should never be called
6591
6560
  return 0;
6592
6561
}
6593
6562
 
6594
6563
String *Item_type_holder::val_str(String*)
6595
6564
{
6596
 
  DBUG_ASSERT(0); // should never be called
 
6565
  assert(0); // should never be called
6597
6566
  return 0;
6598
6567
}
6599
6568
 
6600
6569
void Item_result_field::cleanup()
6601
6570
{
6602
 
  DBUG_ENTER("Item_result_field::cleanup()");
6603
6571
  Item::cleanup();
6604
6572
  result_field= 0;
6605
 
  DBUG_VOID_RETURN;
 
6573
  return;
6606
6574
}
6607
6575
 
6608
6576
/**