~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/item/ref.cc

  • Committer: patrick crews
  • Date: 2011-06-08 03:02:27 UTC
  • mto: This revision was merged to the branch mainline in revision 2329.
  • Revision ID: gleebix@gmail.com-20110608030227-updkyv2652zvfajc
Initial voodoo worked to give us a crashme mode.  Need docs still

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
17
17
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
18
18
 */
19
19
 
20
 
#include "config.h"
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"
28
 
 
29
 
namespace drizzled
30
 
{
 
20
#include <config.h>
 
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>
 
28
#include <drizzled/item/subselect.h>
 
29
#include <drizzled/sql_lex.h>
 
30
 
 
31
namespace drizzled {
31
32
 
32
33
Item_ref::Item_ref(Name_resolution_context *context_arg,
33
34
                   Item **item, const char *table_name_arg,
113
114
{
114
115
  enum_parsing_place place= NO_MATTER;
115
116
  assert(fixed == 0);
116
 
  Select_Lex *current_sel= session->lex->current_select;
 
117
  Select_Lex *current_sel= session->lex().current_select;
117
118
 
118
119
  if (!ref || ref == not_found_item)
119
120
  {
132
133
      {
133
134
        /* The current reference cannot be resolved in this query. */
134
135
        my_error(ER_BAD_FIELD_ERROR,MYF(0),
135
 
                 this->full_name(), current_session->where);
 
136
                 full_name(), session->where());
136
137
        goto error;
137
138
      }
138
139
 
247
248
                       cached_table->select_lex != outer_context->select_lex);
248
249
            }
249
250
            prev_subselect_item->used_tables_cache|= from_field->getTable()->map;
250
 
            prev_subselect_item->const_item_cache= 0;
 
251
            prev_subselect_item->const_item_cache= false;
251
252
            break;
252
253
          }
253
254
        }
255
256
 
256
257
        /* Reference is not found => depend on outer (or just error). */
257
258
        prev_subselect_item->used_tables_cache|= OUTER_REF_TABLE_BIT;
258
 
        prev_subselect_item->const_item_cache= 0;
 
259
        prev_subselect_item->const_item_cache= false;
259
260
 
260
261
        outer_context= outer_context->outer_context;
261
262
      } while (outer_context);
266
267
        Item_field* fld;
267
268
        if (!(fld= new Item_field(from_field)))
268
269
          goto error;
269
 
        session->change_item_tree(reference, fld);
 
270
        *reference= fld;
270
271
        mark_as_dependent(session, last_checked_context->select_lex,
271
 
                          session->lex->current_select, this, fld);
 
272
                          session->lex().current_select, this, fld);
272
273
        /*
273
274
          A reference is resolved to a nest level that's outer or the same as
274
275
          the nest level of the enclosing set function : adjust the value of
275
276
          max_arg_level for the function if it's needed.
276
277
        */
277
 
        if (session->lex->in_sum_func &&
278
 
            session->lex->in_sum_func->nest_level >=
 
278
        if (session->lex().in_sum_func &&
 
279
            session->lex().in_sum_func->nest_level >=
279
280
            last_checked_context->select_lex->nest_level)
280
 
          set_if_bigger(session->lex->in_sum_func->max_arg_level,
 
281
          set_if_bigger(session->lex().in_sum_func->max_arg_level,
281
282
                        last_checked_context->select_lex->nest_level);
282
283
        return false;
283
284
      }
285
286
      {
286
287
        /* The item was not a table field and not a reference */
287
288
        my_error(ER_BAD_FIELD_ERROR, MYF(0),
288
 
                 this->full_name(), current_session->where);
 
289
                 full_name(), session->where());
289
290
        goto error;
290
291
      }
291
292
      /* Should be checked in resolve_ref_in_select_and_group(). */
297
298
        the nest level of the enclosing set function : adjust the value of
298
299
        max_arg_level for the function if it's needed.
299
300
      */
300
 
      if (session->lex->in_sum_func &&
301
 
          session->lex->in_sum_func->nest_level >=
 
301
      if (session->lex().in_sum_func &&
 
302
          session->lex().in_sum_func->nest_level >=
302
303
          last_checked_context->select_lex->nest_level)
303
 
        set_if_bigger(session->lex->in_sum_func->max_arg_level,
 
304
        set_if_bigger(session->lex().in_sum_func->max_arg_level,
304
305
                      last_checked_context->select_lex->nest_level);
305
306
    }
306
307
  }
368
369
}
369
370
 
370
371
 
371
 
void Item_ref::print(String *str, enum_query_type query_type)
 
372
void Item_ref::print(String *str)
372
373
{
373
374
  if (ref)
374
375
  {
378
379
      str->append_identifier(name, (uint32_t) strlen(name));
379
380
    }
380
381
    else
381
 
      (*ref)->print(str, query_type);
 
382
      (*ref)->print(str);
382
383
  }
383
384
  else
384
 
    Item_ident::print(str, query_type);
 
385
    Item_ident::print(str);
385
386
}
386
387
 
387
388
 
388
 
bool Item_ref::send(plugin::Client *client, String *tmp)
 
389
void Item_ref::send(plugin::Client *client, String *tmp)
389
390
{
390
391
  if (result_field)
391
 
    return client->store(result_field);
 
392
  {
 
393
    client->store(result_field);
 
394
    return;
 
395
  }
392
396
  return (*ref)->send(client, tmp);
393
397
}
394
398
 
430
434
}
431
435
 
432
436
 
433
 
my_decimal *Item_ref::val_decimal_result(my_decimal *decimal_value)
 
437
type::Decimal *Item_ref::val_decimal_result(type::Decimal *decimal_value)
434
438
{
435
439
  if (result_field)
436
440
  {
454
458
 
455
459
    case DECIMAL_RESULT:
456
460
      {
457
 
        my_decimal decimal_value;
458
 
        my_decimal *val= result_field->val_decimal(&decimal_value);
 
461
        type::Decimal decimal_value;
 
462
        type::Decimal *val= result_field->val_decimal(&decimal_value);
459
463
        if (val)
460
 
          return !my_decimal_is_zero(val);
 
464
          return not val->isZero();
461
465
        return 0;
462
466
      }
463
467
 
517
521
}
518
522
 
519
523
 
520
 
bool Item_ref::get_date(DRIZZLE_TIME *ltime,uint32_t fuzzydate)
 
524
bool Item_ref::get_date(type::Time &ltime,uint32_t fuzzydate)
521
525
{
522
526
  return (null_value=(*ref)->get_date_result(ltime,fuzzydate));
523
527
}
524
528
 
525
529
 
526
 
my_decimal *Item_ref::val_decimal(my_decimal *decimal_value)
 
530
type::Decimal *Item_ref::val_decimal(type::Decimal *decimal_value)
527
531
{
528
 
  my_decimal *val= (*ref)->val_decimal_result(decimal_value);
 
532
  type::Decimal *val= (*ref)->val_decimal_result(decimal_value);
529
533
  null_value= (*ref)->null_value;
530
534
  return val;
531
535
}