11
#include <drizzled/message/table.pb.h>
33
#include <drizzled/message/statement_transform.h>
12
34
#include <google/protobuf/io/zero_copy_stream.h>
13
35
#include <google/protobuf/io/zero_copy_stream_impl.h>
15
37
using namespace std;
16
using namespace drizzled::message;
17
using namespace google::protobuf::io;
38
using namespace drizzled;
39
using namespace google;
20
42
Written from Google proto example
23
void print_field(const ::drizzled::message::Table::Field &field)
25
cout << "\t`" << field.name() << "`";
27
Table::Field::FieldType field_type= field.type();
29
if(field_type==Table::Field::VIRTUAL)
31
cout << " VIRTUAL"; // FIXME
32
field_type= field.virtual_options().type();
37
case Table::Field::DOUBLE:
40
case Table::Field::VARCHAR:
41
cout << " VARCHAR(" << field.string_options().length() << ")";
43
case Table::Field::BLOB:
44
cout << " BLOB "; /* FIXME: or text, depends on collation */
45
if(field.string_options().has_collation_id())
46
cout << "COLLATION=" << field.string_options().collation_id() << " ";
48
case Table::Field::ENUM:
53
for (x= 0; x < field.set_options().field_value_size() ; x++)
55
const string type= field.set_options().field_value(x);
59
cout << "'" << type << "'";
64
case Table::Field::TINYINT:
67
case Table::Field::INTEGER:
70
case Table::Field::BIGINT:
73
case Table::Field::DECIMAL:
74
cout << " DECIMAL(" << field.numeric_options().precision() << "," << field.numeric_options().scale() << ") ";
76
case Table::Field::DATE:
79
case Table::Field::TIME:
82
case Table::Field::TIMESTAMP:
83
cout << " TIMESTAMP ";
85
case Table::Field::DATETIME:
88
case Table::Field::VIRTUAL:
89
abort(); // handled above.
92
if(field.type()==Table::Field::VIRTUAL)
94
cout << " AS (" << field.virtual_options().expression() << ") ";
95
if(field.virtual_options().physically_stored())
99
if (field.type() == Table::Field::INTEGER
100
|| field.type() == Table::Field::BIGINT
101
|| field.type() == Table::Field::TINYINT)
103
if (field.has_constraints()
104
&& field.constraints().has_is_unsigned())
105
if (field.constraints().is_unsigned())
108
if (field.has_numeric_options() &&
109
field.numeric_options().is_autoincrement())
110
cout << " AUTOINCREMENT ";
113
if (!( field.has_constraints()
114
&& field.constraints().is_nullable()))
115
cout << " NOT NULL ";
117
if (field.type() == Table::Field::BLOB
118
|| field.type() == Table::Field::VARCHAR)
120
if (field.string_options().has_collation())
121
cout << " COLLATE " << field.string_options().collation();
124
if (field.options().has_default_value())
125
cout << " DEFAULT `" << field.options().default_value() << "` " ;
127
if (field.options().has_default_bin_value())
129
string v= field.options().default_bin_value();
130
cout << " DEFAULT 0x";
131
for(unsigned int i=0; i< v.length(); i++)
133
printf("%.2x", *(v.c_str()+i));
137
if (field.type() == Table::Field::TIMESTAMP)
138
if (field.timestamp_options().has_auto_updates()
139
&& field.timestamp_options().auto_updates())
140
cout << " ON UPDATE CURRENT_TIMESTAMP";
142
if (field.has_comment())
143
cout << " COMMENT `" << field.comment() << "` ";
146
void print_engine(const ::drizzled::message::Table::StorageEngine &engine)
150
cout << " ENGINE = " << engine.name() << endl;
152
for (x= 0; x < engine.option_size(); ++x) {
153
const Table::StorageEngine::EngineOption option= engine.option(x);
154
cout << "\t" << option.option_name() << " = "
155
<< option.option_value() << endl;
159
void print_index(const ::drizzled::message::Table::Index &index)
162
if (index.is_primary())
164
else if (index.is_unique())
166
cout << " KEY `" << index.name() << "` (";
170
for (x= 0; x < index.index_part_size() ; x++)
172
const Table::Index::IndexPart part= index.index_part(x);
176
cout << "`" << part.fieldnr() << "`"; /* FIXME */
177
if (part.has_compare_length())
178
cout << "(" << part.compare_length() << ")";
185
void print_table_stats(const ::drizzled::message::Table::TableStats&)
190
void print_table_options(const ::drizzled::message::Table::TableOptions &options)
192
if (options.has_comment())
193
cout << " COMMENT = '" << options.comment() << "' " << endl;
195
if (options.has_collation())
196
cout << " COLLATE = '" << options.collation() << "' " << endl;
198
if (options.has_auto_increment())
199
cout << " AUTOINCREMENT_OFFSET = " << options.auto_increment() << endl;
201
if (options.has_collation_id())
202
cout << "-- collation_id = " << options.collation_id() << endl;
204
if (options.has_connect_string())
205
cout << " CONNECT_STRING = '" << options.connect_string() << "'"<<endl;
207
if (options.has_row_type())
208
cout << " ROW_TYPE = " << options.row_type() << endl;
210
if (options.has_data_file_name())
211
cout << " DATA_FILE_NAME = '" << options.data_file_name() << "'" << endl;
213
if (options.has_index_file_name())
214
cout << " INDEX_FILE_NAME = '" << options.index_file_name() << "'" << endl;
216
if (options.has_max_rows())
217
cout << " MAX_ROWS = " << options.max_rows() << endl;
219
if (options.has_min_rows())
220
cout << " MIN_ROWS = " << options.min_rows() << endl;
222
if (options.has_auto_increment_value())
223
cout << " AUTO_INCREMENT = " << options.auto_increment_value() << endl;
225
if (options.has_avg_row_length())
226
cout << " AVG_ROW_LENGTH = " << options.avg_row_length() << endl;
228
if (options.has_key_block_size())
229
cout << " KEY_BLOCK_SIZE = " << options.key_block_size() << endl;
231
if (options.has_block_size())
232
cout << " BLOCK_SIZE = " << options.block_size() << endl;
234
if (options.has_comment())
235
cout << " COMMENT = '" << options.comment() << "'" << endl;
237
if (options.has_pack_keys())
238
cout << " PACK_KEYS = " << options.pack_keys() << endl;
239
if (options.has_pack_record())
240
cout << " PACK_RECORD = " << options.pack_record() << endl;
241
if (options.has_checksum())
242
cout << " CHECKSUM = " << options.checksum() << endl;
243
if (options.has_page_checksum())
244
cout << " PAGE_CHECKSUM = " << options.page_checksum() << endl;
245
if (options.has_delay_key_write())
246
cout << " DELAY_KEY_WRITE = " << options.delay_key_write() << endl;
250
void print_table(const ::drizzled::message::Table &table)
256
if (table.type() == Table::TEMPORARY)
257
cout << "TEMPORARY ";
259
cout << "TABLE `" << table.name() << "` (" << endl;
261
for (x= 0; x < table.field_size() ; x++)
263
const Table::Field field = table.field(x);
271
for (x= 0; x < table.indexes_size() ; x++)
273
const Table::Index index= table.indexes(x);
276
cout << "," << endl;;
283
cout << ") " << endl;
285
print_engine(table.engine());
287
if (table.has_options())
288
print_table_options(table.options());
290
if (table->has_stats())
291
print_table_stats(&table->stats());
295
45
int main(int argc, char* argv[])
297
47
GOOGLE_PROTOBUF_VERIFY_VERSION;