~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/table_proto_write.cc

  • Committer: Brian Aker
  • Date: 2011-01-06 05:17:09 UTC
  • Revision ID: brian@tangent.org-20110106051709-oa0se8ur02uc6i9o
Added native functions into the function table.

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(),
85
83
 
86
84
      if (field_arg->flags & NOT_NULL_FLAG)
87
85
      {
88
 
        attribute->mutable_constraints()->set_is_notnull(true);
 
86
        attribute->mutable_constraints()->set_is_nullable(false);
 
87
      }
 
88
      else
 
89
      {
 
90
        attribute->mutable_constraints()->set_is_nullable(true);
89
91
      }
90
92
 
91
93
      if (field_arg->flags & UNSIGNED_FLAG and 
98
100
      attribute->set_name(field_arg->field_name);
99
101
    }
100
102
 
101
 
    assert(((field_arg->flags & NOT_NULL_FLAG)) == attribute->constraints().is_notnull());
 
103
    assert((!(field_arg->flags & NOT_NULL_FLAG)) == attribute->constraints().is_nullable());
102
104
    assert(strcmp(attribute->name().c_str(), field_arg->field_name)==0);
103
105
 
104
106
 
107
109
    if (field_arg->sql_type == DRIZZLE_TYPE_NULL)
108
110
    {
109
111
      my_error(ER_CANT_CREATE_TABLE, MYF(ME_BELL+ME_WAITTANG), table_proto.name().c_str(), -1);
110
 
      return true;
 
112
      return -1;
111
113
    }
112
114
 
113
115
    if (field_arg->flags & UNSIGNED_FLAG and 
117
119
 
118
120
      field_arg->sql_type= DRIZZLE_TYPE_LONGLONG;
119
121
      constraints->set_is_unsigned(true);
 
122
 
 
123
      if (field_arg->flags & NOT_NULL_FLAG)
 
124
      {
 
125
        constraints->set_is_nullable(false);
 
126
      }
 
127
      else
 
128
      {
 
129
        constraints->set_is_nullable(true);
 
130
      }
120
131
    }
121
132
 
122
133
    attribute->set_type(message::internalFieldTypeToFieldProtoType(field_arg->sql_type));
123
134
 
124
135
    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:
 
136
    default: /* Only deal with types that need extra information */
132
137
      break;
133
138
    case message::Table::Field::DOUBLE:
134
139
      {
194
199
        enumeration_options->set_collation(field_arg->charset->name);
195
200
        break;
196
201
      }
197
 
 
198
202
    case message::Table::Field::BLOB:
199
203
      {
200
204
        message::Table::Field::StringFieldOptions *string_field_options;
205
209
      }
206
210
 
207
211
      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
212
    }
217
213
 
218
214
    assert (!use_existing_fields || parser_type == attribute->type());
236
232
        my_error(ER_WRONG_STRING_LENGTH, MYF(0),
237
233
                 field_arg->comment.str,"COLUMN COMMENT",
238
234
                 (uint32_t) COLUMN_COMMENT_MAXLEN);
239
 
        return true;
 
235
        return(1);
240
236
      }
241
237
 
242
238
      if (! use_existing_fields)
268
264
      field_options->set_update_expression("CURRENT_TIMESTAMP");
269
265
    }
270
266
 
271
 
    if (field_arg->def == NULL  && not attribute->constraints().is_notnull())
 
267
    if (field_arg->def == NULL  && attribute->constraints().is_nullable())
272
268
    {
273
269
      message::Table::Field::FieldOptions *field_options;
274
270
      field_options= attribute->mutable_options();
297
293
           < default_value->length()))
298
294
        {
299
295
          my_error(ER_INVALID_DEFAULT, MYF(0), field_arg->field_name);
300
 
          return true;
 
296
          return 1;
301
297
        }
302
298
 
303
299
        if (field_arg->sql_type == DRIZZLE_TYPE_DATE
304
300
            || field_arg->sql_type == DRIZZLE_TYPE_TIME
305
301
            || field_arg->sql_type == DRIZZLE_TYPE_DATETIME
306
 
            || field_arg->sql_type == DRIZZLE_TYPE_MICROTIME
307
302
            || field_arg->sql_type == DRIZZLE_TYPE_TIMESTAMP)
308
303
        {
309
304
          type::Time ltime;
310
305
 
311
 
          if (field_arg->def->get_date(ltime, TIME_FUZZY_DATE))
 
306
          if (field_arg->def->get_date(&ltime, TIME_FUZZY_DATE))
312
307
          {
313
308
            my_error(ER_INVALID_DATETIME_VALUE, MYF(ME_FATALERROR),
314
309
                     default_value->c_str());
315
 
            return true;
 
310
            return 1;
316
311
          }
317
312
 
318
313
          /* We now do the casting down to the appropriate type.
386
381
      my_error(ER_WRONG_STRING_LENGTH, MYF(0),
387
382
               table_options->comment().c_str(),"Table COMMENT",
388
383
               (uint32_t) TABLE_COMMENT_MAXLEN);
389
 
      return true;
 
384
      return(1);
390
385
    }
391
386
  }
392
387
 
393
388
  if (create_info->default_table_charset)
394
389
  {
395
 
    table_options->set_collation_id(create_info->default_table_charset->number);
 
390
    table_options->set_collation_id(
 
391
                               create_info->default_table_charset->number);
396
392
    table_options->set_collation(create_info->default_table_charset->name);
397
393
  }
398
394
 
482
478
        my_error(ER_WRONG_STRING_LENGTH, MYF(0),
483
479
                 key_info[i].comment.str,"Index COMMENT",
484
480
                 (uint32_t) TABLE_COMMENT_MAXLEN);
485
 
        return true;
 
481
        return(1);
486
482
      }
487
483
 
488
484
      idx->set_comment(key_info[i].comment.str);
533
529
             table_proto.name().c_str(),
534
530
             table_proto.InitializationErrorString().c_str());
535
531
 
536
 
    return true;
 
532
    return 1;
537
533
  }
538
534
 
539
535
  /*
553
549
               table_proto.name().c_str(),
554
550
               table_proto.InitializationErrorString().c_str());
555
551
 
556
 
      return true;
 
552
      return 1;
557
553
    }
558
554
  }
559
555
 
560
 
  return false;
 
556
  return 0;
561
557
}
562
558
 
563
559
/*
580
576
*/
581
577
 
582
578
bool rea_create_table(Session *session,
583
 
                      const identifier::Table &identifier,
 
579
                      const TableIdentifier &identifier,
584
580
                      message::Table &table_proto,
585
581
                      HA_CREATE_INFO *create_info,
586
582
                      List<CreateField> &create_fields,
589
585
  assert(table_proto.has_name());
590
586
  if (fill_table_proto(table_proto, create_fields, create_info,
591
587
                       keys, key_info))
592
 
  {
593
588
    return false;
594
 
  }
595
589
 
596
590
  assert(table_proto.name() == identifier.getTableName());
597
591
 
598
 
  if (not plugin::StorageEngine::createTable(*session,
599
 
                                             identifier,
600
 
                                             table_proto))
 
592
  if (plugin::StorageEngine::createTable(*session,
 
593
                                         identifier,
 
594
                                         table_proto))
601
595
  {
602
596
    return false;
603
597
  }