63
60
ColumnsTool::Generator::Generator(Field **arg) :
64
DataDictionary::Generator(arg),
65
field_generator(getSession())
61
TablesTool::Generator(arg),
63
is_columns_primed(false)
68
bool ColumnsTool::Generator::nextColumnCore()
70
if (is_columns_primed)
76
if (not isTablesPrimed())
80
is_columns_primed= true;
83
if (column_iterator >= getTableProto().field_size())
86
column= getTableProto().field(column_iterator);
92
bool ColumnsTool::Generator::nextColumn()
94
while (not nextColumnCore())
98
is_columns_primed= false;
69
104
bool ColumnsTool::Generator::populate()
71
drizzled::generator::FieldPair field_pair;
73
while (!!(field_pair= field_generator))
75
const drizzled::message::Table *table_message= field_pair.first;
76
int32_t field_iterator= field_pair.second;
77
const message::Table::Field &column(table_message->field(field_pair.second));
80
push(table_message->schema());
83
push(table_message->name());
89
push(drizzled::message::type(column.type()));
91
/* ORDINAL_POSITION */
92
push(static_cast<int64_t>(field_iterator));
95
if (column.options().has_default_value())
97
push(column.options().default_value());
99
else if (column.options().has_default_bin_value())
101
push(column.options().default_bin_value().c_str(), column.options().default_bin_value().length());
103
else if (column.options().has_default_expression())
105
push(column.options().default_expression());
112
/* COLUMN_DEFAULT_IS_NULL */
113
push(column.options().default_null());
115
/* COLUMN_DEFAULT_UPDATE */
116
push(column.options().update_expression());
118
/* IS_AUTO_INCREMENT */
119
push(column.numeric_options().is_autoincrement());
122
push(column.constraints().is_nullable());
124
/* IS_INDEXED, IS_USED_IN_PRIMARY, IS_UNIQUE, IS_MULTI, IS_FIRST_IN_MULTI, INDEXES_FOUND_IN */
125
bool is_indexed= false;
126
bool is_primary= false;
127
bool is_unique= false;
128
bool is_multi= false;
129
bool is_multi_first= false;
130
int64_t indexes_found_in= 0;
131
for (int32_t x= 0; x < table_message->indexes_size() ; x++)
133
const drizzled::message::Table::Index &index(table_message->indexes(x));
135
for (int32_t y= 0; y < index.index_part_size() ; y++)
107
if (not nextColumn())
115
void ColumnsTool::Generator::fill()
118
assert(getTableProto().schema().length());
119
assert(getTableProto().schema().c_str());
120
push(getTableProto().schema());
123
push(getTableProto().name());
129
pushType(column.type());
131
/* ORDINAL_POSITION */
132
push(static_cast<int64_t>(column_iterator));
135
if (column.options().has_default_value())
137
push(column.options().default_value());
139
else if (column.options().has_default_bin_value())
141
push(column.options().default_bin_value().c_str(), column.options().default_bin_value().length());
148
/* COLUMN_DEFAULT_IS_NULL */
149
push(column.options().default_null());
151
/* COLUMN_DEFAULT_UPDATE */
152
push(column.options().update_value());
155
push(column.constraints().is_nullable());
157
/* IS_INDEXED, IS_USED_IN_PRIMARY, IS_UNIQUE, IS_MULTI, IS_FIRST_IN_MULTI, INDEXES_FOUND_IN */
158
bool is_indexed= false;
159
bool is_primary= false;
160
bool is_unique= false;
161
bool is_multi= false;
162
bool is_multi_first= false;
163
int64_t indexes_found_in= 0;
164
for (int32_t x= 0; x < getTableProto().indexes_size() ; x++)
166
drizzled::message::Table::Index index=
167
getTableProto().indexes(x);
169
for (int32_t y= 0; y < index.index_part_size() ; y++)
171
drizzled::message::Table::Index::IndexPart index_part=
174
if (static_cast<int32_t>(index_part.fieldnr()) == column_iterator)
137
const drizzled::message::Table::Index::IndexPart &index_part(index.index_part(y));
139
if (static_cast<int32_t>(index_part.fieldnr()) == field_iterator)
179
if (index.is_primary())
182
if (index.is_unique())
185
if (index.index_part_size() > 1)
144
if (index.is_primary())
147
if (index.is_unique())
150
if (index.index_part_size() > 1)
155
is_multi_first= true;
190
is_multi_first= true;
160
/* ...IS_INDEXED, IS_USED_IN_PRIMARY, IS_UNIQUE, IS_MULTI, IS_FIRST_IN_MULTI, INDEXES_FOUND_IN */
165
push(is_multi_first);
166
push(indexes_found_in);
169
push(drizzled::message::type(column.type()));
171
/* "CHARACTER_MAXIMUM_LENGTH" */
172
push(static_cast<int64_t>(column.string_options().length()));
174
/* "CHARACTER_OCTET_LENGTH" */
175
push(static_cast<int64_t>(column.string_options().length()) * 4);
177
/* "NUMERIC_PRECISION" */
178
push(static_cast<int64_t>(column.numeric_options().precision()));
180
/* "NUMERIC_SCALE" */
181
push(static_cast<int64_t>(column.numeric_options().scale()));
184
if (column.type() == drizzled::message::Table::Field::ENUM)
187
size_t num_field_values= column.enumeration_values().field_value_size();
188
for (size_t x= 0; x < num_field_values; ++x)
190
const string &type= column.enumeration_values().field_value(x);
193
destination.push_back(',');
195
destination.push_back('\'');
196
destination.append(type);
197
destination.push_back('\'');
206
/* "COLLATION_NAME" */
207
push(column.string_options().collation());
209
/* "COLUMN_COMMENT" */
210
if (column.has_comment())
212
push(column.comment());
195
/* ...IS_INDEXED, IS_USED_IN_PRIMARY, IS_UNIQUE, IS_MULTI, IS_FIRST_IN_MULTI, INDEXES_FOUND_IN */
200
push(is_multi_first);
201
push(indexes_found_in);
204
pushType(column.type());
206
/* "CHARACTER_MAXIMUM_LENGTH" */
207
push(static_cast<int64_t>(column.string_options().length()));
209
/* "CHARACTER_OCTET_LENGTH" */
210
push(static_cast<int64_t>(column.string_options().length()) * 4);
212
/* "NUMERIC_PRECISION" */
213
push(static_cast<int64_t>(column.numeric_options().precision()));
215
/* "NUMERIC_SCALE" */
216
push(static_cast<int64_t>(column.numeric_options().scale()));
218
/* "COLLATION_NAME" */
219
push(column.string_options().collation());
221
/* "COLUMN_COMMENT" */
222
if (column.has_comment())
224
push(column.comment());