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