~drizzle-trunk/drizzle/development

« back to all changes in this revision

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