1
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
* vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
4
* Copyright (C) 2009 Sun Microsystems, Inc.
6
* This program is free software; you can redistribute it and/or modify
7
* it under the terms of the GNU General Public License as published by
8
* the Free Software Foundation; either version 2 of the License, or
9
* (at your option) any later version.
11
* This program is distributed in the hope that it will be useful,
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
* GNU General Public License for more details.
16
* You should have received a copy of the GNU General Public License
17
* along with this program; if not, write to the Free Software
18
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
23
1
#include <sys/types.h>
24
2
#include <sys/stat.h>
33
#include <drizzled/message/statement_transform.h>
11
#include <drizzled/serialize/table.pb.h>
34
12
#include <google/protobuf/io/zero_copy_stream.h>
35
13
#include <google/protobuf/io/zero_copy_stream_impl.h>
37
15
using namespace std;
38
using namespace drizzled;
39
using namespace google;
16
using namespace drizzle;
17
using namespace google::protobuf::io;
42
20
Written from Google proto example
23
void print_field(const ::drizzle::Table::Field &field)
25
cout << "\t`" << field.name() << "`";
28
case Table::Field::DOUBLE:
31
case Table::Field::VARCHAR:
32
cout << " VARCHAR(" << field.string_options().length() << ")";
34
case Table::Field::TEXT:
37
case Table::Field::BLOB:
40
case Table::Field::ENUM:
45
for (x= 0; x < field.set_options().field_value_size() ; x++)
47
const string type= field.set_options().field_value(x);
51
cout << "'" << type << "'";
56
case Table::Field::TINYINT:
59
case Table::Field::INTEGER:
62
case Table::Field::BIGINT:
65
case Table::Field::DECIMAL:
66
cout << " DECIMAL(" << field.numeric_options().precision() << "," << field.numeric_options().scale() << ") ";
68
case Table::Field::DATE:
71
case Table::Field::TIME:
74
case Table::Field::TIMESTAMP:
75
cout << " TIMESTAMP ";
77
case Table::Field::DATETIME:
80
case Table::Field::VIRTUAL:
81
cout << " VIRTUAL"; // FIXME
85
if (field.type() == Table::Field::INTEGER
86
|| field.type() == Table::Field::BIGINT
87
|| field.type() == Table::Field::TINYINT)
89
if (field.has_constraints()
90
&& field.constraints().has_is_unsigned())
91
if (field.constraints().is_unsigned())
94
if (field.has_numeric_options() &&
95
field.numeric_options().is_autoincrement())
96
cout << " AUTOINCREMENT ";
99
if (!( field.has_constraints()
100
&& field.constraints().is_nullable()))
101
cout << " NOT NULL ";
103
if (field.type() == Table::Field::TEXT
104
|| field.type() == Table::Field::VARCHAR)
106
if (field.string_options().has_collation())
107
cout << " COLLATE " << field.string_options().collation();
110
if (field.options().has_default_value())
111
cout << " DEFAULT `" << field.options().default_value() << "` " ;
113
if (field.type() == Table::Field::TIMESTAMP)
114
if (field.timestamp_options().has_auto_updates()
115
&& field.timestamp_options().auto_updates())
116
cout << " ON UPDATE CURRENT_TIMESTAMP";
118
if (field.has_comment())
119
cout << " COMMENT `" << field.comment() << "` ";
122
void print_engine(const ::drizzle::Table::StorageEngine &engine)
126
cout << " ENGINE = " << engine.name() << endl;
128
for (x= 0; x < engine.option_size(); ++x) {
129
const Table::StorageEngine::EngineOption option= engine.option(x);
130
cout << "\t" << option.option_name() << " = "
131
<< option.option_value() << endl;
135
void print_index(const ::drizzle::Table::Index &index)
138
if (index.is_primary())
140
else if (index.is_unique())
142
cout << " KEY `" << index.name() << "` (";
146
for (x= 0; x < index.index_part_size() ; x++)
148
const Table::Index::IndexPart part= index.index_part(x);
152
cout << "`" << part.fieldnr() << "`"; /* FIXME */
153
if (part.has_compare_length())
154
cout << "(" << part.compare_length() << ")";
161
void print_table_stats(const ::drizzle::Table::TableStats&)
166
void print_table_options(const ::drizzle::Table::TableOptions &options)
168
if (options.has_comment())
169
cout << " COMMENT = '" << options.comment() << "' " << endl;
171
if (options.has_collation())
172
cout << " COLLATE = '" << options.collation() << "' " << endl;
174
if (options.has_auto_increment())
175
cout << " AUTOINCREMENT_OFFSET = " << options.auto_increment() << endl;
177
if (options.has_collation_id())
178
cout << "-- collation_id = " << options.collation_id() << endl;
180
if (options.has_connect_string())
181
cout << " CONNECT_STRING = '" << options.connect_string() << "'"<<endl;
183
if (options.has_row_type())
184
cout << " ROW_TYPE = " << options.row_type() << endl;
186
/* optional string data_file_name = 5;
187
optional string index_file_name = 6;
188
optional uint64 max_rows = 7;
189
optional uint64 min_rows = 8;
190
optional uint64 auto_increment_value = 9;
191
optional uint32 avg_row_length = 11;
192
optional uint32 key_block_size = 12;
193
optional uint32 block_size = 13;
194
optional string comment = 14;
195
optional bool pack_keys = 15;
196
optional bool checksum = 16;
197
optional bool page_checksum = 17;
198
optional bool delay_key_write = 18;
203
void print_table(const ::drizzle::Table &table)
209
if (table.type() == Table::TEMPORARY)
210
cout << "TEMPORARY ";
212
cout << "TABLE `" << table.name() << "` (" << endl;
214
for (x= 0; x < table.field_size() ; x++)
216
const Table::Field field = table.field(x);
224
for (x= 0; x < table.indexes_size() ; x++)
226
const Table::Index index= table.indexes(x);
229
cout << "," << endl;;
236
cout << ") " << endl;
238
print_engine(table.engine());
240
if (table.has_options())
241
print_table_options(table.options());
243
if (table->has_stats())
244
print_table_stats(&table->stats());
45
248
int main(int argc, char* argv[])
47
250
GOOGLE_PROTOBUF_VERIFY_VERSION;