~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to plugin/haildb/datadict_table_message.cc

  • Committer: Olaf van der Spek
  • Date: 2011-08-03 10:04:55 UTC
  • mfrom: (2382 drizzle)
  • mto: This revision was merged to the branch mainline in revision 2384.
  • Revision ID: olafvdspek@gmail.com-20110803100455-2oqzyi77v4gykhy0
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
 
#include <haildb.h>
22
 
 
23
 
#include "haildb_engine.h"
24
 
 
25
 
#include <drizzled/charset.h>
26
 
#include <drizzled/message/table.pb.h>
27
 
 
28
 
using namespace drizzled;
29
 
 
30
 
int get_haildb_system_table_message(const char* table_name, drizzled::message::Table *table_message)
31
 
{
32
 
  if (strcmp(table_name, "SYS_TABLES") == 0)
33
 
  {
34
 
    message::Engine *engine= table_message->mutable_engine();
35
 
    engine->set_name("InnoDB");
36
 
    table_message->set_name("haildb_sys_tables");
37
 
    table_message->set_schema("data_dictionary");
38
 
    table_message->set_type(message::Table::STANDARD);
39
 
    table_message->set_creation_timestamp(0);
40
 
    table_message->set_update_timestamp(0);
41
 
 
42
 
    message::Table::TableOptions *options= table_message->mutable_options();
43
 
    options->set_collation_id(my_charset_bin.number);
44
 
    options->set_collation(my_charset_bin.name);
45
 
 
46
 
    message::Table::Field *field= table_message->add_field();
47
 
    field->set_name("NAME");
48
 
    field->set_type(message::Table::Field::VARCHAR);
49
 
    message::Table::Field::StringFieldOptions *stropt= field->mutable_string_options();
50
 
    stropt->set_length(IB_MAX_TABLE_NAME_LEN);
51
 
    stropt->set_collation_id(my_charset_bin.number);
52
 
    stropt->set_collation(my_charset_bin.name);
53
 
 
54
 
    field= table_message->add_field();
55
 
    field->set_name("ID");
56
 
    field->set_type(message::Table::Field::BIGINT);
57
 
 
58
 
    field= table_message->add_field();
59
 
    field->set_name("N_COLS");
60
 
    field->set_type(message::Table::Field::INTEGER);
61
 
 
62
 
    field= table_message->add_field();
63
 
    field->set_name("TYPE");
64
 
    field->set_type(message::Table::Field::INTEGER);
65
 
 
66
 
    field= table_message->add_field();
67
 
    field->set_name("MIX_ID");
68
 
    field->set_type(message::Table::Field::VARCHAR);
69
 
    stropt= field->mutable_string_options();
70
 
    stropt->set_collation_id(my_charset_bin.number);
71
 
    stropt->set_collation(my_charset_bin.name);
72
 
    stropt->set_length(IB_MAX_TABLE_NAME_LEN);
73
 
 
74
 
    field= table_message->add_field();
75
 
    field->set_name("MIX_LEN");
76
 
    field->set_type(message::Table::Field::INTEGER);
77
 
 
78
 
    field= table_message->add_field();
79
 
    field->set_name("CLUSTER_NAME");
80
 
    field->set_type(message::Table::Field::VARCHAR);
81
 
    stropt= field->mutable_string_options();
82
 
    stropt->set_collation_id(my_charset_bin.number);
83
 
    stropt->set_collation(my_charset_bin.name);
84
 
    stropt->set_length(IB_MAX_TABLE_NAME_LEN);
85
 
 
86
 
    field= table_message->add_field();
87
 
    field->set_name("SPACE");
88
 
    field->set_type(message::Table::Field::INTEGER);
89
 
 
90
 
    message::Table::Index *index= table_message->add_indexes();
91
 
    index->set_name("PRIMARY");
92
 
    index->set_is_primary(true);
93
 
    index->set_is_unique(true);
94
 
    index->set_type(message::Table::Index::BTREE);
95
 
    index->set_key_length(IB_MAX_TABLE_NAME_LEN);
96
 
    message::Table::Index::IndexPart *part= index->add_index_part();
97
 
    part->set_fieldnr(0);
98
 
    part->set_compare_length(IB_MAX_TABLE_NAME_LEN);
99
 
 
100
 
    return 0;
101
 
  }
102
 
  else if (strcmp(table_name, "SYS_COLUMNS") == 0)
103
 
  {
104
 
    message::Table::Field::StringFieldOptions *stropt;
105
 
    message::Engine *engine= table_message->mutable_engine();
106
 
    engine->set_name("InnoDB");
107
 
    table_message->set_name("haildb_sys_columns");
108
 
    table_message->set_schema("data_dictionary");
109
 
    table_message->set_type(message::Table::STANDARD);
110
 
    table_message->set_creation_timestamp(0);
111
 
    table_message->set_update_timestamp(0);
112
 
 
113
 
    message::Table::TableOptions *options= table_message->mutable_options();
114
 
    options->set_collation_id(my_charset_bin.number);
115
 
    options->set_collation(my_charset_bin.name);
116
 
 
117
 
    message::Table::Field *field= table_message->add_field();
118
 
    field->set_name("TABLE_ID");
119
 
    field->set_type(message::Table::Field::BIGINT);
120
 
 
121
 
    field= table_message->add_field();
122
 
    field->set_name("POS");
123
 
    field->set_type(message::Table::Field::INTEGER);
124
 
 
125
 
    field= table_message->add_field();
126
 
    field->set_name("NAME");
127
 
    field->set_type(message::Table::Field::VARCHAR);
128
 
    stropt= field->mutable_string_options();
129
 
    stropt->set_collation_id(my_charset_bin.number);
130
 
    stropt->set_collation(my_charset_bin.name);
131
 
    stropt->set_length(IB_MAX_TABLE_NAME_LEN);
132
 
 
133
 
    field= table_message->add_field();
134
 
    field->set_name("MTYPE");
135
 
    field->set_type(message::Table::Field::INTEGER);
136
 
 
137
 
    field= table_message->add_field();
138
 
    field->set_name("PRTYPE");
139
 
    field->set_type(message::Table::Field::INTEGER);
140
 
 
141
 
    field= table_message->add_field();
142
 
    field->set_name("LEN");
143
 
    field->set_type(message::Table::Field::INTEGER);
144
 
 
145
 
    field= table_message->add_field();
146
 
    field->set_name("PREC");
147
 
    field->set_type(message::Table::Field::INTEGER);
148
 
 
149
 
    message::Table::Index *index= table_message->add_indexes();
150
 
    index->set_name("PRIMARY");
151
 
    index->set_is_primary(true);
152
 
    index->set_is_unique(true);
153
 
    index->set_type(message::Table::Index::BTREE);
154
 
    index->set_key_length(sizeof(uint64_t) + sizeof(uint32_t));
155
 
    message::Table::Index::IndexPart *part= index->add_index_part();
156
 
    part->set_fieldnr(0);
157
 
    part->set_compare_length(sizeof(uint64_t));
158
 
    part= index->add_index_part();
159
 
    part->set_fieldnr(1);
160
 
    part->set_compare_length(sizeof(uint32_t));
161
 
 
162
 
    return 0;
163
 
  }
164
 
  else if (strcmp(table_name, "SYS_INDEXES") == 0)
165
 
  {
166
 
    message::Table::Field::StringFieldOptions *stropt;
167
 
    message::Engine *engine= table_message->mutable_engine();
168
 
    engine->set_name("InnoDB");
169
 
    table_message->set_name("haildb_sys_indexes");
170
 
    table_message->set_schema("data_dictionary");
171
 
    table_message->set_type(message::Table::STANDARD);
172
 
    table_message->set_creation_timestamp(0);
173
 
    table_message->set_update_timestamp(0);
174
 
 
175
 
    message::Table::TableOptions *options= table_message->mutable_options();
176
 
    options->set_collation_id(my_charset_bin.number);
177
 
    options->set_collation(my_charset_bin.name);
178
 
 
179
 
    message::Table::Field *field= table_message->add_field();
180
 
    field->set_name("TABLE_ID");
181
 
    field->set_type(message::Table::Field::BIGINT);
182
 
 
183
 
    field= table_message->add_field();
184
 
    field->set_name("ID");
185
 
    field->set_type(message::Table::Field::BIGINT);
186
 
 
187
 
    field= table_message->add_field();
188
 
    field->set_name("NAME");
189
 
    field->set_type(message::Table::Field::VARCHAR);
190
 
    stropt= field->mutable_string_options();
191
 
    stropt->set_collation_id(my_charset_bin.number);
192
 
    stropt->set_collation(my_charset_bin.name);
193
 
    stropt->set_length(IB_MAX_TABLE_NAME_LEN);
194
 
 
195
 
    field= table_message->add_field();
196
 
    field->set_name("N_FIELDS");
197
 
    field->set_type(message::Table::Field::INTEGER);
198
 
 
199
 
    field= table_message->add_field();
200
 
    field->set_name("TYPE");
201
 
    field->set_type(message::Table::Field::INTEGER);
202
 
 
203
 
    field= table_message->add_field();
204
 
    field->set_name("SPACE");
205
 
    field->set_type(message::Table::Field::INTEGER);
206
 
 
207
 
    field= table_message->add_field();
208
 
    field->set_name("PAGE_NO");
209
 
    field->set_type(message::Table::Field::INTEGER);
210
 
 
211
 
    message::Table::Index *index= table_message->add_indexes();
212
 
    index->set_name("PRIMARY");
213
 
    index->set_is_primary(true);
214
 
    index->set_is_unique(true);
215
 
    index->set_type(message::Table::Index::BTREE);
216
 
    index->set_key_length(sizeof(uint64_t) + sizeof(uint32_t));
217
 
    message::Table::Index::IndexPart *part= index->add_index_part();
218
 
    part->set_fieldnr(0);
219
 
    part->set_compare_length(sizeof(uint64_t));
220
 
    part= index->add_index_part();
221
 
    part->set_fieldnr(1);
222
 
    part->set_compare_length(sizeof(uint32_t));
223
 
 
224
 
    return 0;
225
 
  }
226
 
  else if (strcmp(table_name, "SYS_FIELDS") == 0)
227
 
  {
228
 
    message::Table::Field::StringFieldOptions *stropt;
229
 
    message::Engine *engine= table_message->mutable_engine();
230
 
    engine->set_name("InnoDB");
231
 
    table_message->set_name("haildb_sys_fields");
232
 
    table_message->set_schema("data_dictionary");
233
 
    table_message->set_type(message::Table::STANDARD);
234
 
    table_message->set_creation_timestamp(0);
235
 
    table_message->set_update_timestamp(0);
236
 
 
237
 
    message::Table::TableOptions *options= table_message->mutable_options();
238
 
    options->set_collation_id(my_charset_bin.number);
239
 
    options->set_collation(my_charset_bin.name);
240
 
 
241
 
    message::Table::Field *field= table_message->add_field();
242
 
    field->set_name("INDEX_ID");
243
 
    field->set_type(message::Table::Field::BIGINT);
244
 
 
245
 
    field= table_message->add_field();
246
 
    field->set_name("POS");
247
 
    field->set_type(message::Table::Field::INTEGER);
248
 
 
249
 
    field= table_message->add_field();
250
 
    field->set_name("COL_NAME");
251
 
    field->set_type(message::Table::Field::VARCHAR);
252
 
    stropt= field->mutable_string_options();
253
 
    stropt->set_collation_id(my_charset_bin.number);
254
 
    stropt->set_collation(my_charset_bin.name);
255
 
    stropt->set_length(IB_MAX_TABLE_NAME_LEN);
256
 
 
257
 
    message::Table::Index *index= table_message->add_indexes();
258
 
    index->set_name("PRIMARY");
259
 
    index->set_is_primary(true);
260
 
    index->set_is_unique(true);
261
 
    index->set_type(message::Table::Index::BTREE);
262
 
    index->set_key_length(sizeof(uint64_t) + sizeof(uint32_t));
263
 
    message::Table::Index::IndexPart *part= index->add_index_part();
264
 
    part->set_fieldnr(0);
265
 
    part->set_compare_length(sizeof(uint64_t));
266
 
    part= index->add_index_part();
267
 
    part->set_fieldnr(1);
268
 
    part->set_compare_length(sizeof(uint32_t));
269
 
 
270
 
    return 0;
271
 
  }
272
 
  else if (strcmp(table_name, "SYS_FOREIGN") == 0)
273
 
  {
274
 
    message::Table::Field::StringFieldOptions *stropt;
275
 
    message::Engine *engine= table_message->mutable_engine();
276
 
    engine->set_name("InnoDB");
277
 
    table_message->set_name("haildb_sys_foreign");
278
 
    table_message->set_schema("data_dictionary");
279
 
    table_message->set_type(message::Table::STANDARD);
280
 
    table_message->set_creation_timestamp(0);
281
 
    table_message->set_update_timestamp(0);
282
 
 
283
 
    message::Table::TableOptions *options= table_message->mutable_options();
284
 
    options->set_collation_id(my_charset_bin.number);
285
 
    options->set_collation(my_charset_bin.name);
286
 
 
287
 
    message::Table::Field *field= table_message->add_field();
288
 
    field->set_name("ID");
289
 
    field->set_type(message::Table::Field::BIGINT);
290
 
 
291
 
    field= table_message->add_field();
292
 
    field->set_name("FOR_NAME");
293
 
    field->set_type(message::Table::Field::VARCHAR);
294
 
    stropt= field->mutable_string_options();
295
 
    stropt->set_collation_id(my_charset_bin.number);
296
 
    stropt->set_collation(my_charset_bin.name);
297
 
    stropt->set_length(IB_MAX_TABLE_NAME_LEN);
298
 
 
299
 
    field= table_message->add_field();
300
 
    field->set_name("REF_NAME");
301
 
    field->set_type(message::Table::Field::VARCHAR);
302
 
    stropt= field->mutable_string_options();
303
 
    stropt->set_collation_id(my_charset_bin.number);
304
 
    stropt->set_collation(my_charset_bin.name);
305
 
    stropt->set_length(IB_MAX_TABLE_NAME_LEN);
306
 
 
307
 
    field= table_message->add_field();
308
 
    field->set_name("N_COLS");
309
 
    field->set_type(message::Table::Field::INTEGER);
310
 
 
311
 
    message::Table::Index *index= table_message->add_indexes();
312
 
    index->set_name("PRIMARY");
313
 
    index->set_is_primary(true);
314
 
    index->set_is_unique(true);
315
 
    index->set_type(message::Table::Index::BTREE);
316
 
    index->set_key_length(sizeof(uint64_t));
317
 
    message::Table::Index::IndexPart *part= index->add_index_part();
318
 
    part->set_fieldnr(0);
319
 
    part->set_compare_length(sizeof(uint64_t));
320
 
 
321
 
    index= table_message->add_indexes();
322
 
    index->set_name("FOR_IND");
323
 
    index->set_is_primary(false);
324
 
    index->set_is_unique(false);
325
 
    index->set_type(message::Table::Index::BTREE);
326
 
    index->set_key_length(IB_MAX_TABLE_NAME_LEN);
327
 
    part= index->add_index_part();
328
 
    part->set_fieldnr(1);
329
 
    part->set_compare_length(IB_MAX_TABLE_NAME_LEN);
330
 
 
331
 
    index= table_message->add_indexes();
332
 
    index->set_name("REF_IND");
333
 
    index->set_is_primary(false);
334
 
    index->set_is_unique(false);
335
 
    index->set_type(message::Table::Index::BTREE);
336
 
    index->set_key_length(IB_MAX_TABLE_NAME_LEN);
337
 
    part= index->add_index_part();
338
 
    part->set_fieldnr(2);
339
 
    part->set_compare_length(IB_MAX_TABLE_NAME_LEN);
340
 
    return 0;
341
 
  }
342
 
  else if (strcmp(table_name, "SYS_FOREIGN_COLS") == 0)
343
 
  {
344
 
    message::Table::Field::StringFieldOptions *stropt;
345
 
    message::Engine *engine= table_message->mutable_engine();
346
 
    engine->set_name("InnoDB");
347
 
    table_message->set_name("haildb_sys_foreign_cols");
348
 
    table_message->set_schema("data_dictionary");
349
 
    table_message->set_type(message::Table::STANDARD);
350
 
    table_message->set_creation_timestamp(0);
351
 
    table_message->set_update_timestamp(0);
352
 
 
353
 
    message::Table::TableOptions *options= table_message->mutable_options();
354
 
    options->set_collation_id(my_charset_bin.number);
355
 
    options->set_collation(my_charset_bin.name);
356
 
 
357
 
    message::Table::Field *field= table_message->add_field();
358
 
    field->set_name("ID");
359
 
    field->set_type(message::Table::Field::BIGINT);
360
 
 
361
 
    field= table_message->add_field();
362
 
    field->set_name("POS");
363
 
    field->set_type(message::Table::Field::INTEGER);
364
 
 
365
 
    field= table_message->add_field();
366
 
    field->set_name("FOR_COL_NAME");
367
 
    field->set_type(message::Table::Field::VARCHAR);
368
 
    stropt= field->mutable_string_options();
369
 
    stropt->set_collation_id(my_charset_bin.number);
370
 
    stropt->set_collation(my_charset_bin.name);
371
 
    stropt->set_length(IB_MAX_TABLE_NAME_LEN);
372
 
 
373
 
    field= table_message->add_field();
374
 
    field->set_name("REF_COL_NAME");
375
 
    field->set_type(message::Table::Field::VARCHAR);
376
 
    stropt= field->mutable_string_options();
377
 
    stropt->set_collation_id(my_charset_bin.number);
378
 
    stropt->set_collation(my_charset_bin.name);
379
 
    stropt->set_length(IB_MAX_TABLE_NAME_LEN);
380
 
 
381
 
    message::Table::Index *index= table_message->add_indexes();
382
 
    index->set_name("PRIMARY");
383
 
    index->set_is_primary(true);
384
 
    index->set_is_unique(true);
385
 
    index->set_type(message::Table::Index::BTREE);
386
 
    index->set_key_length(sizeof(uint64_t) + sizeof(uint32_t));
387
 
    message::Table::Index::IndexPart *part= index->add_index_part();
388
 
    part->set_fieldnr(0);
389
 
    part->set_compare_length(sizeof(uint64_t));
390
 
    part= index->add_index_part();
391
 
    part->set_fieldnr(1);
392
 
    part->set_compare_length(sizeof(uint32_t));
393
 
 
394
 
    return 0;
395
 
  }
396
 
 
397
 
  return -1;
398
 
}