~posulliv/drizzle/optimizer-style-cleanup

« back to all changes in this revision

Viewing changes to plugin/info_schema/columns.cc

  • Committer: Padraig O'Sullivan
  • Date: 2010-03-15 14:05:26 UTC
  • mfrom: (1237.9.99 staging)
  • Revision ID: osullivan.padraig@gmail.com-20100315140526-opbgwdwn6tfecdkq
MergeĀ fromĀ trunk.

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