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
#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
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::TINYINT:
48
case Table::Field::INTEGER:
51
case Table::Field::BIGINT:
54
case Table::Field::DECIMAL:
55
cout << " DECIMAL(" << field->numeric_options().precision() << "," << field->numeric_options().scale() << ") ";
57
case Table::Field::DATE:
60
case Table::Field::TIME:
63
case Table::Field::TIMESTAMP:
64
cout << " TIMESTAMP ";
66
case Table::Field::DATETIME:
71
if (field->type() == Table::Field::INTEGER
72
|| field->type() == Table::Field::BIGINT
73
|| field->type() == Table::Field::TINYINT)
75
if (field->has_constraints()
76
&& field->constraints().has_is_unsigned())
77
if (field->constraints().is_unsigned())
80
if (field->has_numeric_options() &&
81
field->numeric_options().is_autoincrement())
82
cout << " AUTOINCREMENT ";
85
if (! field->has_constraints()
86
&& field->constraints().is_nullable())
89
if (field->type() == Table::Field::TEXT
90
|| field->type() == Table::Field::VARCHAR)
92
if (field->string_options().has_collation())
93
cout << " COLLATE " << field->string_options().collation();
96
if (field->options().has_default_value())
97
cout << " DEFAULT `" << field->options().default_value() << "` " ;
99
if (field->type() == Table::Field::TIMESTAMP)
100
if (field->timestamp_options().has_auto_updates()
101
&& field->timestamp_options().auto_updates())
102
cout << " ON UPDATE CURRENT_TIMESTAMP";
104
if (field->has_comment())
105
cout << " COMMENT `" << field->comment() << "` ";
108
void print_engine(const drizzle::Table::StorageEngine *engine)
110
using namespace drizzle;
113
cout << " ENGINE = " << engine->name() << endl;
115
for (x= 0; x < engine->option_size(); ++x) {
116
const Table::StorageEngine::EngineOption option= engine->option(x);
117
cout << "\t" << option.name() << " = " << option.value() << endl;
121
void print_index(const drizzle::Table::Index *index)
123
using namespace drizzle;
126
if (index->is_primary())
128
else if (index->is_unique())
130
cout << " KEY `" << index->name() << "` (";
134
for (x= 0; x < index->index_part_size() ; x++)
136
const Table::Index::IndexPart part= index->index_part(x);
140
cout << "`" << part.field().name() << "`";
141
if (part.has_compare_length())
142
cout << "(" << part.compare_length() << ")";
149
void print_table_stats(const drizzle::Table::TableStats *stats)
154
void print_table_options(const drizzle::Table::TableOptions *options)
156
if (options->has_comment())
157
cout << " COMMENT = '" << options->comment() << "' " << endl;
159
if (options->has_collation())
160
cout << " COLLATE = '" << options->collation() << "' " << endl;
164
void print_table(const drizzle::Table *table)
166
using namespace drizzle;
171
if (table->type() == Table::TEMPORARY)
172
cout << "TEMPORARY ";
174
cout << "TABLE `" << table->name() << "` (" << endl;
176
for (x= 0; x < table->field_size() ; x++)
178
const Table::Field field = table->field(x);
186
for (x= 0; x < table->index_size() ; x++)
188
const Table::Index index= table->index(x);
191
cout << "," << endl;;
198
cout << ") " << endl;
200
print_engine(&table->engine());
202
if (table->has_options())
203
print_table_options(&table->options());
205
if (table->has_stats())
206
print_table_stats(&table->stats());
45
210
int main(int argc, char* argv[])
47
212
GOOGLE_PROTOBUF_VERIFY_VERSION;