42
41
Written from Google proto example
44
static void print_field(const message::Table::Field &field)
46
cout << "\t`" << field.name() << "`";
48
message::Table::Field::FieldType field_type= field.type();
52
case message::Table::Field::DOUBLE:
55
case message::Table::Field::VARCHAR:
56
cout << " VARCHAR(" << field.string_options().length() << ")";
58
case message::Table::Field::BLOB:
59
cout << " BLOB "; /* FIXME: or text, depends on collation */
60
if(field.string_options().has_collation_id())
61
cout << "COLLATION=" << field.string_options().collation_id() << " ";
63
case message::Table::Field::ENUM:
68
for (x= 0; x < field.set_options().field_value_size() ; x++)
70
const string type= field.set_options().field_value(x);
74
cout << "'" << type << "'";
79
case message::Table::Field::INTEGER:
82
case message::Table::Field::BIGINT:
85
case message::Table::Field::DECIMAL:
86
cout << " DECIMAL(" << field.numeric_options().precision() << "," << field.numeric_options().scale() << ") ";
88
case message::Table::Field::DATE:
91
case message::Table::Field::TIME:
94
case message::Table::Field::TIMESTAMP:
95
cout << " TIMESTAMP ";
97
case message::Table::Field::DATETIME:
102
if (field.type() == message::Table::Field::INTEGER
103
|| field.type() == message::Table::Field::BIGINT)
105
if (field.has_constraints()
106
&& field.constraints().has_is_unsigned())
107
if (field.constraints().is_unsigned())
110
if (field.has_numeric_options() &&
111
field.numeric_options().is_autoincrement())
112
cout << " AUTOINCREMENT ";
115
if (!( field.has_constraints()
116
&& field.constraints().is_nullable()))
117
cout << " NOT NULL ";
119
if (field.type() == message::Table::Field::BLOB
120
|| field.type() == message::Table::Field::VARCHAR)
122
if (field.string_options().has_collation())
123
cout << " COLLATE " << field.string_options().collation();
126
if (field.options().has_default_value())
127
cout << " DEFAULT `" << field.options().default_value() << "` " ;
129
if (field.options().has_default_bin_value())
131
string v= field.options().default_bin_value();
132
cout << " DEFAULT 0x";
133
for(unsigned int i=0; i< v.length(); i++)
135
printf("%.2x", *(v.c_str()+i));
139
if (field.type() == message::Table::Field::TIMESTAMP)
140
if (field.timestamp_options().has_auto_updates()
141
&& field.timestamp_options().auto_updates())
142
cout << " ON UPDATE CURRENT_TIMESTAMP";
144
if (field.has_comment())
145
cout << " COMMENT `" << field.comment() << "` ";
148
static void print_engine(const message::Table::StorageEngine &engine)
152
cout << " ENGINE = " << engine.name() << endl;
154
for (x= 0; x < engine.option_size(); ++x) {
155
const message::Table::StorageEngine::EngineOption option= engine.option(x);
156
cout << "\t" << option.option_name() << " = "
157
<< option.option_value() << endl;
161
static void print_index(const message::Table::Index &index)
164
if (index.is_primary())
166
else if (index.is_unique())
168
cout << " KEY `" << index.name() << "` (";
172
for (x= 0; x < index.index_part_size() ; x++)
174
const message::Table::Index::IndexPart part= index.index_part(x);
178
cout << "`" << part.fieldnr() << "`"; /* FIXME */
179
if (part.has_compare_length())
180
cout << "(" << part.compare_length() << ")";
187
static void print_table_options(const message::Table::TableOptions &options)
189
if (options.has_comment())
190
cout << " COMMENT = '" << options.comment() << "' " << endl;
192
if (options.has_collation())
193
cout << " COLLATE = '" << options.collation() << "' " << endl;
195
if (options.has_auto_increment())
196
cout << " AUTOINCREMENT_OFFSET = " << options.auto_increment() << endl;
198
if (options.has_collation_id())
199
cout << "-- collation_id = " << options.collation_id() << endl;
201
if (options.has_row_type())
202
cout << " ROW_TYPE = " << options.row_type() << endl;
204
if (options.has_data_file_name())
205
cout << " DATA_FILE_NAME = '" << options.data_file_name() << "'" << endl;
207
if (options.has_index_file_name())
208
cout << " INDEX_FILE_NAME = '" << options.index_file_name() << "'" << endl;
210
if (options.has_max_rows())
211
cout << " MAX_ROWS = " << options.max_rows() << endl;
213
if (options.has_min_rows())
214
cout << " MIN_ROWS = " << options.min_rows() << endl;
216
if (options.has_auto_increment_value())
217
cout << " AUTO_INCREMENT = " << options.auto_increment_value() << endl;
219
if (options.has_avg_row_length())
220
cout << " AVG_ROW_LENGTH = " << options.avg_row_length() << endl;
222
if (options.has_key_block_size())
223
cout << " KEY_BLOCK_SIZE = " << options.key_block_size() << endl;
225
if (options.has_block_size())
226
cout << " BLOCK_SIZE = " << options.block_size() << endl;
228
if (options.has_comment())
229
cout << " COMMENT = '" << options.comment() << "'" << endl;
231
if (options.has_pack_keys())
232
cout << " PACK_KEYS = " << options.pack_keys() << endl;
233
if (options.has_pack_record())
234
cout << " PACK_RECORD = " << options.pack_record() << endl;
235
if (options.has_checksum())
236
cout << " CHECKSUM = " << options.checksum() << endl;
237
if (options.has_page_checksum())
238
cout << " PAGE_CHECKSUM = " << options.page_checksum() << endl;
242
static void print_table(const message::Table &table)
248
if (table.type() == message::Table::TEMPORARY)
249
cout << "TEMPORARY ";
251
cout << "TABLE `" << table.name() << "` (" << endl;
253
for (x= 0; x < table.field_size() ; x++)
255
const message::Table::Field field = table.field(x);
263
for (x= 0; x < table.indexes_size() ; x++)
265
const message::Table::Index index= table.indexes(x);
268
cout << "," << endl;;
275
cout << ") " << endl;
277
print_engine(table.engine());
279
if (table.has_options())
280
print_table_options(table.options());
282
if (table->has_stats())
283
print_table_stats(&table->stats());
45
287
int main(int argc, char* argv[])
47
289
GOOGLE_PROTOBUF_VERIFY_VERSION;