~thomir-deactivatedaccount/drizzle/drizzle-fix-bug653747

« back to all changes in this revision

Viewing changes to client/drizzledump_mysql.cc

  • Committer: Monty Taylor
  • Date: 2010-10-20 16:35:23 UTC
  • mfrom: (1862.1.4 ld-version-script)
  • Revision ID: mordred@inaugust.com-20101020163523-u7ibkag4we6yfrik
Added some replication docs.
Fixed MySQL 5.0 foreign key support in drizzledump.
Fixed the build so that haildb can live in the tree normally.

Show diffs side-by-side

added added

removed removed

Lines of Context:
68
68
    else
69
69
      table->autoIncrement= 0;
70
70
 
71
 
    if (row[4])
 
71
    if ((row[4]) and (strstr(row[4], "InnoDB free") == NULL))
72
72
      table->comment= DrizzleDumpData::escape(row[4], row_sizes[4]);
73
73
    else
74
74
      table->comment= "";
299
299
  if (verbose)
300
300
    std::cerr << _("-- Retrieving foreign keys for ") << tableName << "..." << std::endl;
301
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");
 
302
  query= "SHOW TABLES FROM INFORMATION_SCHEMA LIKE 'REFERENTIAL_CONSTRAINTS'";
307
303
 
308
304
  result= dcon->query(query);
309
305
 
310
306
  if (result == NULL)
311
307
    return false;
312
308
 
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);
 
309
  uint64_t search_count = drizzle_result_row_count(result);
 
310
 
 
311
  dcon->freeResult(result);
 
312
 
 
313
  /* MySQL 5.0 will be 0 and MySQL 5.1 will be 1 */
 
314
  if (search_count > 0)
 
315
  {
 
316
    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='";
 
317
    query.append(database->databaseName);
 
318
    query.append("' and rc.table_name='");
 
319
    query.append(tableName);
 
320
    query.append("' group by rc.constraint_name");
 
321
 
 
322
    result= dcon->query(query);
 
323
 
 
324
    if (result == NULL)
 
325
      return false;
 
326
 
 
327
    while ((row= drizzle_row_next(result)))
 
328
    {
 
329
      fkey= new DrizzleDumpForeignKey(row[0], dcon);
 
330
      fkey->parentColumns= row[6];
 
331
      fkey->childTable= row[1];
 
332
      fkey->childColumns= row[2];
 
333
      fkey->updateRule= (strcmp(row[3], "RESTRICT") != 0) ? row[3] : "";
 
334
      fkey->deleteRule= (strcmp(row[4], "RESTRICT") != 0) ? row[4] : "";
 
335
      fkey->matchOption= (strcmp(row[5], "NONE") != 0) ? row[5] : "";
 
336
 
 
337
      fkeys.push_back(fkey);
 
338
    }
 
339
  }
 
340
  else
 
341
  {
 
342
    query= "SHOW CREATE TABLE `";
 
343
    query.append(database->databaseName);
 
344
    query.append("`.`");
 
345
    query.append(tableName);
 
346
    query.append("`");
 
347
    result= dcon->query(query);
 
348
 
 
349
    if (result == NULL)
 
350
      return false;
 
351
 
 
352
    if ((row= drizzle_row_next(result)))
 
353
    {
 
354
      boost::match_flag_type flags = boost::match_default;
 
355
      boost::regex constraint_regex("CONSTRAINT `(.*)` FOREIGN KEY \\((.*)\\) REFERENCES `(.*)` \\((.*)\\)( ON (UPDATE|DELETE) (CASCADE|RESTRICT|SET NULL))?( ON (UPDATE|DELETE) (CASCADE|RESTRICT|SET NULL))?");
 
356
 
 
357
      boost::match_results<std::string::const_iterator> constraint_results;
 
358
 
 
359
      std::string search_body(row[1]);
 
360
      std::string::const_iterator start, end;
 
361
      start= search_body.begin();
 
362
      end= search_body.end();
 
363
      while (regex_search(start, end, constraint_results, constraint_regex, flags))
 
364
      {
 
365
        fkey= new DrizzleDumpForeignKey(constraint_results[1], dcon);
 
366
        fkey->parentColumns= constraint_results[2];
 
367
        fkey->childTable= constraint_results[3];
 
368
        fkey->childColumns= constraint_results[4];
 
369
        
 
370
        if (constraint_results[5].compare("") != 0)
 
371
        {
 
372
          if (constraint_results[6].compare("UPDATE") == 0)
 
373
            fkey->updateRule= constraint_results[7];
 
374
          else if (constraint_results[6].compare("DELETE") == 0)
 
375
            fkey->deleteRule= constraint_results[7];
 
376
        }
 
377
        if (constraint_results[8].compare("") != 0)
 
378
        {
 
379
          if (constraint_results[9].compare("UPDATE") == 0)
 
380
            fkey->updateRule= constraint_results[10];
 
381
          else if (constraint_results[9].compare("DELETE") == 0)
 
382
            fkey->deleteRule= constraint_results[10];
 
383
        }
 
384
        fkey->matchOption= "";
 
385
 
 
386
        fkeys.push_back(fkey);
 
387
 
 
388
        start= constraint_results[0].second;
 
389
        flags |= boost::match_prev_avail; 
 
390
        flags |= boost::match_not_bob;
 
391
      }
 
392
    }
324
393
  }
325
394
  dcon->freeResult(result);
326
395
  return true;