~drizzle-trunk/drizzle/development

584.4.1 by Monty Taylor
Split out DTCollation.
1
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
 *  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
3
 *
1999.6.1 by kalebral at gmail
update Copyright strings to a more common format to help with creating the master debian copyright file
4
 *  Copyright (C) 2008 Sun Microsystems, Inc.
584.4.1 by Monty Taylor
Split out DTCollation.
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
2234 by Brian Aker
Mass removal of ifdef/endif in favor of pragma once.
20
#pragma once
584.4.1 by Monty Taylor
Split out DTCollation.
21
2173.2.1 by Monty Taylor
Fixes incorrect usage of include
22
#include <drizzled/definitions.h>
23
#include <drizzled/visibility.h>
584.4.1 by Monty Taylor
Split out DTCollation.
24
2252.1.13 by Olaf van der Spek
Common fwd
25
namespace drizzled {
584.4.1 by Monty Taylor
Split out DTCollation.
26
2119.4.1 by Monty Taylor
Turns on -fvisibility=hidden by default. Symbols intended to be used by
27
class DRIZZLED_API DTCollation
28
{
584.4.1 by Monty Taylor
Split out DTCollation.
29
public:
2385.3.6 by Olaf van der Spek
cppcheck
30
  const charset_info_st* collation;
31
  Derivation derivation;
584.4.1 by Monty Taylor
Split out DTCollation.
32
2119.4.1 by Monty Taylor
Turns on -fvisibility=hidden by default. Symbols intended to be used by
33
  DRIZZLED_LOCAL DTCollation();
2385.3.6 by Olaf van der Spek
cppcheck
34
  DRIZZLED_LOCAL DTCollation(const charset_info_st*, Derivation);
584.4.1 by Monty Taylor
Split out DTCollation.
35
  void set(DTCollation &dt);
2385.3.6 by Olaf van der Spek
cppcheck
36
  void set(const charset_info_st*, Derivation);
37
  void set(const charset_info_st*);
584.4.1 by Monty Taylor
Split out DTCollation.
38
  void set(Derivation derivation_arg);
39
  bool set(DTCollation &dt1, DTCollation &dt2, uint32_t flags= 0);
40
41
/**
42
  Aggregate two collations together taking
43
  into account their coercibility (aka derivation):.
44
45
  0 == DERIVATION_EXPLICIT  - an explicitly written COLLATE clause @n
46
  1 == DERIVATION_NONE      - a mix of two different collations @n
47
  2 == DERIVATION_IMPLICIT  - a column @n
48
  3 == DERIVATION_COERCIBLE - a string constant.
49
50
  The most important rules are:
51
  -# If collations are the same:
52
  chose this collation, and the strongest derivation.
53
  -# If collations are different:
54
  - Character sets may differ, but only if conversion without
55
  data loss is possible. The caller provides flags whether
56
  character set conversion attempts should be done. If no
57
  flags are substituted, then the character sets must be the same.
58
  Currently processed flags are:
59
  MY_COLL_ALLOW_SUPERSET_CONV  - allow conversion to a superset
60
  MY_COLL_ALLOW_COERCIBLE_CONV - allow conversion of a coercible value
61
  - two EXPLICIT collations produce an error, e.g. this is wrong:
62
  CONCAT(expr1 collate latin1_swedish_ci, expr2 collate latin1_german_ci)
63
  - the side with smaller derivation value wins,
64
  i.e. a column is stronger than a string constant,
65
  an explicit COLLATE clause is stronger than a column.
66
  - if derivations are the same, we have DERIVATION_NONE,
67
  we'll wait for an explicit COLLATE clause which possibly can
68
  come from another argument later: for example, this is valid,
69
  but we don't know yet when collecting the first two arguments:
70
     @code
71
       CONCAT(latin1_swedish_ci_column,
72
              latin1_german1_ci_column,
73
              expr COLLATE latin1_german2_ci)
74
  @endcode
75
*/
76
2119.4.1 by Monty Taylor
Turns on -fvisibility=hidden by default. Symbols intended to be used by
77
  DRIZZLED_LOCAL bool aggregate(DTCollation &dt, uint32_t flags= 0);
584.4.1 by Monty Taylor
Split out DTCollation.
78
2119.4.1 by Monty Taylor
Turns on -fvisibility=hidden by default. Symbols intended to be used by
79
  DRIZZLED_LOCAL const char *derivation_name() const;
584.4.1 by Monty Taylor
Split out DTCollation.
80
81
};
82
83
84
bool agg_item_collations(DTCollation &c, const char *name,
85
                         Item **items, uint32_t nitems,
86
                         uint32_t flags, int item_sep);
87
bool agg_item_collations_for_comparison(DTCollation &c, const char *name,
88
                                        Item **items, uint32_t nitems,
89
                                        uint32_t flags);
90
1578.6.4 by Brian Aker
Factor out conversion of charset (since we don't have more then one...).
91
/*
92
93
 @note In Drizzle we have just one charset, so no conversion is required (though collation may).
94
584.4.1 by Monty Taylor
Split out DTCollation.
95
  Collect arguments' character sets together.
96
97
  We allow to apply automatic character set conversion in some cases.
98
  The conditions when conversion is possible are:
99
  - arguments A and B have different charsets
100
  - A wins according to coercibility rules
101
    (i.e. a column is stronger than a string constant,
102
     an explicit COLLATE clause is stronger than a column)
103
  - character set of A is either superset for character set of B,
104
    or B is a string constant which can be converted into the
105
    character set of A without data loss.
106
107
  If all of the above is true, then it's possible to convert
108
  B into the character set of A, and then compare according
109
  to the collation of A.
110
111
  For functions with more than two arguments:
112
  @code
113
    collect(A,B,C) ::= collect(collect(A,B),C)
114
  @endcode
115
  Since this function calls Session::change_item_tree() on the passed Item **
116
  pointers, it is necessary to pass the original Item **'s, not copies.
117
  Otherwise their values will not be properly restored (see BUG#20769).
118
  If the items are not consecutive (eg. args[2] and args[5]), use the
119
  item_sep argument, ie.
120
  @code
121
    agg_item_charsets(coll, fname, &args[2], 2, flags, 3)
122
  @endcode
123
*/
124
bool agg_item_charsets(DTCollation &c, const char *name,
125
                       Item **items, uint32_t nitems, uint32_t flags,
126
                       int item_sep);
127
128
129
void my_coll_agg_error(DTCollation &c1, DTCollation &c2, const char *fname);
130
void my_coll_agg_error(DTCollation &c1, DTCollation &c2, DTCollation &c3,
131
                       const char *fname);
132
void my_coll_agg_error(Item** args, uint32_t count, const char *fname,
133
                       int item_sep);
134
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
135
} /* namespace drizzled */
136