~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to plugin/collation_dictionary/character_sets.cc

  • Committer: Monty Taylor
  • Date: 2010-03-11 18:27:20 UTC
  • mfrom: (1333 staging)
  • mto: This revision was merged to the branch mainline in revision 1348.
  • Revision ID: mordred@inaugust.com-20100311182720-hd1h87y6cb1b1mp0
Merged trunk.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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
 
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
 
 
24
using namespace std;
 
25
using namespace drizzled;
 
26
 
 
27
CharacterSetsTool::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);
 
34
}
 
35
 
 
36
CharacterSetsTool::Generator::Generator(Field **arg) :
 
37
  plugin::TableFunction::Generator(arg),
 
38
  is_char_primed(false)
 
39
{
 
40
}
 
41
 
 
42
bool CharacterSetsTool::Generator::checkCharacterSet()
 
43
{
 
44
  if (character_set() && (character_set()->state & MY_CS_PRIMARY) &&
 
45
      (character_set()->state & MY_CS_AVAILABLE) && not (character_set()->state & MY_CS_HIDDEN))
 
46
  {
 
47
    return false;
 
48
  }
 
49
 
 
50
  return true;
 
51
}
 
52
 
 
53
bool CharacterSetsTool::Generator::nextCharacterSetCore()
 
54
{
 
55
  if (is_char_primed)
 
56
  {
 
57
    character_set_iter++;
 
58
  }
 
59
  else
 
60
  {
 
61
    character_set_iter= all_charsets;
 
62
    is_char_primed= true;
 
63
  }
 
64
 
 
65
  if (character_set_iter == all_charsets+255)
 
66
    return false;
 
67
 
 
68
  if (checkCharacterSet())
 
69
      return false;
 
70
 
 
71
  return true;
 
72
}
 
73
 
 
74
bool CharacterSetsTool::Generator::nextCharacterSet()
 
75
{
 
76
  while (not nextCharacterSetCore())
 
77
  {
 
78
    if (character_set_iter == all_charsets+255)
 
79
      return false;
 
80
  }
 
81
 
 
82
  return true;
 
83
}
 
84
 
 
85
bool CharacterSetsTool::Generator::populate()
 
86
{
 
87
  if (nextCharacterSet())
 
88
  {
 
89
    fill();
 
90
    return true;
 
91
  }
 
92
 
 
93
  return false;
 
94
}
 
95
 
 
96
void CharacterSetsTool::Generator::fill()
 
97
{
 
98
  const CHARSET_INFO * const tmp_cs= character_set_iter[0];
 
99
 
 
100
  /* CHARACTER_SET_NAME */
 
101
  push(tmp_cs->csname);
 
102
 
 
103
  /* DEFAULT_COLLATE_NAME */
 
104
  push(tmp_cs->name);
 
105
 
 
106
  /* DESCRIPTION */
 
107
  push(tmp_cs->comment);
 
108
 
 
109
  /* MAXLEN */
 
110
  push(static_cast<int64_t>(tmp_cs->mbmaxlen));
 
111
}