~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to plugin/info_schema/collation.cc

  • Committer: Brian Aker
  • Date: 2009-11-18 23:28:30 UTC
  • mfrom: (1215.2.25 is-split)
  • Revision ID: brian@gaz-20091118232830-v28y7o26squz3c9c
Merge of Padraig

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 "collation.h"
 
32
 
 
33
#include <vector>
 
34
 
 
35
using namespace drizzled;
 
36
using namespace std;
 
37
 
 
38
/*
 
39
 * Vectors of columns for the collation I_S table.
 
40
 */
 
41
static vector<const plugin::ColumnInfo *> *columns= NULL;
 
42
 
 
43
/*
 
44
 * Methods for the collation I_S table.
 
45
 */
 
46
static plugin::InfoSchemaMethods *methods= NULL;
 
47
 
 
48
/*
 
49
 * collation I_S table.
 
50
 */
 
51
static plugin::InfoSchemaTable *coll_table= NULL;
 
52
 
 
53
/**
 
54
 * Populate the vectors of columns for the I_S table.
 
55
 *
 
56
 * @return a pointer to a std::vector of Columns.
 
57
 */
 
58
vector<const plugin::ColumnInfo *> *CollationIS::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 COLLATION table.
 
71
   */
 
72
  columns->push_back(new plugin::ColumnInfo("COLLATION_NAME",
 
73
                                            64,
 
74
                                            DRIZZLE_TYPE_VARCHAR,
 
75
                                            0,
 
76
                                            0,
 
77
                                            "Collation",
 
78
                                            SKIP_OPEN_TABLE));
 
79
 
 
80
  columns->push_back(new plugin::ColumnInfo("CHARACTER_SET_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
                                            "Charset",
 
94
                                            SKIP_OPEN_TABLE));
 
95
 
 
96
  columns->push_back(new plugin::ColumnInfo("ID",
 
97
                                            MY_INT32_NUM_DECIMAL_DIGITS,
 
98
                                            DRIZZLE_TYPE_LONGLONG,
 
99
                                            0,
 
100
                                            0,
 
101
                                            "Id",
 
102
                                            SKIP_OPEN_TABLE));
 
103
 
 
104
  columns->push_back(new plugin::ColumnInfo("IS_DEFAULT",
 
105
                                            3,
 
106
                                            DRIZZLE_TYPE_VARCHAR,
 
107
                                            0,
 
108
                                            0,
 
109
                                            "Default",
 
110
                                            SKIP_OPEN_TABLE));
 
111
 
 
112
  columns->push_back(new plugin::ColumnInfo("IS_COMPILED",
 
113
                                            3,
 
114
                                            DRIZZLE_TYPE_VARCHAR,
 
115
                                            0,
 
116
                                            0,
 
117
                                            "Compiled",
 
118
                                            SKIP_OPEN_TABLE));
 
119
 
 
120
  columns->push_back(new plugin::ColumnInfo("SORTLEN",
 
121
                                            3,
 
122
                                            DRIZZLE_TYPE_LONGLONG,
 
123
                                            0,
 
124
                                            0,
 
125
                                            "Sortlen",
 
126
                                            SKIP_OPEN_TABLE));
 
127
 
 
128
  return columns;
 
129
}
 
130
 
 
131
/**
 
132
 * Initialize the I_S table.
 
133
 *
 
134
 * @return a pointer to an I_S table
 
135
 */
 
136
plugin::InfoSchemaTable *CollationIS::getTable()
 
137
{
 
138
  columns= createColumns();
 
139
 
 
140
  if (methods == NULL)
 
141
  {
 
142
    methods= new CollationISMethods();
 
143
  }
 
144
 
 
145
  if (coll_table == NULL)
 
146
  {
 
147
    coll_table= new(nothrow) plugin::InfoSchemaTable("COLLATIONS",
 
148
                                                     *columns,
 
149
                                                     -1, -1, false, false, 0,
 
150
                                                     methods);
 
151
  }
 
152
 
 
153
  return coll_table;
 
154
}
 
155
 
 
156
/**
 
157
 * Delete memory allocated for the table, columns and methods.
 
158
 */
 
159
void CollationIS::cleanup()
 
160
{
 
161
  clearColumns(*columns);
 
162
  delete coll_table;
 
163
  delete methods;
 
164
  delete columns;
 
165
}
 
166
 
 
167
int CollationISMethods::fillTable(Session *session, TableList *tables)
 
168
{
 
169
  CHARSET_INFO **cs;
 
170
  const char *wild= session->lex->wild ? session->lex->wild->ptr() : NULL;
 
171
  Table *table= tables->table;
 
172
  const CHARSET_INFO * const scs= system_charset_info;
 
173
  for (cs= all_charsets ; cs < all_charsets+255 ; cs++ )
 
174
  {
 
175
    CHARSET_INFO **cl;
 
176
    const CHARSET_INFO *tmp_cs= cs[0];
 
177
    if (! tmp_cs || ! (tmp_cs->state & MY_CS_AVAILABLE) ||
 
178
         (tmp_cs->state & MY_CS_HIDDEN) ||
 
179
        !(tmp_cs->state & MY_CS_PRIMARY))
 
180
      continue;
 
181
    for (cl= all_charsets; cl < all_charsets+255 ;cl ++)
 
182
    {
 
183
      const CHARSET_INFO *tmp_cl= cl[0];
 
184
      if (! tmp_cl || ! (tmp_cl->state & MY_CS_AVAILABLE) ||
 
185
          !my_charset_same(tmp_cs, tmp_cl))
 
186
        continue;
 
187
      if (! (wild && wild[0] &&
 
188
          wild_case_compare(scs, tmp_cl->name,wild)))
 
189
      {
 
190
        const char *tmp_buff;
 
191
        table->restoreRecordAsDefault();
 
192
        table->field[0]->store(tmp_cl->name, strlen(tmp_cl->name), scs);
 
193
        table->field[1]->store(tmp_cl->csname , strlen(tmp_cl->csname), scs);
 
194
        table->field[2]->store((int64_t) tmp_cl->number, true);
 
195
        tmp_buff= (tmp_cl->state & MY_CS_PRIMARY) ? "Yes" : "";
 
196
        table->field[3]->store(tmp_buff, strlen(tmp_buff), scs);
 
197
        tmp_buff= (tmp_cl->state & MY_CS_COMPILED)? "Yes" : "";
 
198
        table->field[4]->store(tmp_buff, strlen(tmp_buff), scs);
 
199
        table->field[5]->store((int64_t) tmp_cl->strxfrm_multiply, true);
 
200
        if (schema_table_store_record(session, table))
 
201
          return 1;
 
202
      }
 
203
    }
 
204
  }
 
205
  return 0;
 
206
}