~mordred/drizzle/add-drizzle-namespace

« back to all changes in this revision

Viewing changes to plugin/info_schema/character_set.cc

MergedĀ fromĀ me.

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) 2009 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
/**
 
22
 * @file 
 
23
 *   Character Set I_S table methods.
 
24
 */
 
25
 
 
26
#include "drizzled/server_includes.h"
 
27
#include "drizzled/session.h"
 
28
#include "drizzled/show.h"
 
29
 
 
30
#include "helper_methods.h"
 
31
#include "character_set.h"
 
32
 
 
33
#include <vector>
 
34
 
 
35
using namespace drizzled;
 
36
using namespace std;
 
37
 
 
38
/*
 
39
 * Vectors of columns for the character set I_S table.
 
40
 */
 
41
static vector<const plugin::ColumnInfo *> *columns= NULL;
 
42
 
 
43
/*
 
44
 * Methods for the character set I_S table.
 
45
 */
 
46
static plugin::InfoSchemaMethods *methods= NULL;
 
47
 
 
48
/*
 
49
 * character set I_S table.
 
50
 */
 
51
static plugin::InfoSchemaTable *char_set_table= NULL;
 
52
 
 
53
/**
 
54
 * Populate the vectors of columns for the I_S table.
 
55
 *
 
56
 * @return false on success; true on failure.
 
57
 */
 
58
vector<const plugin::ColumnInfo *> *CharacterSetIS::createColumns()
 
59
{
 
60
  if (columns == NULL)
 
61
  {
 
62
    columns= new vector<const plugin::ColumnInfo *>;
 
63
  }
 
64
  else
 
65
  {
 
66
    clearColumns(*columns);
 
67
  }
 
68
 
 
69
  /*
 
70
   * Create each column for the CHARACTER_SET table.
 
71
   */
 
72
  columns->push_back(new plugin::ColumnInfo("CHARACTER_SET_NAME",
 
73
                                            64,
 
74
                                            DRIZZLE_TYPE_VARCHAR,
 
75
                                            0,
 
76
                                            0,
 
77
                                            "Charset",
 
78
                                            SKIP_OPEN_TABLE));
 
79
 
 
80
  columns->push_back(new plugin::ColumnInfo("DEFAULT_COLLATE_NAME",
 
81
                                            64,
 
82
                                            DRIZZLE_TYPE_VARCHAR,
 
83
                                            0,
 
84
                                            0,
 
85
                                            "Default collation",
 
86
                                            SKIP_OPEN_TABLE));
 
87
 
 
88
  columns->push_back(new plugin::ColumnInfo("DESCRIPTION",
 
89
                                            60,
 
90
                                            DRIZZLE_TYPE_VARCHAR,
 
91
                                            0,
 
92
                                            0,
 
93
                                            "Description",
 
94
                                            SKIP_OPEN_TABLE));
 
95
 
 
96
  columns->push_back(new plugin::ColumnInfo("MAXLEN",
 
97
                                            3,
 
98
                                            DRIZZLE_TYPE_LONGLONG,
 
99
                                            0,
 
100
                                            0,
 
101
                                            "Maxlen",
 
102
                                            SKIP_OPEN_TABLE));
 
103
 
 
104
  return columns;
 
105
}
 
106
 
 
107
/**
 
108
 * Initialize the I_S table.
 
109
 *
 
110
 * @return a pointer to an I_S table
 
111
 */
 
112
plugin::InfoSchemaTable *CharacterSetIS::getTable()
 
113
{
 
114
  columns= createColumns();
 
115
 
 
116
  if (methods == NULL)
 
117
  {
 
118
    methods= new CharSetISMethods();
 
119
  }
 
120
 
 
121
  if (char_set_table == NULL)
 
122
  {
 
123
    char_set_table= new plugin::InfoSchemaTable("CHARACTER_SETS",
 
124
                                                *columns,
 
125
                                                -1, -1, false, false, 0,
 
126
                                                methods);
 
127
  }
 
128
 
 
129
  return char_set_table;
 
130
}
 
131
 
 
132
/**
 
133
 * Delete memory allocated for the table, columns and methods.
 
134
 */
 
135
void CharacterSetIS::cleanup()
 
136
{
 
137
  clearColumns(*columns);
 
138
  delete char_set_table;
 
139
  delete methods;
 
140
  delete columns;
 
141
}
 
142
 
 
143
int CharSetISMethods::fillTable(Session *session, TableList *tables)
 
144
{
 
145
  CHARSET_INFO **cs;
 
146
  const char *wild= session->lex->wild ? session->lex->wild->ptr() : NULL;
 
147
  Table *table= tables->table;
 
148
  const CHARSET_INFO * const scs= system_charset_info;
 
149
 
 
150
  for (cs= all_charsets ; cs < all_charsets+255 ; cs++)
 
151
  {
 
152
    const CHARSET_INFO * const tmp_cs= cs[0];
 
153
    if (tmp_cs && (tmp_cs->state & MY_CS_PRIMARY) &&
 
154
        (tmp_cs->state & MY_CS_AVAILABLE) &&
 
155
        !(tmp_cs->state & MY_CS_HIDDEN) &&
 
156
        !(wild && wild[0] &&
 
157
          wild_case_compare(scs, tmp_cs->csname,wild)))
 
158
    {
 
159
      const char *comment;
 
160
      table->restoreRecordAsDefault();
 
161
      table->field[0]->store(tmp_cs->csname, strlen(tmp_cs->csname), scs);
 
162
      table->field[1]->store(tmp_cs->name, strlen(tmp_cs->name), scs);
 
163
      comment= tmp_cs->comment ? tmp_cs->comment : "";
 
164
      table->field[2]->store(comment, strlen(comment), scs);
 
165
      table->field[3]->store((int64_t) tmp_cs->mbmaxlen, true);
 
166
      if (schema_table_store_record(session, table))
 
167
        return 1;
 
168
    }
 
169
  }
 
170
  return 0;
 
171
}
 
172
 
 
173
int CharSetISMethods::oldFormat(Session *session, drizzled::plugin::InfoSchemaTable *schema_table)
 
174
  const
 
175
{
 
176
  int fields_arr[]= {0, 2, 1, 3, -1};
 
177
  int *field_num= fields_arr;
 
178
  const drizzled::plugin::InfoSchemaTable::Columns tab_columns= schema_table->getColumns();
 
179
  const drizzled::plugin::ColumnInfo *column= NULL;
 
180
  Name_resolution_context *context= &session->lex->select_lex.context;
 
181
 
 
182
  for (; *field_num >= 0; field_num++)
 
183
  {
 
184
    column= tab_columns[*field_num];
 
185
    Item_field *field= new Item_field(context,
 
186
                                      NULL, NULL, column->getName().c_str());
 
187
    if (field)
 
188
    {
 
189
      field->set_name(column->getOldName().c_str(),
 
190
                      column->getOldName().length(),
 
191
                      system_charset_info);
 
192
      if (session->add_item_to_list(field))
 
193
        return 1;
 
194
    }
 
195
  }
 
196
  return 0;
 
197
}