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();
50
if(field_type==message::Table::Field::VIRTUAL)
52
cout << " VIRTUAL"; // FIXME
53
field_type= field.virtual_options().type();
58
case message::Table::Field::DOUBLE:
61
case message::Table::Field::VARCHAR:
62
cout << " VARCHAR(" << field.string_options().length() << ")";
64
case message::Table::Field::BLOB:
65
cout << " BLOB "; /* FIXME: or text, depends on collation */
66
if(field.string_options().has_collation_id())
67
cout << "COLLATION=" << field.string_options().collation_id() << " ";
69
case message::Table::Field::ENUM:
74
for (x= 0; x < field.set_options().field_value_size() ; x++)
76
const string type= field.set_options().field_value(x);
80
cout << "'" << type << "'";
85
case message::Table::Field::TINYINT:
88
case message::Table::Field::INTEGER:
91
case message::Table::Field::BIGINT:
94
case message::Table::Field::DECIMAL:
95
cout << " DECIMAL(" << field.numeric_options().precision() << "," << field.numeric_options().scale() << ") ";
97
case message::Table::Field::DATE:
100
case message::Table::Field::TIME:
103
case message::Table::Field::TIMESTAMP:
104
cout << " TIMESTAMP ";
106
case message::Table::Field::DATETIME:
107
cout << " DATETIME ";
109
case message::Table::Field::VIRTUAL:
110
abort(); // handled above.
113
if(field.type()==message::Table::Field::VIRTUAL)
115
cout << " AS (" << field.virtual_options().expression() << ") ";
116
if(field.virtual_options().physically_stored())
120
if (field.type() == message::Table::Field::INTEGER
121
|| field.type() == message::Table::Field::BIGINT
122
|| field.type() == message::Table::Field::TINYINT)
124
if (field.has_constraints()
125
&& field.constraints().has_is_unsigned())
126
if (field.constraints().is_unsigned())
129
if (field.has_numeric_options() &&
130
field.numeric_options().is_autoincrement())
131
cout << " AUTOINCREMENT ";
134
if (!( field.has_constraints()
135
&& field.constraints().is_nullable()))
136
cout << " NOT NULL ";
138
if (field.type() == message::Table::Field::BLOB
139
|| field.type() == message::Table::Field::VARCHAR)
141
if (field.string_options().has_collation())
142
cout << " COLLATE " << field.string_options().collation();
145
if (field.options().has_default_value())
146
cout << " DEFAULT `" << field.options().default_value() << "` " ;
148
if (field.options().has_default_bin_value())
150
string v= field.options().default_bin_value();
151
cout << " DEFAULT 0x";
152
for(unsigned int i=0; i< v.length(); i++)
154
printf("%.2x", *(v.c_str()+i));
158
if (field.type() == message::Table::Field::TIMESTAMP)
159
if (field.timestamp_options().has_auto_updates()
160
&& field.timestamp_options().auto_updates())
161
cout << " ON UPDATE CURRENT_TIMESTAMP";
163
if (field.has_comment())
164
cout << " COMMENT `" << field.comment() << "` ";
167
static void print_engine(const message::Table::StorageEngine &engine)
171
cout << " ENGINE = " << engine.name() << endl;
173
for (x= 0; x < engine.option_size(); ++x) {
174
const message::Table::StorageEngine::EngineOption option= engine.option(x);
175
cout << "\t" << option.option_name() << " = "
176
<< option.option_value() << endl;
180
static void print_index(const message::Table::Index &index)
183
if (index.is_primary())
185
else if (index.is_unique())
187
cout << " KEY `" << index.name() << "` (";
191
for (x= 0; x < index.index_part_size() ; x++)
193
const message::Table::Index::IndexPart part= index.index_part(x);
197
cout << "`" << part.fieldnr() << "`"; /* FIXME */
198
if (part.has_compare_length())
199
cout << "(" << part.compare_length() << ")";
206
static void print_table_options(const message::Table::TableOptions &options)
208
if (options.has_comment())
209
cout << " COMMENT = '" << options.comment() << "' " << endl;
211
if (options.has_collation())
212
cout << " COLLATE = '" << options.collation() << "' " << endl;
214
if (options.has_auto_increment())
215
cout << " AUTOINCREMENT_OFFSET = " << options.auto_increment() << endl;
217
if (options.has_collation_id())
218
cout << "-- collation_id = " << options.collation_id() << endl;
220
if (options.has_connect_string())
221
cout << " CONNECT_STRING = '" << options.connect_string() << "'"<<endl;
223
if (options.has_row_type())
224
cout << " ROW_TYPE = " << options.row_type() << endl;
226
if (options.has_data_file_name())
227
cout << " DATA_FILE_NAME = '" << options.data_file_name() << "'" << endl;
229
if (options.has_index_file_name())
230
cout << " INDEX_FILE_NAME = '" << options.index_file_name() << "'" << endl;
232
if (options.has_max_rows())
233
cout << " MAX_ROWS = " << options.max_rows() << endl;
235
if (options.has_min_rows())
236
cout << " MIN_ROWS = " << options.min_rows() << endl;
238
if (options.has_auto_increment_value())
239
cout << " AUTO_INCREMENT = " << options.auto_increment_value() << endl;
241
if (options.has_avg_row_length())
242
cout << " AVG_ROW_LENGTH = " << options.avg_row_length() << endl;
244
if (options.has_key_block_size())
245
cout << " KEY_BLOCK_SIZE = " << options.key_block_size() << endl;
247
if (options.has_block_size())
248
cout << " BLOCK_SIZE = " << options.block_size() << endl;
250
if (options.has_comment())
251
cout << " COMMENT = '" << options.comment() << "'" << endl;
253
if (options.has_pack_keys())
254
cout << " PACK_KEYS = " << options.pack_keys() << endl;
255
if (options.has_pack_record())
256
cout << " PACK_RECORD = " << options.pack_record() << endl;
257
if (options.has_checksum())
258
cout << " CHECKSUM = " << options.checksum() << endl;
259
if (options.has_page_checksum())
260
cout << " PAGE_CHECKSUM = " << options.page_checksum() << endl;
264
static void print_table(const message::Table &table)
270
if (table.type() == message::Table::TEMPORARY)
271
cout << "TEMPORARY ";
273
cout << "TABLE `" << table.name() << "` (" << endl;
275
for (x= 0; x < table.field_size() ; x++)
277
const message::Table::Field field = table.field(x);
285
for (x= 0; x < table.indexes_size() ; x++)
287
const message::Table::Index index= table.indexes(x);
290
cout << "," << endl;;
297
cout << ") " << endl;
299
print_engine(table.engine());
301
if (table.has_options())
302
print_table_options(table.options());
304
if (table->has_stats())
305
print_table_stats(&table->stats());
45
309
int main(int argc, char* argv[])
47
311
GOOGLE_PROTOBUF_VERIFY_VERSION;