~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to plugin/embedded_innodb/datadict_table_message.cc

  • Committer: Joseph Daly
  • Date: 2010-09-28 01:43:36 UTC
  • mfrom: (1799 staging)
  • mto: (1799.1.1 build)
  • mto: This revision was merged to the branch mainline in revision 1800.
  • Revision ID: jdaly@rx7-20100928014336-wxjexq5c8js3cs8v
merge trunk

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
  Copyright (C) 2010 Stewart Smith
 
3
 
 
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.
 
8
 
 
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.
 
13
 
 
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.
 
17
*/
 
18
 
 
19
#include <config.h>
 
20
 
 
21
#if defined(HAVE_HAILDB_H)
 
22
# include <haildb.h>
 
23
#else
 
24
# include <embedded_innodb-1.0/innodb.h>
 
25
#endif /* HAVE_HAILDB_H */
 
26
 
 
27
#include "embedded_innodb_engine.h"
 
28
 
 
29
#include <drizzled/charset_info.h>
 
30
#include <drizzled/message/table.pb.h>
 
31
 
 
32
using namespace drizzled;
 
33
 
 
34
int get_innodb_system_table_message(const char* table_name, drizzled::message::Table *table_message)
 
35
{
 
36
  if (strcmp(table_name, "SYS_TABLES") == 0)
 
37
  {
 
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);
 
45
 
 
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);
 
49
 
 
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);
 
57
 
 
58
    field= table_message->add_field();
 
59
    field->set_name("ID");
 
60
    field->set_type(message::Table::Field::BIGINT);
 
61
 
 
62
    field= table_message->add_field();
 
63
    field->set_name("N_COLS");
 
64
    field->set_type(message::Table::Field::INTEGER);
 
65
 
 
66
    field= table_message->add_field();
 
67
    field->set_name("TYPE");
 
68
    field->set_type(message::Table::Field::INTEGER);
 
69
 
 
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);
 
77
 
 
78
    field= table_message->add_field();
 
79
    field->set_name("MIX_LEN");
 
80
    field->set_type(message::Table::Field::INTEGER);
 
81
 
 
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);
 
89
 
 
90
    field= table_message->add_field();
 
91
    field->set_name("SPACE");
 
92
    field->set_type(message::Table::Field::INTEGER);
 
93
 
 
94
 
 
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);
 
104
 
 
105
    return 0;
 
106
  }
 
107
  else if (strcmp(table_name, "SYS_COLUMNS") == 0)
 
108
  {
 
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);
 
117
 
 
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);
 
121
 
 
122
    message::Table::Field *field= table_message->add_field();
 
123
    field->set_name("TABLE_ID");
 
124
    field->set_type(message::Table::Field::BIGINT);
 
125
 
 
126
    field= table_message->add_field();
 
127
    field->set_name("POS");
 
128
    field->set_type(message::Table::Field::INTEGER);
 
129
 
 
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);
 
137
 
 
138
    field= table_message->add_field();
 
139
    field->set_name("MTYPE");
 
140
    field->set_type(message::Table::Field::INTEGER);
 
141
 
 
142
    field= table_message->add_field();
 
143
    field->set_name("PRTYPE");
 
144
    field->set_type(message::Table::Field::INTEGER);
 
145
 
 
146
    field= table_message->add_field();
 
147
    field->set_name("LEN");
 
148
    field->set_type(message::Table::Field::INTEGER);
 
149
 
 
150
    field= table_message->add_field();
 
151
    field->set_name("PREC");
 
152
    field->set_type(message::Table::Field::INTEGER);
 
153
 
 
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);
 
164
 
 
165
    return 0;
 
166
  }
 
167
  else if (strcmp(table_name, "SYS_INDEXES") == 0)
 
168
  {
 
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);
 
177
 
 
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);
 
181
 
 
182
    message::Table::Field *field= table_message->add_field();
 
183
    field->set_name("TABLE_ID");
 
184
    field->set_type(message::Table::Field::BIGINT);
 
185
 
 
186
    field= table_message->add_field();
 
187
    field->set_name("ID");
 
188
    field->set_type(message::Table::Field::BIGINT);
 
189
 
 
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);
 
197
 
 
198
    field= table_message->add_field();
 
199
    field->set_name("N_FIELDS");
 
200
    field->set_type(message::Table::Field::INTEGER);
 
201
 
 
202
    field= table_message->add_field();
 
203
    field->set_name("TYPE");
 
204
    field->set_type(message::Table::Field::INTEGER);
 
205
 
 
206
    field= table_message->add_field();
 
207
    field->set_name("SPACE");
 
208
    field->set_type(message::Table::Field::INTEGER);
 
209
 
 
210
    field= table_message->add_field();
 
211
    field->set_name("PAGE_NO");
 
212
    field->set_type(message::Table::Field::INTEGER);
 
213
 
 
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);
 
224
 
 
225
    return 0;
 
226
  }
 
227
  else if (strcmp(table_name, "SYS_FIELDS") == 0)
 
228
  {
 
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);
 
237
 
 
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);
 
241
 
 
242
    message::Table::Field *field= table_message->add_field();
 
243
    field->set_name("INDEX_ID");
 
244
    field->set_type(message::Table::Field::BIGINT);
 
245
 
 
246
    field= table_message->add_field();
 
247
    field->set_name("POS");
 
248
    field->set_type(message::Table::Field::INTEGER);
 
249
 
 
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);
 
257
 
 
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);
 
268
 
 
269
    return 0;
 
270
  }
 
271
  else if (strcmp(table_name, "SYS_FOREIGN") == 0)
 
272
  {
 
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);
 
281
 
 
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);
 
285
 
 
286
    message::Table::Field *field= table_message->add_field();
 
287
    field->set_name("ID");
 
288
    field->set_type(message::Table::Field::BIGINT);
 
289
 
 
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);
 
297
 
 
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);
 
305
 
 
306
    field= table_message->add_field();
 
307
    field->set_name("N_COLS");
 
308
    field->set_type(message::Table::Field::INTEGER);
 
309
 
 
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);
 
318
 
 
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);
 
327
 
 
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);
 
336
 
 
337
    return 0;
 
338
  }
 
339
  else if (strcmp(table_name, "SYS_FOREIGN_COLS") == 0)
 
340
  {
 
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);
 
349
 
 
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);
 
353
 
 
354
    message::Table::Field *field= table_message->add_field();
 
355
    field->set_name("ID");
 
356
    field->set_type(message::Table::Field::BIGINT);
 
357
 
 
358
    field= table_message->add_field();
 
359
    field->set_name("POS");
 
360
    field->set_type(message::Table::Field::INTEGER);
 
361
 
 
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);
 
369
 
 
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);
 
377
 
 
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);
 
388
 
 
389
    return 0;
 
390
  }
 
391
 
 
392
  return -1;
 
393
}