1
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
* vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
4
* Copyright (C) 2008 Sun Microsystems
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.
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.
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
20
#ifndef DRIZZLED_DTCOLLATION_H
21
#define DRIZZLED_DTCOLLATION_H
25
#include <drizzled/definitions.h>
28
typedef struct charset_info_st CHARSET_INFO;
33
const CHARSET_INFO *collation;
34
enum Derivation derivation;
37
DTCollation(const CHARSET_INFO * const collation_arg,
38
Derivation derivation_arg);
39
void set(DTCollation &dt);
40
void set(const CHARSET_INFO * const collation_arg,
41
Derivation derivation_arg);
42
void set(const CHARSET_INFO * const collation_arg);
43
void set(Derivation derivation_arg);
44
bool set(DTCollation &dt1, DTCollation &dt2, uint32_t flags= 0);
47
Aggregate two collations together taking
48
into account their coercibility (aka derivation):.
50
0 == DERIVATION_EXPLICIT - an explicitly written COLLATE clause @n
51
1 == DERIVATION_NONE - a mix of two different collations @n
52
2 == DERIVATION_IMPLICIT - a column @n
53
3 == DERIVATION_COERCIBLE - a string constant.
55
The most important rules are:
56
-# If collations are the same:
57
chose this collation, and the strongest derivation.
58
-# If collations are different:
59
- Character sets may differ, but only if conversion without
60
data loss is possible. The caller provides flags whether
61
character set conversion attempts should be done. If no
62
flags are substituted, then the character sets must be the same.
63
Currently processed flags are:
64
MY_COLL_ALLOW_SUPERSET_CONV - allow conversion to a superset
65
MY_COLL_ALLOW_COERCIBLE_CONV - allow conversion of a coercible value
66
- two EXPLICIT collations produce an error, e.g. this is wrong:
67
CONCAT(expr1 collate latin1_swedish_ci, expr2 collate latin1_german_ci)
68
- the side with smaller derivation value wins,
69
i.e. a column is stronger than a string constant,
70
an explicit COLLATE clause is stronger than a column.
71
- if derivations are the same, we have DERIVATION_NONE,
72
we'll wait for an explicit COLLATE clause which possibly can
73
come from another argument later: for example, this is valid,
74
but we don't know yet when collecting the first two arguments:
76
CONCAT(latin1_swedish_ci_column,
77
latin1_german1_ci_column,
78
expr COLLATE latin1_german2_ci)
82
bool aggregate(DTCollation &dt, uint32_t flags= 0);
84
const char *derivation_name() const;
89
bool agg_item_collations(DTCollation &c, const char *name,
90
Item **items, uint32_t nitems,
91
uint32_t flags, int item_sep);
92
bool agg_item_collations_for_comparison(DTCollation &c, const char *name,
93
Item **items, uint32_t nitems,
97
Collect arguments' character sets together.
99
We allow to apply automatic character set conversion in some cases.
100
The conditions when conversion is possible are:
101
- arguments A and B have different charsets
102
- A wins according to coercibility rules
103
(i.e. a column is stronger than a string constant,
104
an explicit COLLATE clause is stronger than a column)
105
- character set of A is either superset for character set of B,
106
or B is a string constant which can be converted into the
107
character set of A without data loss.
109
If all of the above is true, then it's possible to convert
110
B into the character set of A, and then compare according
111
to the collation of A.
113
For functions with more than two arguments:
115
collect(A,B,C) ::= collect(collect(A,B),C)
117
Since this function calls Session::change_item_tree() on the passed Item **
118
pointers, it is necessary to pass the original Item **'s, not copies.
119
Otherwise their values will not be properly restored (see BUG#20769).
120
If the items are not consecutive (eg. args[2] and args[5]), use the
121
item_sep argument, ie.
123
agg_item_charsets(coll, fname, &args[2], 2, flags, 3)
126
bool agg_item_charsets(DTCollation &c, const char *name,
127
Item **items, uint32_t nitems, uint32_t flags,
131
void my_coll_agg_error(DTCollation &c1, DTCollation &c2, const char *fname);
132
void my_coll_agg_error(DTCollation &c1, DTCollation &c2, DTCollation &c3,
134
void my_coll_agg_error(Item** args, uint32_t count, const char *fname,
137
#endif /* DRIZZLED_DTCOLLATION_H */