8
8
Written from Google proto example
11
void updateTable(drizzle::Table *table, const char *name)
11
void fill_engine(drizzle::Table::StorageEngine *engine) {
12
using namespace drizzle;
16
engine->set_name("InnoDB");
17
Table::StorageEngine::EngineOption *option;
19
string option_names[2]= {
24
string option_values[2]= {
25
"/var/drizzle/indexdir"
26
, "/var/drizzle/datadir"
29
/* Add some engine options */
30
for (x= 0; x < 2; ++x) {
31
option= engine->add_option();
32
option->set_name(option_names[x]);
33
option->set_value(option_values[x]);
34
option->set_type(Table::StorageEngine::EngineOption::STRING);
38
void new_index_to_table(
40
, const std::string name
41
, uint16_t num_index_parts
42
, uint32_t field_indexes[]
43
, uint32_t compare_lengths[]
47
using namespace drizzle;
52
Table::Index::IndexPart *index_part;
54
index= table->add_index();
56
index->set_name(name);
57
index->set_type(Table::Index::BTREE);
58
index->set_is_primary(is_primary);
59
index->set_is_unique(is_unique);
61
while (x < num_index_parts) {
63
index_part= index->add_index_part();
65
field= index_part->mutable_field();
66
*field= table->field(field_indexes[x]);
68
if (compare_lengths[x] > 0)
69
index_part->set_compare_length(compare_lengths[x]);
75
void fill_table(drizzle::Table *table, const char *name)
79
using namespace drizzle;
82
Table::Field::FieldConstraints *field_constraints;
83
Table::Field::FieldOptions *field_options;
84
Table::Field::StringFieldOptions *string_field_options;
85
Table::Field::NumericFieldOptions *numeric_field_options;
86
Table::Field::SetFieldOptions *set_field_options;
15
88
table->set_name(name);
16
table->set_engine("Innodb");
89
table->set_type(Table::STANDARD);
18
91
/* Write out some random varchar */
19
92
for (x= 0; x < 3; x++)
22
drizzle::Table::Field *field = table->add_field();
95
field= table->add_field();
96
field_constraints= field->mutable_constraints();
97
string_field_options= field->mutable_string_options();
24
99
sprintf(buffer, "sample%u", x);
26
101
field->set_name(buffer);
27
field->set_type(drizzle::Table::VARCHAR);
29
field->set_is_notnull(true);
31
field->set_length(rand() % 100);
102
field->set_type(Table::Field::VARCHAR);
104
field_constraints->set_is_nullable((x % 2));
106
string_field_options->set_length(rand() % 100);
35
field->set_collation("utf8_swedish_ci");
36
field->set_characterset("utf8");
110
string_field_options->set_collation("utf8_swedish_ci");
111
string_field_options->set_charset("utf8");
40
115
/* Write out an INTEGER */
42
drizzle::Table::Field *field = table->add_field();
117
field= table->add_field();
43
118
field->set_name("number");
44
field->set_type(drizzle::Table::INTEGER);
119
field->set_type(Table::Field::INTEGER);
46
121
/* Write out a ENUM */
48
drizzle::Table::Field *field = table->add_field();
49
field->set_type(drizzle::Table::ENUM);
123
field= table->add_field();
124
field->set_type(Table::Field::ENUM);
50
125
field->set_name("colors");
51
field->add_values("red");
52
field->add_values("blue");
53
field->add_values("green");
127
set_field_options= field->mutable_set_options();
128
set_field_options->add_value("red");
129
set_field_options->add_value("blue");
130
set_field_options->add_value("green");
131
set_field_options->set_count_elements(set_field_options->value_size());
55
133
/* Write out a BLOB */
57
drizzle::Table::Field *field = table->add_field();
135
field= table->add_field();
58
136
field->set_name("some_btye_string");
59
field->set_type(drizzle::Table::BLOB);
137
field->set_type(Table::Field::BLOB);
61
139
/* Write out a DECIMAL */
63
drizzle::Table::Field *field = table->add_field();
141
field= table->add_field();
64
142
field->set_name("important_number");
65
field->set_type(drizzle::Table::DECIMAL);
69
/* Write out a VARCHAR with index */
71
drizzle::Table::Field *field = table->add_field();
72
field->set_name("important_string");
73
field->set_type(drizzle::Table::VARCHAR);
74
field->set_length(20);
75
field->set_unique(true);
79
drizzle::Table::Index *index = table->add_index();
80
index->set_name("number");
81
index->set_primary(true);
84
for (x= 0; x < 2; x++)
87
drizzle::Table::Index *index = table->add_index();
88
drizzle::Table::KeyPart *keypart = index->add_values();
90
sprintf(buffer, "sample%u", x);
91
index->set_name(buffer);
93
keypart->set_name(buffer);
143
field->set_type(Table::Field::DECIMAL);
145
field_constraints= field->mutable_constraints();
146
field_constraints->set_is_nullable(true);
148
numeric_field_options= field->mutable_numeric_options();
149
numeric_field_options->set_precision(8);
150
numeric_field_options->set_scale(3);
154
uint32_t fields_in_index[1]= {6};
155
uint32_t compare_lengths_in_index[1]= {0};
156
bool is_unique= true;
157
bool is_primary= false;
158
/* Add a single-column index on important_number field */
161
, "idx_important_decimal"
164
, compare_lengths_in_index
171
/* Add a double-column index on first two varchar fields */
172
uint32_t fields_in_index[2]= {0,1};
173
uint32_t compare_lengths_in_index[2]= {20,35};
174
bool is_unique= true;
175
bool is_primary= true;
181
, compare_lengths_in_index
187
/* Do engine-specific stuff */
188
Table::StorageEngine *engine= table->mutable_engine();