~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/item/field.cc

  • Committer: Brian Aker
  • Date: 2009-12-03 04:18:00 UTC
  • mto: (1237.3.3 push)
  • mto: This revision was merged to the branch mainline in revision 1238.
  • Revision ID: brian@gaz-20091203041800-rxbans14m0bo0xcs
Final move of index flags up to Engine (new interface still needed).

Show diffs side-by-side

added added

removed removed

Lines of Context:
17
17
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
18
18
 */
19
19
 
20
 
#include "config.h"
21
 
 
 
20
#include <drizzled/server_includes.h>
 
21
#include CSTDINT_H
22
22
#include <drizzled/session.h>
23
23
#include <drizzled/table.h>
24
24
#include <drizzled/error.h>
25
 
#include <drizzled/join.h>
26
25
#include <drizzled/sql_base.h>
27
26
#include <drizzled/sql_select.h>
28
27
#include <drizzled/item/cmpfunc.h>
30
29
#include <drizzled/item/outer_ref.h>
31
30
#include <drizzled/plugin/client.h>
32
31
 
33
 
#include <boost/dynamic_bitset.hpp>
34
 
 
35
 
namespace drizzled
36
 
{
 
32
using namespace drizzled;
37
33
 
38
34
/**
39
35
  Store the pointer to this item field into a list if not already there.
86
82
 
87
83
bool Item_field::find_item_in_field_list_processor(unsigned char *arg)
88
84
{
89
 
  KeyPartInfo *first_non_group_part= *((KeyPartInfo **) arg);
90
 
  KeyPartInfo *last_part= *(((KeyPartInfo **) arg) + 1);
91
 
  KeyPartInfo *cur_part;
 
85
  KEY_PART_INFO *first_non_group_part= *((KEY_PART_INFO **) arg);
 
86
  KEY_PART_INFO *last_part= *(((KEY_PART_INFO **) arg) + 1);
 
87
  KEY_PART_INFO *cur_part;
92
88
 
93
89
  for (cur_part= first_non_group_part; cur_part != last_part; cur_part++)
94
90
  {
110
106
bool Item_field::register_field_in_read_map(unsigned char *arg)
111
107
{
112
108
  Table *table= (Table *) arg;
113
 
  if (field->getTable() == table || !table)
114
 
    field->getTable()->setReadSet(field->position());
 
109
  if (field->table == table || !table)
 
110
    field->table->setReadSet(field->field_index);
115
111
 
116
112
  return 0;
117
113
}
118
114
 
119
115
 
120
116
Item_field::Item_field(Field *f)
121
 
  :Item_ident(0, NULL, f->getTable()->getAlias(), f->field_name),
 
117
  :Item_ident(0, NULL, *f->table_name, f->field_name),
122
118
   item_equal(0), no_const_subst(0),
123
119
   have_privileges(0), any_privileges(0)
124
120
{
138
134
  Item_field (this is important in prepared statements).
139
135
*/
140
136
 
141
 
Item_field::Item_field(Session *,
142
 
                       Name_resolution_context *context_arg,
143
 
                       Field *f) :
144
 
  Item_ident(context_arg,
145
 
             f->getTable()->getShare()->getSchemaName(),
146
 
             f->getTable()->getAlias(),
147
 
             f->field_name),
148
 
   item_equal(0),
149
 
   no_const_subst(0),
150
 
   have_privileges(0),
151
 
   any_privileges(0)
 
137
Item_field::Item_field(Session *, Name_resolution_context *context_arg,
 
138
                       Field *f)
 
139
  :Item_ident(context_arg, f->table->s->db.str, *f->table_name, f->field_name),
 
140
   item_equal(0), no_const_subst(0),
 
141
   have_privileges(0), any_privileges(0)
152
142
{
153
143
  set_field(f);
154
144
}
156
146
 
157
147
Item_field::Item_field(Name_resolution_context *context_arg,
158
148
                       const char *db_arg,const char *table_name_arg,
159
 
                       const char *field_name_arg) :
160
 
  Item_ident(context_arg, db_arg,table_name_arg,field_name_arg),
161
 
   field(0),
162
 
   result_field(0),
163
 
   item_equal(0),
164
 
   no_const_subst(0),
165
 
   have_privileges(0),
166
 
   any_privileges(0)
 
149
                       const char *field_name_arg)
 
150
  :Item_ident(context_arg, db_arg,table_name_arg,field_name_arg),
 
151
   field(0), result_field(0), item_equal(0), no_const_subst(0),
 
152
   have_privileges(0), any_privileges(0)
167
153
{
168
154
  Select_Lex *select= current_session->lex->current_select;
169
155
  collation.set(DERIVATION_IMPLICIT);
170
 
 
171
156
  if (select && select->parsing_place != IN_HAVING)
172
157
      select->select_n_where_fields++;
173
158
}
176
161
  Constructor need to process subselect with temporary tables (see Item)
177
162
*/
178
163
 
179
 
Item_field::Item_field(Session *session, Item_field *item) :
180
 
  Item_ident(session, item),
181
 
  field(item->field),
182
 
  result_field(item->result_field),
183
 
  item_equal(item->item_equal),
184
 
  no_const_subst(item->no_const_subst),
185
 
  have_privileges(item->have_privileges),
186
 
  any_privileges(item->any_privileges)
 
164
Item_field::Item_field(Session *session, Item_field *item)
 
165
  :Item_ident(session, item),
 
166
   field(item->field),
 
167
   result_field(item->result_field),
 
168
   item_equal(item->item_equal),
 
169
   no_const_subst(item->no_const_subst),
 
170
   have_privileges(item->have_privileges),
 
171
   any_privileges(item->any_privileges)
187
172
{
188
173
  collation.set(DERIVATION_IMPLICIT);
189
174
}
194
179
  maybe_null=field->maybe_null();
195
180
  decimals= field->decimals();
196
181
  max_length= field_par->max_display_length();
197
 
  table_name= field_par->getTable()->getAlias();
 
182
  table_name= *field_par->table_name;
198
183
  field_name= field_par->field_name;
199
 
  db_name= field_par->getTable()->getShare()->getSchemaName();
200
 
  alias_name_used= field_par->getTable()->alias_name_used;
 
184
  db_name= field_par->table->s->db.str;
 
185
  alias_name_used= field_par->table->alias_name_used;
201
186
  unsigned_flag=test(field_par->flags & UNSIGNED_FLAG);
202
187
  collation.set(field_par->charset(), field_par->derivation());
203
188
  fixed= 1;
 
189
  if (field->table->s->tmp_table == SYSTEM_TMP_TABLE)
 
190
    any_privileges= 0;
204
191
}
205
192
 
206
193
 
323
310
  switch (result_field->result_type()) {
324
311
  case INT_RESULT:
325
312
    return result_field->val_int() != 0;
326
 
 
327
313
  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
 
 
 
314
  {
 
315
    my_decimal decimal_value;
 
316
    my_decimal *val= result_field->val_decimal(&decimal_value);
 
317
    if (val)
 
318
      return !my_decimal_is_zero(val);
 
319
    return 0;
 
320
  }
336
321
  case REAL_RESULT:
337
322
  case STRING_RESULT:
338
323
    return result_field->val_real() != 0.0;
339
 
 
340
324
  case ROW_RESULT:
 
325
  default:
341
326
    assert(0);
342
327
    return 0;                                   // Shut up compiler
343
328
  }
344
 
 
345
 
  assert(0);
346
 
  return 0;                                   // Shut up compiler
347
329
}
348
330
 
349
331
 
372
354
           (!my_strcasecmp(table_alias_charset, item_field->table_name,
373
355
                           table_name) &&
374
356
            (!item_field->db_name || !db_name ||
375
 
             (item_field->db_name && !strcasecmp(item_field->db_name,
 
357
             (item_field->db_name && !strcmp(item_field->db_name,
376
358
                                             db_name))))));
377
359
}
378
360
 
379
361
 
380
362
table_map Item_field::used_tables() const
381
363
{
382
 
  if (field->getTable()->const_table)
 
364
  if (field->table->const_table)
383
365
    return 0;                                   // const item
384
 
  return (depended_from ? OUTER_REF_TABLE_BIT : field->getTable()->map);
 
366
  return (depended_from ? OUTER_REF_TABLE_BIT : field->table->map);
385
367
}
386
368
 
387
369
enum Item_result Item_field::result_type () const
537
519
      {
538
520
        if (*from_field != view_ref_found)
539
521
        {
540
 
          prev_subselect_item->used_tables_cache|= (*from_field)->getTable()->map;
 
522
          prev_subselect_item->used_tables_cache|= (*from_field)->table->map;
541
523
          prev_subselect_item->const_item_cache= 0;
542
524
          set_field(*from_field);
543
525
          if (!last_checked_context->select_lex->having_fix_field &&
704
686
    {
705
687
      Item_ref *rf;
706
688
      rf= new Item_ref(context,
707
 
                       (cached_table->getSchemaName()[0] ? cached_table->getSchemaName() : 0),
 
689
                       (cached_table->db[0] ? cached_table->db : 0),
708
690
                       (char*) cached_table->alias, (char*) field_name);
709
691
      if (!rf)
710
692
        return -1;
796
778
      {
797
779
        uint32_t counter;
798
780
        enum_resolution_type resolution;
799
 
        Item** res= find_item_in_list(session,
800
 
                                      this, session->lex->current_select->item_list,
 
781
        Item** res= find_item_in_list(this, session->lex->current_select->item_list,
801
782
                                      &counter, REPORT_EXCEPT_NOT_FOUND,
802
783
                                      &resolution);
803
784
        if (!res)
895
876
  }
896
877
  else if (session->mark_used_columns != MARK_COLUMNS_NONE)
897
878
  {
898
 
    Table *table= field->getTable();
899
 
    boost::dynamic_bitset<> *current_bitmap, *other_bitmap;
 
879
    Table *table= field->table;
 
880
    MyBitmap *current_bitmap, *other_bitmap;
900
881
    if (session->mark_used_columns == MARK_COLUMNS_READ)
901
882
    {
902
883
      current_bitmap= table->read_set;
907
888
      current_bitmap= table->write_set;
908
889
      other_bitmap=   table->read_set;
909
890
    }
910
 
    //if (! current_bitmap->testAndSet(field->position()))
911
 
    if (! current_bitmap->test(field->position()))
 
891
    if (! current_bitmap->testAndSet(field->field_index))
912
892
    {
913
 
      if (! other_bitmap->test(field->position()))
 
893
      if (! other_bitmap->isBitSet(field->field_index))
914
894
      {
915
895
        /* First usage of column */
916
896
        table->used_fields++;                     // Used to optimize loops
1208
1188
    need to set no_errors to prevent warnings about type conversion
1209
1189
    popping up.
1210
1190
  */
1211
 
  Session *session= field->getTable()->in_use;
 
1191
  Session *session= field->table->in_use;
1212
1192
  int no_errors;
1213
1193
 
1214
1194
  no_errors= session->no_errors;
1245
1225
  Select_Lex *select= (Select_Lex*)select_arg;
1246
1226
  assert(fixed);
1247
1227
 
1248
 
  if (field->getTable() != select->context.table_list->table)
 
1228
  if (field->table != select->context.table_list->table)
1249
1229
  {
1250
1230
    List<Item> *all_fields= &select->join->all_fields;
1251
1231
    Item **ref_pointer_array= select->ref_pointer_array;
1264
1244
 
1265
1245
void Item_field::print(String *str, enum_query_type query_type)
1266
1246
{
1267
 
  if (field && field->getTable()->const_table)
 
1247
  if (field && field->table->const_table)
1268
1248
  {
1269
1249
    char buff[MAX_FIELD_WIDTH];
1270
1250
    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
 
    }
 
1251
    field->val_str(&tmp);
 
1252
    str->append('\'');
 
1253
    str->append(tmp);
 
1254
    str->append('\'');
1280
1255
    return;
1281
1256
  }
1282
1257
  Item_ident::print(str, query_type);
1283
1258
}
1284
 
 
1285
 
 
1286
 
} /* namespace drizzled */