~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/item/ref.cc

  • Committer: Brian Aker
  • Date: 2009-02-21 00:18:15 UTC
  • Revision ID: brian@tangent.org-20090221001815-x20e8h71e984lvs1
Completion (?) of uint conversion.

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"
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 <drizzled/server_includes.h>
 
21
#include CSTDINT_H
 
22
#include <drizzled/session.h>
 
23
#include <drizzled/error.h>
 
24
#include <drizzled/show.h>
 
25
#include <drizzled/item/ref.h>
31
26
 
32
27
Item_ref::Item_ref(Name_resolution_context *context_arg,
33
28
                   Item **item, const char *table_name_arg,
132
127
      {
133
128
        /* The current reference cannot be resolved in this query. */
134
129
        my_error(ER_BAD_FIELD_ERROR,MYF(0),
135
 
                 full_name(), session->where());
 
130
                 this->full_name(), current_session->where);
136
131
        goto error;
137
132
      }
138
133
 
184
179
          condition, so that we can give a better error message -
185
180
          ER_WRONG_FIELD_WITH_GROUP, instead of the less informative
186
181
          ER_BAD_FIELD_ERROR which we produce now.
187
 
 
188
 
          @todo determine if this is valid.
189
182
        */
190
183
        if ((place != IN_HAVING ||
191
184
             (!select->with_sum_func &&
202
195
                                           outer_context->
203
196
                                             last_name_resolution_table,
204
197
                                           reference,
205
 
                                           IGNORE_EXCEPT_NON_UNIQUE, true);
 
198
                                           IGNORE_EXCEPT_NON_UNIQUE,
 
199
                                           true, true);
206
200
          if (! from_field)
207
201
            goto error;
208
202
          if (from_field == view_ref_found)
246
240
              } while (outer_context && outer_context->select_lex &&
247
241
                       cached_table->select_lex != outer_context->select_lex);
248
242
            }
249
 
            prev_subselect_item->used_tables_cache|= from_field->getTable()->map;
250
 
            prev_subselect_item->const_item_cache= false;
 
243
            prev_subselect_item->used_tables_cache|= from_field->table->map;
 
244
            prev_subselect_item->const_item_cache= 0;
251
245
            break;
252
246
          }
253
247
        }
255
249
 
256
250
        /* Reference is not found => depend on outer (or just error). */
257
251
        prev_subselect_item->used_tables_cache|= OUTER_REF_TABLE_BIT;
258
 
        prev_subselect_item->const_item_cache= false;
 
252
        prev_subselect_item->const_item_cache= 0;
259
253
 
260
254
        outer_context= outer_context->outer_context;
261
255
      } while (outer_context);
285
279
      {
286
280
        /* The item was not a table field and not a reference */
287
281
        my_error(ER_BAD_FIELD_ERROR, MYF(0),
288
 
                 full_name(), session->where());
 
282
                 this->full_name(), current_session->where);
289
283
        goto error;
290
284
      }
291
285
      /* Should be checked in resolve_ref_in_select_and_group(). */
385
379
}
386
380
 
387
381
 
388
 
bool Item_ref::send(plugin::Client *client, String *tmp)
 
382
bool Item_ref::send(Protocol *prot, String *tmp)
389
383
{
390
384
  if (result_field)
391
 
    return client->store(result_field);
392
 
  return (*ref)->send(client, tmp);
 
385
    return prot->store(result_field);
 
386
  return (*ref)->send(prot, tmp);
393
387
}
394
388
 
395
389
 
430
424
}
431
425
 
432
426
 
433
 
type::Decimal *Item_ref::val_decimal_result(type::Decimal *decimal_value)
 
427
my_decimal *Item_ref::val_decimal_result(my_decimal *decimal_value)
434
428
{
435
429
  if (result_field)
436
430
  {
451
445
    switch (result_field->result_type()) {
452
446
    case INT_RESULT:
453
447
      return result_field->val_int() != 0;
454
 
 
455
448
    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
 
 
 
449
    {
 
450
      my_decimal decimal_value;
 
451
      my_decimal *val= result_field->val_decimal(&decimal_value);
 
452
      if (val)
 
453
        return !my_decimal_is_zero(val);
 
454
      return 0;
 
455
    }
464
456
    case REAL_RESULT:
465
457
    case STRING_RESULT:
466
458
      return result_field->val_real() != 0.0;
467
 
 
468
459
    case ROW_RESULT:
 
460
    default:
469
461
      assert(0);
470
462
    }
471
463
  }
472
 
 
473
464
  return val_bool();
474
465
}
475
466
 
517
508
}
518
509
 
519
510
 
520
 
bool Item_ref::get_date(type::Time &ltime,uint32_t fuzzydate)
 
511
bool Item_ref::get_date(DRIZZLE_TIME *ltime,uint32_t fuzzydate)
521
512
{
522
513
  return (null_value=(*ref)->get_date_result(ltime,fuzzydate));
523
514
}
524
515
 
525
516
 
526
 
type::Decimal *Item_ref::val_decimal(type::Decimal *decimal_value)
 
517
my_decimal *Item_ref::val_decimal(my_decimal *decimal_value)
527
518
{
528
 
  type::Decimal *val= (*ref)->val_decimal_result(decimal_value);
 
519
  my_decimal *val= (*ref)->val_decimal_result(decimal_value);
529
520
  null_value= (*ref)->null_value;
530
521
  return val;
531
522
}
546
537
}
547
538
 
548
539
 
549
 
void Item_ref::make_field(SendField *field)
 
540
void Item_ref::make_field(Send_field *field)
550
541
{
551
542
  (*ref)->make_field(field);
552
543
  /* Non-zero in case of a view */
581
572
    depended_from= NULL;
582
573
  }
583
574
}
584
 
 
585
 
} /* namespace drizzled */