~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to client/drizzledump_mysql.cc

  • Committer: Monty Taylor
  • Date: 2010-12-05 07:35:32 UTC
  • mfrom: (1974 b)
  • mto: (1975.1.1 build)
  • mto: This revision was merged to the branch mainline in revision 1976.
  • Revision ID: mordred@inaugust.com-20101205073532-hehqwv27pbd7byjm
Merged source.

Show diffs side-by-side

added added

removed removed

Lines of Context:
167
167
  if (verbose)
168
168
    std::cerr << _("-- Retrieving fields for ") << tableName << "..." << std::endl;
169
169
 
170
 
  query="SELECT COLUMN_NAME, COLUMN_TYPE, COLUMN_DEFAULT, IS_NULLABLE, CHARACTER_MAXIMUM_LENGTH, NUMERIC_PRECISION, NUMERIC_SCALE, COLLATION_NAME, EXTRA, COLUMN_COMMENT FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_SCHEMA='";
 
170
  query="SELECT COLUMN_NAME, COLUMN_TYPE, COLUMN_DEFAULT, IS_NULLABLE, CHARACTER_MAXIMUM_LENGTH, NUMERIC_PRECISION, NUMERIC_SCALE, COLLATION_NAME, EXTRA FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_SCHEMA='";
171
171
  query.append(database->databaseName);
172
172
  query.append("' AND TABLE_NAME='");
173
173
  query.append(tableName);
190
190
    if (field->type.compare("ENUM") == 0)
191
191
      field->isNull= true;
192
192
 
193
 
    if ((row[2]) and (field->type.compare("TEXT") != 0))
 
193
    if (row[2])
194
194
    {
195
195
      field->defaultValue= row[2];
196
196
      if (field->convertDateTime)
199
199
      }
200
200
    }
201
201
    else
202
 
    {
203
 
      field->defaultValue= "";
204
 
    }
 
202
     field->defaultValue= "";
205
203
 
206
204
    field->isAutoIncrement= (strcmp(row[8], "auto_increment") == 0) ? true : false;
207
205
    field->defaultIsNull= field->isNull;
208
 
 
209
 
    /* Seriously MySQL, why is BIT length in NUMERIC_PRECISION? */
210
 
    if ((strncmp(row[1], "bit", 3) == 0) and (row[5] != NULL))
211
 
      field->length= ((boost::lexical_cast<uint32_t>(row[5]) - 1) / 8) + 1;
 
206
    field->length= (row[4]) ? boost::lexical_cast<uint32_t>(row[4]) : 0;
 
207
    if ((row[5] != NULL) and (row[6] != NULL))
 
208
    {
 
209
      field->decimalPrecision= boost::lexical_cast<uint32_t>(row[5]);
 
210
      field->decimalScale= boost::lexical_cast<uint32_t>(row[6]);
 
211
    }
212
212
    else
213
 
      field->length= (row[4]) ? boost::lexical_cast<uint32_t>(row[4]) : 0;
214
 
 
215
 
    /* Also, CHAR(0) is valid?? */
216
 
    if (((field->type.compare("VARBINARY") == 0) 
217
 
      or (field->type.compare("VARCHAR") == 0))
218
 
      and (field->length == 0))
219
213
    {
220
 
      field->length= 1;
 
214
      field->decimalPrecision= 0;
 
215
      field->decimalScale= 0;
221
216
    }
222
217
 
223
 
    field->decimalPrecision= (row[5]) ? boost::lexical_cast<uint32_t>(row[5]) : 0;
224
 
    field->decimalScale= (row[6]) ? boost::lexical_cast<uint32_t>(row[6]) : 0;
225
 
    field->comment= (row[9]) ? row[9] : "";
226
218
    fields.push_back(field);
227
219
  }
228
220
 
327
319
  if ((row= drizzle_row_next(result)))
328
320
  {
329
321
    boost::match_flag_type flags = boost::match_default;
330
 
    boost::regex constraint_regex("CONSTRAINT `(.*?)` FOREIGN KEY \\((.*?)\\) REFERENCES `(.*?)` \\((.*?)\\)( ON (UPDATE|DELETE) (CASCADE|RESTRICT|SET NULL))?( ON (UPDATE|DELETE) (CASCADE|RESTRICT|SET NULL))?");
 
322
    boost::regex constraint_regex("CONSTRAINT `(.*)` FOREIGN KEY \\((.*)\\) REFERENCES `(.*)` \\((.*)\\)( ON (UPDATE|DELETE) (CASCADE|RESTRICT|SET NULL))?( ON (UPDATE|DELETE) (CASCADE|RESTRICT|SET NULL))?");
331
323
 
332
324
    boost::match_results<std::string::const_iterator> constraint_results;
333
325
 
375
367
  std::string extra;
376
368
  size_t pos;
377
369
  
378
 
  if (((pos= old_type.find("(")) != std::string::npos) or
379
 
    ((pos= old_type.find(" ")) != std::string::npos))
 
370
  if ((pos= old_type.find("(")) != std::string::npos)
380
371
  {
381
372
    extra= old_type.substr(pos);
382
373
    old_type.erase(pos, std::string::npos);
387
378
    (old_type.find("TEXT") != std::string::npos))
388
379
    setCollate(raw_collation);
389
380
 
390
 
  if ((old_type.compare("BIGINT") == 0) and
391
 
    ((extra.find("unsigned") != std::string::npos)))
392
 
  {
393
 
    rangeCheck= true;
394
 
  }
395
 
 
396
381
  if ((old_type.compare("INT") == 0) and 
397
382
    ((extra.find("unsigned") != std::string::npos)))
398
383
  {
434
419
  if (old_type.compare("BINARY") == 0)
435
420
  {
436
421
    type= "VARBINARY";
437
 
    
438
422
    return;
439
423
  }
440
424
 
467
451
    return;
468
452
  }
469
453
 
470
 
  if (old_type.compare("BIT") == 0)
471
 
  {
472
 
    type= "VARBINARY";
473
 
    return;
474
 
  }
475
 
 
476
454
  type= old_type;
477
455
  return;
478
456
}