64
63
ColumnsTool::Generator::Generator(Field **arg) :
65
DataDictionary::Generator(arg),
66
field_generator(getSession())
64
TablesTool::Generator(arg),
66
is_columns_primed(false)
71
bool ColumnsTool::Generator::nextColumnCore()
73
if (is_columns_primed)
79
if (not isTablesPrimed())
83
is_columns_primed= true;
86
if (column_iterator >= getTableProto().field_size())
89
column= getTableProto().field(column_iterator);
95
bool ColumnsTool::Generator::nextColumn()
97
while (not nextColumnCore())
101
is_columns_primed= false;
70
107
bool ColumnsTool::Generator::populate()
72
drizzled::generator::FieldPair field_pair;
74
while (!!(field_pair= field_generator))
76
const drizzled::message::Table *table_message= field_pair.first;
77
int32_t field_iterator= field_pair.second;
78
const message::Table::Field &column(table_message->field(field_pair.second));
81
push(table_message->schema());
84
push(table_message->name());
90
push(drizzled::message::type(column.type()));
92
/* ORDINAL_POSITION */
93
push(static_cast<int64_t>(field_iterator));
96
if (column.options().has_default_value())
98
push(column.options().default_value());
100
else if (column.options().has_default_bin_value())
102
push(column.options().default_bin_value().c_str(), column.options().default_bin_value().length());
104
else if (column.options().has_default_expression())
106
push(column.options().default_expression());
113
/* COLUMN_DEFAULT_IS_NULL */
114
push(column.options().default_null());
116
/* COLUMN_DEFAULT_UPDATE */
117
push(column.options().update_expression());
120
if (drizzled::message::is_numeric(column))
129
/* IS_AUTO_INCREMENT */
130
push(column.numeric_options().is_autoincrement());
133
push(not column.constraints().is_notnull());
135
/* IS_INDEXED, IS_USED_IN_PRIMARY, IS_UNIQUE, IS_MULTI, IS_FIRST_IN_MULTI, INDEXES_FOUND_IN */
136
bool is_indexed= false;
137
bool is_primary= false;
138
bool is_unique= false;
139
bool is_multi= false;
140
bool is_multi_first= false;
141
int64_t indexes_found_in= 0;
142
for (int32_t x= 0; x < table_message->indexes_size() ; x++)
144
const drizzled::message::Table::Index &index(table_message->indexes(x));
146
for (int32_t y= 0; y < index.index_part_size() ; y++)
110
if (not nextColumn())
118
void ColumnsTool::Generator::fill()
121
assert(getTableProto().schema().length());
122
assert(getTableProto().schema().c_str());
123
push(getTableProto().schema());
126
push(getTableProto().name());
132
pushType(column.type());
134
/* ORDINAL_POSITION */
135
push(static_cast<int64_t>(column_iterator));
138
if (column.options().has_default_value())
140
push(column.options().default_value());
142
else if (column.options().has_default_bin_value())
144
push(column.options().default_bin_value().c_str(), column.options().default_bin_value().length());
146
else if (column.options().has_default_expression())
148
push(column.options().default_expression());
155
/* COLUMN_DEFAULT_IS_NULL */
156
push(column.options().default_null());
158
/* COLUMN_DEFAULT_UPDATE */
159
push(column.options().update_expression());
161
/* IS_AUTO_INCREMENT */
162
push(column.numeric_options().is_autoincrement());
165
push(column.constraints().is_nullable());
167
/* IS_INDEXED, IS_USED_IN_PRIMARY, IS_UNIQUE, IS_MULTI, IS_FIRST_IN_MULTI, INDEXES_FOUND_IN */
168
bool is_indexed= false;
169
bool is_primary= false;
170
bool is_unique= false;
171
bool is_multi= false;
172
bool is_multi_first= false;
173
int64_t indexes_found_in= 0;
174
for (int32_t x= 0; x < getTableProto().indexes_size() ; x++)
176
drizzled::message::Table::Index index=
177
getTableProto().indexes(x);
179
for (int32_t y= 0; y < index.index_part_size() ; y++)
181
drizzled::message::Table::Index::IndexPart index_part=
184
if (static_cast<int32_t>(index_part.fieldnr()) == column_iterator)
148
const drizzled::message::Table::Index::IndexPart &index_part(index.index_part(y));
150
if (static_cast<int32_t>(index_part.fieldnr()) == field_iterator)
189
if (index.is_primary())
192
if (index.is_unique())
195
if (index.index_part_size() > 1)
155
if (index.is_primary())
158
if (index.is_unique())
161
if (index.index_part_size() > 1)
166
is_multi_first= true;
200
is_multi_first= true;
171
/* ...IS_INDEXED, IS_USED_IN_PRIMARY, IS_UNIQUE, IS_MULTI, IS_FIRST_IN_MULTI, INDEXES_FOUND_IN */
176
push(is_multi_first);
177
push(indexes_found_in);
179
/* DATA_TYPE <-- display the type that the user is going to expect, which is not the same as the type we store internally */
180
push(drizzled::message::type(column));
183
push(drizzled::message::type(column.type()));
185
/* "CHARACTER_MAXIMUM_LENGTH" */
186
push(static_cast<int64_t>(column.string_options().length()));
188
/* "CHARACTER_OCTET_LENGTH" */
189
push(static_cast<int64_t>(column.string_options().length()) * 4);
191
/* "NUMERIC_PRECISION" */
192
push(static_cast<int64_t>(column.numeric_options().precision()));
194
/* "NUMERIC_SCALE" */
195
push(static_cast<int64_t>(column.numeric_options().scale()));
198
if (column.type() == drizzled::message::Table::Field::ENUM)
201
size_t num_field_values= column.enumeration_values().field_value_size();
202
for (size_t x= 0; x < num_field_values; ++x)
204
const string &type= column.enumeration_values().field_value(x);
207
destination.push_back(',');
209
destination.push_back('\'');
210
destination.append(type);
211
destination.push_back('\'');
220
/* "COLLATION_NAME" */
221
push(column.string_options().collation());
223
/* "COLUMN_COMMENT" */
224
if (column.has_comment())
226
push(column.comment());
205
/* ...IS_INDEXED, IS_USED_IN_PRIMARY, IS_UNIQUE, IS_MULTI, IS_FIRST_IN_MULTI, INDEXES_FOUND_IN */
210
push(is_multi_first);
211
push(indexes_found_in);
214
pushType(column.type());
216
/* "CHARACTER_MAXIMUM_LENGTH" */
217
push(static_cast<int64_t>(column.string_options().length()));
219
/* "CHARACTER_OCTET_LENGTH" */
220
push(static_cast<int64_t>(column.string_options().length()) * 4);
222
/* "NUMERIC_PRECISION" */
223
push(static_cast<int64_t>(column.numeric_options().precision()));
225
/* "NUMERIC_SCALE" */
226
push(static_cast<int64_t>(column.numeric_options().scale()));
229
if (column.type() == drizzled::message::Table::Field::ENUM)
232
size_t num_field_values= column.enumeration_values().field_value_size();
233
for (size_t x= 0; x < num_field_values; ++x)
235
const string &type= column.enumeration_values().field_value(x);
238
destination.push_back(',');
240
destination.push_back('\'');
241
destination.append(type);
242
destination.push_back('\'');
249
/* "COLLATION_NAME" */
250
push(column.string_options().collation());
252
/* "COLUMN_COMMENT" */
253
if (column.has_comment())
255
push(column.comment());