~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/table_proto_write.cc

  • Committer: Brian Aker
  • Date: 2011-02-22 06:12:02 UTC
  • mfrom: (2190.1.6 drizzle-build)
  • Revision ID: brian@tangent.org-20110222061202-k03czxykqy4x9hjs
List update, header fixes, multiple symbols, and David deletes some code.

Show diffs side-by-side

added added

removed removed

Lines of Context:
13
13
   along with this program; if not, write to the Free Software
14
14
   Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA */
15
15
 
16
 
#include "config.h"
 
16
#include <config.h>
17
17
#include <drizzled/error.h>
18
18
#include <drizzled/session.h>
19
19
#include <drizzled/unireg.h>
20
 
#include "drizzled/sql_table.h"
21
 
#include "drizzled/global_charset_info.h"
22
 
#include "drizzled/message/statement_transform.h"
23
 
 
24
 
#include "drizzled/internal/my_sys.h"
25
 
 
 
20
#include <drizzled/sql_table.h>
 
21
#include <drizzled/global_charset_info.h>
 
22
#include <drizzled/message/statement_transform.h>
 
23
 
 
24
#include <drizzled/plugin/storage_engine.h>
 
25
 
 
26
#include <drizzled/internal/my_sys.h>
 
27
#include <drizzled/typelib.h>
26
28
 
27
29
/* For proto */
28
30
#include <string>
37
39
#include <drizzled/table_proto.h>
38
40
#include <drizzled/charset.h>
39
41
 
40
 
#include "drizzled/function/time/typecast.h"
 
42
#include <drizzled/function/time/typecast.h>
41
43
 
42
44
using namespace std;
43
45
 
44
46
namespace drizzled {
45
47
 
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)
 
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)
51
53
{
52
54
  CreateField *field_arg;
53
 
  List_iterator<CreateField> it(create_fields);
 
55
  List<CreateField>::iterator it(create_fields.begin());
54
56
  message::Table::TableOptions *table_options= table_proto.mutable_options();
55
57
 
56
58
  if (create_fields.elements > MAX_FIELDS)
57
59
  {
58
60
    my_error(ER_TOO_MANY_FIELDS, MYF(0), ER(ER_TOO_MANY_FIELDS));
59
 
    return(1);
 
61
    return true;
60
62
  }
61
63
 
62
64
  assert(strcmp(table_proto.engine().name().c_str(),
83
85
 
84
86
      if (field_arg->flags & NOT_NULL_FLAG)
85
87
      {
86
 
        attribute->mutable_constraints()->set_is_nullable(false);
87
 
      }
88
 
      else
89
 
      {
90
 
        attribute->mutable_constraints()->set_is_nullable(true);
 
88
        attribute->mutable_constraints()->set_is_notnull(true);
91
89
      }
92
90
 
93
91
      if (field_arg->flags & UNSIGNED_FLAG and 
100
98
      attribute->set_name(field_arg->field_name);
101
99
    }
102
100
 
103
 
    assert((!(field_arg->flags & NOT_NULL_FLAG)) == attribute->constraints().is_nullable());
 
101
    assert(((field_arg->flags & NOT_NULL_FLAG)) == attribute->constraints().is_notnull());
104
102
    assert(strcmp(attribute->name().c_str(), field_arg->field_name)==0);
105
103
 
106
104
 
109
107
    if (field_arg->sql_type == DRIZZLE_TYPE_NULL)
110
108
    {
111
109
      my_error(ER_CANT_CREATE_TABLE, MYF(ME_BELL+ME_WAITTANG), table_proto.name().c_str(), -1);
112
 
      return -1;
 
110
      return true;
113
111
    }
114
112
 
115
113
    if (field_arg->flags & UNSIGNED_FLAG and 
119
117
 
120
118
      field_arg->sql_type= DRIZZLE_TYPE_LONGLONG;
121
119
      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
 
      }
131
120
    }
132
121
 
133
122
    attribute->set_type(message::internalFieldTypeToFieldProtoType(field_arg->sql_type));
134
123
 
135
124
    switch (attribute->type()) {
136
 
    default: /* Only deal with types that need extra information */
 
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:
137
132
      break;
138
133
    case message::Table::Field::DOUBLE:
139
134
      {
199
194
        enumeration_options->set_collation(field_arg->charset->name);
200
195
        break;
201
196
      }
 
197
 
202
198
    case message::Table::Field::BLOB:
203
199
      {
204
200
        message::Table::Field::StringFieldOptions *string_field_options;
209
205
      }
210
206
 
211
207
      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;
212
216
    }
213
217
 
214
218
    assert (!use_existing_fields || parser_type == attribute->type());
232
236
        my_error(ER_WRONG_STRING_LENGTH, MYF(0),
233
237
                 field_arg->comment.str,"COLUMN COMMENT",
234
238
                 (uint32_t) COLUMN_COMMENT_MAXLEN);
235
 
        return(1);
 
239
        return true;
236
240
      }
237
241
 
238
242
      if (! use_existing_fields)
264
268
      field_options->set_update_expression("CURRENT_TIMESTAMP");
265
269
    }
266
270
 
267
 
    if (field_arg->def == NULL  && attribute->constraints().is_nullable())
 
271
    if (field_arg->def == NULL  && not attribute->constraints().is_notnull())
268
272
    {
269
273
      message::Table::Field::FieldOptions *field_options;
270
274
      field_options= attribute->mutable_options();
293
297
           < default_value->length()))
294
298
        {
295
299
          my_error(ER_INVALID_DEFAULT, MYF(0), field_arg->field_name);
296
 
          return 1;
 
300
          return true;
297
301
        }
298
302
 
299
 
        if (field_arg->sql_type == DRIZZLE_TYPE_DATE
300
 
            || field_arg->sql_type == DRIZZLE_TYPE_TIME
301
 
            || field_arg->sql_type == DRIZZLE_TYPE_DATETIME
302
 
            || field_arg->sql_type == DRIZZLE_TYPE_TIMESTAMP)
 
303
        if (field::isDateTime(field_arg->sql_type))
303
304
        {
304
 
          DRIZZLE_TIME ltime;
 
305
          type::Time ltime;
305
306
 
306
 
          if (field_arg->def->get_date(&ltime, TIME_FUZZY_DATE))
 
307
          if (field_arg->def->get_date(ltime, TIME_FUZZY_DATE))
307
308
          {
308
309
            my_error(ER_INVALID_DATETIME_VALUE, MYF(ME_FATALERROR),
309
310
                     default_value->c_str());
310
 
            return 1;
 
311
            return true;
311
312
          }
312
313
 
313
314
          /* We now do the casting down to the appropriate type.
381
382
      my_error(ER_WRONG_STRING_LENGTH, MYF(0),
382
383
               table_options->comment().c_str(),"Table COMMENT",
383
384
               (uint32_t) TABLE_COMMENT_MAXLEN);
384
 
      return(1);
 
385
      return true;
385
386
    }
386
387
  }
387
388
 
388
389
  if (create_info->default_table_charset)
389
390
  {
390
 
    table_options->set_collation_id(
391
 
                               create_info->default_table_charset->number);
 
391
    table_options->set_collation_id(create_info->default_table_charset->number);
392
392
    table_options->set_collation(create_info->default_table_charset->name);
393
393
  }
394
394
 
478
478
        my_error(ER_WRONG_STRING_LENGTH, MYF(0),
479
479
                 key_info[i].comment.str,"Index COMMENT",
480
480
                 (uint32_t) TABLE_COMMENT_MAXLEN);
481
 
        return(1);
 
481
        return true;
482
482
      }
483
483
 
484
484
      idx->set_comment(key_info[i].comment.str);
529
529
             table_proto.name().c_str(),
530
530
             table_proto.InitializationErrorString().c_str());
531
531
 
532
 
    return 1;
 
532
    return true;
533
533
  }
534
534
 
535
535
  /*
549
549
               table_proto.name().c_str(),
550
550
               table_proto.InitializationErrorString().c_str());
551
551
 
552
 
      return 1;
 
552
      return true;
553
553
    }
554
554
  }
555
555
 
556
 
  return 0;
 
556
  return false;
557
557
}
558
558
 
559
559
/*
576
576
*/
577
577
 
578
578
bool rea_create_table(Session *session,
579
 
                      const TableIdentifier &identifier,
 
579
                      const identifier::Table &identifier,
580
580
                      message::Table &table_proto,
581
581
                      HA_CREATE_INFO *create_info,
582
582
                      List<CreateField> &create_fields,
585
585
  assert(table_proto.has_name());
586
586
  if (fill_table_proto(table_proto, create_fields, create_info,
587
587
                       keys, key_info))
 
588
  {
588
589
    return false;
 
590
  }
589
591
 
590
592
  assert(table_proto.name() == identifier.getTableName());
591
593
 
592
 
  if (plugin::StorageEngine::createTable(*session,
593
 
                                         identifier,
594
 
                                         table_proto))
 
594
  if (not plugin::StorageEngine::createTable(*session,
 
595
                                             identifier,
 
596
                                             table_proto))
595
597
  {
596
598
    return false;
597
599
  }