42
42
Written from Google proto example
45
static void print_field(const message::Table::Field &field)
47
cout << "\t`" << field.name() << "`";
49
message::Table::Field::FieldType field_type= field.type();
53
case message::Table::Field::DOUBLE:
56
case message::Table::Field::VARCHAR:
57
cout << " VARCHAR(" << field.string_options().length() << ")";
59
case message::Table::Field::BLOB:
60
cout << " BLOB "; /* FIXME: or text, depends on collation */
61
if(field.string_options().has_collation_id())
62
cout << "COLLATION=" << field.string_options().collation_id() << " ";
64
case message::Table::Field::ENUM:
69
for (x= 0; x < field.set_options().field_value_size() ; x++)
71
const string type= field.set_options().field_value(x);
75
cout << "'" << type << "'";
80
case message::Table::Field::INTEGER:
83
case message::Table::Field::BIGINT:
86
case message::Table::Field::DECIMAL:
87
cout << " DECIMAL(" << field.numeric_options().precision() << "," << field.numeric_options().scale() << ") ";
89
case message::Table::Field::DATE:
92
case message::Table::Field::TIME:
95
case message::Table::Field::TIMESTAMP:
96
cout << " TIMESTAMP ";
98
case message::Table::Field::DATETIME:
103
if (field.type() == message::Table::Field::INTEGER
104
|| field.type() == message::Table::Field::BIGINT)
106
if (field.has_constraints()
107
&& field.constraints().has_is_unsigned())
108
if (field.constraints().is_unsigned())
111
if (field.has_numeric_options() &&
112
field.numeric_options().is_autoincrement())
113
cout << " AUTOINCREMENT ";
116
if (!( field.has_constraints()
117
&& field.constraints().is_nullable()))
118
cout << " NOT NULL ";
120
if (field.type() == message::Table::Field::BLOB
121
|| field.type() == message::Table::Field::VARCHAR)
123
if (field.string_options().has_collation())
124
cout << " COLLATE " << field.string_options().collation();
127
if (field.options().has_default_value())
128
cout << " DEFAULT `" << field.options().default_value() << "` " ;
130
if (field.options().has_default_bin_value())
132
string v= field.options().default_bin_value();
133
cout << " DEFAULT 0x";
134
for(unsigned int i=0; i< v.length(); i++)
136
printf("%.2x", *(v.c_str()+i));
140
if (field.type() == message::Table::Field::TIMESTAMP)
141
if (field.timestamp_options().has_auto_updates()
142
&& field.timestamp_options().auto_updates())
143
cout << " ON UPDATE CURRENT_TIMESTAMP";
145
if (field.has_comment())
146
cout << " COMMENT `" << field.comment() << "` ";
149
static void print_engine(const message::Table::StorageEngine &engine)
153
cout << " ENGINE = " << engine.name() << endl;
155
for (x= 0; x < engine.option_size(); ++x) {
156
const message::Table::StorageEngine::EngineOption option= engine.option(x);
157
cout << "\t" << option.option_name() << " = "
158
<< option.option_value() << endl;
162
static void print_index(const message::Table::Index &index)
165
if (index.is_primary())
167
else if (index.is_unique())
169
cout << " KEY `" << index.name() << "` (";
173
for (x= 0; x < index.index_part_size() ; x++)
175
const message::Table::Index::IndexPart part= index.index_part(x);
179
cout << "`" << part.fieldnr() << "`"; /* FIXME */
180
if (part.has_compare_length())
181
cout << "(" << part.compare_length() << ")";
188
static void print_table_options(const message::Table::TableOptions &options)
190
if (options.has_comment())
191
cout << " COMMENT = '" << options.comment() << "' " << endl;
193
if (options.has_collation())
194
cout << " COLLATE = '" << options.collation() << "' " << endl;
196
if (options.has_auto_increment())
197
cout << " AUTOINCREMENT_OFFSET = " << options.auto_increment() << endl;
199
if (options.has_collation_id())
200
cout << "-- collation_id = " << options.collation_id() << endl;
202
if (options.has_row_type())
203
cout << " ROW_TYPE = " << options.row_type() << endl;
205
if (options.has_data_file_name())
206
cout << " DATA_FILE_NAME = '" << options.data_file_name() << "'" << endl;
208
if (options.has_index_file_name())
209
cout << " INDEX_FILE_NAME = '" << options.index_file_name() << "'" << endl;
211
if (options.has_max_rows())
212
cout << " MAX_ROWS = " << options.max_rows() << endl;
214
if (options.has_min_rows())
215
cout << " MIN_ROWS = " << options.min_rows() << endl;
217
if (options.has_auto_increment_value())
218
cout << " AUTO_INCREMENT = " << options.auto_increment_value() << endl;
220
if (options.has_avg_row_length())
221
cout << " AVG_ROW_LENGTH = " << options.avg_row_length() << endl;
223
if (options.has_key_block_size())
224
cout << " KEY_BLOCK_SIZE = " << options.key_block_size() << endl;
226
if (options.has_block_size())
227
cout << " BLOCK_SIZE = " << options.block_size() << endl;
229
if (options.has_comment())
230
cout << " COMMENT = '" << options.comment() << "'" << endl;
232
if (options.has_pack_keys())
233
cout << " PACK_KEYS = " << options.pack_keys() << endl;
234
if (options.has_pack_record())
235
cout << " PACK_RECORD = " << options.pack_record() << endl;
236
if (options.has_checksum())
237
cout << " CHECKSUM = " << options.checksum() << endl;
238
if (options.has_page_checksum())
239
cout << " PAGE_CHECKSUM = " << options.page_checksum() << endl;
243
static void print_table(const message::Table &table)
249
if (table.type() == message::Table::TEMPORARY)
250
cout << "TEMPORARY ";
252
cout << "TABLE `" << table.name() << "` (" << endl;
254
for (x= 0; x < table.field_size() ; x++)
256
const message::Table::Field field = table.field(x);
264
for (x= 0; x < table.indexes_size() ; x++)
266
const message::Table::Index index= table.indexes(x);
269
cout << "," << endl;;
276
cout << ") " << endl;
278
print_engine(table.engine());
280
if (table.has_options())
281
print_table_options(table.options());
283
if (table->has_stats())
284
print_table_stats(&table->stats());
288
45
int main(int argc, char* argv[])
290
47
GOOGLE_PROTOBUF_VERIFY_VERSION;