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
* referential constraints I_S table methods.
26
#include "drizzled/server_includes.h"
27
#include "drizzled/session.h"
28
#include "drizzled/show.h"
30
#include "helper_methods.h"
31
#include "referential_constraints.h"
35
using namespace drizzled;
39
* Vectors of columns for the referential constraints I_S table.
41
static vector<const plugin::ColumnInfo *> *columns= NULL;
44
* Methods for the referential constraints I_S table.
46
static plugin::InfoSchemaMethods *methods= NULL;
49
* processlist I_S table.
51
static plugin::InfoSchemaTable *rc_table= NULL;
54
* Populate the vectors of columns for the I_S table.
56
* @return a pointer to a std::vector of Columns.
58
vector<const plugin::ColumnInfo *> *ReferentialConstraintsIS::createColumns()
62
columns= new vector<const plugin::ColumnInfo *>;
66
clearColumns(*columns);
69
columns->push_back(new plugin::ColumnInfo("CONSTRAINT_CATALOG",
77
columns->push_back(new plugin::ColumnInfo("CONSTRAINT_SCHEMA",
85
columns->push_back(new plugin::ColumnInfo("CONSTRAINT_NAME",
93
columns->push_back(new plugin::ColumnInfo("UNIQUE_CONSTRAINT_CATALOG",
101
columns->push_back(new plugin::ColumnInfo("UNIQUE_CONSTRAINT_SCHEMA",
103
DRIZZLE_TYPE_VARCHAR,
109
columns->push_back(new plugin::ColumnInfo("UNIQUE_CONSTRAINT_NAME",
111
DRIZZLE_TYPE_VARCHAR,
117
columns->push_back(new plugin::ColumnInfo("MATCH_OPTION",
119
DRIZZLE_TYPE_VARCHAR,
125
columns->push_back(new plugin::ColumnInfo("UPDATE_RULE",
127
DRIZZLE_TYPE_VARCHAR,
133
columns->push_back(new plugin::ColumnInfo("DELETE_RULE",
135
DRIZZLE_TYPE_VARCHAR,
141
columns->push_back(new plugin::ColumnInfo("TABLE_NAME",
143
DRIZZLE_TYPE_VARCHAR,
149
columns->push_back(new plugin::ColumnInfo("REFERENCED_TABLE_NAME",
151
DRIZZLE_TYPE_VARCHAR,
161
* Initialize the I_S table.
163
* @return a pointer to an I_S table
165
plugin::InfoSchemaTable *ReferentialConstraintsIS::getTable()
167
columns= createColumns();
171
methods= new RefConstraintsISMethods();
174
if (rc_table == NULL)
176
rc_table= new plugin::InfoSchemaTable("REFERENTIAL_CONSTRAINTS",
187
* Delete memory allocated for the table, columns and methods.
189
void ReferentialConstraintsIS::cleanup()
191
clearColumns(*columns);
198
RefConstraintsISMethods::processTable(Session *session,
203
LEX_STRING *table_name)
206
const CHARSET_INFO * const cs= system_charset_info;
210
if (session->is_error())
212
push_warning(session,
213
DRIZZLE_ERROR::WARN_LEVEL_WARN,
214
session->main_da.sql_errno(),
215
session->main_da.message());
217
session->clear_error();
222
List<FOREIGN_KEY_INFO> f_key_list;
223
Table *show_table= tables->table;
224
show_table->cursor->info(HA_STATUS_VARIABLE |
228
show_table->cursor->get_foreign_key_list(session, &f_key_list);
229
FOREIGN_KEY_INFO *f_key_info;
230
List_iterator_fast<FOREIGN_KEY_INFO> it(f_key_list);
231
while ((f_key_info= it++))
233
table->restoreRecordAsDefault();
234
table->field[1]->store(db_name->str, db_name->length, cs);
235
table->field[9]->store(table_name->str, table_name->length, cs);
236
table->field[2]->store(f_key_info->forein_id->str,
237
f_key_info->forein_id->length, cs);
238
table->field[4]->store(f_key_info->referenced_db->str,
239
f_key_info->referenced_db->length, cs);
240
table->field[10]->store(f_key_info->referenced_table->str,
241
f_key_info->referenced_table->length, cs);
242
if (f_key_info->referenced_key_name)
244
table->field[5]->store(f_key_info->referenced_key_name->str,
245
f_key_info->referenced_key_name->length, cs);
246
table->field[5]->set_notnull();
250
table->field[5]->set_null();
252
table->field[6]->store(STRING_WITH_LEN("NONE"), cs);
253
table->field[7]->store(f_key_info->update_method->str,
254
f_key_info->update_method->length, cs);
255
table->field[8]->store(f_key_info->delete_method->str,
256
f_key_info->delete_method->length, cs);
257
if (schema_table_store_record(session, table))