1 | /* -*- c-basic-offset: 2 -*- */ |
2 | /* |
3 | Copyright(C) 2013 Kouhei Sutou <kou@clear-code.com> |
4 | |
5 | This library is free software; you can redistribute it and/or |
6 | modify it under the terms of the GNU Lesser General Public |
7 | License as published by the Free Software Foundation; either |
8 | version 2.1 of the License, or (at your option) any later version. |
9 | |
10 | This library 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 GNU |
13 | Lesser General Public License for more details. |
14 | |
15 | You should have received a copy of the GNU Lesser General Public |
16 | License along with this library; if not, write to the Free Software |
17 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
18 | */ |
19 | |
20 | #ifndef MRN_CONDITION_CONVERTER_HPP_ |
21 | #define MRN_CONDITION_CONVERTER_HPP_ |
22 | |
23 | #include <mrn_mysql_compat.h> |
24 | |
25 | #include <item_cmpfunc.h> |
26 | |
27 | #include <groonga.h> |
28 | |
29 | namespace mrn { |
30 | class ConditionConverter { |
31 | public: |
32 | ConditionConverter(grn_ctx *ctx, grn_obj *table, bool is_storage_mode); |
33 | ~ConditionConverter(); |
34 | |
35 | bool is_convertable(const Item *item); |
36 | unsigned int count_match_against(const Item *item); |
37 | // caller must check "where" can be convertable by |
38 | // is_convertable(). This method doesn't validate "where". |
39 | void convert(const Item *where, grn_obj *expression); |
40 | |
41 | private: |
42 | enum NormalizedType { |
43 | STRING_TYPE, |
44 | INT_TYPE, |
45 | TIME_TYPE, |
46 | UNSUPPORTED_TYPE, |
47 | }; |
48 | |
49 | grn_ctx *ctx_; |
50 | grn_obj *table_; |
51 | bool is_storage_mode_; |
52 | grn_obj column_name_; |
53 | grn_obj value_; |
54 | |
55 | bool is_convertable(const Item_cond *cond_item); |
56 | bool is_convertable(const Item_func *func_item); |
57 | bool is_convertable_binary_operation(const Item_field *field_item, |
58 | Item *value_item, |
59 | Item_func::Functype func_type); |
60 | bool is_convertable_between(const Item_field *field_item, |
61 | Item *min_item, |
62 | Item *max_item); |
63 | bool is_valid_time_value(const Item_field *field_item, |
64 | Item *value_item); |
65 | bool get_time_value(const Item_field *field_item, |
66 | Item *value_item, |
67 | MYSQL_TIME *mysql_time); |
68 | bool have_index(const Item_field *field_item, grn_operator _operator); |
69 | bool have_index(const Item_field *field_item, Item_func::Functype func_type); |
70 | |
71 | NormalizedType normalize_field_type(enum_field_types field_type); |
72 | |
73 | void convert_binary_operation(const Item_func *func_item, |
74 | grn_obj *expression, |
75 | grn_operator _operator); |
76 | void convert_between(const Item_func *func_item, grn_obj *expression); |
77 | void append_field_value(const Item_field *field_item, |
78 | grn_obj *expression); |
79 | void append_const_item(const Item_field *field_item, |
80 | Item *const_item, |
81 | grn_obj *expression); |
82 | }; |
83 | } |
84 | |
85 | #endif /* MRN_CONDITION_CONVERTER_HPP_ */ |
86 | |