~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/item/field.cc

  • Committer: Stewart Smith
  • Date: 2009-06-17 06:44:38 UTC
  • mto: This revision was merged to the branch mainline in revision 1094.
  • Revision ID: stewart@flamingspork.com-20090617064438-062owpgtdzgr4lvx
type_float.test for MyISAM as temp only

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>
29
28
#include <drizzled/item/field.h>
30
29
#include <drizzled/item/outer_ref.h>
31
 
#include <drizzled/plugin/client.h>
32
 
 
33
 
#include <boost/dynamic_bitset.hpp>
34
 
 
35
 
namespace drizzled
36
 
{
 
30
 
37
31
 
38
32
/**
39
33
  Store the pointer to this item field into a list if not already there.
86
80
 
87
81
bool Item_field::find_item_in_field_list_processor(unsigned char *arg)
88
82
{
89
 
  KeyPartInfo *first_non_group_part= *((KeyPartInfo **) arg);
90
 
  KeyPartInfo *last_part= *(((KeyPartInfo **) arg) + 1);
91
 
  KeyPartInfo *cur_part;
 
83
  KEY_PART_INFO *first_non_group_part= *((KEY_PART_INFO **) arg);
 
84
  KEY_PART_INFO *last_part= *(((KEY_PART_INFO **) arg) + 1);
 
85
  KEY_PART_INFO *cur_part;
92
86
 
93
87
  for (cur_part= first_non_group_part; cur_part != last_part; cur_part++)
94
88
  {
110
104
bool Item_field::register_field_in_read_map(unsigned char *arg)
111
105
{
112
106
  Table *table= (Table *) arg;
113
 
  if (field->getTable() == table || !table)
114
 
    field->getTable()->setReadSet(field->position());
115
 
 
116
 
  return 0;
117
 
}
118
 
 
 
107
  if (field->table == table || !table)
 
108
    field->table->setReadSet(field->field_index);
 
109
 
 
110
  return 0;
 
111
}
 
112
 
 
113
 
 
114
Item_field *Item::filed_for_view_update()
 
115
{
 
116
  return 0;
 
117
}
119
118
 
120
119
Item_field::Item_field(Field *f)
121
 
  :Item_ident(0, NULL, f->getTable()->getAlias(), f->field_name),
 
120
  :Item_ident(0, NULL, *f->table_name, f->field_name),
122
121
   item_equal(0), no_const_subst(0),
123
122
   have_privileges(0), any_privileges(0)
124
123
{
138
137
  Item_field (this is important in prepared statements).
139
138
*/
140
139
 
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)
 
140
Item_field::Item_field(Session *, Name_resolution_context *context_arg,
 
141
                       Field *f)
 
142
  :Item_ident(context_arg, f->table->s->db.str, *f->table_name, f->field_name),
 
143
   item_equal(0), no_const_subst(0),
 
144
   have_privileges(0), any_privileges(0)
152
145
{
153
146
  set_field(f);
154
147
}
156
149
 
157
150
Item_field::Item_field(Name_resolution_context *context_arg,
158
151
                       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)
 
152
                       const char *field_name_arg)
 
153
  :Item_ident(context_arg, db_arg,table_name_arg,field_name_arg),
 
154
   field(0), result_field(0), item_equal(0), no_const_subst(0),
 
155
   have_privileges(0), any_privileges(0)
167
156
{
168
157
  Select_Lex *select= current_session->lex->current_select;
169
158
  collation.set(DERIVATION_IMPLICIT);
170
 
 
171
159
  if (select && select->parsing_place != IN_HAVING)
172
160
      select->select_n_where_fields++;
173
161
}
176
164
  Constructor need to process subselect with temporary tables (see Item)
177
165
*/
178
166
 
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)
 
167
Item_field::Item_field(Session *session, Item_field *item)
 
168
  :Item_ident(session, item),
 
169
   field(item->field),
 
170
   result_field(item->result_field),
 
171
   item_equal(item->item_equal),
 
172
   no_const_subst(item->no_const_subst),
 
173
   have_privileges(item->have_privileges),
 
174
   any_privileges(item->any_privileges)
187
175
{
188
176
  collation.set(DERIVATION_IMPLICIT);
189
177
}
194
182
  maybe_null=field->maybe_null();
195
183
  decimals= field->decimals();
196
184
  max_length= field_par->max_display_length();
197
 
  table_name= field_par->getTable()->getAlias();
 
185
  table_name= *field_par->table_name;
198
186
  field_name= field_par->field_name;
199
 
  db_name= field_par->getTable()->getShare()->getSchemaName();
200
 
  alias_name_used= field_par->getTable()->alias_name_used;
 
187
  db_name= field_par->table->s->db.str;
 
188
  alias_name_used= field_par->table->alias_name_used;
201
189
  unsigned_flag=test(field_par->flags & UNSIGNED_FLAG);
202
190
  collation.set(field_par->charset(), field_par->derivation());
203
191
  fixed= 1;
 
192
  if (field->table->s->tmp_table == SYSTEM_TMP_TABLE)
 
193
    any_privileges= 0;
204
194
}
205
195
 
206
196
 
323
313
  switch (result_field->result_type()) {
324
314
  case INT_RESULT:
325
315
    return result_field->val_int() != 0;
326
 
 
327
316
  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
 
 
 
317
  {
 
318
    my_decimal decimal_value;
 
319
    my_decimal *val= result_field->val_decimal(&decimal_value);
 
320
    if (val)
 
321
      return !my_decimal_is_zero(val);
 
322
    return 0;
 
323
  }
336
324
  case REAL_RESULT:
337
325
  case STRING_RESULT:
338
326
    return result_field->val_real() != 0.0;
339
 
 
340
327
  case ROW_RESULT:
 
328
  default:
341
329
    assert(0);
342
330
    return 0;                                   // Shut up compiler
343
331
  }
344
 
 
345
 
  assert(0);
346
 
  return 0;                                   // Shut up compiler
347
332
}
348
333
 
349
334
 
372
357
           (!my_strcasecmp(table_alias_charset, item_field->table_name,
373
358
                           table_name) &&
374
359
            (!item_field->db_name || !db_name ||
375
 
             (item_field->db_name && !strcasecmp(item_field->db_name,
 
360
             (item_field->db_name && !strcmp(item_field->db_name,
376
361
                                             db_name))))));
377
362
}
378
363
 
379
364
 
380
365
table_map Item_field::used_tables() const
381
366
{
382
 
  if (field->getTable()->const_table)
 
367
  if (field->table->const_table)
383
368
    return 0;                                   // const item
384
 
  return (depended_from ? OUTER_REF_TABLE_BIT : field->getTable()->map);
 
369
  return (depended_from ? OUTER_REF_TABLE_BIT : field->table->map);
385
370
}
386
371
 
387
372
enum Item_result Item_field::result_type () const
530
515
                                            last_name_resolution_table,
531
516
                                          reference,
532
517
                                          IGNORE_EXCEPT_NON_UNIQUE,
533
 
                                          true)) !=
 
518
                                          true, true)) !=
534
519
        not_found_field)
535
520
    {
536
521
      if (*from_field)
537
522
      {
538
523
        if (*from_field != view_ref_found)
539
524
        {
540
 
          prev_subselect_item->used_tables_cache|= (*from_field)->getTable()->map;
 
525
          prev_subselect_item->used_tables_cache|= (*from_field)->table->map;
541
526
          prev_subselect_item->const_item_cache= 0;
542
527
          set_field(*from_field);
543
528
          if (!last_checked_context->select_lex->having_fix_field &&
645
630
      find_field_in_tables(session, this,
646
631
                           context->first_name_resolution_table,
647
632
                           context->last_name_resolution_table,
648
 
                           reference, REPORT_ALL_ERRORS, true);
 
633
                           reference, REPORT_ALL_ERRORS,
 
634
                           !any_privileges &&
 
635
                           true, true);
649
636
    }
650
637
    return -1;
651
638
  }
704
691
    {
705
692
      Item_ref *rf;
706
693
      rf= new Item_ref(context,
707
 
                       (cached_table->getSchemaName()[0] ? cached_table->getSchemaName() : 0),
 
694
                       (cached_table->db[0] ? cached_table->db : 0),
708
695
                       (char*) cached_table->alias, (char*) field_name);
709
696
      if (!rf)
710
697
        return -1;
787
774
                                          reference,
788
775
                                          session->lex->use_only_table_context ?
789
776
                                            REPORT_ALL_ERRORS :
790
 
                                            IGNORE_EXCEPT_NON_UNIQUE, true)) ==
791
 
        not_found_field)
 
777
                                            IGNORE_EXCEPT_NON_UNIQUE,
 
778
                                          !any_privileges,
 
779
                                          true)) ==
 
780
        not_found_field)
792
781
    {
793
782
      int ret;
794
783
      /* Look up in current select's item_list to find aliased fields */
796
785
      {
797
786
        uint32_t counter;
798
787
        enum_resolution_type resolution;
799
 
        Item** res= find_item_in_list(session,
800
 
                                      this, session->lex->current_select->item_list,
 
788
        Item** res= find_item_in_list(this, session->lex->current_select->item_list,
801
789
                                      &counter, REPORT_EXCEPT_NOT_FOUND,
802
790
                                      &resolution);
803
791
        if (!res)
895
883
  }
896
884
  else if (session->mark_used_columns != MARK_COLUMNS_NONE)
897
885
  {
898
 
    Table *table= field->getTable();
899
 
    boost::dynamic_bitset<> *current_bitmap, *other_bitmap;
 
886
    Table *table= field->table;
 
887
    MY_BITMAP *current_bitmap, *other_bitmap;
900
888
    if (session->mark_used_columns == MARK_COLUMNS_READ)
901
889
    {
902
890
      current_bitmap= table->read_set;
907
895
      current_bitmap= table->write_set;
908
896
      other_bitmap=   table->read_set;
909
897
    }
910
 
    //if (! current_bitmap->testAndSet(field->position()))
911
 
    if (! current_bitmap->test(field->position()))
 
898
    if (!bitmap_test_and_set(current_bitmap, field->field_index))
912
899
    {
913
 
      if (! other_bitmap->test(field->position()))
 
900
      if (!bitmap_is_set(other_bitmap, field->field_index))
914
901
      {
915
902
        /* First usage of column */
916
903
        table->used_fields++;                     // Used to optimize loops
 
904
        /* purecov: begin inspected */
917
905
        table->covering_keys&= field->part_of_key;
 
906
        /* purecov: end */
918
907
      }
919
908
    }
920
909
  }
1196
1185
}
1197
1186
 
1198
1187
 
1199
 
bool Item_field::send(plugin::Client *client, String *)
 
1188
bool Item_field::send(Protocol *protocol, String *)
1200
1189
{
1201
 
  return client->store(result_field);
 
1190
  return protocol->store(result_field);
1202
1191
}
1203
1192
 
1204
1193
 
1208
1197
    need to set no_errors to prevent warnings about type conversion
1209
1198
    popping up.
1210
1199
  */
1211
 
  Session *session= field->getTable()->in_use;
 
1200
  Session *session= field->table->in_use;
1212
1201
  int no_errors;
1213
1202
 
1214
1203
  no_errors= session->no_errors;
1245
1234
  Select_Lex *select= (Select_Lex*)select_arg;
1246
1235
  assert(fixed);
1247
1236
 
1248
 
  if (field->getTable() != select->context.table_list->table)
 
1237
  if (field->table != select->context.table_list->table)
1249
1238
  {
1250
1239
    List<Item> *all_fields= &select->join->all_fields;
1251
1240
    Item **ref_pointer_array= select->ref_pointer_array;
1264
1253
 
1265
1254
void Item_field::print(String *str, enum_query_type query_type)
1266
1255
{
1267
 
  if (field && field->getTable()->const_table)
 
1256
  if (field && field->table->const_table)
1268
1257
  {
1269
1258
    char buff[MAX_FIELD_WIDTH];
1270
1259
    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
 
    }
 
1260
    field->val_str(&tmp);
 
1261
    str->append('\'');
 
1262
    str->append(tmp);
 
1263
    str->append('\'');
1280
1264
    return;
1281
1265
  }
1282
1266
  Item_ident::print(str, query_type);
1283
1267
}
1284
 
 
1285
 
 
1286
 
} /* namespace drizzled */