~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/serialize/table_reader.cc

  • Committer: Monty Taylor
  • Date: 2009-01-28 04:37:46 UTC
  • mto: (779.7.3 devel)
  • mto: This revision was merged to the branch mainline in revision 816.
  • Revision ID: mordred@inaugust.com-20090128043746-d2yukekishwn3ftm
TurnedĀ onĀ -Wshadow.

Show diffs side-by-side

added added

removed removed

Lines of Context:
4
4
#include <drizzled/serialize/table.pb.h>
5
5
 
6
6
using namespace std;
 
7
using namespace drizzle;
7
8
 
8
9
/*
9
10
  Written from Google proto example
10
11
*/
11
12
 
12
 
void print_field(const drizzle::Table::Field *field)
 
13
void print_field(const ::drizzle::Table::Field &field)
13
14
{
14
 
  using namespace drizzle;
15
 
  cout << "\t`" << field->name() << "`";
16
 
  switch (field->type())
 
15
  cout << "\t`" << field.name() << "`";
 
16
  switch (field.type())
17
17
  {
18
18
    case Table::Field::DOUBLE:
19
19
    cout << " DOUBLE ";
20
20
    break;
21
21
  case Table::Field::VARCHAR:
22
 
    cout << " VARCHAR(" << field->string_options().length() << ")";
 
22
    cout << " VARCHAR(" << field.string_options().length() << ")";
23
23
    break;
24
24
  case Table::Field::TEXT:
25
25
    cout << " TEXT ";
32
32
      int x;
33
33
 
34
34
      cout << " ENUM(";
35
 
      for (x= 0; x < field->set_options().value_size() ; x++)
 
35
      for (x= 0; x < field.set_options().value_size() ; x++)
36
36
      {
37
 
        const string type= field->set_options().value(x);
 
37
        const string type= field.set_options().value(x);
38
38
 
39
39
        if (x != 0)
40
40
          cout << ",";
53
53
    cout << " BIGINT ";
54
54
    break;
55
55
  case Table::Field::DECIMAL:
56
 
    cout << " DECIMAL(" << field->numeric_options().precision() << "," << field->numeric_options().scale() << ") ";
 
56
    cout << " DECIMAL(" << field.numeric_options().precision() << "," << field.numeric_options().scale() << ") ";
57
57
    break;
58
58
  case Table::Field::DATE:
59
59
    cout << " DATE ";
69
69
    break;
70
70
  }
71
71
 
72
 
  if (field->type() == Table::Field::INTEGER
73
 
      || field->type() == Table::Field::BIGINT
74
 
      || field->type() == Table::Field::TINYINT)
 
72
  if (field.type() == Table::Field::INTEGER
 
73
      || field.type() == Table::Field::BIGINT
 
74
      || field.type() == Table::Field::TINYINT)
75
75
  {
76
 
    if (field->has_constraints()
77
 
        && field->constraints().has_is_unsigned())
78
 
      if (field->constraints().is_unsigned())
 
76
    if (field.has_constraints()
 
77
        && field.constraints().has_is_unsigned())
 
78
      if (field.constraints().is_unsigned())
79
79
        cout << " UNSIGNED";
80
80
 
81
 
    if (field->has_numeric_options() &&
82
 
      field->numeric_options().is_autoincrement())
 
81
    if (field.has_numeric_options() &&
 
82
      field.numeric_options().is_autoincrement())
83
83
      cout << " AUTOINCREMENT ";
84
84
  }
85
85
 
86
 
  if (! field->has_constraints()
87
 
      && field->constraints().is_nullable())
 
86
  if (! field.has_constraints()
 
87
      && field.constraints().is_nullable())
88
88
    cout << " NOT NULL ";
89
89
 
90
 
  if (field->type() == Table::Field::TEXT
91
 
      || field->type() == Table::Field::VARCHAR)
 
90
  if (field.type() == Table::Field::TEXT
 
91
      || field.type() == Table::Field::VARCHAR)
92
92
  {
93
 
    if (field->string_options().has_collation())
94
 
      cout << " COLLATE " << field->string_options().collation();
 
93
    if (field.string_options().has_collation())
 
94
      cout << " COLLATE " << field.string_options().collation();
95
95
  }
96
96
 
97
 
  if (field->options().has_default_value())
98
 
    cout << " DEFAULT `" << field->options().default_value() << "` " ;
 
97
  if (field.options().has_default_value())
 
98
    cout << " DEFAULT `" << field.options().default_value() << "` " ;
99
99
 
100
 
  if (field->type() == Table::Field::TIMESTAMP)
101
 
    if (field->timestamp_options().has_auto_updates()
102
 
      && field->timestamp_options().auto_updates())
 
100
  if (field.type() == Table::Field::TIMESTAMP)
 
101
    if (field.timestamp_options().has_auto_updates()
 
102
      && field.timestamp_options().auto_updates())
103
103
      cout << " ON UPDATE CURRENT_TIMESTAMP";
104
104
 
105
 
  if (field->has_comment())
106
 
    cout << " COMMENT `" << field->comment() << "` ";
 
105
  if (field.has_comment())
 
106
    cout << " COMMENT `" << field.comment() << "` ";
107
107
}
108
108
 
109
 
void print_engine(const drizzle::Table::StorageEngine *engine)
 
109
void print_engine(const ::drizzle::Table::StorageEngine &engine)
110
110
{
111
 
  using namespace drizzle;
112
 
  uint32_t x;
113
 
 
114
 
  cout << " ENGINE = " << engine->name()  << endl;
115
 
 
116
 
  for (x= 0; x < engine->option_size(); ++x) {
117
 
    const Table::StorageEngine::EngineOption option= engine->option(x);
 
111
  int32_t x;
 
112
 
 
113
  cout << " ENGINE = " << engine.name()  << endl;
 
114
 
 
115
  for (x= 0; x < engine.option_size(); ++x) {
 
116
    const Table::StorageEngine::EngineOption option= engine.option(x);
118
117
    cout << "\t" << option.name() << " = " << option.value() << endl;
119
118
  }
120
119
}
121
120
 
122
 
void print_index(const drizzle::Table::Index *index)
 
121
void print_index(const ::drizzle::Table::Index &index)
123
122
{
124
 
  using namespace drizzle;
125
 
  uint32_t x;
126
123
 
127
 
  if (index->is_primary())
 
124
  if (index.is_primary())
128
125
    cout << " PRIMARY";
129
 
  else if (index->is_unique())
 
126
  else if (index.is_unique())
130
127
    cout << " UNIQUE";
131
 
  cout << " KEY `" << index->name() << "` (";
 
128
  cout << " KEY `" << index.name() << "` (";
132
129
  {
133
 
    int x;
 
130
    int32_t x;
134
131
 
135
 
    for (x= 0; x < index->index_part_size() ; x++)
 
132
    for (x= 0; x < index.index_part_size() ; x++)
136
133
    {
137
 
      const Table::Index::IndexPart part= index->index_part(x);
 
134
      const Table::Index::IndexPart part= index.index_part(x);
138
135
 
139
136
      if (x != 0)
140
137
        cout << ",";
147
144
  cout << "\t";
148
145
}
149
146
 
150
 
void print_table_stats(const drizzle::Table::TableStats *stats)
151
 
{
152
 
 
153
 
}
154
 
 
155
 
void print_table_options(const drizzle::Table::TableOptions *options)
156
 
{
157
 
  if (options->has_comment())
158
 
    cout << " COMMENT = '" << options->comment() << "' " << endl;
159
 
 
160
 
  if (options->has_collation())
161
 
    cout << " COLLATE = '" << options->collation() << "' " << endl;
162
 
}
163
 
 
164
 
 
165
 
void print_table(const drizzle::Table *table)
166
 
{
167
 
  using namespace drizzle;
168
 
  uint32_t x;
 
147
void print_table_stats(const ::drizzle::Table::TableStats&) 
 
148
{
 
149
 
 
150
}
 
151
 
 
152
void print_table_options(const ::drizzle::Table::TableOptions &options)
 
153
{
 
154
  if (options.has_comment())
 
155
    cout << " COMMENT = '" << options.comment() << "' " << endl;
 
156
 
 
157
  if (options.has_collation())
 
158
    cout << " COLLATE = '" << options.collation() << "' " << endl;
 
159
}
 
160
 
 
161
 
 
162
void print_table(const ::drizzle::Table &table)
 
163
{
 
164
  int32_t x;
169
165
 
170
166
  cout << "CREATE ";
171
167
 
172
 
  if (table->type() == Table::TEMPORARY)
 
168
  if (table.type() == Table::TEMPORARY)
173
169
    cout << "TEMPORARY ";
174
170
 
175
 
  cout << "TABLE `" << table->name() << "` (" << endl;
 
171
  cout << "TABLE `" << table.name() << "` (" << endl;
176
172
 
177
 
  for (x= 0; x < table->field_size() ; x++)
 
173
  for (x= 0; x < table.field_size() ; x++)
178
174
  {
179
 
    const Table::Field field = table->field(x);
 
175
    const Table::Field field = table.field(x);
180
176
 
181
177
    if (x != 0)
182
178
      cout << "," << endl;
183
179
 
184
 
    print_field(&field);
 
180
    print_field(field);
185
181
  }
186
182
 
187
 
  for (x= 0; x < table->index_size() ; x++)
 
183
  for (x= 0; x < table.index_size() ; x++)
188
184
  {
189
 
    const Table::Index index= table->index(x);
 
185
    const Table::Index index= table.index(x);
190
186
 
191
187
    if (x != 0)
192
188
      cout << "," << endl;;
193
189
 
194
 
    print_index(&index);
 
190
    print_index(index);
195
191
 
196
192
  }
197
193
  cout << endl;
198
194
 
199
195
  cout << ") " << endl;
200
196
 
201
 
  print_engine(&table->engine());
 
197
  print_engine(table.engine());
202
198
 
203
 
  if (table->has_options())
204
 
    print_table_options(&table->options());
 
199
  if (table.has_options())
 
200
    print_table_options(table.options());
205
201
  /*
206
202
  if (table->has_stats())
207
203
    print_table_stats(&table->stats());
217
213
    return -1;
218
214
  }
219
215
 
220
 
  drizzle::Table table;
 
216
  Table table;
221
217
 
222
218
  {
223
219
    // Read the existing address book.
229
225
    }
230
226
  }
231
227
 
232
 
  print_table(&table);
 
228
  print_table(table);
233
229
 
234
230
  return 0;
235
231
}