~drizzle-trunk/drizzle/development

1273.13.3 by Brian Aker
Added character sets.
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) 2010 Sun Microsystems, Inc.
1273.13.3 by Brian Aker
Added character sets.
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
2173.2.1 by Monty Taylor
Fixes incorrect usage of include
21
#include <config.h>
22
#include <plugin/collation_dictionary/dictionary.h>
1273.13.3 by Brian Aker
Added character sets.
23
24
using namespace std;
25
using namespace drizzled;
26
1273.13.7 by Brian Aker
Updates to the classes (first pass).
27
CharacterSetsTool::CharacterSetsTool() :
1273.13.32 by Brian Aker
Big ole patch. This covers moving information_schema to old_* table names
28
  plugin::TableFunction("DATA_DICTIONARY", "CHARACTER_SETS")
1273.13.3 by Brian Aker
Added character sets.
29
{
1273.13.18 by Brian Aker
Update code, first pass through cleaner method for recursing through
30
  add_field("CHARACTER_SET_NAME");
31
  add_field("DEFAULT_COLLATE_NAME");
32
  add_field("DESCRIPTION");
1643.3.10 by Brian Aker
Column support, clean up of IS/DD for NULL type.
33
  add_field("MAXLEN", plugin::TableFunction::NUMBER, 0, false);
1273.13.3 by Brian Aker
Added character sets.
34
}
35
1273.13.18 by Brian Aker
Update code, first pass through cleaner method for recursing through
36
CharacterSetsTool::Generator::Generator(Field **arg) :
1273.13.69 by Brian Aker
Monty's fixes, my rewrite of collations dictionary.
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;
1273.13.3 by Brian Aker
Added character sets.
83
}
84
1273.13.21 by Brian Aker
Fix interface (we no longer need Fields passed around).
85
bool CharacterSetsTool::Generator::populate()
1273.13.3 by Brian Aker
Added character sets.
86
{
1273.13.69 by Brian Aker
Monty's fixes, my rewrite of collations dictionary.
87
  if (nextCharacterSet())
1273.13.3 by Brian Aker
Added character sets.
88
  {
1273.13.69 by Brian Aker
Monty's fixes, my rewrite of collations dictionary.
89
    fill();
90
    return true;
1273.13.3 by Brian Aker
Added character sets.
91
  }
92
93
  return false;
94
}
1273.13.69 by Brian Aker
Monty's fixes, my rewrite of collations dictionary.
95
96
void CharacterSetsTool::Generator::fill()
97
{
2254 by Brian Aker
Shift CHARSET_INFO to charset_info_st
98
  const charset_info_st * const tmp_cs= character_set_iter[0];
1273.13.69 by Brian Aker
Monty's fixes, my rewrite of collations dictionary.
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 */
1273.13.82 by Brian Aker
Revert OSX fix, requiring more cast.
110
  push(static_cast<int64_t>(tmp_cs->mbmaxlen));
1273.13.69 by Brian Aker
Monty's fixes, my rewrite of collations dictionary.
111
}