~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to plugin/info_schema/columns.cc

Merge Valgrind.

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