1
/* - mode: c; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
* vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
4
* Copyright (C) 2009 Sun Microsystems
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.
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.
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
23
* Character Set I_S table methods.
26
#include "drizzled/server_includes.h"
27
#include "drizzled/session.h"
28
#include "drizzled/show.h"
30
#include "helper_methods.h"
31
#include "character_set.h"
35
using namespace drizzled;
39
* Vectors of columns for the character set I_S table.
41
static vector<const plugin::ColumnInfo *> *columns= NULL;
44
* Methods for the character set I_S table.
46
static plugin::InfoSchemaMethods *methods= NULL;
49
* character set I_S table.
51
static plugin::InfoSchemaTable *char_set_table= NULL;
54
* Populate the vectors of columns for the I_S table.
56
* @return false on success; true on failure.
58
vector<const plugin::ColumnInfo *> *CharacterSetIS::createColumns()
62
columns= new vector<const plugin::ColumnInfo *>;
66
clearColumns(*columns);
70
* Create each column for the CHARACTER_SET table.
72
columns->push_back(new plugin::ColumnInfo("CHARACTER_SET_NAME",
80
columns->push_back(new plugin::ColumnInfo("DEFAULT_COLLATE_NAME",
88
columns->push_back(new plugin::ColumnInfo("DESCRIPTION",
96
columns->push_back(new plugin::ColumnInfo("MAXLEN",
98
DRIZZLE_TYPE_LONGLONG,
108
* Initialize the I_S table.
110
* @return a pointer to an I_S table
112
plugin::InfoSchemaTable *CharacterSetIS::getTable()
114
columns= createColumns();
118
methods= new CharSetISMethods();
121
if (char_set_table == NULL)
123
char_set_table= new plugin::InfoSchemaTable("CHARACTER_SETS",
125
-1, -1, false, false, 0,
129
return char_set_table;
133
* Delete memory allocated for the table, columns and methods.
135
void CharacterSetIS::cleanup()
137
clearColumns(*columns);
138
delete char_set_table;
143
int CharSetISMethods::fillTable(Session *session, TableList *tables)
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;
150
for (cs= all_charsets ; cs < all_charsets+255 ; cs++)
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) &&
157
wild_case_compare(scs, tmp_cs->csname,wild)))
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))
173
int CharSetISMethods::oldFormat(Session *session, drizzled::plugin::InfoSchemaTable *schema_table)
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;
182
for (; *field_num >= 0; field_num++)
184
column= tab_columns[*field_num];
185
Item_field *field= new Item_field(context,
186
NULL, NULL, column->getName().c_str());
189
field->set_name(column->getOldName().c_str(),
190
column->getOldName().length(),
191
system_charset_info);
192
if (session->add_item_to_list(field))