drizzle
C++ MySQL-protocol-compatible database server
Loading...
Searching...
No Matches
item.h
1/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
3 *
4 * Copyright (C) 2008 Sun Microsystems, Inc.
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; version 2 of the License.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18 */
19
20
21
22#pragma once
23
24#include <drizzled/dtcollation.h>
25#include <drizzled/charset.h>
26#include <drizzled/item_result.h>
27#include <drizzled/memory/sql_alloc.h>
28#include <drizzled/sql_list.h>
29#include <drizzled/sql_string.h>
30
31#include <drizzled/visibility.h>
32
33#include <boost/noncopyable.hpp>
34
35namespace drizzled {
36
37/*
38 Analyzer function
39 SYNOPSIS
40 argp in/out IN: Analysis parameter
41 OUT: Parameter to be passed to the transformer
42
43 RETURN
44 true Invoke the transformer
45 false Don't do it
46
47*/
48typedef bool (Item::*Item_analyzer) (unsigned char **argp);
49typedef Item* (Item::*Item_transformer) (unsigned char *arg);
50typedef void (*Cond_traverser) (const Item *item, void *arg);
51typedef bool (Item::*Item_processor) (unsigned char *arg);
52
58class DRIZZLED_API Item : public memory::SqlAlloc, boost::noncopyable
59{
60 /* Cache of the result of is_expensive(). */
61 int8_t is_expensive_cache;
62 virtual bool is_expensive_processor(unsigned char *arg);
63
64public:
65
66 enum Type
67 {
68 FIELD_ITEM= 0,
69 FUNC_ITEM,
70 SUM_FUNC_ITEM,
71 STRING_ITEM,
72 INT_ITEM,
73 REAL_ITEM,
74 NULL_ITEM,
75 VARBIN_ITEM,
76 COPY_STR_ITEM,
77 FIELD_AVG_ITEM,
78 DEFAULT_VALUE_ITEM,
79 PROC_ITEM,
80 COND_ITEM,
81 REF_ITEM,
82 FIELD_STD_ITEM,
83 FIELD_VARIANCE_ITEM,
84 INSERT_VALUE_ITEM,
85 SUBSELECT_ITEM,
86 ROW_ITEM, CACHE_ITEM,
87 TYPE_HOLDER,
88 PARAM_ITEM,
89 BOOLEAN_ITEM,
90 DECIMAL_ITEM
91 };
92 enum traverse_order
93 {
94 T_POSTFIX,
95 T_PREFIX
96 };
97 enum cond_result
98 {
99 COND_UNDEF,
100 COND_OK,
101 COND_TRUE,
102 COND_FALSE
103 };
104
110
112 const char *name;
113
115 uint32_t name_length;
116
117 Item *next;
118 uint32_t max_length;
119
120 int8_t marker;
121 uint8_t decimals;
122 bool fixed;
125 bool unsigned_flag;
126
127 bool is_unsigned() const
128 {
129 return unsigned_flag;
130 }
131
132 virtual bool negative() const
133 {
134 return false;
135 }
136
137 bool with_sum_func;
139
145 DTCollation collation;
146 Item_result cmp_context;
147
155 Item();
156
167 Item(Session *session, Item *item);
168
169 virtual ~Item()
170 {
171 }
172
173 void set_name(str_ref arg)
174 {
175 set_name(arg.data(), arg.size());
176 }
177
178 void set_name(const char* arg)
179 {
180 set_name(str_ref(arg));
181 }
182
183 void set_name(const char *str, uint32_t length, const charset_info_st* cs= system_charset_info);
184 void init_make_field(SendField *tmp_field, enum_field_types type);
185 virtual void cleanup();
186 virtual void make_field(SendField *field);
196 Field *make_string_field(Table *table);
197 virtual bool fix_fields(Session *, Item **);
198
203 virtual void fix_after_pullout(Select_Lex *new_parent, Item **ref);
204
209 inline void quick_fix_field()
210 {
211 fixed= true;
212 }
213
214 virtual int save_in_field(Field *field, bool no_conversions);
215 virtual void save_org_in_field(Field *field)
216 {
217 (void) save_in_field(field, true);
218 }
219 virtual int save_safe_in_field(Field *field)
220 {
221 return save_in_field(field, true);
222 }
226 virtual void send(plugin::Client *client, String *str);
237 virtual bool eq(const Item *, bool binary_cmp) const;
238 virtual Item_result result_type() const
239 {
240 return REAL_RESULT;
241 }
242 virtual Item_result cast_to_int_type() const
243 {
244 return result_type();
245 }
246 virtual enum_field_types string_field_type() const;
247 virtual enum_field_types field_type() const;
248 virtual enum Type type() const =0;
249
286 virtual int64_t val_int_endpoint(bool left_endp, bool *incl_endp);
287
288 /* valXXX methods must return NULL or 0 or 0.0 if null_value is set. */
297 virtual double val_real()=0;
306 virtual int64_t val_int()=0;
311 inline uint64_t val_uint()
312 {
313 return (uint64_t) val_int();
314 }
315
350 virtual String *val_str(String *str)=0;
351
370 virtual type::Decimal *val_decimal(type::Decimal *decimal_buffer)= 0;
371
380 virtual bool val_bool();
381
382 /* Helper functions, see item_sum.cc */
383 String *val_string_from_real(String *str);
384 String *val_string_from_int(String *str);
385 String *val_string_from_decimal(String *str);
386 type::Decimal *val_decimal_from_real(type::Decimal *decimal_value);
387 type::Decimal *val_decimal_from_int(type::Decimal *decimal_value);
388 type::Decimal *val_decimal_from_string(type::Decimal *decimal_value);
389 type::Decimal *val_decimal_from_date(type::Decimal *decimal_value);
390 type::Decimal *val_decimal_from_time(type::Decimal *decimal_value);
391 int64_t val_int_from_decimal();
392 double val_real_from_decimal();
393
394 bool save_time_in_field(Field *field);
395 bool save_date_in_field(Field *field);
396
414 int save_str_value_in_field(Field *field, String *result);
415
416 virtual Field *get_tmp_table_field(void)
417 {
418 return NULL;
419 }
420 /* This is also used to create fields in CREATE ... SELECT: */
421 virtual Field *tmp_table_field(Table *t_arg);
422 virtual const char *full_name(void) const;
423
424 /*
425 *result* family of methods is analog of *val* family (see above) but
426 return value of result_field of item if it is present. If Item have not
427 result field, it return val(). This methods set null_value flag in same
428 way as *val* methods do it.
429 */
430 virtual double val_result()
431 {
432 return val_real();
433 }
434 virtual int64_t val_int_result()
435 {
436 return val_int();
437 }
438 virtual String *str_result(String* tmp)
439 {
440 return val_str(tmp);
441 }
442 virtual type::Decimal *val_decimal_result(type::Decimal *val)
443 {
444 return val_decimal(val);
445 }
446 virtual bool val_bool_result()
447 {
448 return val_bool();
449 }
453 virtual table_map used_tables() const
454 {
455 return (table_map) 0L;
456 }
457
468 virtual table_map not_null_tables() const
469 {
470 return used_tables();
471 }
472
476 virtual bool basic_const_item() const
477 {
478 return false;
479 }
480 /* cloning of constant items (NULL if it is not const) */
481 virtual Item *clone_item()
482 {
483 return NULL;
484 }
485 virtual cond_result eq_cmp_result() const
486 {
487 return COND_OK;
488 }
489 uint32_t float_length(uint32_t decimals_par) const;
490 virtual uint32_t decimal_precision() const;
491 int decimal_int_part() const;
492
497 virtual bool const_item() const
498 {
499 return used_tables() == 0;
500 }
501
505 virtual bool const_during_execution() const
506 {
507 return (used_tables() & ~PARAM_TABLE_BIT) == 0;
508 }
509
521 virtual void print(String *str);
522
523 void print_item_w_name(String *);
524 virtual void update_used_tables() {}
525 virtual void split_sum_func(Session *session,
526 Item **ref_pointer_array,
527 List<Item> &fields);
546 void split_sum_func(Session *session,
547 Item **ref_pointer_array,
548 List<Item> &fields,
549 Item **ref,
550 bool skip_registered);
551
556 virtual bool get_date(type::Time &ltime, uint32_t fuzzydate);
562 virtual bool get_time(type::Time &ltime);
563 virtual bool get_date_result(type::Time &ltime,uint32_t fuzzydate);
564
572 virtual bool is_null();
573
575 virtual void update_null_value ();
576
588 virtual void top_level_item(void);
593 virtual void set_result_field(Field *field);
594 virtual bool is_result_field(void);
595 virtual bool is_bool_func(void);
596 virtual void save_in_result_field(bool no_conversions);
597
601 virtual void no_rows_in_result(void);
602 virtual Item *copy_or_same(Session *session);
603
604 virtual Item *copy_andor_structure(Session *session);
605
606 virtual Item *real_item(void);
607 virtual const Item *real_item(void) const;
608 virtual Item *get_tmp_table_item(Session *session);
609
610 static const charset_info_st *default_charset();
611 virtual const charset_info_st *compare_collation();
612
613 virtual bool walk(Item_processor processor,
614 bool walk_subquery,
615 unsigned char *arg);
616
631 virtual Item* transform(Item_transformer transformer, unsigned char *arg);
632
651 virtual Item* compile(Item_analyzer analyzer,
652 unsigned char **arg_p,
653 Item_transformer transformer,
654 unsigned char *arg_t);
655
656 virtual void traverse_cond(Cond_traverser traverser,
657 void *arg,
658 traverse_order order);
659
660 virtual bool remove_dependence_processor(unsigned char * arg);
661 virtual bool collect_item_field_processor(unsigned char * arg);
662 virtual bool find_item_in_field_list_processor(unsigned char *arg);
663 virtual bool change_context_processor(unsigned char *context);
664 virtual bool register_field_in_read_map(unsigned char *arg);
665 virtual bool subst_argument_checker(unsigned char **arg);
666
667 virtual bool cache_const_expr_analyzer(unsigned char **arg);
668 virtual Item* cache_const_expr_transformer(unsigned char *arg);
669
670 virtual Item *equal_fields_propagator(unsigned char * arg);
671 virtual bool set_no_const_sub(unsigned char *arg);
672 virtual Item *replace_equal_field(unsigned char * arg);
673
674 // Row emulation
675 virtual uint32_t cols();
676 virtual Item* element_index(uint32_t i);
677 virtual Item** addr(uint32_t i);
678 virtual bool check_cols(uint32_t c);
679 // It is not row => null inside is impossible
680 virtual bool null_inside();
681 // used in row subselects to get value of elements
682 virtual void bring_value();
683
695 Field *tmp_table_field_from_field_type(Table *table, bool fixed_length);
696
697 virtual Item *neg_transformer(Session *session);
698 virtual Item *update_value_transformer(unsigned char *select_arg);
699 virtual Item *safe_charset_converter(const charset_info_st * const tocs);
700 void delete_self();
701
708 virtual bool result_as_int64_t();
709 bool is_datetime();
710
729 virtual bool is_expensive();
730
731 String *check_well_formed_result(String *str, bool send_error= 0);
752 bool eq_by_collation(Item *item, bool binary_cmp, const charset_info_st * const cs);
753
754 inline uint32_t char_to_byte_length_safe(uint32_t char_length_arg, uint32_t mbmaxlen_arg)
755 {
756 uint64_t tmp= ((uint64_t) char_length_arg) * mbmaxlen_arg;
757 return (tmp > UINT32_MAX) ? (uint32_t) UINT32_MAX : (uint32_t) tmp;
758 }
759
760 uint32_t max_char_length() const;
761
762 void fix_char_length(uint32_t max_char_length_arg);
763
764protected:
765 Session &getSession()
766 {
767 return _session;
768 }
769
770private:
771 Session &_session;
772};
773
774namespace display {
775const std::string &type(Item::Type type);
776} /* namespace display */
777
778std::ostream& operator<<(std::ostream& output, const Item &item);
779
780} /* namespace drizzled */
781
783#include <drizzled/item/ident.h>
784
785namespace drizzled
786{
787
799void mark_as_dependent(Session *session,
800 Select_Lex *last,
801 Select_Lex *current,
802 Item_ident *resolved_item,
803 Item_ident *mark_item);
804
840Item** resolve_ref_in_select_and_group(Session *session, Item_ident *ref, Select_Lex *select);
841
862 Select_Lex *last_select,
863 Select_Lex *current_sel,
864 Field *found_field, Item *found_item,
865 Item_ident *resolved_item);
866
867extern void resolve_const_item(Session *session, Item **ref, Item *cmp_item);
875extern bool field_is_equal_to_item(Field *field,Item *item);
876
911 Table *table,
912 Item *item,
913 Item::Type type,
914 Item ***copy_func,
915 Field **from_field,
916 Field **def_field,
917 bool group,
918 bool modify_item,
919 bool make_copy_field,
920 uint32_t convert_blob_length);
921
922} /* namespace drizzled */
bool is_autogenerated_name
Definition item.h:138
virtual int64_t val_int()=0
bool fixed
Definition item.h:122
virtual double val_real()=0
virtual table_map not_null_tables() const
Definition item.h:468
int save_str_value_in_field(Field *field, String *result)
Definition item.cc:272
uint32_t name_length
Definition item.h:115
virtual bool const_during_execution() const
Definition item.h:505
bool null_value
Definition item.h:124
virtual bool const_item() const
Definition item.h:497
const char * name
Definition item.h:112
virtual bool basic_const_item() const
Definition item.h:476
Item_result cmp_context
Definition item.h:146
virtual type::Decimal * val_decimal(type::Decimal *decimal_buffer)=0
bool maybe_null
Definition item.h:123
void quick_fix_field()
Definition item.h:209
bool with_subselect
Definition item.h:144
virtual table_map used_tables() const
Definition item.h:453
uint64_t val_uint()
Definition item.h:311
virtual String * val_str(String *str)=0
String str_value
Definition item.h:109
virtual bool val_bool()
Definition item.cc:95
Convert from decimal to binary representation.
Definition common_fwd.h:215
TODO: Rename this file - func.h is stupid.
Field * create_tmp_field(Session *session, Table *table, Item *item, Item::Type type, Item ***copy_func, Field **from_field, Field **default_field, bool group, bool modify_item, bool make_copy_field, uint32_t convert_blob_length)
Definition item.cc:1677
void mark_select_range_as_dependent(Session *session, Select_Lex *last_select, Select_Lex *current_sel, Field *found_field, Item *found_item, Item_ident *resolved_item)
Definition item.cc:797
bool field_is_equal_to_item(Field *field, Item *item)
Definition item.cc:1486
Item ** resolve_ref_in_select_and_group(Session *session, Item_ident *ref, Select_Lex *select)
Definition item.cc:940
void mark_as_dependent(Session *session, Select_Lex *last, Select_Lex *current, Item_ident *resolved_item, Item_ident *mark_item)
Definition item.cc:772
Visibility Control Macros.
#define DRIZZLED_API
Definition visibility.h:38