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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
|
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
* vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
*
* Copyright (C) 2008 Sun Microsystems, Inc.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; version 2 of the License.
*
* 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 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
*/
#ifndef DRIZZLED_DTCOLLATION_H
#define DRIZZLED_DTCOLLATION_H
#include <drizzled/definitions.h>
#include <drizzled/visibility.h>
namespace drizzled
{
class Item;
struct charset_info_st;
class DRIZZLED_API DTCollation
{
public:
const charset_info_st *collation;
enum Derivation derivation;
DRIZZLED_LOCAL DTCollation();
DRIZZLED_LOCAL DTCollation(const charset_info_st * const collation_arg,
Derivation derivation_arg);
void set(DTCollation &dt);
void set(const charset_info_st * const collation_arg,
Derivation derivation_arg);
void set(const charset_info_st * const collation_arg);
void set(Derivation derivation_arg);
bool set(DTCollation &dt1, DTCollation &dt2, uint32_t flags= 0);
/**
Aggregate two collations together taking
into account their coercibility (aka derivation):.
0 == DERIVATION_EXPLICIT - an explicitly written COLLATE clause @n
1 == DERIVATION_NONE - a mix of two different collations @n
2 == DERIVATION_IMPLICIT - a column @n
3 == DERIVATION_COERCIBLE - a string constant.
The most important rules are:
-# If collations are the same:
chose this collation, and the strongest derivation.
-# If collations are different:
- Character sets may differ, but only if conversion without
data loss is possible. The caller provides flags whether
character set conversion attempts should be done. If no
flags are substituted, then the character sets must be the same.
Currently processed flags are:
MY_COLL_ALLOW_SUPERSET_CONV - allow conversion to a superset
MY_COLL_ALLOW_COERCIBLE_CONV - allow conversion of a coercible value
- two EXPLICIT collations produce an error, e.g. this is wrong:
CONCAT(expr1 collate latin1_swedish_ci, expr2 collate latin1_german_ci)
- the side with smaller derivation value wins,
i.e. a column is stronger than a string constant,
an explicit COLLATE clause is stronger than a column.
- if derivations are the same, we have DERIVATION_NONE,
we'll wait for an explicit COLLATE clause which possibly can
come from another argument later: for example, this is valid,
but we don't know yet when collecting the first two arguments:
@code
CONCAT(latin1_swedish_ci_column,
latin1_german1_ci_column,
expr COLLATE latin1_german2_ci)
@endcode
*/
DRIZZLED_LOCAL bool aggregate(DTCollation &dt, uint32_t flags= 0);
DRIZZLED_LOCAL const char *derivation_name() const;
};
bool agg_item_collations(DTCollation &c, const char *name,
Item **items, uint32_t nitems,
uint32_t flags, int item_sep);
bool agg_item_collations_for_comparison(DTCollation &c, const char *name,
Item **items, uint32_t nitems,
uint32_t flags);
/*
@note In Drizzle we have just one charset, so no conversion is required (though collation may).
Collect arguments' character sets together.
We allow to apply automatic character set conversion in some cases.
The conditions when conversion is possible are:
- arguments A and B have different charsets
- A wins according to coercibility rules
(i.e. a column is stronger than a string constant,
an explicit COLLATE clause is stronger than a column)
- character set of A is either superset for character set of B,
or B is a string constant which can be converted into the
character set of A without data loss.
If all of the above is true, then it's possible to convert
B into the character set of A, and then compare according
to the collation of A.
For functions with more than two arguments:
@code
collect(A,B,C) ::= collect(collect(A,B),C)
@endcode
Since this function calls Session::change_item_tree() on the passed Item **
pointers, it is necessary to pass the original Item **'s, not copies.
Otherwise their values will not be properly restored (see BUG#20769).
If the items are not consecutive (eg. args[2] and args[5]), use the
item_sep argument, ie.
@code
agg_item_charsets(coll, fname, &args[2], 2, flags, 3)
@endcode
*/
bool agg_item_charsets(DTCollation &c, const char *name,
Item **items, uint32_t nitems, uint32_t flags,
int item_sep);
void my_coll_agg_error(DTCollation &c1, DTCollation &c2, const char *fname);
void my_coll_agg_error(DTCollation &c1, DTCollation &c2, DTCollation &c3,
const char *fname);
void my_coll_agg_error(Item** args, uint32_t count, const char *fname,
int item_sep);
} /* namespace drizzled */
#endif /* DRIZZLED_DTCOLLATION_H */
|