11
#include <drizzled/serialize/table.pb.h>
12
#include <google/protobuf/io/zero_copy_stream.h>
13
#include <google/protobuf/io/zero_copy_stream_impl.h>
5
15
using namespace std;
16
using namespace drizzle;
17
using namespace google::protobuf::io;
8
20
Written from Google proto example
11
void print_field(const drizzle::Table::Field *field)
23
void print_field(const ::drizzle::Table::Field &field)
13
using namespace drizzle;
14
cout << "\t`" << field->name() << "`";
15
switch (field->type())
25
cout << "\t`" << field.name() << "`";
17
28
case Table::Field::DOUBLE:
18
29
cout << " DOUBLE ";
20
31
case Table::Field::VARCHAR:
21
cout << " VARCHAR(" << field->string_options().length() << ")";
32
cout << " VARCHAR(" << field.string_options().length() << ")";
23
34
case Table::Field::TEXT:
80
if (field->type() == Table::Field::INTEGER
81
|| field->type() == Table::Field::BIGINT
82
|| field->type() == Table::Field::SMALLINT
83
|| field->type() == Table::Field::TINYINT) {
84
if (field->has_constraints()
85
&& field->constraints().has_is_unsigned())
86
if (field->constraints().is_unsigned())
82
if (field.type() == Table::Field::INTEGER
83
|| field.type() == Table::Field::BIGINT
84
|| field.type() == Table::Field::TINYINT)
86
if (field.has_constraints()
87
&& field.constraints().has_is_unsigned())
88
if (field.constraints().is_unsigned())
87
89
cout << " UNSIGNED";
89
if (field->has_numeric_options() &&
90
field->numeric_options().is_autoincrement())
91
if (field.has_numeric_options() &&
92
field.numeric_options().is_autoincrement())
91
93
cout << " AUTOINCREMENT ";
94
if (! field->has_constraints()
95
&& field->constraints().is_nullable())
96
if (! field.has_constraints()
97
&& field.constraints().is_nullable())
96
98
cout << " NOT NULL ";
98
if (field->type() == Table::Field::TEXT
99
|| field->type() == Table::Field::VARCHAR) {
100
if (field->string_options().has_charset())
101
cout << " CHARACTER SET " << field->string_options().charset();
103
if (field->string_options().has_collation())
104
cout << " COLLATE " << field->string_options().collation();
100
if (field.type() == Table::Field::TEXT
101
|| field.type() == Table::Field::VARCHAR)
103
if (field.string_options().has_collation())
104
cout << " COLLATE " << field.string_options().collation();
107
if (field->options().has_default_value())
108
cout << " DEFAULT `" << field->options().default_value() << "` " ;
107
if (field.options().has_default_value())
108
cout << " DEFAULT `" << field.options().default_value() << "` " ;
110
if (field->type() == Table::Field::TIMESTAMP)
111
if (field->timestamp_options().has_auto_updates()
112
&& field->timestamp_options().auto_updates())
110
if (field.type() == Table::Field::TIMESTAMP)
111
if (field.timestamp_options().has_auto_updates()
112
&& field.timestamp_options().auto_updates())
113
113
cout << " ON UPDATE CURRENT_TIMESTAMP";
115
if (field->has_comment())
116
cout << " COMMENT `" << field->comment() << "` ";
115
if (field.has_comment())
116
cout << " COMMENT `" << field.comment() << "` ";
119
void print_engine(const drizzle::Table::StorageEngine *engine) {
120
using namespace drizzle;
123
cout << " ENGINE = " << engine->name() << endl;
125
for (x= 0; x < engine->option_size(); ++x) {
126
const Table::StorageEngine::EngineOption option= engine->option(x);
127
cout << "\t" << option.name() << " = " << option.value() << endl;
119
void print_engine(const ::drizzle::Table::StorageEngine &engine)
123
cout << " ENGINE = " << engine.name() << endl;
125
for (x= 0; x < engine.option_size(); ++x) {
126
const Table::StorageEngine::EngineOption option= engine.option(x);
127
cout << "\t" << option.option_name() << " = "
128
<< option.option_value() << endl;
131
void print_index(const drizzle::Table::Index *index) {
132
using namespace drizzle;
132
void print_index(const ::drizzle::Table::Index &index)
135
if (index->is_primary())
137
else if (index->is_unique())
139
cout << " KEY `" << index->name() << "` (";
135
if (index.is_primary())
137
else if (index.is_unique())
139
cout << " KEY `" << index.name() << "` (";
143
for (x= 0; x < index->index_part_size() ; x++)
143
for (x= 0; x < index.index_part_size() ; x++)
145
const Table::Index::IndexPart part= index->index_part(x);
145
const Table::Index::IndexPart part= index.index_part(x);
149
cout << "`" << part.field().name() << "`";
149
cout << "`" << part.fieldnr() << "`"; /* FIXME */
150
150
if (part.has_compare_length())
151
151
cout << "(" << part.compare_length() << ")";
158
void print_table(const drizzle::Table *table)
160
using namespace drizzle;
158
void print_table_stats(const ::drizzle::Table::TableStats&)
163
void print_table_options(const ::drizzle::Table::TableOptions &options)
165
if (options.has_comment())
166
cout << " COMMENT = '" << options.comment() << "' " << endl;
168
if (options.has_collation())
169
cout << " COLLATE = '" << options.collation() << "' " << endl;
171
if (options.has_auto_increment())
172
cout << " AUTOINCREMENT_OFFSET = " << options.auto_increment() << endl;
174
if (options.has_collation_id())
175
cout << "-- collation_id = " << options.collation_id() << endl;
177
if (options.has_connect_string())
178
cout << " CONNECT_STRING = '" << options.connect_string() << "'"<<endl;
180
if (options.has_row_type())
181
cout << " ROW_TYPE = " << options.row_type() << endl;
183
/* optional string data_file_name = 5;
184
optional string index_file_name = 6;
185
optional uint64 max_rows = 7;
186
optional uint64 min_rows = 8;
187
optional uint64 auto_increment_value = 9;
188
optional uint32 avg_row_length = 11;
189
optional uint32 key_block_size = 12;
190
optional uint32 block_size = 13;
191
optional string comment = 14;
192
optional bool pack_keys = 15;
193
optional bool checksum = 16;
194
optional bool page_checksum = 17;
195
optional bool delay_key_write = 18;
200
void print_table(const ::drizzle::Table &table)
163
204
cout << "CREATE ";
165
if (table->type() == Table::TEMPORARY)
206
if (table.type() == Table::TEMPORARY)
166
207
cout << "TEMPORARY ";
168
cout << "TABLE `" << table->name() << "` (" << endl;
170
for (x= 0; x < table->field_size() ; x++)
209
cout << "TABLE `" << table.name() << "` (" << endl;
211
for (x= 0; x < table.field_size() ; x++)
172
const Table::Field field = table->field(x);
213
const Table::Field field = table.field(x);
175
216
cout << "," << endl;
180
for (x= 0; x < table->index_size() ; x++)
221
for (x= 0; x < table.indexes_size() ; x++)
182
const Table::Index index= table->index(x);
223
const Table::Index index= table.indexes(x);
185
226
cout << "," << endl;;
192
233
cout << ") " << endl;
194
print_engine(&table->engine());
235
print_engine(table.engine());
237
if (table.has_options())
238
print_table_options(table.options());
197
if (table->has_options())
198
print_table_options(&table->options());
199
240
if (table->has_stats())
200
241
print_table_stats(&table->stats());
202
if (table->has_comment())
203
cout << " COMMENT = `" << table->comment() << "` " << endl;
206
void print_table_stats(const drizzle::Table::TableStats *stats) {
210
void print_table_options(const drizzle::Table::TableOptions *options) {
211
if (options->has_collation())
212
cout << " COLLATE = `" << options->collation() << "` " << endl;
213
if (options->has_charset())
214
cout << " CHARACTER SET = `" << options->charset() << "` " << endl;
217
int main(int argc, char* argv[])
245
int main(int argc, char* argv[])
219
247
GOOGLE_PROTOBUF_VERIFY_VERSION;