~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/item/ref.cc

  • Committer: Olaf van der Spek
  • Date: 2011-02-12 18:24:24 UTC
  • mto: (2167.1.2 build) (2172.1.4 build)
  • mto: This revision was merged to the branch mainline in revision 2168.
  • Revision ID: olafvdspek@gmail.com-20110212182424-kgnm9osi7qo97at2
casts

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
2
 *  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
3
3
 *
4
 
 *  Copyright (C) 2008 Sun Microsystems
 
4
 *  Copyright (C) 2008 Sun Microsystems, Inc.
5
5
 *
6
6
 *  This program is free software; you can redistribute it and/or modify
7
7
 *  it under the terms of the GNU General Public License as published by
132
132
      {
133
133
        /* The current reference cannot be resolved in this query. */
134
134
        my_error(ER_BAD_FIELD_ERROR,MYF(0),
135
 
                 this->full_name(), current_session->where);
 
135
                 full_name(), session->where());
136
136
        goto error;
137
137
      }
138
138
 
184
184
          condition, so that we can give a better error message -
185
185
          ER_WRONG_FIELD_WITH_GROUP, instead of the less informative
186
186
          ER_BAD_FIELD_ERROR which we produce now.
 
187
 
 
188
          @todo determine if this is valid.
187
189
        */
188
190
        if ((place != IN_HAVING ||
189
191
             (!select->with_sum_func &&
244
246
              } while (outer_context && outer_context->select_lex &&
245
247
                       cached_table->select_lex != outer_context->select_lex);
246
248
            }
247
 
            prev_subselect_item->used_tables_cache|= from_field->table->map;
248
 
            prev_subselect_item->const_item_cache= 0;
 
249
            prev_subselect_item->used_tables_cache|= from_field->getTable()->map;
 
250
            prev_subselect_item->const_item_cache= false;
249
251
            break;
250
252
          }
251
253
        }
253
255
 
254
256
        /* Reference is not found => depend on outer (or just error). */
255
257
        prev_subselect_item->used_tables_cache|= OUTER_REF_TABLE_BIT;
256
 
        prev_subselect_item->const_item_cache= 0;
 
258
        prev_subselect_item->const_item_cache= false;
257
259
 
258
260
        outer_context= outer_context->outer_context;
259
261
      } while (outer_context);
283
285
      {
284
286
        /* The item was not a table field and not a reference */
285
287
        my_error(ER_BAD_FIELD_ERROR, MYF(0),
286
 
                 this->full_name(), current_session->where);
 
288
                 full_name(), session->where());
287
289
        goto error;
288
290
      }
289
291
      /* Should be checked in resolve_ref_in_select_and_group(). */
428
430
}
429
431
 
430
432
 
431
 
my_decimal *Item_ref::val_decimal_result(my_decimal *decimal_value)
 
433
type::Decimal *Item_ref::val_decimal_result(type::Decimal *decimal_value)
432
434
{
433
435
  if (result_field)
434
436
  {
449
451
    switch (result_field->result_type()) {
450
452
    case INT_RESULT:
451
453
      return result_field->val_int() != 0;
 
454
 
452
455
    case DECIMAL_RESULT:
453
 
    {
454
 
      my_decimal decimal_value;
455
 
      my_decimal *val= result_field->val_decimal(&decimal_value);
456
 
      if (val)
457
 
        return !my_decimal_is_zero(val);
458
 
      return 0;
459
 
    }
 
456
      {
 
457
        type::Decimal decimal_value;
 
458
        type::Decimal *val= result_field->val_decimal(&decimal_value);
 
459
        if (val)
 
460
          return not val->isZero();
 
461
        return 0;
 
462
      }
 
463
 
460
464
    case REAL_RESULT:
461
465
    case STRING_RESULT:
462
466
      return result_field->val_real() != 0.0;
 
467
 
463
468
    case ROW_RESULT:
464
 
    default:
465
469
      assert(0);
466
470
    }
467
471
  }
 
472
 
468
473
  return val_bool();
469
474
}
470
475
 
512
517
}
513
518
 
514
519
 
515
 
bool Item_ref::get_date(DRIZZLE_TIME *ltime,uint32_t fuzzydate)
 
520
bool Item_ref::get_date(type::Time &ltime,uint32_t fuzzydate)
516
521
{
517
522
  return (null_value=(*ref)->get_date_result(ltime,fuzzydate));
518
523
}
519
524
 
520
525
 
521
 
my_decimal *Item_ref::val_decimal(my_decimal *decimal_value)
 
526
type::Decimal *Item_ref::val_decimal(type::Decimal *decimal_value)
522
527
{
523
 
  my_decimal *val= (*ref)->val_decimal_result(decimal_value);
 
528
  type::Decimal *val= (*ref)->val_decimal_result(decimal_value);
524
529
  null_value= (*ref)->null_value;
525
530
  return val;
526
531
}