~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to plugin/info_schema/character_set.cc

  • Committer: Brian Aker
  • Date: 2010-01-22 00:53:13 UTC
  • Revision ID: brian@gaz-20100122005313-jmizcbcdi1lt4tcx
Revert db patch.

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