~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to client/drizzledump_drizzle.cc

  • Committer: Andrew Hutchings
  • Date: 2010-09-24 13:38:21 UTC
  • mto: (1792.1.1 build)
  • mto: This revision was merged to the branch mainline in revision 1793.
  • Revision ID: andrew@linuxjedi.co.uk-20100924133821-jzesmb013qy3525m
Fix error handling
Make work with dtr drizzledump test case

Show diffs side-by-side

added added

removed removed

Lines of Context:
33
33
  drizzle_row_t row;
34
34
  std::string query;
35
35
 
36
 
  dcon->setDB(databaseName);
 
36
  if (not dcon->setDB(databaseName))
 
37
    return false;
37
38
 
38
39
  if (verbose)
39
40
    std::cerr << _("-- Retrieving table structures for ") << databaseName << "..." << std::endl;
44
45
 
45
46
  result= dcon->query(query);
46
47
 
 
48
  if (result == NULL)
 
49
    return false;
 
50
 
47
51
  while ((row= drizzle_row_next(result)))
48
52
  {
49
53
    std::string tableName(row[0]);
50
 
    if (not ignoreTable(tableName))
 
54
    std::string displayName(tableName);
 
55
    cleanTableName(displayName);
 
56
    if (not ignoreTable(displayName))
51
57
      continue;
52
58
 
53
59
    DrizzleDumpTable *table = new DrizzleDumpTableDrizzle(tableName, dcon);
 
60
    table->displayName= displayName;
54
61
    table->collate= row[1];
55
62
    table->engineName= row[2];
56
63
    table->autoIncrement= 0;
57
64
    table->database= this;
58
 
    table->populateFields();
59
 
    table->populateIndexes();
 
65
    if ((not table->populateFields()) or (not table->populateIndexes()))
 
66
    {
 
67
      delete table;
 
68
      return false;
 
69
    }
60
70
    tables.push_back(table);
61
71
  }
62
72
 
71
81
  drizzle_row_t row;
72
82
  std::string query;
73
83
 
74
 
  dcon->setDB(databaseName);
 
84
  if (not dcon->setDB(databaseName))
 
85
    return false;
75
86
 
76
87
  if (verbose)
77
88
    std::cerr << _("-- Retrieving table structures for ") << databaseName << "..." << std::endl;
78
89
  for (std::vector<std::string>::const_iterator it= table_names.begin(); it != table_names.end(); ++it)
79
90
  {
80
91
    std::string tableName= *it;
81
 
    if (not ignoreTable(tableName))
 
92
    std::string displayName(tableName);
 
93
    cleanTableName(displayName);
 
94
    if (not ignoreTable(displayName))
82
95
      continue;
83
96
 
84
97
    query="SELECT TABLE_NAME, TABLE_COLLATION, ENGINE FROM DATA_DICTIONARY.TABLES WHERE TABLE_SCHEMA='";
89
102
 
90
103
    result= dcon->query(query);
91
104
 
 
105
    if (result == NULL)
 
106
    {
 
107
      std::cerr << "Error: Could not obtain schema for table " << displayName << std::endl;
 
108
      return false;
 
109
    }
 
110
 
92
111
    if ((row= drizzle_row_next(result)))
93
112
    {
94
113
      DrizzleDumpTableDrizzle *table = new DrizzleDumpTableDrizzle(tableName, dcon);
 
114
      table->displayName= displayName;
95
115
      table->collate= row[1];
96
116
      table->engineName= row[2];
97
117
      table->autoIncrement= 0;
98
118
      table->database= this;
99
 
      table->populateFields();
100
 
      table->populateIndexes();
 
119
      if ((not table->populateFields()) or (not table->populateIndexes()))
 
120
      {
 
121
        std::cerr  << "Error: Could not get fields and/ot indexes for table " << displayName << std::endl;
 
122
        delete table;
 
123
        dcon->freeResult(result);
 
124
        return false;
 
125
      }
101
126
      tables.push_back(table);
102
127
      dcon->freeResult(result);
103
128
    }
104
129
    else
105
130
    {
 
131
      std::cerr << "Error: Table " << displayName << " not found." << std::endl;
106
132
      dcon->freeResult(result);
107
133
      return false;
108
134
    }
137
163
 
138
164
  result= dcon->query(query);
139
165
 
 
166
  if (result == NULL)
 
167
    return false;
 
168
 
140
169
  while ((row= drizzle_row_next(result)))
141
170
  {
142
171
    std::string fieldName(row[0]);
185
214
 
186
215
  result= dcon->query(query);
187
216
 
 
217
  if (result == NULL)
 
218
    return false;
 
219
 
188
220
  while ((row= drizzle_row_next(result)))
189
221
  {
190
222
    std::string indexName(row[0]);
210
242
 
211
243
DrizzleDumpData* DrizzleDumpTableDrizzle::getData(void)
212
244
{
213
 
  return new DrizzleDumpDataDrizzle(this, dcon);
 
245
  try
 
246
  {
 
247
    return new DrizzleDumpDataDrizzle(this, dcon);
 
248
  }
 
249
  catch(...)
 
250
  {
 
251
    return NULL;
 
252
  }
214
253
}
215
254
 
216
255
 
250
289
{
251
290
  std::string query;
252
291
  query= "SELECT * FROM `";
253
 
  query.append(table->tableName);
 
292
  query.append(table->displayName);
254
293
  query.append("`");
255
294
 
256
295
  result= dcon->query(query);
 
296
 
 
297
  if (result == NULL)
 
298
    throw 1;
257
299
}
258
300
 
259
301
DrizzleDumpDataDrizzle::~DrizzleDumpDataDrizzle()