~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/sql_class.cc

Initial submit of code and tests

Show diffs side-by-side

added added

removed removed

Lines of Context:
183
183
}
184
184
 
185
185
 
 
186
/*
 
187
  Check if the foreign key options are compatible with columns
 
188
  on which the FK is created.
 
189
 
 
190
  RETURN
 
191
    0   Key valid
 
192
    1   Key invalid
 
193
*/
 
194
bool Foreign_key::validate(List<Create_field> &table_fields)
 
195
{
 
196
  Create_field  *sql_field;
 
197
  Key_part_spec *column;
 
198
  List_iterator<Key_part_spec> cols(columns);
 
199
  List_iterator<Create_field> it(table_fields);
 
200
  while ((column= cols++))
 
201
  {
 
202
    it.rewind();
 
203
    while ((sql_field= it++) &&
 
204
           my_strcasecmp(system_charset_info,
 
205
                         column->field_name.str,
 
206
                         sql_field->field_name)) {}
 
207
    if (!sql_field)
 
208
    {
 
209
      my_error(ER_KEY_COLUMN_DOES_NOT_EXITS, MYF(0), column->field_name.str);
 
210
      return true;
 
211
    }
 
212
    if (type == Key::FOREIGN_KEY && sql_field->vcol_info)
 
213
    {
 
214
      if (delete_opt == FK_OPTION_SET_NULL)
 
215
      {
 
216
        my_error(ER_WRONG_FK_OPTION_FOR_VIRTUAL_COLUMN, MYF(0), 
 
217
                 "ON DELETE SET NULL");
 
218
        return true;
 
219
      }
 
220
      if (update_opt == FK_OPTION_SET_NULL)
 
221
      {
 
222
        my_error(ER_WRONG_FK_OPTION_FOR_VIRTUAL_COLUMN, MYF(0), 
 
223
                 "ON UPDATE SET NULL");
 
224
        return true;
 
225
      }
 
226
      if (update_opt == FK_OPTION_CASCADE)
 
227
      {
 
228
        my_error(ER_WRONG_FK_OPTION_FOR_VIRTUAL_COLUMN, MYF(0), 
 
229
                 "ON UPDATE CASCADE");
 
230
        return true;
 
231
      }
 
232
    }
 
233
  }
 
234
  return false;
 
235
}
 
236
 
 
237
 
186
238
/****************************************************************************
187
239
** Thread specific functions
188
240
****************************************************************************/