forked from alibaba/AliSQL
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcomponent.cc
More file actions
127 lines (101 loc) · 4.21 KB
/
component.cc
File metadata and controls
127 lines (101 loc) · 4.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
/*****************************************************************************
Copyright (c) 2025, Alibaba and/or its affiliates. All Rights Reserved.
This program is free software; you can redistribute it and/or modify it under
the terms of the GNU General Public License, version 2.0, as published by the
Free Software Foundation.
This program is also distributed with certain software (including but not
limited to OpenSSL) that is licensed under separate terms, as designated in a
particular file or component or in included license documentation. The authors
of MySQL hereby grant you an additional permission to link the program and
your derivative works with the separately licensed software that they have
included with MySQL.
This program is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
FOR A PARTICULAR PURPOSE. See the GNU General Public License, version 2.0,
for more details.
You should have received a copy of the GNU General Public License along with
this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*****************************************************************************/
#include "sql/common/component.h"
#include <boost/algorithm/string/case_conv.hpp>
#include "sql/sql_class.h"
#include "sql/item.h"
#include "sql/item_timefunc.h"
namespace im {
template <typename F, typename S>
bool Pair_key_comparator<F, S>::operator()(
const Pair_key_type<F, S> &lhs, const Pair_key_type<F, S> &rhs) const {
return (strcmp(lhs.first.c_str(), rhs.first.c_str()) == 0 &&
strcmp(lhs.second.c_str(), rhs.second.c_str()) == 0);
}
template bool Pair_key_comparator<std::string, std::string>::operator()(
const Pair_key_type<std::string, std::string> &lhs,
const Pair_key_type<std::string, std::string> &rhs) const;
/* String compare ignoring case */
template <typename F, typename S>
bool Pair_key_icase_comparator<F, S>::operator()(
const Pair_key_type<F, S> &lhs, const Pair_key_type<F, S> &rhs) const {
F l_f = lhs.first;
S l_s = lhs.second;
F r_f = rhs.first;
S r_s = rhs.second;
boost::algorithm::to_upper(l_f);
boost::algorithm::to_upper(l_s);
boost::algorithm::to_upper(r_f);
boost::algorithm::to_upper(r_s);
return (l_f.compare(r_f) == 0 && l_s.compare(r_s) == 0);
}
template bool Pair_key_icase_comparator<std::string, std::string>::operator()(
const Pair_key_type<std::string, std::string> &lhs,
const Pair_key_type<std::string, std::string> &rhs) const;
template <typename F, typename S>
size_t Pair_key_icase_hash<F, S>::operator()(
const im::Pair_key_type<F, S> &p) const {
F s1 = p.first;
S s2 = p.second;
boost::algorithm::to_upper(s1);
boost::algorithm::to_upper(s2);
return std::hash<F>()(static_cast<const F>(s1)) ^
std::hash<S>()(static_cast<const S>(s2));
}
template size_t Pair_key_icase_hash<std::string, std::string>::operator()(
const im::Pair_key_type<std::string, std::string> &p) const;
} /* namespace im */
namespace std {
template<typename F, typename S>
size_t hash<im::Pair_key_type<F, S>>::operator()(
const im::Pair_key_type<F, S> &p) const {
return hash<F>()(static_cast<const F>(p.first)) ^
hash<S>()(static_cast<const S>(p.second));
}
template size_t hash<im::Pair_key_type<std::string, std::string>>::operator()(
const im::Pair_key_type<std::string, std::string> &p) const;
} /* namespace std */
static bool is_string_item(Item *item) {
switch (item->data_type()) {
case MYSQL_TYPE_VARCHAR:
case MYSQL_TYPE_TINY_BLOB:
case MYSQL_TYPE_MEDIUM_BLOB:
case MYSQL_TYPE_LONG_BLOB:
case MYSQL_TYPE_BLOB:
case MYSQL_TYPE_VAR_STRING:
case MYSQL_TYPE_STRING:
return true;
default:
return false;
}
}
bool try_cast_to_datetime(THD *thd, Item **item) {
Item *cast;
/* String could be casted to datetime */
if (!is_string_item(*item)) return true;
assert(thd);
if (!(cast = new (thd->mem_root) Item_typecast_datetime(*item, true)))
return true;
/* If cannot cast, errors will be raised when evaluating */
cast->fix_fields(thd, item);
/* No need to register to the thd->change_list */
*item = cast;
return false;
}