~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to plugin/info_schema/table_constraints.cc

Merged trunk.

Show diffs side-by-side

added added

removed removed

Lines of Context:
71
71
                                            DRIZZLE_TYPE_VARCHAR,
72
72
                                            0,
73
73
                                            1,
74
 
                                            "",
75
 
                                            OPEN_FULL_TABLE));
 
74
                                            ""));
76
75
 
77
76
  columns->push_back(new plugin::ColumnInfo("CONSTRAINT_SCHEMA",
78
77
                                            NAME_CHAR_LEN,
79
78
                                            DRIZZLE_TYPE_VARCHAR,
80
79
                                            0,
81
80
                                            0,
82
 
                                            "",
83
 
                                            OPEN_FULL_TABLE));
 
81
                                            ""));
84
82
 
85
83
  columns->push_back(new plugin::ColumnInfo("CONSTRAINT_NAME",
86
84
                                            NAME_CHAR_LEN,
87
85
                                            DRIZZLE_TYPE_VARCHAR,
88
86
                                            0,
89
87
                                            0,
90
 
                                            "",
91
 
                                            OPEN_FULL_TABLE));
 
88
                                            ""));
92
89
 
93
90
  columns->push_back(new plugin::ColumnInfo("TABLE_SCHEMA",
94
91
                                            NAME_CHAR_LEN,
95
92
                                            DRIZZLE_TYPE_VARCHAR,
96
93
                                            0,
97
94
                                            0,
98
 
                                            "",
99
 
                                            OPEN_FULL_TABLE));
 
95
                                            ""));
100
96
 
101
97
  columns->push_back(new plugin::ColumnInfo("TABLE_NAME",
102
98
                                            NAME_CHAR_LEN,
103
99
                                            DRIZZLE_TYPE_VARCHAR,
104
100
                                            0,
105
101
                                            0,
106
 
                                            "",
107
 
                                            OPEN_FULL_TABLE));
 
102
                                            ""));
108
103
 
109
104
  columns->push_back(new plugin::ColumnInfo("CONSTRAINT_TYPE",
110
105
                                            NAME_CHAR_LEN,
111
106
                                            DRIZZLE_TYPE_VARCHAR,
112
107
                                            0,
113
108
                                            0,
114
 
                                            "",
115
 
                                            OPEN_FULL_TABLE));
 
109
                                            ""));
116
110
  return columns;
117
111
}
118
112
 
153
147
  delete columns;
154
148
}
155
149
 
156
 
static bool store_constraints(Session *session, 
157
 
                              Table *table, 
 
150
static bool store_constraints(Table *table, 
158
151
                              LEX_STRING *db_name,
159
152
                              LEX_STRING *table_name, 
160
153
                              const char *key_name,
161
154
                              uint32_t key_len, 
162
155
                              const char *con_type, 
163
 
                              uint32_t con_len)
 
156
                              uint32_t con_len,
 
157
                              plugin::InfoSchemaTable *schema_table)
164
158
{
165
159
  const CHARSET_INFO * const cs= system_charset_info;
166
160
  table->restoreRecordAsDefault();
 
161
  table->setWriteSet(1);
 
162
  table->setWriteSet(2);
 
163
  table->setWriteSet(3);
 
164
  table->setWriteSet(4);
 
165
  table->setWriteSet(5);
167
166
  table->field[1]->store(db_name->str, db_name->length, cs);
168
167
  table->field[2]->store(key_name, key_len, cs);
169
168
  table->field[3]->store(db_name->str, db_name->length, cs);
170
169
  table->field[4]->store(table_name->str, table_name->length, cs);
171
170
  table->field[5]->store(con_type, con_len, cs);
172
 
  return schema_table_store_record(session, table);
 
171
  schema_table->addRow(table->record[0], table->s->reclength);
 
172
  return false;
173
173
}
174
174
 
175
 
int TabConstraintsISMethods::processTable(Session *session, 
 
175
int TabConstraintsISMethods::processTable(plugin::InfoSchemaTable *store_table,
 
176
                                          Session *session, 
176
177
                                          TableList *tables,
177
178
                                          Table *table, 
178
179
                                          bool res,
179
180
                                          LEX_STRING *db_name,
180
 
                                          LEX_STRING *table_name) const
 
181
                                          LEX_STRING *table_name)
181
182
{
182
183
  if (res)
183
184
  {
209
210
 
210
211
      if (i == primary_key && is_primary_key(key_info))
211
212
      {
212
 
        if (store_constraints(session, 
213
 
                              table, 
 
213
        if (store_constraints(table, 
214
214
                              db_name, 
215
215
                              table_name, 
216
216
                              key_info->name,
217
217
                              strlen(key_info->name),
218
 
                              STRING_WITH_LEN("PRIMARY KEY")))
 
218
                              STRING_WITH_LEN("PRIMARY KEY"),
 
219
                              store_table))
219
220
        {
220
221
          return 1;
221
222
        }
222
223
      }
223
224
      else if (key_info->flags & HA_NOSAME)
224
225
      {
225
 
        if (store_constraints(session, 
226
 
                              table, 
 
226
        if (store_constraints(table, 
227
227
                              db_name, 
228
228
                              table_name, 
229
229
                              key_info->name,
230
230
                              strlen(key_info->name),
231
 
                              STRING_WITH_LEN("UNIQUE")))
 
231
                              STRING_WITH_LEN("UNIQUE"),
 
232
                              store_table))
232
233
        {
233
234
          return 1;
234
235
        }
240
241
    List_iterator_fast<FOREIGN_KEY_INFO> it(f_key_list);
241
242
    while ((f_key_info= it++))
242
243
    {
243
 
      if (store_constraints(session, 
244
 
                            table, 
 
244
      if (store_constraints(table, 
245
245
                            db_name, 
246
246
                            table_name,
247
247
                            f_key_info->forein_id->str,
248
248
                            strlen(f_key_info->forein_id->str),
249
 
                            "FOREIGN KEY", 11))
 
249
                            "FOREIGN KEY", 11,
 
250
                            store_table))
250
251
      {
251
252
        return 1;
252
253
      }