~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to client/drizzledump_mysql.cc

  • Committer: lbieber at stabletransit
  • Date: 2010-10-15 22:03:32 UTC
  • mfrom: (1856.1.5 build)
  • Revision ID: lbieber@drizzle-build-n02.wc1.dfw1.stabletransit.com-20101015220332-yzt1trfuff2gxkwv
Merge Andrew - Bug #654269: drizzledump doesn't handle foriegn keys 
Merge Andrew - Bug #659103: drizzledump could grab the wrong indexes
Merge Barry - Fixed memory leak in event observer plugin.
Merge Lee - Fix test output for haildb test, instead of No database selected, the message is now No schema selected

Show diffs side-by-side

added added

removed removed

Lines of Context:
74
74
      table->comment= "";
75
75
 
76
76
    table->database= this;
77
 
    if ((not table->populateFields()) or (not table->populateIndexes()))
 
77
    if ((not table->populateFields()) or (not table->populateIndexes()) or
 
78
     (not table->populateFkeys()))
78
79
    {
79
80
      delete table;
80
81
      if (not ignore_errors)
288
289
  return true;
289
290
}
290
291
 
 
292
bool DrizzleDumpTableMySQL::populateFkeys()
 
293
{
 
294
  drizzle_result_st *result;
 
295
  drizzle_row_t row;
 
296
  std::string query;
 
297
  DrizzleDumpForeignKey *fkey;
 
298
 
 
299
  if (verbose)
 
300
    std::cerr << _("-- Retrieving foreign keys for ") << tableName << "..." << std::endl;
 
301
 
 
302
  query= "select rc.constraint_name, rc.referenced_table_name, group_concat(distinct concat('`',kc.column_name,'`')), rc.update_rule, rc.delete_rule, rc.match_option, group_concat(distinct concat('`',kt.column_name,'`')) from information_schema.referential_constraints rc join information_schema.key_column_usage kt on (rc.constraint_schema = kt.constraint_schema and rc.constraint_name = kt.constraint_name) join information_schema.key_column_usage kc on (rc.constraint_schema = kc.constraint_schema and rc.referenced_table_name = kc.table_name and rc.unique_constraint_name = kc.constraint_name) where rc.constraint_schema='";
 
303
  query.append(database->databaseName);
 
304
  query.append("' and rc.table_name='");
 
305
  query.append(tableName);
 
306
  query.append("' group by rc.constraint_name");
 
307
 
 
308
  result= dcon->query(query);
 
309
 
 
310
  if (result == NULL)
 
311
    return false;
 
312
 
 
313
  while ((row= drizzle_row_next(result)))
 
314
  {
 
315
    fkey= new DrizzleDumpForeignKey(row[0], dcon);
 
316
    fkey->parentColumns= row[6];
 
317
    fkey->childTable= row[1];
 
318
    fkey->childColumns= row[2];
 
319
    fkey->updateRule= (strcmp(row[3], "RESTRICT") != 0) ? row[3] : "";
 
320
    fkey->deleteRule= (strcmp(row[4], "RESTRICT") != 0) ? row[4] : "";
 
321
    fkey->matchOption= (strcmp(row[5], "NONE") != 0) ? row[5] : "";
 
322
 
 
323
    fkeys.push_back(fkey);
 
324
  }
 
325
  dcon->freeResult(result);
 
326
  return true;
 
327
}
 
328
 
291
329
void DrizzleDumpFieldMySQL::setType(const char* raw_type, const char* raw_collation)
292
330
{
293
331
  std::string old_type(raw_type);