~posulliv/drizzle/optimizer-style-cleanup

« back to all changes in this revision

Viewing changes to plugin/info_schema/referential_constraints.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
 
 *   referential constraints I_S table methods.
24
 
 */
25
 
 
26
 
#include "config.h"
27
 
#include "drizzled/session.h"
28
 
#include "drizzled/show.h"
29
 
 
30
 
#include "helper_methods.h"
31
 
#include "referential_constraints.h"
32
 
 
33
 
#include <vector>
34
 
 
35
 
using namespace drizzled;
36
 
using namespace std;
37
 
 
38
 
/*
39
 
 * Vectors of columns for the referential constraints I_S table.
40
 
 */
41
 
static vector<const plugin::ColumnInfo *> *columns= NULL;
42
 
 
43
 
/*
44
 
 * Methods for the referential constraints I_S table.
45
 
 */
46
 
static plugin::InfoSchemaMethods *methods= NULL;
47
 
 
48
 
/*
49
 
 * processlist I_S table.
50
 
 */
51
 
static plugin::InfoSchemaTable *rc_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 *> *ReferentialConstraintsIS::createColumns()
59
 
{
60
 
  if (columns == NULL)
61
 
  {
62
 
    columns= new vector<const plugin::ColumnInfo *>;
63
 
  }
64
 
  else
65
 
  {
66
 
    clearColumns(*columns);
67
 
  }
68
 
 
69
 
  columns->push_back(new plugin::ColumnInfo("CONSTRAINT_CATALOG",
70
 
                                            FN_REFLEN,
71
 
                                            DRIZZLE_TYPE_VARCHAR,
72
 
                                            0,
73
 
                                            1,
74
 
                                            ""));
75
 
 
76
 
  columns->push_back(new plugin::ColumnInfo("CONSTRAINT_SCHEMA",
77
 
                                            NAME_CHAR_LEN,
78
 
                                            DRIZZLE_TYPE_VARCHAR,
79
 
                                            0,
80
 
                                            0,
81
 
                                            ""));
82
 
 
83
 
  columns->push_back(new plugin::ColumnInfo("CONSTRAINT_NAME",
84
 
                                            NAME_CHAR_LEN,
85
 
                                            DRIZZLE_TYPE_VARCHAR,
86
 
                                            0,
87
 
                                            0,
88
 
                                            ""));
89
 
 
90
 
  columns->push_back(new plugin::ColumnInfo("UNIQUE_CONSTRAINT_CATALOG",
91
 
                                            FN_REFLEN,
92
 
                                            DRIZZLE_TYPE_VARCHAR,
93
 
                                            0,
94
 
                                            1,
95
 
                                            ""));
96
 
 
97
 
  columns->push_back(new plugin::ColumnInfo("UNIQUE_CONSTRAINT_SCHEMA",
98
 
                                            NAME_CHAR_LEN,
99
 
                                            DRIZZLE_TYPE_VARCHAR,
100
 
                                            0,
101
 
                                            0,
102
 
                                            ""));
103
 
 
104
 
  columns->push_back(new plugin::ColumnInfo("UNIQUE_CONSTRAINT_NAME",
105
 
                                            NAME_CHAR_LEN,
106
 
                                            DRIZZLE_TYPE_VARCHAR,
107
 
                                            0,
108
 
                                            MY_I_S_MAYBE_NULL,
109
 
                                            ""));
110
 
 
111
 
  columns->push_back(new plugin::ColumnInfo("MATCH_OPTION",
112
 
                                            NAME_CHAR_LEN,
113
 
                                            DRIZZLE_TYPE_VARCHAR,
114
 
                                            0,
115
 
                                            0,
116
 
                                            ""));
117
 
 
118
 
  columns->push_back(new plugin::ColumnInfo("UPDATE_RULE",
119
 
                                            NAME_CHAR_LEN,
120
 
                                            DRIZZLE_TYPE_VARCHAR,
121
 
                                            0,
122
 
                                            0,
123
 
                                            ""));
124
 
 
125
 
  columns->push_back(new plugin::ColumnInfo("DELETE_RULE",
126
 
                                            NAME_CHAR_LEN,
127
 
                                            DRIZZLE_TYPE_VARCHAR,
128
 
                                            0,
129
 
                                            0,
130
 
                                            ""));
131
 
 
132
 
  columns->push_back(new plugin::ColumnInfo("TABLE_NAME",
133
 
                                            NAME_CHAR_LEN,
134
 
                                            DRIZZLE_TYPE_VARCHAR,
135
 
                                            0,
136
 
                                            0,
137
 
                                            ""));
138
 
 
139
 
  columns->push_back(new plugin::ColumnInfo("REFERENCED_TABLE_NAME",
140
 
                                            NAME_CHAR_LEN,
141
 
                                            DRIZZLE_TYPE_VARCHAR,
142
 
                                            0,
143
 
                                            0,
144
 
                                            ""));
145
 
 
146
 
  return columns;
147
 
}
148
 
 
149
 
/**
150
 
 * Initialize the I_S table.
151
 
 *
152
 
 * @return a pointer to an I_S table
153
 
 */
154
 
plugin::InfoSchemaTable *ReferentialConstraintsIS::getTable()
155
 
{
156
 
  columns= createColumns();
157
 
 
158
 
  if (methods == NULL)
159
 
  {
160
 
    methods= new RefConstraintsISMethods();
161
 
  }
162
 
 
163
 
  if (rc_table == NULL)
164
 
  {
165
 
    rc_table= new plugin::InfoSchemaTable("OLD_REFERENTIAL_CONSTRAINTS",
166
 
                                          *columns,
167
 
                                          1, 9, false, true,
168
 
                                          0,
169
 
                                          methods);
170
 
  }
171
 
 
172
 
  return rc_table;
173
 
}
174
 
 
175
 
/**
176
 
 * Delete memory allocated for the table, columns and methods.
177
 
 */
178
 
void ReferentialConstraintsIS::cleanup()
179
 
{
180
 
  clearColumns(*columns);
181
 
  delete rc_table;
182
 
  delete methods;
183
 
  delete columns;
184
 
}
185
 
 
186
 
int
187
 
RefConstraintsISMethods::processTable(plugin::InfoSchemaTable *store_table,
188
 
                                      Session *session, 
189
 
                                      TableList *tables,
190
 
                                      Table *table, 
191
 
                                      bool res,
192
 
                                      LEX_STRING *db_name, 
193
 
                                      LEX_STRING *table_name)
194
 
{
195
 
  const CHARSET_INFO * const cs= system_charset_info;
196
 
 
197
 
  if (res)
198
 
  {
199
 
    if (session->is_error())
200
 
    {
201
 
      push_warning(session, 
202
 
                   DRIZZLE_ERROR::WARN_LEVEL_WARN,
203
 
                   session->main_da.sql_errno(), 
204
 
                   session->main_da.message());
205
 
    }
206
 
    session->clear_error();
207
 
    return 0;
208
 
  }
209
 
 
210
 
  {
211
 
    List<FOREIGN_KEY_INFO> f_key_list;
212
 
    Table *show_table= tables->table;
213
 
    show_table->cursor->info(HA_STATUS_VARIABLE |
214
 
                             HA_STATUS_NO_LOCK |
215
 
                             HA_STATUS_TIME);
216
 
 
217
 
    show_table->cursor->get_foreign_key_list(session, &f_key_list);
218
 
    FOREIGN_KEY_INFO *f_key_info;
219
 
    List_iterator_fast<FOREIGN_KEY_INFO> it(f_key_list);
220
 
    while ((f_key_info= it++))
221
 
    {
222
 
      table->restoreRecordAsDefault();
223
 
      table->setWriteSet(1);
224
 
      table->setWriteSet(2);
225
 
      table->setWriteSet(4);
226
 
      table->setWriteSet(5);
227
 
      table->setWriteSet(6);
228
 
      table->setWriteSet(7);
229
 
      table->setWriteSet(8);
230
 
      table->setWriteSet(9);
231
 
      table->setWriteSet(10);
232
 
      table->field[1]->store(db_name->str, db_name->length, cs);
233
 
      table->field[9]->store(table_name->str, table_name->length, cs);
234
 
      table->field[2]->store(f_key_info->forein_id->str,
235
 
                             f_key_info->forein_id->length, cs);
236
 
      table->field[4]->store(f_key_info->referenced_db->str,
237
 
                             f_key_info->referenced_db->length, cs);
238
 
      table->field[10]->store(f_key_info->referenced_table->str,
239
 
                              f_key_info->referenced_table->length, cs);
240
 
      if (f_key_info->referenced_key_name)
241
 
      {
242
 
        table->field[5]->store(f_key_info->referenced_key_name->str,
243
 
                               f_key_info->referenced_key_name->length, cs);
244
 
        table->field[5]->set_notnull();
245
 
      }
246
 
      else
247
 
      {
248
 
        table->field[5]->set_null();
249
 
      }
250
 
      table->field[6]->store(STRING_WITH_LEN("NONE"), cs);
251
 
      table->field[7]->store(f_key_info->update_method->str,
252
 
                             f_key_info->update_method->length, cs);
253
 
      table->field[8]->store(f_key_info->delete_method->str,
254
 
                             f_key_info->delete_method->length, cs);
255
 
      store_table->addRow(table->record[0], table->s->reclength);
256
 
    }
257
 
  }
258
 
  return 0;
259
 
}
260