~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/item/field.cc

  • Committer: Patrick Crews
  • Date: 2010-09-14 20:21:03 UTC
  • mto: (1771.1.1 pcrews)
  • mto: This revision was merged to the branch mainline in revision 1772.
  • Revision ID: gleebix@gmail.com-20100914202103-1db2n0bshzafep19
Moved transaction_log tests into updated non-publisher-based tree

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
30
30
#include <drizzled/item/outer_ref.h>
31
31
#include <drizzled/plugin/client.h>
32
32
 
33
 
#include <boost/dynamic_bitset.hpp>
34
 
 
35
33
namespace drizzled
36
34
{
37
35
 
111
109
{
112
110
  Table *table= (Table *) arg;
113
111
  if (field->getTable() == table || !table)
114
 
    field->getTable()->setReadSet(field->position());
 
112
    field->getTable()->setReadSet(field->field_index);
115
113
 
116
114
  return 0;
117
115
}
165
163
   have_privileges(0),
166
164
   any_privileges(0)
167
165
{
168
 
  Select_Lex *select= getSession().getLex()->current_select;
 
166
  Select_Lex *select= current_session->lex->current_select;
169
167
  collation.set(DERIVATION_IMPLICIT);
170
168
 
171
169
  if (select && select->parsing_place != IN_HAVING)
246
244
}
247
245
 
248
246
 
249
 
type::Decimal *Item_field::val_decimal(type::Decimal *decimal_value)
 
247
my_decimal *Item_field::val_decimal(my_decimal *decimal_value)
250
248
{
251
249
  if ((null_value= field->is_null()))
252
250
    return 0;
262
260
  return result_field->val_str(str,&str_value);
263
261
}
264
262
 
265
 
bool Item_field::get_date(type::Time &ltime,uint32_t fuzzydate)
 
263
bool Item_field::get_date(DRIZZLE_TIME *ltime,uint32_t fuzzydate)
266
264
{
267
265
  if ((null_value=field->is_null()) || field->get_date(ltime,fuzzydate))
268
266
  {
269
 
    ltime.reset();
 
267
    memset(ltime, 0, sizeof(*ltime));
270
268
    return 1;
271
269
  }
272
270
  return 0;
273
271
}
274
272
 
275
 
bool Item_field::get_date_result(type::Time &ltime,uint32_t fuzzydate)
 
273
bool Item_field::get_date_result(DRIZZLE_TIME *ltime,uint32_t fuzzydate)
276
274
{
277
275
  if ((null_value=result_field->is_null()) ||
278
276
      result_field->get_date(ltime,fuzzydate))
279
277
  {
280
 
    ltime.reset();
 
278
    memset(ltime, 0, sizeof(*ltime));
281
279
    return 1;
282
280
  }
283
281
  return 0;
284
282
}
285
283
 
286
 
bool Item_field::get_time(type::Time &ltime)
 
284
bool Item_field::get_time(DRIZZLE_TIME *ltime)
287
285
{
288
286
  if ((null_value=field->is_null()) || field->get_time(ltime))
289
287
  {
290
 
    ltime.reset();
 
288
    memset(ltime, 0, sizeof(*ltime));
291
289
    return 1;
292
290
  }
293
291
  return 0;
308
306
}
309
307
 
310
308
 
311
 
type::Decimal *Item_field::val_decimal_result(type::Decimal *decimal_value)
 
309
my_decimal *Item_field::val_decimal_result(my_decimal *decimal_value)
312
310
{
313
311
  if ((null_value= result_field->is_null()))
314
312
    return 0;
319
317
bool Item_field::val_bool_result()
320
318
{
321
319
  if ((null_value= result_field->is_null()))
322
 
  {
323
320
    return false;
324
 
  }
325
 
 
326
321
  switch (result_field->result_type()) {
327
322
  case INT_RESULT:
328
323
    return result_field->val_int() != 0;
329
 
 
330
324
  case DECIMAL_RESULT:
331
 
    {
332
 
      type::Decimal decimal_value;
333
 
      type::Decimal *val= result_field->val_decimal(&decimal_value);
334
 
      if (val)
335
 
        return not val->isZero();
336
 
      return 0;
337
 
    }
338
 
 
 
325
  {
 
326
    my_decimal decimal_value;
 
327
    my_decimal *val= result_field->val_decimal(&decimal_value);
 
328
    if (val)
 
329
      return !my_decimal_is_zero(val);
 
330
    return 0;
 
331
  }
339
332
  case REAL_RESULT:
340
333
  case STRING_RESULT:
341
334
    return result_field->val_real() != 0.0;
342
 
 
343
335
  case ROW_RESULT:
 
336
  default:
344
337
    assert(0);
345
338
    return 0;                                   // Shut up compiler
346
339
  }
347
 
 
348
 
  assert(0);
349
 
  return 0;                                   // Shut up compiler
350
340
}
351
341
 
352
342
 
369
359
    (In cases where we would choose wrong we would have to generate a
370
360
    ER_NON_UNIQ_ERROR).
371
361
  */
372
 
  return (not my_strcasecmp(system_charset_info, item_field->name, field_name) &&
373
 
          (not item_field->table_name || not table_name ||
374
 
           (not my_strcasecmp(table_alias_charset, item_field->table_name, table_name) &&
375
 
            (not item_field->db_name || not db_name ||
376
 
             (item_field->db_name && not my_strcasecmp(system_charset_info, item_field->db_name, db_name))))));
 
362
  return (!my_strcasecmp(system_charset_info, item_field->name,
 
363
                         field_name) &&
 
364
          (!item_field->table_name || !table_name ||
 
365
           (!my_strcasecmp(table_alias_charset, item_field->table_name,
 
366
                           table_name) &&
 
367
            (!item_field->db_name || !db_name ||
 
368
             (item_field->db_name && !strcasecmp(item_field->db_name,
 
369
                                             db_name))))));
377
370
}
378
371
 
379
372
 
380
373
table_map Item_field::used_tables() const
381
374
{
382
375
  if (field->getTable()->const_table)
383
 
  {
384
376
    return 0;                                   // const item
385
 
  }
386
 
 
387
377
  return (depended_from ? OUTER_REF_TABLE_BIT : field->getTable()->map);
388
378
}
389
379
 
541
531
        if (*from_field != view_ref_found)
542
532
        {
543
533
          prev_subselect_item->used_tables_cache|= (*from_field)->getTable()->map;
544
 
          prev_subselect_item->const_item_cache= false;
 
534
          prev_subselect_item->const_item_cache= 0;
545
535
          set_field(*from_field);
546
536
          if (!last_checked_context->select_lex->having_fix_field &&
547
537
              select->group_list.elements &&
629
619
      case it does not matter which used tables bits we set)
630
620
    */
631
621
    prev_subselect_item->used_tables_cache|= OUTER_REF_TABLE_BIT;
632
 
    prev_subselect_item->const_item_cache= false;
 
622
    prev_subselect_item->const_item_cache= 0;
633
623
  }
634
624
 
635
625
  assert(ref != 0);
640
630
    if (upward_lookup)
641
631
    {
642
632
      // We can't say exactly what absent table or field
643
 
      my_error(ER_BAD_FIELD_ERROR, MYF(0), full_name(), session->where());
 
633
      my_error(ER_BAD_FIELD_ERROR, MYF(0), full_name(), session->where);
644
634
    }
645
635
    else
646
636
    {
707
697
    {
708
698
      Item_ref *rf;
709
699
      rf= new Item_ref(context,
710
 
                       (cached_table->getSchemaName()[0] ? cached_table->getSchemaName() : 0),
 
700
                       (cached_table->db[0] ? cached_table->db : 0),
711
701
                       (char*) cached_table->alias, (char*) field_name);
712
702
      if (!rf)
713
703
        return -1;
824
814
            {
825
815
              /* The column to which we link isn't valid. */
826
816
              my_error(ER_BAD_FIELD_ERROR, MYF(0), (*res)->name,
827
 
                       session->where());
 
817
                       current_session->where);
828
818
              return(1);
829
819
            }
830
820
 
899
889
  else if (session->mark_used_columns != MARK_COLUMNS_NONE)
900
890
  {
901
891
    Table *table= field->getTable();
902
 
    boost::dynamic_bitset<> *current_bitmap, *other_bitmap;
 
892
    MyBitmap *current_bitmap, *other_bitmap;
903
893
    if (session->mark_used_columns == MARK_COLUMNS_READ)
904
894
    {
905
895
      current_bitmap= table->read_set;
910
900
      current_bitmap= table->write_set;
911
901
      other_bitmap=   table->read_set;
912
902
    }
913
 
    //if (! current_bitmap->testAndSet(field->position()))
914
 
    if (! current_bitmap->test(field->position()))
 
903
    if (! current_bitmap->testAndSet(field->field_index))
915
904
    {
916
 
      if (! other_bitmap->test(field->position()))
 
905
      if (! other_bitmap->isBitSet(field->field_index))
917
906
      {
918
907
        /* First usage of column */
919
908
        table->used_fields++;                     // Used to optimize loops
1271
1260
  {
1272
1261
    char buff[MAX_FIELD_WIDTH];
1273
1262
    String tmp(buff,sizeof(buff),str->charset());
1274
 
    field->val_str_internal(&tmp);
 
1263
    field->val_str(&tmp);
1275
1264
    if (field->is_null())  {
1276
1265
      str->append("NULL");
1277
1266
    }