drizzle
C++ MySQL-protocol-compatible database server
Loading...
Searching...
No Matches
collations.cc
1/* - mode: c; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
3 *
4 * Copyright (C) 2010 Sun Microsystems, Inc.
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; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19 */
20
21#include <config.h>
22#include <plugin/collation_dictionary/dictionary.h>
23
24using namespace std;
25using namespace drizzled;
26
27
28CollationsTool::CollationsTool() :
29 CharacterSetsTool("COLLATIONS")
30{
31 add_field("CHARACTER_SET_NAME");
32 add_field("COLLATION_NAME");
33 add_field("DESCRIPTION");
34 add_field("ID", plugin::TableFunction::NUMBER, 0, false);
35 add_field("IS_DEFAULT", plugin::TableFunction::BOOLEAN, 0, false);
36 add_field("IS_COMPILED", plugin::TableFunction::BOOLEAN, 0, false);
37 add_field("SORTLEN", plugin::TableFunction::NUMBER, 0, false);
38}
39
40CollationsTool::Generator::Generator(Field **arg) :
41 CharacterSetsTool::Generator(arg),
42 collation_iter(NULL),
43 is_collation_primed(false)
44{
45}
46
47
48bool CollationsTool::Generator::end()
49{
50 return collation_iter == all_charsets+255;
51}
52
53
54bool CollationsTool::Generator::check()
55{
56 const charset_info_st *tmp_cs= character_set();
57 const charset_info_st *tmp_cl= collation();
58
59 if (not tmp_cl ||
60 not (tmp_cl->state & MY_CS_AVAILABLE) ||
61 not my_charset_same(tmp_cs, tmp_cl))
62 return true;
63
64 return false;
65}
66
67bool CollationsTool::Generator::nextCollationCore()
68{
69 if (isPrimed())
70 {
71 collation_iter++;
72 }
73 else
74 {
75 if (not isCharacterSetPrimed())
76 return false;
77
78 collation_iter= all_charsets;
79 prime();
80 }
81
82 if (end())
83 return false;
84
85 if (check())
86 return false;
87
88 return true;
89}
90
91
92bool CollationsTool::Generator::next()
93{
94 while (not nextCollationCore())
95 {
96
97 if (isPrimed() && not end())
98 continue;
99
100 if (not nextCharacterSet())
101 return false;
102
103 prime(false);
104 }
105
106 return true;
107}
108
109bool CollationsTool::Generator::populate()
110{
111 if (not next())
112 return false;
113
114 fill();
115
116 return true;
117}
118
119void CollationsTool::Generator::fill()
120{
121 const charset_info_st *tmp_cs= character_set();
122 const charset_info_st *tmp_cl= collation_iter[0];
123
124 assert(tmp_cs);
125 assert(tmp_cl);
126
127 assert(tmp_cs->name);
128 /* CHARACTER_SET_NAME */
129 push(tmp_cs->name);
130
131 /* "COLLATION_NAME" */
132 assert(tmp_cl->name);
133 push(tmp_cl->name);
134
135 /* "DESCRIPTION" */
136 push(tmp_cl->csname);
137
138 /* COLLATION_ID */
139 push(static_cast<int64_t>(tmp_cl->number));
140
141 /* IS_DEFAULT */
142 push((bool)(tmp_cl->state & MY_CS_PRIMARY));
143
144 /* IS_COMPILED */
145 push((bool)(tmp_cl->state & MY_CS_COMPILED));
146
147 /* SORTLEN */
148 push(static_cast<int64_t>(tmp_cl->strxfrm_multiply));
149}
TODO: Rename this file - func.h is stupid.
STL namespace.