1
/* - mode: c; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
* vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
4
* Copyright (C) 2009 Sun Microsystems
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.
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.
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
23
* key column usage I_S table methods.
27
#include "drizzled/session.h"
28
#include "drizzled/show.h"
29
#include "drizzled/global_charset_info.h"
32
#include "helper_methods.h"
33
#include "key_column_usage.h"
37
using namespace drizzled;
41
* Vectors of columns for the key column usage I_S table.
43
static vector<const plugin::ColumnInfo *> *columns= NULL;
46
* Methods for the key column usage I_S table.
48
static plugin::InfoSchemaMethods *methods= NULL;
51
* key column usage I_S table.
53
static plugin::InfoSchemaTable *key_col_table= NULL;
56
* Populate the vectors of columns for the I_S table.
58
* @return a pointer to a std::vector of Columns.
60
vector<const plugin::ColumnInfo *> *KeyColumnUsageIS::createColumns()
64
columns= new vector<const plugin::ColumnInfo *>;
68
clearColumns(*columns);
71
columns->push_back(new plugin::ColumnInfo("CONSTRAINT_CATALOG",
78
columns->push_back(new plugin::ColumnInfo("CONSTRAINT_SCHEMA",
85
columns->push_back(new plugin::ColumnInfo("CONSTRAINT_NAME",
92
columns->push_back(new plugin::ColumnInfo("TABLE_CATALOG",
99
columns->push_back(new plugin::ColumnInfo("TABLE_SCHEMA",
101
DRIZZLE_TYPE_VARCHAR,
106
columns->push_back(new plugin::ColumnInfo("TABLE_NAME",
108
DRIZZLE_TYPE_VARCHAR,
113
columns->push_back(new plugin::ColumnInfo("COLUMN_NAME",
115
DRIZZLE_TYPE_VARCHAR,
120
columns->push_back(new plugin::ColumnInfo("ORDINAL_POSITION",
122
DRIZZLE_TYPE_LONGLONG,
127
columns->push_back(new plugin::ColumnInfo("POSITION_IN_UNIQUE_CONSTRAINT",
129
DRIZZLE_TYPE_LONGLONG,
134
columns->push_back(new plugin::ColumnInfo("REFERENCED_TABLE_SCHEMA",
136
DRIZZLE_TYPE_VARCHAR,
141
columns->push_back(new plugin::ColumnInfo("REFERENCED_TABLE_NAME",
143
DRIZZLE_TYPE_VARCHAR,
148
columns->push_back(new plugin::ColumnInfo("REFERENCED_COLUMN_NAME",
150
DRIZZLE_TYPE_VARCHAR,
159
* Initialize the I_S table.
161
* @return a pointer to an I_S table
163
plugin::InfoSchemaTable *KeyColumnUsageIS::getTable()
165
columns= createColumns();
169
methods= new KeyColUsageISMethods();
172
if (key_col_table == NULL)
174
key_col_table= new plugin::InfoSchemaTable("KEY_COLUMN_USAGE",
181
return key_col_table;
185
* Delete memory allocated for the table, columns and methods.
187
void KeyColumnUsageIS::cleanup()
189
clearColumns(*columns);
190
delete key_col_table;
195
int KeyColUsageISMethods::processTable(plugin::InfoSchemaTable *store_table,
198
Table *table, bool res,
200
LEX_STRING *table_name)
204
if (session->is_error())
205
push_warning(session, DRIZZLE_ERROR::WARN_LEVEL_WARN,
206
session->main_da.sql_errno(), session->main_da.message());
207
session->clear_error();
212
List<FOREIGN_KEY_INFO> f_key_list;
213
Table *show_table= tables->table;
214
KEY *key_info=show_table->key_info;
215
uint32_t primary_key= show_table->s->primary_key;
216
show_table->cursor->info(HA_STATUS_VARIABLE |
219
for (uint32_t i=0 ; i < show_table->s->keys ; i++, key_info++)
221
if (i != primary_key && !(key_info->flags & HA_NOSAME))
226
KEY_PART_INFO *key_part= key_info->key_part;
227
for (uint32_t j=0 ; j < key_info->key_parts ; j++,key_part++)
232
table->restoreRecordAsDefault();
233
store_key_column_usage(table, db_name, table_name,
235
strlen(key_info->name),
236
key_part->field->field_name,
237
strlen(key_part->field->field_name),
239
store_table->addRow(table->record[0],
240
table->s->reclength);
245
show_table->cursor->get_foreign_key_list(session, &f_key_list);
246
FOREIGN_KEY_INFO *f_key_info;
247
List_iterator_fast<FOREIGN_KEY_INFO> fkey_it(f_key_list);
248
while ((f_key_info= fkey_it++))
252
List_iterator_fast<LEX_STRING> it(f_key_info->foreign_fields),
253
it1(f_key_info->referenced_fields);
255
while ((f_info= it++))
259
table->restoreRecordAsDefault();
260
store_key_column_usage(table, db_name, table_name,
261
f_key_info->forein_id->str,
262
f_key_info->forein_id->length,
263
f_info->str, f_info->length,
265
table->setWriteSet(8);
266
table->setWriteSet(9);
267
table->setWriteSet(10);
268
table->setWriteSet(11);
269
table->field[8]->store((int64_t) f_idx, true);
270
table->field[8]->set_notnull();
271
table->field[9]->store(f_key_info->referenced_db->str,
272
f_key_info->referenced_db->length,
273
system_charset_info);
274
table->field[9]->set_notnull();
275
table->field[10]->store(f_key_info->referenced_table->str,
276
f_key_info->referenced_table->length,
277
system_charset_info);
278
table->field[10]->set_notnull();
279
table->field[11]->store(r_info->str, r_info->length,
280
system_charset_info);
281
table->field[11]->set_notnull();
282
store_table->addRow(table->record[0], table->s->reclength);