243
243
std::string query;
245
245
if (connected_server_type == SERVER_MYSQL_FOUND)
246
query="SELECT COLUMN_NAME, COLUMN_TYPE, COLUMN_DEFAULT, 'NO', IS_NULLABLE, 'NO', CHARACTER_MAXIMUM_LENGTH, NUMERIC_PRECISION, NUMERIC_SCALE, COLLATION_NAME FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_SCHEMA='";
246
query="SELECT COLUMN_NAME, COLUMN_TYPE, COLUMN_DEFAULT, 'NO', IS_NULLABLE, CHARACTER_MAXIMUM_LENGTH, NUMERIC_PRECISION, NUMERIC_SCALE, COLLATION_NAME FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_SCHEMA='";
248
query= "SELECT COLUMN_NAME, DATA_TYPE, COLUMN_DEFAULT, COLUMN_DEFAULT_IS_NULL, IS_NULLABLE, IS_USED_IN_PRIMARY, CHARACTER_MAXIMUM_LENGTH, NUMERIC_PRECISION, NUMERIC_SCALE, COLLATION_NAME FROM DATA_DICTIONARY.COLUMNS WHERE TABLE_SCHEMA='";
248
query= "SELECT COLUMN_NAME, DATA_TYPE, COLUMN_DEFAULT, COLUMN_DEFAULT_IS_NULL, IS_NULLABLE, CHARACTER_MAXIMUM_LENGTH, NUMERIC_PRECISION, NUMERIC_SCALE, COLLATION_NAME FROM DATA_DICTIONARY.COLUMNS WHERE TABLE_SCHEMA='";
249
249
query.append(database->databaseName);
250
250
query.append("' AND TABLE_NAME='");
251
251
query.append(tableName);
279
279
std::string fieldName(row[0]);
280
280
DrizzleDumpField *field = new DrizzleDumpField(fieldName);
281
281
/* Also sets collation */
282
field->setType(row[1], row[9]);
283
// Default conversion needed
284
field->defaultValue= (row[2]) ? row[2] : "";
282
field->setType(row[1], row[8]);
285
if (field->convertDateTime)
287
field->dateTimeConvert(row[2]);
290
field->defaultValue= row[2];
293
field->defaultValue= "";
285
294
if (connected_server_type == SERVER_MYSQL_FOUND)
286
295
field->defaultIsNull= true;
288
297
field->defaultIsNull= (strcmp(row[3], "YES") == 0) ? true : false;
289
298
field->isNull= (strcmp(row[4], "YES") == 0) ? true : false;
290
field->isPrimary= (strcmp(row[5], "YES") == 0) ? true : false;
291
field->length= (row[6]) ? boost::lexical_cast<uint32_t>(row[6]) : 0;
292
field->decimalPrecision= (row[7]) ? boost::lexical_cast<uint32_t>(row[7]) : 0;
293
field->decimalScale= (row[8]) ? boost::lexical_cast<uint32_t>(row[8]) : 0;
299
field->length= (row[5]) ? boost::lexical_cast<uint32_t>(row[5]) : 0;
300
field->decimalPrecision= (row[6]) ? boost::lexical_cast<uint32_t>(row[6]) : 0;
301
field->decimalScale= (row[7]) ? boost::lexical_cast<uint32_t>(row[7]) : 0;
295
303
fields.push_back(field);
310
void DrizzleDumpField::dateTimeConvert(const char* oldDefault)
312
boost::match_flag_type flags = boost::match_default;
314
if (strcmp(oldDefault, "CURRENT_TIMESTAMP") == 0)
316
defaultValue= oldDefault;
320
if (type.compare("INT") == 0)
322
/* We were a TIME, now we are an INT */
323
std::string ts(oldDefault);
324
boost::posix_time::time_duration td(boost::posix_time::duration_from_string(ts));
325
defaultValue= boost::lexical_cast<string>(td.total_seconds());
329
boost::regex date_regex("([0-9]{3}[1-9]-(0[1-9]|1[012])-(0[1-9]|[12][0-9]|3[01]))");
331
if (regex_search(oldDefault, date_regex, flags))
333
defaultValue= oldDefault;
302
343
bool DrizzleDumpTable::populateIndexes(drizzle_con_st &connection)
304
345
drizzle_result_st result;
507
if ((old_type.find("TIME") != string::npos) or
508
(old_type.find("DATE") != string::npos))
510
/* Intended to catch TIME/DATE/TIMESTAMP/DATETIME
511
We may have a default TIME/DATE which needs converting */
512
convertDateTime= true;
466
515
if (old_type.compare("TIME") == 0)
521
if (old_type.compare("FLOAT") == 0)
567
623
os << "(" << obj.length << ")";
626
if ((obj.type.compare("DECIMAL") == 0) or
627
(obj.type.compare("DOUBLE") == 0))
629
os << "(" << obj.decimalPrecision << "," << obj.decimalScale << ")";
570
632
if (obj.type.compare("ENUM") == 0)
634
//output fields, currently broken in Drizzle
575
637
if (not obj.isNull)