~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/item/cmpfunc.cc

Merge Stewart

Show diffs side-by-side

added added

removed removed

Lines of Context:
203
203
    collect_cmp_types()
204
204
      items             Array of items to collect types from
205
205
      nitems            Number of items in the array
 
206
      skip_nulls        Don't collect types of NULL items if TRUE
206
207
 
207
208
  DESCRIPTION
208
209
    This function collects different result types for comparison of the first
213
214
    Bitmap of collected types - otherwise
214
215
*/
215
216
 
216
 
static uint32_t collect_cmp_types(Item **items, uint32_t nitems)
 
217
static uint32_t collect_cmp_types(Item **items, uint32_t nitems, bool skip_nulls= false)
217
218
{
218
219
  uint32_t i;
219
220
  uint32_t found_types;
222
223
  found_types= 0;
223
224
  for (i= 1; i < nitems ; i++)
224
225
  {
 
226
    if (skip_nulls && items[i]->type() == Item::NULL_ITEM)
 
227
      continue; // Skip NULL constant items
225
228
    if ((left_result == ROW_RESULT ||
226
229
         items[i]->result_type() == ROW_RESULT) &&
227
230
        cmp_row_type(items[0], items[i]))
229
232
    found_types|= 1<< (uint32_t)item_cmp_type(left_result,
230
233
                                           items[i]->result_type());
231
234
  }
 
235
  /*
 
236
   Even if all right-hand items are NULLs and we are skipping them all, we need
 
237
   at least one type bit in the found_type bitmask.
 
238
  */
 
239
  if (skip_nulls && !found_types)
 
240
    found_types= 1 << (uint)left_result;
232
241
  return found_types;
233
242
}
234
243
 
3525
3534
  uint32_t type_cnt= 0, i;
3526
3535
  Item_result cmp_type= STRING_RESULT;
3527
3536
  left_result_type= args[0]->result_type();
3528
 
  if (!(found_types= collect_cmp_types(args, arg_count)))
 
3537
  if (!(found_types= collect_cmp_types(args, arg_count, true)))
3529
3538
    return;
3530
3539
 
3531
3540
  for (arg= args + 1, arg_end= args + arg_count; arg != arg_end ; arg++)
3702
3711
      uint32_t j=0;
3703
3712
      for (uint32_t arg_num=1 ; arg_num < arg_count ; arg_num++)
3704
3713
      {
3705
 
        array->set(j,args[arg_num]);
3706
3714
        if (!args[arg_num]->null_value)                 // Skip NULL values
 
3715
        {
 
3716
          array->set(j,args[arg_num]);
3707
3717
          j++;
 
3718
        }
3708
3719
        else
3709
3720
          have_null= 1;
3710
3721
      }