~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to client/drizzledump_drizzle.cc

  • Committer: Andrew Hutchings
  • Date: 2010-10-12 15:43:24 UTC
  • mto: (1856.1.3 build)
  • mto: This revision was merged to the branch mainline in revision 1857.
  • Revision ID: andrew@linuxjedi.co.uk-20101012154324-mf9lnvixb4lay5ut
Add foreign keys to Drizzle server

Show diffs side-by-side

added added

removed removed

Lines of Context:
68
68
    else
69
69
      table->comment= "";
70
70
    table->database= this;
71
 
    if ((not table->populateFields()) or (not table->populateIndexes()))
 
71
    if ((not table->populateFields()) or (not table->populateIndexes()) or
 
72
      (not table->populateFkeys()))
72
73
    {
73
74
      delete table;
74
75
      if (not ignore_errors)
256
257
  return true;
257
258
}
258
259
 
 
260
bool DrizzleDumpTableDrizzle::populateFkeys()
 
261
{
 
262
  drizzle_result_st *result;
 
263
  drizzle_row_t row;
 
264
  std::string query;
 
265
  DrizzleDumpForeignKey *fkey;
 
266
 
 
267
  if (verbose)
 
268
    std::cerr << _("-- Retrieving foreign keys for ") << tableName << "..." << std::endl;
 
269
 
 
270
  query= "SELECT CONSTRAINT_NAME, CONSTRAINT_COLUMNS, REFERENCED_TABLE_NAME, REFERENCED_TABLE_COLUMNS, MATCH_OPTION, DELETE_RULE, UPDATE_RULE FROM DATA_DICTIONARY.REFERENTIAL_CONSTRAINTS WHERE CONSTRAINT_SCHEMA='";
 
271
  query.append(database->databaseName);
 
272
  query.append("' AND CONSTRAINT_TABLE='");
 
273
  query.append(tableName);
 
274
  query.append("'");
 
275
 
 
276
  result= dcon->query(query);
 
277
 
 
278
  if (result == NULL)
 
279
    return false;
 
280
 
 
281
  while ((row= drizzle_row_next(result)))
 
282
  {
 
283
    fkey= new DrizzleDumpForeignKey(row[0], dcon);
 
284
    fkey->parentColumns= row[1];
 
285
    fkey->childTable= row[2];
 
286
    fkey->childColumns= row[3];
 
287
    if (strcmp(row[4], "NONE") != 0)
 
288
      fkey->matchOption= row[4];
 
289
    else
 
290
      fkey->matchOption= "";
 
291
 
 
292
    if (strcmp(row[5], "UNDEFINED") != 0)
 
293
      fkey->deleteRule= row[5];
 
294
    else
 
295
      fkey->deleteRule= "";
 
296
 
 
297
    if (strcmp(row[6], "UNDEFINED") != 0)
 
298
      fkey->updateRule= row[6];
 
299
    else
 
300
      fkey->updateRule= "";
 
301
 
 
302
    fkeys.push_back(fkey);
 
303
  }
 
304
  dcon->freeResult(result);
 
305
  return true;
 
306
}
 
307
 
259
308
DrizzleDumpData* DrizzleDumpTableDrizzle::getData(void)
260
309
{
261
310
  try