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
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
#include <sys/types.h>
33
#include <drizzled/message/statement_transform.h>
34
#include <google/protobuf/io/zero_copy_stream.h>
35
#include <google/protobuf/io/zero_copy_stream_impl.h>
37
5
using namespace std;
38
using namespace drizzled;
39
using namespace google;
42
8
Written from Google proto example
45
int main(int argc, char* argv[])
11
void print_field(const drizzle::Table::Field *field)
13
using namespace drizzle;
14
cout << "\t`" << field->name() << "`";
15
switch (field->type())
17
case Table::Field::DOUBLE:
20
case Table::Field::VARCHAR:
21
cout << " VARCHAR(" << field->string_options().length() << ")";
23
case Table::Field::TEXT:
26
case Table::Field::BLOB:
29
case Table::Field::ENUM:
34
for (x= 0; x < field->set_options().value_size() ; x++)
36
const string type= field->set_options().value(x);
40
cout << "'" << type << "'";
45
case Table::Field::SET:
48
case Table::Field::TINYINT:
51
case Table::Field::SMALLINT:
54
case Table::Field::INTEGER:
57
case Table::Field::BIGINT:
60
case Table::Field::DECIMAL:
61
cout << " DECIMAL(" << field->numeric_options().precision() << "," << field->numeric_options().scale() << ") ";
63
case Table::Field::VARBINARY:
64
cout << " VARBINARY(" << field->string_options().length() << ") ";
66
case Table::Field::DATE:
69
case Table::Field::TIME:
72
case Table::Field::TIMESTAMP:
73
cout << " TIMESTAMP ";
75
case Table::Field::DATETIME:
80
if (field->type() == Table::Field::INTEGER
81
|| field->type() == Table::Field::BIGINT
82
|| field->type() == Table::Field::SMALLINT
83
|| field->type() == Table::Field::TINYINT) {
84
if (field->has_constraints()
85
&& field->constraints().has_is_unsigned())
86
if (field->constraints().is_unsigned())
89
if (field->has_numeric_options() &&
90
field->numeric_options().is_autoincrement())
91
cout << " AUTOINCREMENT ";
94
if (! field->has_constraints()
95
&& field->constraints().is_nullable())
98
if (field->type() == Table::Field::TEXT
99
|| field->type() == Table::Field::VARCHAR) {
100
if (field->string_options().has_charset())
101
cout << " CHARACTER SET " << field->string_options().charset();
103
if (field->string_options().has_collation())
104
cout << " COLLATE " << field->string_options().collation();
107
if (field->options().has_default_value())
108
cout << " DEFAULT `" << field->options().default_value() << "` " ;
110
if (field->type() == Table::Field::TIMESTAMP)
111
if (field->timestamp_options().has_auto_updates()
112
&& field->timestamp_options().auto_updates())
113
cout << " ON UPDATE CURRENT_TIMESTAMP";
115
if (field->has_comment())
116
cout << " COMMENT `" << field->comment() << "` ";
119
void print_engine(const drizzle::Table::StorageEngine *engine) {
120
using namespace drizzle;
123
cout << " ENGINE = " << engine->name() << endl;
125
for (x= 0; x < engine->option_size(); ++x) {
126
const Table::StorageEngine::EngineOption option= engine->option(x);
127
cout << "\t" << option.name() << " = " << option.value() << endl;
131
void print_index(const drizzle::Table::Index *index) {
132
using namespace drizzle;
135
if (index->is_primary())
137
else if (index->is_unique())
139
cout << " KEY `" << index->name() << "` (";
143
for (x= 0; x < index->index_part_size() ; x++)
145
const Table::Index::IndexPart part= index->index_part(x);
149
cout << "`" << part.field().name() << "`";
150
if (part.has_compare_length())
151
cout << "(" << part.compare_length() << ")";
158
void print_table(const drizzle::Table *table)
160
using namespace drizzle;
165
if (table->type() == Table::TEMPORARY)
166
cout << "TEMPORARY ";
168
cout << "TABLE `" << table->name() << "` (" << endl;
170
for (x= 0; x < table->field_size() ; x++)
172
const Table::Field field = table->field(x);
180
for (x= 0; x < table->index_size() ; x++)
182
const Table::Index index= table->index(x);
185
cout << "," << endl;;
192
cout << ") " << endl;
194
print_engine(&table->engine());
197
if (table->has_options())
198
print_table_options(&table->options());
199
if (table->has_stats())
200
print_table_stats(&table->stats());
202
if (table->has_comment())
203
cout << " COMMENT = `" << table->comment() << "` " << endl;
206
void print_table_stats(const drizzle::Table::TableStats *stats) {
210
void print_table_options(const drizzle::Table::TableOptions *options) {
211
if (options->has_collation())
212
cout << " COLLATE = `" << options->collation() << "` " << endl;
213
if (options->has_charset())
214
cout << " CHARACTER SET = `" << options->charset() << "` " << endl;
217
int main(int argc, char* argv[])
47
219
GOOGLE_PROTOBUF_VERIFY_VERSION;