~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to client/drizzledump_mysql.cc

  • Committer: Andrew Hutchings
  • Date: 2010-09-23 20:32:31 UTC
  • mto: (1792.1.1 build)
  • mto: This revision was merged to the branch mainline in revision 1793.
  • Revision ID: andrew@linuxjedi.co.uk-20100923203231-9bpfjwm0fih91ize
Fix various bugs

Show diffs side-by-side

added added

removed removed

Lines of Context:
26
26
#include <boost/date_time/posix_time/posix_time.hpp>
27
27
#include <drizzled/gettext.h>
28
28
 
 
29
extern bool  verbose;
 
30
 
29
31
bool DrizzleDumpDatabaseMySQL::populateTables()
30
32
{
31
33
  drizzle_result_st *result;
34
36
 
35
37
  dcon->setDB(databaseName);
36
38
 
 
39
  if (verbose)
 
40
    std::cerr << _("-- Retrieving table structures for ") << databaseName << "..." << std::endl;
 
41
 
37
42
  query="SELECT TABLE_NAME, TABLE_COLLATION, ENGINE, AUTO_INCREMENT FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA='";
38
43
  query.append(databaseName);
39
44
  query.append("' ORDER BY TABLE_NAME");
62
67
  return true;
63
68
}
64
69
 
 
70
bool DrizzleDumpDatabaseMySQL::populateTables(const std::vector<std::string> &table_names)
 
71
{
 
72
  drizzle_result_st *result;
 
73
  drizzle_row_t row;
 
74
  std::string query;
 
75
 
 
76
  dcon->setDB(databaseName);
 
77
 
 
78
  if (verbose)
 
79
    std::cerr << _("-- Retrieving table structures for ") << databaseName << "..." << std::endl;
 
80
  for (std::vector<std::string>::const_iterator it= table_names.begin(); it != table_names.end(); ++it)
 
81
  {
 
82
    std::string tableName= *it;
 
83
    query="SELECT TABLE_NAME, TABLE_COLLATION, ENGINE, AUTO_INCREMENT FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA='";
 
84
    query.append(databaseName);
 
85
    query.append("' AND TABLE_NAME = '");
 
86
    query.append(tableName);
 
87
    query.append("'");
 
88
 
 
89
    result= dcon->query(query);
 
90
 
 
91
    if ((row= drizzle_row_next(result)))
 
92
    {
 
93
      DrizzleDumpTableMySQL *table = new DrizzleDumpTableMySQL(tableName, dcon);
 
94
      table->setCollate(row[1]);
 
95
      table->setEngine(row[2]);
 
96
      if (row[3])
 
97
        table->autoIncrement= boost::lexical_cast<uint64_t>(row[3]);
 
98
      else
 
99
        table->autoIncrement= 0;
 
100
 
 
101
      table->database= this;
 
102
      table->populateFields();
 
103
      table->populateIndexes();
 
104
      tables.push_back(table);
 
105
      dcon->freeResult(result);
 
106
    }
 
107
    else
 
108
    {
 
109
      dcon->freeResult(result);
 
110
      return false;
 
111
    }
 
112
  }
 
113
 
 
114
  return true;
 
115
 
 
116
}
 
117
 
65
118
bool DrizzleDumpTableMySQL::populateFields()
66
119
{
67
120
  drizzle_result_st *result;
68
121
  drizzle_row_t row;
69
122
  std::string query;
70
123
 
 
124
  if (verbose)
 
125
    std::cerr << _("-- Retrieving fields for ") << tableName << "..." << std::endl;
 
126
 
71
127
  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='";
72
128
  query.append(database->databaseName);
73
129
  query.append("' AND TABLE_NAME='");
154
210
  bool firstIndex= true;
155
211
  DrizzleDumpIndex *index;
156
212
 
 
213
  if (verbose)
 
214
    std::cerr << _("-- Retrieving indexes for ") << tableName << "..." << std::endl;
 
215
 
157
216
  query="SHOW INDEXES FROM ";
158
217
  query.append(tableName);
159
218