4
4
#include <drizzled/serialize/table.pb.h>
7
using namespace drizzle;
9
10
Written from Google proto example
12
void print_field(const drizzle::Table::Field *field)
13
void print_field(const ::drizzle::Table::Field &field)
14
using namespace drizzle;
15
cout << "\t`" << field->name() << "`";
16
switch (field->type())
15
cout << "\t`" << field.name() << "`";
18
18
case Table::Field::DOUBLE:
19
19
cout << " DOUBLE ";
21
21
case Table::Field::VARCHAR:
22
cout << " VARCHAR(" << field->string_options().length() << ")";
22
cout << " VARCHAR(" << field.string_options().length() << ")";
24
24
case Table::Field::TEXT:
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)
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";
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 ";
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 ";
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)
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();
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() << "` " ;
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";
105
if (field->has_comment())
106
cout << " COMMENT `" << field->comment() << "` ";
105
if (field.has_comment())
106
cout << " COMMENT `" << field.comment() << "` ";
109
void print_engine(const drizzle::Table::StorageEngine *engine)
109
void print_engine(const ::drizzle::Table::StorageEngine &engine)
111
using namespace drizzle;
114
cout << " ENGINE = " << engine->name() << endl;
116
for (x= 0; x < engine->option_size(); ++x) {
117
const Table::StorageEngine::EngineOption option= engine->option(x);
113
cout << " ENGINE = " << engine.name() << endl;
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;
122
void print_index(const drizzle::Table::Index *index)
121
void print_index(const ::drizzle::Table::Index &index)
124
using namespace drizzle;
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() << "` (";
135
for (x= 0; x < index->index_part_size() ; x++)
132
for (x= 0; x < index.index_part_size() ; x++)
137
const Table::Index::IndexPart part= index->index_part(x);
134
const Table::Index::IndexPart part= index.index_part(x);
150
void print_table_stats(const drizzle::Table::TableStats *stats)
155
void print_table_options(const drizzle::Table::TableOptions *options)
157
if (options->has_comment())
158
cout << " COMMENT = '" << options->comment() << "' " << endl;
160
if (options->has_collation())
161
cout << " COLLATE = '" << options->collation() << "' " << endl;
165
void print_table(const drizzle::Table *table)
167
using namespace drizzle;
147
void print_table_stats(const ::drizzle::Table::TableStats&)
152
void print_table_options(const ::drizzle::Table::TableOptions &options)
154
if (options.has_comment())
155
cout << " COMMENT = '" << options.comment() << "' " << endl;
157
if (options.has_collation())
158
cout << " COLLATE = '" << options.collation() << "' " << endl;
162
void print_table(const ::drizzle::Table &table)
170
166
cout << "CREATE ";
172
if (table->type() == Table::TEMPORARY)
168
if (table.type() == Table::TEMPORARY)
173
169
cout << "TEMPORARY ";
175
cout << "TABLE `" << table->name() << "` (" << endl;
171
cout << "TABLE `" << table.name() << "` (" << endl;
177
for (x= 0; x < table->field_size() ; x++)
173
for (x= 0; x < table.field_size() ; x++)
179
const Table::Field field = table->field(x);
175
const Table::Field field = table.field(x);
182
178
cout << "," << endl;
187
for (x= 0; x < table->index_size() ; x++)
183
for (x= 0; x < table.index_size() ; x++)
189
const Table::Index index= table->index(x);
185
const Table::Index index= table.index(x);
192
188
cout << "," << endl;;
199
195
cout << ") " << endl;
201
print_engine(&table->engine());
197
print_engine(table.engine());
203
if (table->has_options())
204
print_table_options(&table->options());
199
if (table.has_options())
200
print_table_options(table.options());
206
202
if (table->has_stats())
207
203
print_table_stats(&table->stats());