~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/table_proto_write.cc

  • Committer: Lee Bieber
  • Date: 2010-11-14 23:15:42 UTC
  • mfrom: (1929.1.42 warning-stack-frame)
  • Revision ID: kalebral@gmail.com-20101114231542-fnnu6ydd2p17n582
Merge Monty - fix bug 672372: some functions use > 32k stack

Show diffs side-by-side

added added

removed removed

Lines of Context:
21
21
#include "drizzled/global_charset_info.h"
22
22
#include "drizzled/message/statement_transform.h"
23
23
 
24
 
#include <drizzled/plugin/storage_engine.h>
25
 
 
26
24
#include "drizzled/internal/my_sys.h"
27
25
 
28
26
 
45
43
 
46
44
namespace drizzled {
47
45
 
48
 
bool fill_table_proto(message::Table &table_proto,
49
 
                      List<CreateField> &create_fields,
50
 
                      HA_CREATE_INFO *create_info,
51
 
                      uint32_t keys,
52
 
                      KeyInfo *key_info)
 
46
static int fill_table_proto(message::Table &table_proto,
 
47
                            List<CreateField> &create_fields,
 
48
                            HA_CREATE_INFO *create_info,
 
49
                            uint32_t keys,
 
50
                            KeyInfo *key_info)
53
51
{
54
52
  CreateField *field_arg;
55
53
  List_iterator<CreateField> it(create_fields);
58
56
  if (create_fields.elements > MAX_FIELDS)
59
57
  {
60
58
    my_error(ER_TOO_MANY_FIELDS, MYF(0), ER(ER_TOO_MANY_FIELDS));
61
 
    return true;
 
59
    return(1);
62
60
  }
63
61
 
64
62
  assert(strcmp(table_proto.engine().name().c_str(),
75
73
       filled out Field messages */
76
74
 
77
75
    if (use_existing_fields)
78
 
    {
79
76
      attribute= table_proto.mutable_field(field_number++);
80
 
    }
81
77
    else
82
78
    {
83
79
      /* Other code paths still have to fill out the proto */
85
81
 
86
82
      if (field_arg->flags & NOT_NULL_FLAG)
87
83
      {
88
 
        attribute->mutable_constraints()->set_is_notnull(true);
89
 
      }
 
84
        message::Table::Field::FieldConstraints *constraints;
90
85
 
91
 
      if (field_arg->flags & UNSIGNED_FLAG and 
92
 
          (field_arg->sql_type == DRIZZLE_TYPE_LONGLONG or field_arg->sql_type == DRIZZLE_TYPE_LONG))
93
 
      {
94
 
        field_arg->sql_type= DRIZZLE_TYPE_LONGLONG;
95
 
        attribute->mutable_constraints()->set_is_unsigned(true);
 
86
        constraints= attribute->mutable_constraints();
 
87
        constraints->set_is_nullable(false);
96
88
      }
97
89
 
98
90
      attribute->set_name(field_arg->field_name);
99
91
    }
100
92
 
101
 
    assert(((field_arg->flags & NOT_NULL_FLAG)) == attribute->constraints().is_notnull());
 
93
    assert((!(field_arg->flags & NOT_NULL_FLAG)) == attribute->constraints().is_nullable());
102
94
    assert(strcmp(attribute->name().c_str(), field_arg->field_name)==0);
103
95
 
104
96
 
107
99
    if (field_arg->sql_type == DRIZZLE_TYPE_NULL)
108
100
    {
109
101
      my_error(ER_CANT_CREATE_TABLE, MYF(ME_BELL+ME_WAITTANG), table_proto.name().c_str(), -1);
110
 
      return true;
111
 
    }
112
 
 
113
 
    if (field_arg->flags & UNSIGNED_FLAG and 
114
 
       (field_arg->sql_type == DRIZZLE_TYPE_LONGLONG or field_arg->sql_type == DRIZZLE_TYPE_LONG))
115
 
    {
116
 
      message::Table::Field::FieldConstraints *constraints= attribute->mutable_constraints();
117
 
 
118
 
      field_arg->sql_type= DRIZZLE_TYPE_LONGLONG;
119
 
      constraints->set_is_unsigned(true);
 
102
      return -1;
120
103
    }
121
104
 
122
105
    attribute->set_type(message::internalFieldTypeToFieldProtoType(field_arg->sql_type));
123
106
 
124
107
    switch (attribute->type()) {
125
 
    case message::Table::Field::BIGINT:
126
 
    case message::Table::Field::INTEGER:
127
 
    case message::Table::Field::DATE:
128
 
    case message::Table::Field::DATETIME:
129
 
    case message::Table::Field::UUID:
130
 
    case message::Table::Field::TIME:
131
 
    case message::Table::Field::BOOLEAN:
 
108
    default: /* Only deal with types that need extra information */
132
109
      break;
133
110
    case message::Table::Field::DOUBLE:
134
111
      {
194
171
        enumeration_options->set_collation(field_arg->charset->name);
195
172
        break;
196
173
      }
197
 
 
198
174
    case message::Table::Field::BLOB:
199
175
      {
200
176
        message::Table::Field::StringFieldOptions *string_field_options;
205
181
      }
206
182
 
207
183
      break;
208
 
 
209
 
    case message::Table::Field::EPOCH:
210
 
      {
211
 
        if (field_arg->sql_type == DRIZZLE_TYPE_MICROTIME)
212
 
          attribute->mutable_time_options()->set_microseconds(true);
213
 
      }
214
 
 
215
 
      break;
216
184
    }
217
185
 
218
186
    assert (!use_existing_fields || parser_type == attribute->type());
236
204
        my_error(ER_WRONG_STRING_LENGTH, MYF(0),
237
205
                 field_arg->comment.str,"COLUMN COMMENT",
238
206
                 (uint32_t) COLUMN_COMMENT_MAXLEN);
239
 
        return true;
 
207
        return(1);
240
208
      }
241
209
 
242
210
      if (! use_existing_fields)
268
236
      field_options->set_update_expression("CURRENT_TIMESTAMP");
269
237
    }
270
238
 
271
 
    if (field_arg->def == NULL  && not attribute->constraints().is_notnull())
 
239
    if (field_arg->def == NULL  && attribute->constraints().is_nullable())
272
240
    {
273
241
      message::Table::Field::FieldOptions *field_options;
274
242
      field_options= attribute->mutable_options();
297
265
           < default_value->length()))
298
266
        {
299
267
          my_error(ER_INVALID_DEFAULT, MYF(0), field_arg->field_name);
300
 
          return true;
 
268
          return 1;
301
269
        }
302
270
 
303
271
        if (field_arg->sql_type == DRIZZLE_TYPE_DATE
304
 
            || field_arg->sql_type == DRIZZLE_TYPE_TIME
305
272
            || field_arg->sql_type == DRIZZLE_TYPE_DATETIME
306
 
            || field_arg->sql_type == DRIZZLE_TYPE_MICROTIME
307
273
            || field_arg->sql_type == DRIZZLE_TYPE_TIMESTAMP)
308
274
        {
309
 
          type::Time ltime;
 
275
          DRIZZLE_TIME ltime;
310
276
 
311
 
          if (field_arg->def->get_date(ltime, TIME_FUZZY_DATE))
 
277
          if (field_arg->def->get_date(&ltime, TIME_FUZZY_DATE))
312
278
          {
313
279
            my_error(ER_INVALID_DATETIME_VALUE, MYF(ME_FATALERROR),
314
280
                     default_value->c_str());
315
 
            return true;
 
281
            return 1;
316
282
          }
317
283
 
318
284
          /* We now do the casting down to the appropriate type.
386
352
      my_error(ER_WRONG_STRING_LENGTH, MYF(0),
387
353
               table_options->comment().c_str(),"Table COMMENT",
388
354
               (uint32_t) TABLE_COMMENT_MAXLEN);
389
 
      return true;
 
355
      return(1);
390
356
    }
391
357
  }
392
358
 
393
359
  if (create_info->default_table_charset)
394
360
  {
395
 
    table_options->set_collation_id(create_info->default_table_charset->number);
 
361
    table_options->set_collation_id(
 
362
                               create_info->default_table_charset->number);
396
363
    table_options->set_collation(create_info->default_table_charset->name);
397
364
  }
398
365
 
482
449
        my_error(ER_WRONG_STRING_LENGTH, MYF(0),
483
450
                 key_info[i].comment.str,"Index COMMENT",
484
451
                 (uint32_t) TABLE_COMMENT_MAXLEN);
485
 
        return true;
 
452
        return(1);
486
453
      }
487
454
 
488
455
      idx->set_comment(key_info[i].comment.str);
529
496
 
530
497
  if (not table_proto.IsInitialized())
531
498
  {
532
 
    my_error(ER_CORRUPT_TABLE_DEFINITION, MYF(0),
533
 
             table_proto.name().c_str(),
534
 
             table_proto.InitializationErrorString().c_str());
535
 
 
536
 
    return true;
 
499
    my_error(ER_CORRUPT_TABLE_DEFINITION, MYF(0), table_proto.InitializationErrorString().c_str());
 
500
    return 1;
537
501
  }
538
502
 
539
503
  /*
550
514
    catch (...)
551
515
    {
552
516
      my_error(ER_CORRUPT_TABLE_DEFINITION, MYF(0),
553
 
               table_proto.name().c_str(),
554
 
               table_proto.InitializationErrorString().c_str());
 
517
               table_proto.InitializationErrorString().empty() ? "": table_proto.InitializationErrorString().c_str());
555
518
 
556
 
      return true;
 
519
      return 1;
557
520
    }
558
521
  }
559
522
 
560
 
  return false;
 
523
  return 0;
561
524
}
562
525
 
563
526
/*
580
543
*/
581
544
 
582
545
bool rea_create_table(Session *session,
583
 
                      const identifier::Table &identifier,
 
546
                      TableIdentifier &identifier,
584
547
                      message::Table &table_proto,
585
548
                      HA_CREATE_INFO *create_info,
586
549
                      List<CreateField> &create_fields,
589
552
  assert(table_proto.has_name());
590
553
  if (fill_table_proto(table_proto, create_fields, create_info,
591
554
                       keys, key_info))
592
 
  {
593
555
    return false;
594
 
  }
595
556
 
596
557
  assert(table_proto.name() == identifier.getTableName());
597
558
 
598
 
  if (not plugin::StorageEngine::createTable(*session,
599
 
                                             identifier,
600
 
                                             table_proto))
 
559
  if (plugin::StorageEngine::createTable(*session,
 
560
                                         identifier,
 
561
                                         table_proto))
601
562
  {
602
563
    return false;
603
564
  }