drizzle
C++ MySQL-protocol-compatible database server
Loading...
Searching...
No Matches
character_sets.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
27CharacterSetsTool::CharacterSetsTool() :
28 plugin::TableFunction("DATA_DICTIONARY", "CHARACTER_SETS")
29{
30 add_field("CHARACTER_SET_NAME");
31 add_field("DEFAULT_COLLATE_NAME");
32 add_field("DESCRIPTION");
33 add_field("MAXLEN", plugin::TableFunction::NUMBER, 0, false);
34}
35
36CharacterSetsTool::Generator::Generator(Field **arg) :
37 plugin::TableFunction::Generator(arg),
38 character_set_iter(NULL),
39 is_char_primed(false)
40{
41}
42
43bool CharacterSetsTool::Generator::checkCharacterSet()
44{
45 if (character_set() && (character_set()->state & MY_CS_PRIMARY) &&
46 (character_set()->state & MY_CS_AVAILABLE) && not (character_set()->state & MY_CS_HIDDEN))
47 {
48 return false;
49 }
50
51 return true;
52}
53
54bool CharacterSetsTool::Generator::nextCharacterSetCore()
55{
56 if (is_char_primed)
57 {
58 character_set_iter++;
59 }
60 else
61 {
62 character_set_iter= all_charsets;
63 is_char_primed= true;
64 }
65
66 if (character_set_iter == all_charsets+255)
67 return false;
68
69 if (checkCharacterSet())
70 return false;
71
72 return true;
73}
74
75bool CharacterSetsTool::Generator::nextCharacterSet()
76{
77 while (not nextCharacterSetCore())
78 {
79 if (character_set_iter == all_charsets+255)
80 return false;
81 }
82
83 return true;
84}
85
86bool CharacterSetsTool::Generator::populate()
87{
88 if (nextCharacterSet())
89 {
90 fill();
91 return true;
92 }
93
94 return false;
95}
96
97void CharacterSetsTool::Generator::fill()
98{
99 const charset_info_st * const tmp_cs= character_set_iter[0];
100
101 /* CHARACTER_SET_NAME */
102 push(tmp_cs->csname);
103
104 /* DEFAULT_COLLATE_NAME */
105 push(tmp_cs->name);
106
107 /* DESCRIPTION */
108 push(tmp_cs->comment);
109
110 /* MAXLEN */
111 push(static_cast<int64_t>(tmp_cs->mbmaxlen));
112}
TODO: Rename this file - func.h is stupid.
STL namespace.