43
case drizzle::Table::SET:
45
case Table::Field::SET:
46
case drizzle::Table::TINYINT:
48
case Table::Field::TINYINT:
49
case drizzle::Table::SMALLINT:
51
case Table::Field::SMALLINT:
50
52
cout << " SMALLINT ";
52
case drizzle::Table::INTEGER:
54
case Table::Field::INTEGER:
53
55
cout << " INTEGER ";
55
case drizzle::Table::BIGINT:
57
case Table::Field::BIGINT:
56
58
cout << " BIGINT ";
58
case drizzle::Table::DECIMAL:
59
cout << " DECIMAL(" << field->length() << "," << field->scale() << ") ";
61
case drizzle::Table::VARBINARY:
62
cout << " VARBINARY(" << field->length() << ") ";
64
case drizzle::Table::DATE:
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:
67
case drizzle::Table::TIME:
69
case Table::Field::TIME:
70
case drizzle::Table::TIMESTAMP:
72
case Table::Field::TIMESTAMP:
71
73
cout << " TIMESTAMP ";
73
case drizzle::Table::DATETIME:
75
case Table::Field::DATETIME:
74
76
cout << " DATETIME ";
78
if (field->has_characterset())
79
cout << " CHARACTER SET " << field->characterset();
81
if (field->has_collation())
82
cout << " COLLATE " << field->collation();
84
if (field->is_notnull())
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())
85
96
cout << " NOT NULL ";
87
if (field->has_default_value())
88
cout << " DEFAULT `" << field->default_value() << "` " ;
90
if (field->on_update())
91
cout << " ON UPDATE CURRENT_TIMESTAMP";
93
if (field->autoincrement())
94
cout << " AUTOINCREMENT ";
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";
96
115
if (field->has_comment())
97
116
cout << " COMMENT `" << field->comment() << "` ";
100
void printTable(const drizzle::Table *table)
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;
104
cout << "CREATE TABLE";
107
cout << " TEMPORARY";
109
cout << " `" << table->name() << "` (" << endl;
165
if (table->type() == Table::TEMPORARY)
166
cout << "TEMPORARY ";
168
cout << "TABLE `" << table->name() << "` (" << endl;
111
170
for (x= 0; x < table->field_size() ; x++)
113
const drizzle::Table::Field field = table->field(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);
116
185
cout << "," << endl;;
118
cout << "\t`" << field.name() << "`";
122
for (x= 0; x < table->index_size() ; x++)
124
const drizzle::Table::Index index = table->index(x);
126
cout << "," << endl;;
131
cout << " PRIMARY KEY (`" << index.name() << "`)";
136
cout << " UNIQUE KEY `" << index.name() << "` (";
137
for (x= 0; x < index.values_size() ; x++)
139
const drizzle::Table::KeyPart key= index.values(x);
143
cout << "`" << key.name() << "`";
150
192
cout << ") " << endl;
151
if (table->has_collation())
152
cout << " COLLATE = `" << table->collation() << "` " << endl;;
153
if (table->has_characterset())
154
cout << " CHARACTER SET = `" << table->characterset() << "` " << 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());
155
202
if (table->has_comment())
156
cout << " COMMENT = `" << table->comment() << "` " << endl;;
157
if (table->has_engine())
158
if (table->has_data_directory())
159
cout << " DATA DIRECTORY = `" << table->data_directory() << "` " << endl;;
160
if (table->has_index_directory())
161
cout << " INDEX DIRECTORY = `" << table->index_directory() << "`" << endl;
162
cout << " ENGINE = " << table->engine() << ";" << endl;
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;
165
217
int main(int argc, char* argv[])