2
Copyright (C) 2010 Stewart Smith
4
This program is free software; you can redistribute it and/or
5
modify it under the terms of the GNU General Public License
6
as published by the Free Software Foundation; either version 2
7
of the License, or (at your option) any later version.
9
This program is distributed in the hope that it will be useful,
10
but WITHOUT ANY WARRANTY; without even the implied warranty of
11
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
GNU General Public License for more details.
14
You should have received a copy of the GNU General Public License
15
along with this program; if not, write to the Free Software
16
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
21
#if defined(HAVE_HAILDB_H)
24
# include <embedded_innodb-1.0/innodb.h>
25
#endif /* HAVE_HAILDB_H */
27
#include "embedded_innodb_engine.h"
29
#include <drizzled/charset_info.h>
30
#include <drizzled/message/table.pb.h>
32
using namespace drizzled;
34
int get_innodb_system_table_message(const char* table_name, drizzled::message::Table *table_message)
36
if (strcmp(table_name, "SYS_TABLES") == 0)
38
message::Engine *engine= table_message->mutable_engine();
39
engine->set_name("InnoDB");
40
table_message->set_name("innodb_sys_tables");
41
table_message->set_schema("data_dictionary");
42
table_message->set_type(message::Table::STANDARD);
43
table_message->set_creation_timestamp(0);
44
table_message->set_update_timestamp(0);
46
message::Table::TableOptions *options= table_message->mutable_options();
47
options->set_collation_id(my_charset_bin.number);
48
options->set_collation(my_charset_bin.name);
50
message::Table::Field *field= table_message->add_field();
51
field->set_name("NAME");
52
field->set_type(message::Table::Field::VARCHAR);
53
message::Table::Field::StringFieldOptions *stropt= field->mutable_string_options();
54
stropt->set_length(IB_MAX_TABLE_NAME_LEN);
55
stropt->set_collation_id(my_charset_bin.number);
56
stropt->set_collation(my_charset_bin.name);
58
field= table_message->add_field();
59
field->set_name("ID");
60
field->set_type(message::Table::Field::BIGINT);
62
field= table_message->add_field();
63
field->set_name("N_COLS");
64
field->set_type(message::Table::Field::INTEGER);
66
field= table_message->add_field();
67
field->set_name("TYPE");
68
field->set_type(message::Table::Field::INTEGER);
70
field= table_message->add_field();
71
field->set_name("MIX_ID");
72
field->set_type(message::Table::Field::VARCHAR);
73
stropt= field->mutable_string_options();
74
stropt->set_collation_id(my_charset_bin.number);
75
stropt->set_collation(my_charset_bin.name);
76
stropt->set_length(IB_MAX_TABLE_NAME_LEN);
78
field= table_message->add_field();
79
field->set_name("MIX_LEN");
80
field->set_type(message::Table::Field::INTEGER);
82
field= table_message->add_field();
83
field->set_name("CLUSTER_NAME");
84
field->set_type(message::Table::Field::VARCHAR);
85
stropt= field->mutable_string_options();
86
stropt->set_collation_id(my_charset_bin.number);
87
stropt->set_collation(my_charset_bin.name);
88
stropt->set_length(IB_MAX_TABLE_NAME_LEN);
90
field= table_message->add_field();
91
field->set_name("SPACE");
92
field->set_type(message::Table::Field::INTEGER);
95
message::Table::Index *index= table_message->add_indexes();
96
index->set_name("PRIMARY");
97
index->set_is_primary(true);
98
index->set_is_unique(true);
99
index->set_type(message::Table::Index::BTREE);
100
index->set_key_length(IB_MAX_TABLE_NAME_LEN);
101
message::Table::Index::IndexPart *part= index->add_index_part();
102
part->set_fieldnr(0);
103
part->set_compare_length(IB_MAX_TABLE_NAME_LEN);
107
else if (strcmp(table_name, "SYS_COLUMNS") == 0)
109
message::Table::Field::StringFieldOptions *stropt;
110
message::Engine *engine= table_message->mutable_engine();
111
engine->set_name("InnoDB");
112
table_message->set_name("innodb_sys_columns");
113
table_message->set_schema("data_dictionary");
114
table_message->set_type(message::Table::STANDARD);
115
table_message->set_creation_timestamp(0);
116
table_message->set_update_timestamp(0);
118
message::Table::TableOptions *options= table_message->mutable_options();
119
options->set_collation_id(my_charset_bin.number);
120
options->set_collation(my_charset_bin.name);
122
message::Table::Field *field= table_message->add_field();
123
field->set_name("TABLE_ID");
124
field->set_type(message::Table::Field::BIGINT);
126
field= table_message->add_field();
127
field->set_name("POS");
128
field->set_type(message::Table::Field::INTEGER);
130
field= table_message->add_field();
131
field->set_name("NAME");
132
field->set_type(message::Table::Field::VARCHAR);
133
stropt= field->mutable_string_options();
134
stropt->set_collation_id(my_charset_bin.number);
135
stropt->set_collation(my_charset_bin.name);
136
stropt->set_length(IB_MAX_TABLE_NAME_LEN);
138
field= table_message->add_field();
139
field->set_name("MTYPE");
140
field->set_type(message::Table::Field::INTEGER);
142
field= table_message->add_field();
143
field->set_name("PRTYPE");
144
field->set_type(message::Table::Field::INTEGER);
146
field= table_message->add_field();
147
field->set_name("LEN");
148
field->set_type(message::Table::Field::INTEGER);
150
field= table_message->add_field();
151
field->set_name("PREC");
152
field->set_type(message::Table::Field::INTEGER);
154
message::Table::Index *index= table_message->add_indexes();
155
index->set_name("PRIMARY");
156
index->set_is_primary(true);
157
index->set_is_unique(true);
158
index->set_type(message::Table::Index::BTREE);
159
index->set_key_length(IB_MAX_TABLE_NAME_LEN);
160
message::Table::Index::IndexPart *part= index->add_index_part();
161
part->set_fieldnr(0);
162
part= index->add_index_part();
163
part->set_fieldnr(1);
167
else if (strcmp(table_name, "SYS_INDEXES") == 0)
169
message::Table::Field::StringFieldOptions *stropt;
170
message::Engine *engine= table_message->mutable_engine();
171
engine->set_name("InnoDB");
172
table_message->set_name("innodb_sys_indexes");
173
table_message->set_schema("data_dictionary");
174
table_message->set_type(message::Table::STANDARD);
175
table_message->set_creation_timestamp(0);
176
table_message->set_update_timestamp(0);
178
message::Table::TableOptions *options= table_message->mutable_options();
179
options->set_collation_id(my_charset_bin.number);
180
options->set_collation(my_charset_bin.name);
182
message::Table::Field *field= table_message->add_field();
183
field->set_name("TABLE_ID");
184
field->set_type(message::Table::Field::BIGINT);
186
field= table_message->add_field();
187
field->set_name("ID");
188
field->set_type(message::Table::Field::BIGINT);
190
field= table_message->add_field();
191
field->set_name("NAME");
192
field->set_type(message::Table::Field::VARCHAR);
193
stropt= field->mutable_string_options();
194
stropt->set_collation_id(my_charset_bin.number);
195
stropt->set_collation(my_charset_bin.name);
196
stropt->set_length(IB_MAX_TABLE_NAME_LEN);
198
field= table_message->add_field();
199
field->set_name("N_FIELDS");
200
field->set_type(message::Table::Field::INTEGER);
202
field= table_message->add_field();
203
field->set_name("TYPE");
204
field->set_type(message::Table::Field::INTEGER);
206
field= table_message->add_field();
207
field->set_name("SPACE");
208
field->set_type(message::Table::Field::INTEGER);
210
field= table_message->add_field();
211
field->set_name("PAGE_NO");
212
field->set_type(message::Table::Field::INTEGER);
214
message::Table::Index *index= table_message->add_indexes();
215
index->set_name("PRIMARY");
216
index->set_is_primary(true);
217
index->set_is_unique(true);
218
index->set_type(message::Table::Index::BTREE);
219
index->set_key_length(IB_MAX_TABLE_NAME_LEN);
220
message::Table::Index::IndexPart *part= index->add_index_part();
221
part->set_fieldnr(0);
222
part= index->add_index_part();
223
part->set_fieldnr(1);
227
else if (strcmp(table_name, "SYS_FIELDS") == 0)
229
message::Table::Field::StringFieldOptions *stropt;
230
message::Engine *engine= table_message->mutable_engine();
231
engine->set_name("InnoDB");
232
table_message->set_name("innodb_sys_fields");
233
table_message->set_schema("data_dictionary");
234
table_message->set_type(message::Table::STANDARD);
235
table_message->set_creation_timestamp(0);
236
table_message->set_update_timestamp(0);
238
message::Table::TableOptions *options= table_message->mutable_options();
239
options->set_collation_id(my_charset_bin.number);
240
options->set_collation(my_charset_bin.name);
242
message::Table::Field *field= table_message->add_field();
243
field->set_name("INDEX_ID");
244
field->set_type(message::Table::Field::BIGINT);
246
field= table_message->add_field();
247
field->set_name("POS");
248
field->set_type(message::Table::Field::INTEGER);
250
field= table_message->add_field();
251
field->set_name("COL_NAME");
252
field->set_type(message::Table::Field::VARCHAR);
253
stropt= field->mutable_string_options();
254
stropt->set_collation_id(my_charset_bin.number);
255
stropt->set_collation(my_charset_bin.name);
256
stropt->set_length(IB_MAX_TABLE_NAME_LEN);
258
message::Table::Index *index= table_message->add_indexes();
259
index->set_name("PRIMARY");
260
index->set_is_primary(true);
261
index->set_is_unique(true);
262
index->set_type(message::Table::Index::BTREE);
263
index->set_key_length(IB_MAX_TABLE_NAME_LEN);
264
message::Table::Index::IndexPart *part= index->add_index_part();
265
part->set_fieldnr(0);
266
part= index->add_index_part();
267
part->set_fieldnr(1);
271
else if (strcmp(table_name, "SYS_FOREIGN") == 0)
273
message::Table::Field::StringFieldOptions *stropt;
274
message::Engine *engine= table_message->mutable_engine();
275
engine->set_name("InnoDB");
276
table_message->set_name("innodb_sys_foreign");
277
table_message->set_schema("data_dictionary");
278
table_message->set_type(message::Table::STANDARD);
279
table_message->set_creation_timestamp(0);
280
table_message->set_update_timestamp(0);
282
message::Table::TableOptions *options= table_message->mutable_options();
283
options->set_collation_id(my_charset_bin.number);
284
options->set_collation(my_charset_bin.name);
286
message::Table::Field *field= table_message->add_field();
287
field->set_name("ID");
288
field->set_type(message::Table::Field::BIGINT);
290
field= table_message->add_field();
291
field->set_name("FOR_NAME");
292
field->set_type(message::Table::Field::VARCHAR);
293
stropt= field->mutable_string_options();
294
stropt->set_collation_id(my_charset_bin.number);
295
stropt->set_collation(my_charset_bin.name);
296
stropt->set_length(IB_MAX_TABLE_NAME_LEN);
298
field= table_message->add_field();
299
field->set_name("REF_NAME");
300
field->set_type(message::Table::Field::VARCHAR);
301
stropt= field->mutable_string_options();
302
stropt->set_collation_id(my_charset_bin.number);
303
stropt->set_collation(my_charset_bin.name);
304
stropt->set_length(IB_MAX_TABLE_NAME_LEN);
306
field= table_message->add_field();
307
field->set_name("N_COLS");
308
field->set_type(message::Table::Field::INTEGER);
310
message::Table::Index *index= table_message->add_indexes();
311
index->set_name("PRIMARY");
312
index->set_is_primary(true);
313
index->set_is_unique(true);
314
index->set_type(message::Table::Index::BTREE);
315
index->set_key_length(IB_MAX_TABLE_NAME_LEN);
316
message::Table::Index::IndexPart *part= index->add_index_part();
317
part->set_fieldnr(0);
319
index= table_message->add_indexes();
320
index->set_name("FOR_IND");
321
index->set_is_primary(false);
322
index->set_is_unique(false);
323
index->set_type(message::Table::Index::BTREE);
324
index->set_key_length(IB_MAX_TABLE_NAME_LEN);
325
part= index->add_index_part();
326
part->set_fieldnr(1);
328
index= table_message->add_indexes();
329
index->set_name("REF_IND");
330
index->set_is_primary(false);
331
index->set_is_unique(false);
332
index->set_type(message::Table::Index::BTREE);
333
index->set_key_length(IB_MAX_TABLE_NAME_LEN);
334
part= index->add_index_part();
335
part->set_fieldnr(2);
339
else if (strcmp(table_name, "SYS_FOREIGN_COLS") == 0)
341
message::Table::Field::StringFieldOptions *stropt;
342
message::Engine *engine= table_message->mutable_engine();
343
engine->set_name("InnoDB");
344
table_message->set_name("innodb_sys_foreign_cols");
345
table_message->set_schema("data_dictionary");
346
table_message->set_type(message::Table::STANDARD);
347
table_message->set_creation_timestamp(0);
348
table_message->set_update_timestamp(0);
350
message::Table::TableOptions *options= table_message->mutable_options();
351
options->set_collation_id(my_charset_bin.number);
352
options->set_collation(my_charset_bin.name);
354
message::Table::Field *field= table_message->add_field();
355
field->set_name("ID");
356
field->set_type(message::Table::Field::BIGINT);
358
field= table_message->add_field();
359
field->set_name("POS");
360
field->set_type(message::Table::Field::INTEGER);
362
field= table_message->add_field();
363
field->set_name("FOR_COL_NAME");
364
field->set_type(message::Table::Field::VARCHAR);
365
stropt= field->mutable_string_options();
366
stropt->set_collation_id(my_charset_bin.number);
367
stropt->set_collation(my_charset_bin.name);
368
stropt->set_length(IB_MAX_TABLE_NAME_LEN);
370
field= table_message->add_field();
371
field->set_name("REF_COL_NAME");
372
field->set_type(message::Table::Field::VARCHAR);
373
stropt= field->mutable_string_options();
374
stropt->set_collation_id(my_charset_bin.number);
375
stropt->set_collation(my_charset_bin.name);
376
stropt->set_length(IB_MAX_TABLE_NAME_LEN);
378
message::Table::Index *index= table_message->add_indexes();
379
index->set_name("PRIMARY");
380
index->set_is_primary(true);
381
index->set_is_unique(true);
382
index->set_type(message::Table::Index::BTREE);
383
index->set_key_length(IB_MAX_TABLE_NAME_LEN);
384
message::Table::Index::IndexPart *part= index->add_index_part();
385
part->set_fieldnr(0);
386
part= index->add_index_part();
387
part->set_fieldnr(1);