~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/message/table_writer.cc

  • Committer: Tim Penhey
  • Date: 2010-01-20 02:39:01 UTC
  • mto: This revision was merged to the branch mainline in revision 1275.
  • Revision ID: tim.penhey@canonical.com-20100120023901-8teeunid6gwlthzx
Add in a rot 13 function.

Show diffs side-by-side

added added

removed removed

Lines of Context:
22
22
#include <iostream>
23
23
#include <fstream>
24
24
#include <string>
25
 
#include <getopt.h>
26
25
#include <drizzled/message/table.pb.h>
27
26
 
28
27
using namespace std;
79
78
  index->set_is_primary(is_primary);
80
79
  index->set_is_unique(is_unique);
81
80
 
82
 
  int key_length= 0;
83
 
 
84
 
  for(int i=0; i< num_index_parts; i++)
85
 
    key_length+= compare_lengths[i];
86
 
 
87
 
  index->set_key_length(key_length);
88
 
 
89
81
  while (x < num_index_parts)
90
82
  {
91
83
    index_part= index->add_index_part();
107
99
  message::Table::Field::FieldConstraints *field_constraints;
108
100
  message::Table::Field::StringFieldOptions *string_field_options;
109
101
  message::Table::Field::NumericFieldOptions *numeric_field_options;
110
 
  message::Table::Field::EnumerationValues *enumeration_options;
 
102
  message::Table::Field::SetFieldOptions *set_field_options;
111
103
 
112
104
  table->set_name(name);
113
105
  table->set_type(message::Table::STANDARD);
120
112
    field_constraints= field->mutable_constraints();
121
113
    string_field_options= field->mutable_string_options();
122
114
 
123
 
    snprintf(buffer, sizeof(buffer), "sample%u", x);
 
115
    sprintf(buffer, "sample%u", x);
124
116
 
125
117
    field->set_name(buffer);
126
118
    field->set_type(message::Table::Field::VARCHAR);
147
139
    field->set_type(message::Table::Field::ENUM);
148
140
    field->set_name("colors");
149
141
 
150
 
    enumeration_options= field->mutable_enumeration_values();
151
 
    enumeration_options->add_field_value("red");
152
 
    enumeration_options->add_field_value("blue");
153
 
    enumeration_options->add_field_value("green");
 
142
    set_field_options= field->mutable_set_options();
 
143
    set_field_options->add_field_value("red");
 
144
    set_field_options->add_field_value("blue");
 
145
    set_field_options->add_field_value("green");
 
146
    set_field_options->set_count_elements(set_field_options->field_value_size());
154
147
  }
155
148
  /* Write out a BLOB */
156
149
  {
197
190
 
198
191
}
199
192
 
200
 
static void fill_table1(message::Table *table)
201
 
{
202
 
  message::Table::Field *field;
203
 
  message::Table::TableOptions *tableopts;
204
 
 
205
 
  table->set_name("t1");
206
 
  table->set_type(message::Table::INTERNAL);
207
 
 
208
 
  tableopts= table->mutable_options();
209
 
  tableopts->set_comment("Table without a StorageEngine message");
210
 
 
211
 
  {
212
 
    field= table->add_field();
213
 
    field->set_name("number");
214
 
    field->set_type(message::Table::Field::INTEGER);
215
 
  }
216
 
 
217
 
}
218
 
 
219
 
static void usage(char *argv0)
220
 
{
221
 
  cerr << "Usage:  " << argv0 << " [-t N] TABLE_NAME.dfe" << endl;
222
 
  cerr << endl;
223
 
  cerr << "-t N\tTable Number" << endl;
224
 
  cerr << "\t0 - default" << endl;
225
 
  cerr << endl;
226
 
}
227
 
 
228
193
int main(int argc, char* argv[])
229
194
{
230
 
  int opt;
231
 
  int table_number= 0;
232
 
 
233
195
  GOOGLE_PROTOBUF_VERIFY_VERSION;
234
196
 
235
 
  while ((opt= getopt(argc, argv, "t:")) != -1)
 
197
  if (argc != 2)
236
198
  {
237
 
    switch (opt)
238
 
    {
239
 
    case 't':
240
 
      table_number= atoi(optarg);
241
 
      break;
242
 
    default:
243
 
      usage(argv[0]);
244
 
      exit(EXIT_FAILURE);
245
 
    }
246
 
  }
247
 
 
248
 
  if (optind >= argc) {
249
 
    fprintf(stderr, "Expected Table name argument\n\n");
250
 
    usage(argv[0]);
251
 
    exit(EXIT_FAILURE);
 
199
    cerr << "Usage:  " << argv[0] << " SCHEMA" << endl;
 
200
    return -1;
252
201
  }
253
202
 
254
203
  message::Table table;
255
204
 
256
 
  switch (table_number)
257
 
  {
258
 
  case 0:
259
 
    fill_table(&table, "example_table");
260
 
    break;
261
 
  case 1:
262
 
    fill_table1(&table);
263
 
    break;
264
 
  default:
265
 
    fprintf(stderr, "Invalid table number.\n\n");
266
 
    usage(argv[0]);
267
 
    exit(EXIT_FAILURE);
268
 
  }
 
205
  fill_table(&table, "example_table");
269
206
 
270
 
  fstream output(argv[optind], ios::out | ios::trunc | ios::binary);
 
207
  fstream output(argv[1], ios::out | ios::trunc | ios::binary);
271
208
  if (!table.SerializeToOstream(&output))
272
209
  {
273
210
    cerr << "Failed to write schema." << endl;