~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/item/field.cc

  • Committer: Brian Aker
  • Date: 2010-05-17 23:12:39 UTC
  • Revision ID: brian@gaz-20100517231239-kgcnn613z0gga7ie
Code shuffle on ReadRecord

Show diffs side-by-side

added added

removed removed

Lines of Context:
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
 
110
108
bool Item_field::register_field_in_read_map(unsigned char *arg)
111
109
{
112
110
  Table *table= (Table *) arg;
113
 
  if (field->getTable() == table || !table)
114
 
    field->getTable()->setReadSet(field->position());
 
111
  if (field->table == table || !table)
 
112
    field->table->setReadSet(field->field_index);
115
113
 
116
114
  return 0;
117
115
}
118
116
 
119
117
 
120
118
Item_field::Item_field(Field *f)
121
 
  :Item_ident(0, NULL, f->getTable()->getAlias(), f->field_name),
 
119
  :Item_ident(0, NULL, *f->table_name, f->field_name),
122
120
   item_equal(0), no_const_subst(0),
123
121
   have_privileges(0), any_privileges(0)
124
122
{
142
140
                       Name_resolution_context *context_arg,
143
141
                       Field *f) :
144
142
  Item_ident(context_arg,
145
 
             f->getTable()->getShare()->getSchemaName(),
146
 
             f->getTable()->getAlias(),
 
143
             f->table->s->getSchemaName(),
 
144
             *f->table_name,
147
145
             f->field_name),
148
146
   item_equal(0),
149
147
   no_const_subst(0),
194
192
  maybe_null=field->maybe_null();
195
193
  decimals= field->decimals();
196
194
  max_length= field_par->max_display_length();
197
 
  table_name= field_par->getTable()->getAlias();
 
195
  table_name= *field_par->table_name;
198
196
  field_name= field_par->field_name;
199
 
  db_name= field_par->getTable()->getShare()->getSchemaName();
200
 
  alias_name_used= field_par->getTable()->alias_name_used;
 
197
  db_name= field_par->table->s->getSchemaName();
 
198
  alias_name_used= field_par->table->alias_name_used;
201
199
  unsigned_flag=test(field_par->flags & UNSIGNED_FLAG);
202
200
  collation.set(field_par->charset(), field_par->derivation());
203
201
  fixed= 1;
323
321
  switch (result_field->result_type()) {
324
322
  case INT_RESULT:
325
323
    return result_field->val_int() != 0;
326
 
 
327
324
  case DECIMAL_RESULT:
328
 
    {
329
 
      my_decimal decimal_value;
330
 
      my_decimal *val= result_field->val_decimal(&decimal_value);
331
 
      if (val)
332
 
        return !my_decimal_is_zero(val);
333
 
      return 0;
334
 
    }
335
 
 
 
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
  }
336
332
  case REAL_RESULT:
337
333
  case STRING_RESULT:
338
334
    return result_field->val_real() != 0.0;
339
 
 
340
335
  case ROW_RESULT:
 
336
  default:
341
337
    assert(0);
342
338
    return 0;                                   // Shut up compiler
343
339
  }
344
 
 
345
 
  assert(0);
346
 
  return 0;                                   // Shut up compiler
347
340
}
348
341
 
349
342
 
379
372
 
380
373
table_map Item_field::used_tables() const
381
374
{
382
 
  if (field->getTable()->const_table)
 
375
  if (field->table->const_table)
383
376
    return 0;                                   // const item
384
 
  return (depended_from ? OUTER_REF_TABLE_BIT : field->getTable()->map);
 
377
  return (depended_from ? OUTER_REF_TABLE_BIT : field->table->map);
385
378
}
386
379
 
387
380
enum Item_result Item_field::result_type () const
537
530
      {
538
531
        if (*from_field != view_ref_found)
539
532
        {
540
 
          prev_subselect_item->used_tables_cache|= (*from_field)->getTable()->map;
 
533
          prev_subselect_item->used_tables_cache|= (*from_field)->table->map;
541
534
          prev_subselect_item->const_item_cache= 0;
542
535
          set_field(*from_field);
543
536
          if (!last_checked_context->select_lex->having_fix_field &&
704
697
    {
705
698
      Item_ref *rf;
706
699
      rf= new Item_ref(context,
707
 
                       (cached_table->getSchemaName()[0] ? cached_table->getSchemaName() : 0),
 
700
                       (cached_table->db[0] ? cached_table->db : 0),
708
701
                       (char*) cached_table->alias, (char*) field_name);
709
702
      if (!rf)
710
703
        return -1;
796
789
      {
797
790
        uint32_t counter;
798
791
        enum_resolution_type resolution;
799
 
        Item** res= find_item_in_list(session,
800
 
                                      this, session->lex->current_select->item_list,
 
792
        Item** res= find_item_in_list(this, session->lex->current_select->item_list,
801
793
                                      &counter, REPORT_EXCEPT_NOT_FOUND,
802
794
                                      &resolution);
803
795
        if (!res)
895
887
  }
896
888
  else if (session->mark_used_columns != MARK_COLUMNS_NONE)
897
889
  {
898
 
    Table *table= field->getTable();
899
 
    boost::dynamic_bitset<> *current_bitmap, *other_bitmap;
 
890
    Table *table= field->table;
 
891
    MyBitmap *current_bitmap, *other_bitmap;
900
892
    if (session->mark_used_columns == MARK_COLUMNS_READ)
901
893
    {
902
894
      current_bitmap= table->read_set;
907
899
      current_bitmap= table->write_set;
908
900
      other_bitmap=   table->read_set;
909
901
    }
910
 
    //if (! current_bitmap->testAndSet(field->position()))
911
 
    if (! current_bitmap->test(field->position()))
 
902
    if (! current_bitmap->testAndSet(field->field_index))
912
903
    {
913
 
      if (! other_bitmap->test(field->position()))
 
904
      if (! other_bitmap->isBitSet(field->field_index))
914
905
      {
915
906
        /* First usage of column */
916
907
        table->used_fields++;                     // Used to optimize loops
1208
1199
    need to set no_errors to prevent warnings about type conversion
1209
1200
    popping up.
1210
1201
  */
1211
 
  Session *session= field->getTable()->in_use;
 
1202
  Session *session= field->table->in_use;
1212
1203
  int no_errors;
1213
1204
 
1214
1205
  no_errors= session->no_errors;
1245
1236
  Select_Lex *select= (Select_Lex*)select_arg;
1246
1237
  assert(fixed);
1247
1238
 
1248
 
  if (field->getTable() != select->context.table_list->table)
 
1239
  if (field->table != select->context.table_list->table)
1249
1240
  {
1250
1241
    List<Item> *all_fields= &select->join->all_fields;
1251
1242
    Item **ref_pointer_array= select->ref_pointer_array;
1264
1255
 
1265
1256
void Item_field::print(String *str, enum_query_type query_type)
1266
1257
{
1267
 
  if (field && field->getTable()->const_table)
 
1258
  if (field && field->table->const_table)
1268
1259
  {
1269
1260
    char buff[MAX_FIELD_WIDTH];
1270
1261
    String tmp(buff,sizeof(buff),str->charset());
1271
 
    field->val_str_internal(&tmp);
1272
 
    if (field->is_null())  {
1273
 
      str->append("NULL");
1274
 
    }
1275
 
    else {
1276
 
      str->append('\'');
1277
 
      str->append(tmp);
1278
 
      str->append('\'');
1279
 
    }
 
1262
    field->val_str(&tmp);
 
1263
    str->append('\'');
 
1264
    str->append(tmp);
 
1265
    str->append('\'');
1280
1266
    return;
1281
1267
  }
1282
1268
  Item_ident::print(str, query_type);