~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/item/ref.cc

  • Committer: Djellel E. Difallah
  • Date: 2010-03-27 10:10:49 UTC
  • mto: This revision was merged to the branch mainline in revision 1429.
  • Revision ID: ded@ubuntu-20100327101049-oo3arvatjoyku124
merge my_decimal and decimal

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, Inc.
 
4
 *  Copyright (C) 2008 Sun Microsystems
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
17
17
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
18
18
 */
19
19
 
20
 
#include <config.h>
 
20
#include "config.h"
21
21
 
22
 
#include <drizzled/session.h>
23
 
#include <drizzled/error.h>
24
 
#include <drizzled/show.h>
25
 
#include <drizzled/item/ref.h>
26
 
#include <drizzled/plugin/client.h>
27
 
#include <drizzled/item/sum.h>
 
22
#include "drizzled/session.h"
 
23
#include "drizzled/error.h"
 
24
#include "drizzled/show.h"
 
25
#include "drizzled/item/ref.h"
 
26
#include "drizzled/plugin/client.h"
 
27
#include "drizzled/item/sum.h"
28
28
 
29
29
namespace drizzled
30
30
{
113
113
{
114
114
  enum_parsing_place place= NO_MATTER;
115
115
  assert(fixed == 0);
116
 
  Select_Lex *current_sel= session->getLex()->current_select;
 
116
  Select_Lex *current_sel= session->lex->current_select;
117
117
 
118
118
  if (!ref || ref == not_found_item)
119
119
  {
132
132
      {
133
133
        /* The current reference cannot be resolved in this query. */
134
134
        my_error(ER_BAD_FIELD_ERROR,MYF(0),
135
 
                 full_name(), session->where());
 
135
                 this->full_name(), current_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.
189
187
        */
190
188
        if ((place != IN_HAVING ||
191
189
             (!select->with_sum_func &&
246
244
              } while (outer_context && outer_context->select_lex &&
247
245
                       cached_table->select_lex != outer_context->select_lex);
248
246
            }
249
 
            prev_subselect_item->used_tables_cache|= from_field->getTable()->map;
250
 
            prev_subselect_item->const_item_cache= false;
 
247
            prev_subselect_item->used_tables_cache|= from_field->table->map;
 
248
            prev_subselect_item->const_item_cache= 0;
251
249
            break;
252
250
          }
253
251
        }
255
253
 
256
254
        /* Reference is not found => depend on outer (or just error). */
257
255
        prev_subselect_item->used_tables_cache|= OUTER_REF_TABLE_BIT;
258
 
        prev_subselect_item->const_item_cache= false;
 
256
        prev_subselect_item->const_item_cache= 0;
259
257
 
260
258
        outer_context= outer_context->outer_context;
261
259
      } while (outer_context);
268
266
          goto error;
269
267
        session->change_item_tree(reference, fld);
270
268
        mark_as_dependent(session, last_checked_context->select_lex,
271
 
                          session->getLex()->current_select, this, fld);
 
269
                          session->lex->current_select, this, fld);
272
270
        /*
273
271
          A reference is resolved to a nest level that's outer or the same as
274
272
          the nest level of the enclosing set function : adjust the value of
275
273
          max_arg_level for the function if it's needed.
276
274
        */
277
 
        if (session->getLex()->in_sum_func &&
278
 
            session->getLex()->in_sum_func->nest_level >=
 
275
        if (session->lex->in_sum_func &&
 
276
            session->lex->in_sum_func->nest_level >=
279
277
            last_checked_context->select_lex->nest_level)
280
 
          set_if_bigger(session->getLex()->in_sum_func->max_arg_level,
 
278
          set_if_bigger(session->lex->in_sum_func->max_arg_level,
281
279
                        last_checked_context->select_lex->nest_level);
282
280
        return false;
283
281
      }
285
283
      {
286
284
        /* The item was not a table field and not a reference */
287
285
        my_error(ER_BAD_FIELD_ERROR, MYF(0),
288
 
                 full_name(), session->where());
 
286
                 this->full_name(), current_session->where);
289
287
        goto error;
290
288
      }
291
289
      /* Should be checked in resolve_ref_in_select_and_group(). */
297
295
        the nest level of the enclosing set function : adjust the value of
298
296
        max_arg_level for the function if it's needed.
299
297
      */
300
 
      if (session->getLex()->in_sum_func &&
301
 
          session->getLex()->in_sum_func->nest_level >=
 
298
      if (session->lex->in_sum_func &&
 
299
          session->lex->in_sum_func->nest_level >=
302
300
          last_checked_context->select_lex->nest_level)
303
 
        set_if_bigger(session->getLex()->in_sum_func->max_arg_level,
 
301
        set_if_bigger(session->lex->in_sum_func->max_arg_level,
304
302
                      last_checked_context->select_lex->nest_level);
305
303
    }
306
304
  }
430
428
}
431
429
 
432
430
 
433
 
type::Decimal *Item_ref::val_decimal_result(type::Decimal *decimal_value)
 
431
my_decimal *Item_ref::val_decimal_result(my_decimal *decimal_value)
434
432
{
435
433
  if (result_field)
436
434
  {
451
449
    switch (result_field->result_type()) {
452
450
    case INT_RESULT:
453
451
      return result_field->val_int() != 0;
454
 
 
455
452
    case DECIMAL_RESULT:
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
 
 
 
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
    }
464
460
    case REAL_RESULT:
465
461
    case STRING_RESULT:
466
462
      return result_field->val_real() != 0.0;
467
 
 
468
463
    case ROW_RESULT:
 
464
    default:
469
465
      assert(0);
470
466
    }
471
467
  }
472
 
 
473
468
  return val_bool();
474
469
}
475
470
 
517
512
}
518
513
 
519
514
 
520
 
bool Item_ref::get_date(type::Time &ltime,uint32_t fuzzydate)
 
515
bool Item_ref::get_date(DRIZZLE_TIME *ltime,uint32_t fuzzydate)
521
516
{
522
517
  return (null_value=(*ref)->get_date_result(ltime,fuzzydate));
523
518
}
524
519
 
525
520
 
526
 
type::Decimal *Item_ref::val_decimal(type::Decimal *decimal_value)
 
521
my_decimal *Item_ref::val_decimal(my_decimal *decimal_value)
527
522
{
528
 
  type::Decimal *val= (*ref)->val_decimal_result(decimal_value);
 
523
  my_decimal *val= (*ref)->val_decimal_result(decimal_value);
529
524
  null_value= (*ref)->null_value;
530
525
  return val;
531
526
}