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.
27
#include "drizzled/session.h"
28
#include "drizzled/show.h"
29
#include "drizzled/charset.h"
31
#include "helper_methods.h"
32
#include "character_set.h"
36
using namespace drizzled;
40
* Vectors of columns for the character set I_S table.
42
static vector<const plugin::ColumnInfo *> *columns= NULL;
45
* Methods for the character set I_S table.
47
static plugin::InfoSchemaMethods *methods= NULL;
50
* character set I_S table.
52
static plugin::InfoSchemaTable *char_set_table= NULL;
55
* Populate the vectors of columns for the I_S table.
57
* @return false on success; true on failure.
59
vector<const plugin::ColumnInfo *> *CharacterSetIS::createColumns()
63
columns= new vector<const plugin::ColumnInfo *>;
67
clearColumns(*columns);
71
* Create each column for the CHARACTER_SET table.
73
columns->push_back(new plugin::ColumnInfo("CHARACTER_SET_NAME",
80
columns->push_back(new plugin::ColumnInfo("DEFAULT_COLLATE_NAME",
85
"Default collation"));
87
columns->push_back(new plugin::ColumnInfo("DESCRIPTION",
94
columns->push_back(new plugin::ColumnInfo("MAXLEN",
96
DRIZZLE_TYPE_LONGLONG,
105
* Initialize the I_S table.
107
* @return a pointer to an I_S table
109
plugin::InfoSchemaTable *CharacterSetIS::getTable()
111
columns= createColumns();
115
methods= new CharSetISMethods();
118
if (char_set_table == NULL)
120
char_set_table= new plugin::InfoSchemaTable("CHARACTER_SETS",
122
-1, -1, false, false, 0,
126
return char_set_table;
130
* Delete memory allocated for the table, columns and methods.
132
void CharacterSetIS::cleanup()
134
clearColumns(*columns);
135
delete char_set_table;
140
int CharSetISMethods::fillTable(Session *session,
142
plugin::InfoSchemaTable *schema_table)
145
const char *wild= session->lex->wild ? session->lex->wild->ptr() : NULL;
146
const CHARSET_INFO * const scs= system_charset_info;
148
for (cs= all_charsets ; cs < all_charsets+255 ; cs++)
150
const CHARSET_INFO * const tmp_cs= cs[0];
151
if (tmp_cs && (tmp_cs->state & MY_CS_PRIMARY) &&
152
(tmp_cs->state & MY_CS_AVAILABLE) &&
153
!(tmp_cs->state & MY_CS_HIDDEN) &&
155
wild_case_compare(scs, tmp_cs->csname,wild)))
158
table->restoreRecordAsDefault();
159
table->setWriteSet(0);
160
table->setWriteSet(1);
161
table->setWriteSet(2);
162
table->setWriteSet(3);
163
table->field[0]->store(tmp_cs->csname, strlen(tmp_cs->csname), scs);
164
table->field[1]->store(tmp_cs->name, strlen(tmp_cs->name), scs);
165
comment= tmp_cs->comment ? tmp_cs->comment : "";
166
table->field[2]->store(comment, strlen(comment), scs);
167
table->field[3]->store((int64_t) tmp_cs->mbmaxlen, true);
168
schema_table->addRow(table->record[0], table->s->reclength);
174
int CharSetISMethods::oldFormat(Session *session, drizzled::plugin::InfoSchemaTable *schema_table)
177
int fields_arr[]= {0, 2, 1, 3, -1};
178
int *field_num= fields_arr;
179
const drizzled::plugin::InfoSchemaTable::Columns tab_columns= schema_table->getColumns();
180
const drizzled::plugin::ColumnInfo *column= NULL;
181
Name_resolution_context *context= &session->lex->select_lex.context;
183
for (; *field_num >= 0; field_num++)
185
column= tab_columns[*field_num];
186
Item_field *field= new Item_field(context,
187
NULL, NULL, column->getName().c_str());
190
field->set_name(column->getOldName().c_str(),
191
column->getOldName().length(),
192
system_charset_info);
193
if (session->add_item_to_list(field))