~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to plugin/info_schema/columns.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 "columns.h"
 
32
 
 
33
#include <vector>
 
34
 
 
35
using namespace drizzled;
 
36
using namespace std;
 
37
 
 
38
/*
 
39
 * Vectors of columns for the columns I_S table.
 
40
 */
 
41
static vector<const plugin::ColumnInfo *> *columns= NULL;
 
42
 
 
43
/*
 
44
 * Methods for the columns I_S table.
 
45
 */
 
46
static plugin::InfoSchemaMethods *methods= NULL;
 
47
 
 
48
/*
 
49
 * columns I_S table.
 
50
 */
 
51
static plugin::InfoSchemaTable *cols_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 *> *ColumnsIS::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 COLUMNS table.
 
71
   */
 
72
  columns->push_back(new plugin::ColumnInfo("TABLE_CATALOG",
 
73
                                            FN_REFLEN,
 
74
                                            DRIZZLE_TYPE_VARCHAR,
 
75
                                            0,
 
76
                                            1,
 
77
                                            "",
 
78
                                            OPEN_FRM_ONLY));
 
79
 
 
80
  columns->push_back(new plugin::ColumnInfo("TABLE_SCHEMA",
 
81
                                            NAME_CHAR_LEN,
 
82
                                            DRIZZLE_TYPE_VARCHAR,
 
83
                                            0,
 
84
                                            0,
 
85
                                            "",
 
86
                                            OPEN_FRM_ONLY));
 
87
 
 
88
  columns->push_back(new plugin::ColumnInfo("TABLE_NAME",
 
89
                                            NAME_CHAR_LEN,
 
90
                                            DRIZZLE_TYPE_VARCHAR,
 
91
                                            0,
 
92
                                            0,
 
93
                                            "",
 
94
                                            OPEN_FRM_ONLY));
 
95
 
 
96
  columns->push_back(new plugin::ColumnInfo("COLUMN_NAME",
 
97
                                            NAME_CHAR_LEN,
 
98
                                            DRIZZLE_TYPE_VARCHAR,
 
99
                                            0,
 
100
                                            0,
 
101
                                            "Field",
 
102
                                            OPEN_FRM_ONLY));
 
103
 
 
104
  columns->push_back(new plugin::ColumnInfo("ORDINAL_POSITION",
 
105
                                            MY_INT64_NUM_DECIMAL_DIGITS,
 
106
                                            DRIZZLE_TYPE_LONGLONG,
 
107
                                            0,
 
108
                                            MY_I_S_UNSIGNED,
 
109
                                            "",
 
110
                                            OPEN_FRM_ONLY));
 
111
 
 
112
  columns->push_back(new plugin::ColumnInfo("COLUMN_DEFAULT",
 
113
                                            MAX_FIELD_VARCHARLENGTH,
 
114
                                            DRIZZLE_TYPE_VARCHAR,
 
115
                                            0,
 
116
                                            1,
 
117
                                            "Default",
 
118
                                            OPEN_FRM_ONLY));
 
119
 
 
120
  columns->push_back(new plugin::ColumnInfo("IS_NULLABLE",
 
121
                                            3,
 
122
                                            DRIZZLE_TYPE_VARCHAR,
 
123
                                            0,
 
124
                                            0,
 
125
                                            "Null",
 
126
                                            OPEN_FRM_ONLY));
 
127
 
 
128
  columns->push_back(new plugin::ColumnInfo("DATA_TYPE",
 
129
                                            NAME_CHAR_LEN,
 
130
                                            DRIZZLE_TYPE_VARCHAR,
 
131
                                            0,
 
132
                                            0,
 
133
                                            "",
 
134
                                            OPEN_FRM_ONLY));
 
135
 
 
136
  columns->push_back(new plugin::ColumnInfo("CHARACTER_MAXIMUM_LENGTH",
 
137
                                           MY_INT64_NUM_DECIMAL_DIGITS,
 
138
                                           DRIZZLE_TYPE_LONGLONG,
 
139
                                           0,
 
140
                                           (MY_I_S_MAYBE_NULL | MY_I_S_UNSIGNED),
 
141
                                           "",
 
142
                                           OPEN_FRM_ONLY));
 
143
 
 
144
  columns->push_back(new plugin::ColumnInfo("CHARACTER_OCTET_LENGTH",
 
145
                                            MY_INT64_NUM_DECIMAL_DIGITS,
 
146
                                            DRIZZLE_TYPE_LONGLONG,
 
147
                                            0,
 
148
                                            (MY_I_S_MAYBE_NULL | MY_I_S_UNSIGNED),
 
149
                                            "",
 
150
                                            OPEN_FRM_ONLY));
 
151
 
 
152
  columns->push_back(new plugin::ColumnInfo("NUMERIC_PRECISION",
 
153
                                            MY_INT64_NUM_DECIMAL_DIGITS,
 
154
                                            DRIZZLE_TYPE_LONGLONG,
 
155
                                            0,
 
156
                                            (MY_I_S_MAYBE_NULL | MY_I_S_UNSIGNED),
 
157
                                            "",
 
158
                                            OPEN_FRM_ONLY));
 
159
 
 
160
  columns->push_back(new plugin::ColumnInfo("NUMERIC_SCALE",
 
161
                                            MY_INT64_NUM_DECIMAL_DIGITS,
 
162
                                            DRIZZLE_TYPE_LONGLONG,
 
163
                                            0,
 
164
                                            (MY_I_S_MAYBE_NULL | MY_I_S_UNSIGNED),
 
165
                                            "",
 
166
                                            OPEN_FRM_ONLY));
 
167
 
 
168
  columns->push_back(new plugin::ColumnInfo("CHARACTER_SET_NAME",
 
169
                                            64,
 
170
                                            DRIZZLE_TYPE_VARCHAR,
 
171
                                            0,
 
172
                                            1,
 
173
                                            "",
 
174
                                            OPEN_FRM_ONLY));
 
175
 
 
176
  columns->push_back(new plugin::ColumnInfo("COLLATION_NAME",
 
177
                                            64,
 
178
                                            DRIZZLE_TYPE_VARCHAR,
 
179
                                            0,
 
180
                                            1,
 
181
                                            "Collation",
 
182
                                            OPEN_FRM_ONLY));
 
183
 
 
184
  columns->push_back(new plugin::ColumnInfo("COLUMN_TYPE",
 
185
                                            65535,
 
186
                                            DRIZZLE_TYPE_VARCHAR,
 
187
                                            0,
 
188
                                            0,
 
189
                                            "Type",
 
190
                                            OPEN_FRM_ONLY));
 
191
 
 
192
  columns->push_back(new plugin::ColumnInfo("COLUMN_KEY",
 
193
                                            3,
 
194
                                            DRIZZLE_TYPE_VARCHAR,
 
195
                                            0,
 
196
                                            0,
 
197
                                            "Key",
 
198
                                            OPEN_FRM_ONLY));
 
199
 
 
200
  columns->push_back(new plugin::ColumnInfo("EXTRA",
 
201
                                            27,
 
202
                                            DRIZZLE_TYPE_VARCHAR,
 
203
                                            0,
 
204
                                            0,
 
205
                                            "Extra",
 
206
                                            OPEN_FRM_ONLY));
 
207
 
 
208
  columns->push_back(new plugin::ColumnInfo("PRIVILEGES",
 
209
                                            80,
 
210
                                            DRIZZLE_TYPE_VARCHAR,
 
211
                                            0,
 
212
                                            0,
 
213
                                            "Privileges",
 
214
                                            OPEN_FRM_ONLY));
 
215
 
 
216
  columns->push_back(new plugin::ColumnInfo("COLUMN_COMMENT",
 
217
                                            COLUMN_COMMENT_MAXLEN,
 
218
                                            DRIZZLE_TYPE_VARCHAR,
 
219
                                            0,
 
220
                                            0,
 
221
                                            "Comment",
 
222
                                            OPEN_FRM_ONLY));
 
223
 
 
224
  columns->push_back(new plugin::ColumnInfo("STORAGE",
 
225
                                            8,
 
226
                                            DRIZZLE_TYPE_VARCHAR,
 
227
                                            0,
 
228
                                            0,
 
229
                                            "Storage",
 
230
                                            OPEN_FRM_ONLY));
 
231
 
 
232
  columns->push_back(new plugin::ColumnInfo("FORMAT",
 
233
                                            8,
 
234
                                            DRIZZLE_TYPE_VARCHAR,
 
235
                                            0,
 
236
                                            0,
 
237
                                            "Format",
 
238
                                            OPEN_FRM_ONLY));
 
239
  return columns;
 
240
}
 
241
 
 
242
/**
 
243
 * Initialize the I_S table.
 
244
 *
 
245
 * @return a pointer to an I_S table
 
246
 */
 
247
plugin::InfoSchemaTable *ColumnsIS::getTable()
 
248
{
 
249
  columns= createColumns();
 
250
 
 
251
  if (methods == NULL)
 
252
  {
 
253
    methods= new ColumnsISMethods();
 
254
  }
 
255
 
 
256
  if (cols_table == NULL)
 
257
  {
 
258
    cols_table= new plugin::InfoSchemaTable("COLUMNS",
 
259
                                            *columns,
 
260
                                            1, 2, false, true,
 
261
                                            OPTIMIZE_I_S_TABLE,
 
262
                                            methods);
 
263
  }
 
264
 
 
265
  return cols_table;
 
266
}
 
267
 
 
268
/**
 
269
 * Delete memory allocated for the table, columns and methods.
 
270
 */
 
271
void ColumnsIS::cleanup()
 
272
{
 
273
  clearColumns(*columns);
 
274
  delete cols_table;
 
275
  delete methods;
 
276
  delete columns;
 
277
}
 
278
 
 
279
int ColumnsISMethods::oldFormat(Session *session, drizzled::plugin::InfoSchemaTable *schema_table)
 
280
  const
 
281
{
 
282
  int fields_arr[]= {3, 14, 13, 6, 15, 5, 16, 17, 18, -1};
 
283
  int *field_num= fields_arr;
 
284
  const drizzled::plugin::InfoSchemaTable::Columns tab_columns= schema_table->getColumns();
 
285
  const drizzled::plugin::ColumnInfo *column;
 
286
  Name_resolution_context *context= &session->lex->select_lex.context;
 
287
 
 
288
  for (; *field_num >= 0; field_num++)
 
289
  {
 
290
    column= tab_columns[*field_num];
 
291
    if (! session->lex->verbose && (*field_num == 13 ||
 
292
                                    *field_num == 17 ||
 
293
                                    *field_num == 18))
 
294
    {
 
295
      continue;
 
296
    }
 
297
    Item_field *field= new Item_field(context,
 
298
                                      NULL, NULL, column->getName().c_str());
 
299
    if (field)
 
300
    {
 
301
      field->set_name(column->getOldName().c_str(),
 
302
                      column->getOldName().length(),
 
303
                      system_charset_info);
 
304
      if (session->add_item_to_list(field))
 
305
      {
 
306
        return 1;
 
307
      }
 
308
    }
 
309
  }
 
310
  return 0;
 
311
}