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();
51
if(field_type==message::Table::Field::VIRTUAL)
53
cout << " VIRTUAL"; // FIXME
54
field_type= field.virtual_options().type();
59
case message::Table::Field::DOUBLE:
62
case message::Table::Field::VARCHAR:
63
cout << " VARCHAR(" << field.string_options().length() << ")";
65
case message::Table::Field::BLOB:
66
cout << " BLOB "; /* FIXME: or text, depends on collation */
67
if(field.string_options().has_collation_id())
68
cout << "COLLATION=" << field.string_options().collation_id() << " ";
70
case message::Table::Field::ENUM:
75
for (x= 0; x < field.set_options().field_value_size() ; x++)
77
const string type= field.set_options().field_value(x);
81
cout << "'" << type << "'";
86
case message::Table::Field::TINYINT:
89
case message::Table::Field::INTEGER:
92
case message::Table::Field::BIGINT:
95
case message::Table::Field::DECIMAL:
96
cout << " DECIMAL(" << field.numeric_options().precision() << "," << field.numeric_options().scale() << ") ";
98
case message::Table::Field::DATE:
101
case message::Table::Field::TIME:
104
case message::Table::Field::TIMESTAMP:
105
cout << " TIMESTAMP ";
107
case message::Table::Field::DATETIME:
108
cout << " DATETIME ";
110
case message::Table::Field::VIRTUAL:
111
abort(); // handled above.
114
if(field.type()==message::Table::Field::VIRTUAL)
116
cout << " AS (" << field.virtual_options().expression() << ") ";
117
if(field.virtual_options().physically_stored())
121
if (field.type() == message::Table::Field::INTEGER
122
|| field.type() == message::Table::Field::BIGINT
123
|| field.type() == message::Table::Field::TINYINT)
125
if (field.has_constraints()
126
&& field.constraints().has_is_unsigned())
127
if (field.constraints().is_unsigned())
130
if (field.has_numeric_options() &&
131
field.numeric_options().is_autoincrement())
132
cout << " AUTOINCREMENT ";
135
if (!( field.has_constraints()
136
&& field.constraints().is_nullable()))
137
cout << " NOT NULL ";
139
if (field.type() == message::Table::Field::BLOB
140
|| field.type() == message::Table::Field::VARCHAR)
142
if (field.string_options().has_collation())
143
cout << " COLLATE " << field.string_options().collation();
146
if (field.options().has_default_value())
147
cout << " DEFAULT `" << field.options().default_value() << "` " ;
149
if (field.options().has_default_bin_value())
151
string v= field.options().default_bin_value();
152
cout << " DEFAULT 0x";
153
for(unsigned int i=0; i< v.length(); i++)
155
printf("%.2x", *(v.c_str()+i));
159
if (field.type() == message::Table::Field::TIMESTAMP)
160
if (field.timestamp_options().has_auto_updates()
161
&& field.timestamp_options().auto_updates())
162
cout << " ON UPDATE CURRENT_TIMESTAMP";
164
if (field.has_comment())
165
cout << " COMMENT `" << field.comment() << "` ";
168
static void print_engine(const message::Table::StorageEngine &engine)
172
cout << " ENGINE = " << engine.name() << endl;
174
for (x= 0; x < engine.option_size(); ++x) {
175
const message::Table::StorageEngine::EngineOption option= engine.option(x);
176
cout << "\t" << option.option_name() << " = "
177
<< option.option_value() << endl;
181
static void print_index(const message::Table::Index &index)
184
if (index.is_primary())
186
else if (index.is_unique())
188
cout << " KEY `" << index.name() << "` (";
192
for (x= 0; x < index.index_part_size() ; x++)
194
const message::Table::Index::IndexPart part= index.index_part(x);
198
cout << "`" << part.fieldnr() << "`"; /* FIXME */
199
if (part.has_compare_length())
200
cout << "(" << part.compare_length() << ")";
207
static void print_table_options(const message::Table::TableOptions &options)
209
if (options.has_comment())
210
cout << " COMMENT = '" << options.comment() << "' " << endl;
212
if (options.has_collation())
213
cout << " COLLATE = '" << options.collation() << "' " << endl;
215
if (options.has_auto_increment())
216
cout << " AUTOINCREMENT_OFFSET = " << options.auto_increment() << endl;
218
if (options.has_collation_id())
219
cout << "-- collation_id = " << options.collation_id() << endl;
221
if (options.has_connect_string())
222
cout << " CONNECT_STRING = '" << options.connect_string() << "'"<<endl;
224
if (options.has_row_type())
225
cout << " ROW_TYPE = " << options.row_type() << endl;
227
if (options.has_data_file_name())
228
cout << " DATA_FILE_NAME = '" << options.data_file_name() << "'" << endl;
230
if (options.has_index_file_name())
231
cout << " INDEX_FILE_NAME = '" << options.index_file_name() << "'" << endl;
233
if (options.has_max_rows())
234
cout << " MAX_ROWS = " << options.max_rows() << endl;
236
if (options.has_min_rows())
237
cout << " MIN_ROWS = " << options.min_rows() << endl;
239
if (options.has_auto_increment_value())
240
cout << " AUTO_INCREMENT = " << options.auto_increment_value() << endl;
242
if (options.has_avg_row_length())
243
cout << " AVG_ROW_LENGTH = " << options.avg_row_length() << endl;
245
if (options.has_key_block_size())
246
cout << " KEY_BLOCK_SIZE = " << options.key_block_size() << endl;
248
if (options.has_block_size())
249
cout << " BLOCK_SIZE = " << options.block_size() << endl;
251
if (options.has_comment())
252
cout << " COMMENT = '" << options.comment() << "'" << endl;
254
if (options.has_pack_keys())
255
cout << " PACK_KEYS = " << options.pack_keys() << endl;
256
if (options.has_pack_record())
257
cout << " PACK_RECORD = " << options.pack_record() << endl;
258
if (options.has_checksum())
259
cout << " CHECKSUM = " << options.checksum() << endl;
260
if (options.has_page_checksum())
261
cout << " PAGE_CHECKSUM = " << options.page_checksum() << endl;
265
static void print_table(const message::Table &table)
271
if (table.type() == message::Table::TEMPORARY)
272
cout << "TEMPORARY ";
274
cout << "TABLE `" << table.name() << "` (" << endl;
276
for (x= 0; x < table.field_size() ; x++)
278
const message::Table::Field field = table.field(x);
286
for (x= 0; x < table.indexes_size() ; x++)
288
const message::Table::Index index= table.indexes(x);
291
cout << "," << endl;;
298
cout << ") " << endl;
300
print_engine(table.engine());
302
if (table.has_options())
303
print_table_options(table.options());
305
if (table->has_stats())
306
print_table_stats(&table->stats());
45
310
int main(int argc, char* argv[])
47
312
GOOGLE_PROTOBUF_VERIFY_VERSION;