~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/table_proto_write.cc

  • Committer: Stewart Smith
  • Date: 2010-11-07 04:22:31 UTC
  • mto: (1911.1.2 build)
  • mto: This revision was merged to the branch mainline in revision 1912.
  • Revision ID: stewart@flamingspork.com-20101107042231-ola4sl7j0qvg58tz
fix ARCHIVE storage engine calling exit (lintian warning). Was because we were linking in libinternal into libazio, which links into archive plugin. Just link libinternal into the command line utilities.

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/plugin/storage_engine.h>
25
 
 
26
 
#include <drizzled/internal/my_sys.h>
27
 
#include <drizzled/typelib.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
 
28
26
 
29
27
/* For proto */
30
28
#include <string>
39
37
#include <drizzled/table_proto.h>
40
38
#include <drizzled/charset.h>
41
39
 
42
 
#include <drizzled/function/time/typecast.h>
 
40
#include "drizzled/function/time/typecast.h"
43
41
 
44
42
using namespace std;
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
 
  List<CreateField>::iterator it(create_fields.begin());
 
53
  List_iterator<CreateField> it(create_fields);
56
54
  message::Table::TableOptions *table_options= table_proto.mutable_options();
57
55
 
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
 
105
97
    message::Table::Field::FieldType parser_type= attribute->type();
106
98
 
107
 
    if (field_arg->sql_type == DRIZZLE_TYPE_NULL)
108
 
    {
109
 
      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);
120
 
    }
121
 
 
122
99
    attribute->set_type(message::internalFieldTypeToFieldProtoType(field_arg->sql_type));
123
100
 
124
101
    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:
 
102
    default: /* Only deal with types that need extra information */
132
103
      break;
133
104
    case message::Table::Field::DOUBLE:
134
105
      {
194
165
        enumeration_options->set_collation(field_arg->charset->name);
195
166
        break;
196
167
      }
197
 
 
198
168
    case message::Table::Field::BLOB:
199
169
      {
200
170
        message::Table::Field::StringFieldOptions *string_field_options;
205
175
      }
206
176
 
207
177
      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
178
    }
217
179
 
218
180
    assert (!use_existing_fields || parser_type == attribute->type());
236
198
        my_error(ER_WRONG_STRING_LENGTH, MYF(0),
237
199
                 field_arg->comment.str,"COLUMN COMMENT",
238
200
                 (uint32_t) COLUMN_COMMENT_MAXLEN);
239
 
        return true;
 
201
        return(1);
240
202
      }
241
203
 
242
204
      if (! use_existing_fields)
268
230
      field_options->set_update_expression("CURRENT_TIMESTAMP");
269
231
    }
270
232
 
271
 
    if (field_arg->def == NULL  && not attribute->constraints().is_notnull())
 
233
    if (field_arg->def == NULL  && attribute->constraints().is_nullable())
272
234
    {
273
235
      message::Table::Field::FieldOptions *field_options;
274
236
      field_options= attribute->mutable_options();
297
259
           < default_value->length()))
298
260
        {
299
261
          my_error(ER_INVALID_DEFAULT, MYF(0), field_arg->field_name);
300
 
          return true;
 
262
          return 1;
301
263
        }
302
264
 
303
 
        if (field::isDateTime(field_arg->sql_type))
 
265
        if (field_arg->sql_type == DRIZZLE_TYPE_DATE
 
266
            || field_arg->sql_type == DRIZZLE_TYPE_DATETIME
 
267
            || field_arg->sql_type == DRIZZLE_TYPE_TIMESTAMP)
304
268
        {
305
 
          type::Time ltime;
 
269
          DRIZZLE_TIME ltime;
306
270
 
307
 
          if (field_arg->def->get_date(ltime, TIME_FUZZY_DATE))
 
271
          if (field_arg->def->get_date(&ltime, TIME_FUZZY_DATE))
308
272
          {
309
273
            my_error(ER_INVALID_DATETIME_VALUE, MYF(ME_FATALERROR),
310
274
                     default_value->c_str());
311
 
            return true;
 
275
            return 1;
312
276
          }
313
277
 
314
278
          /* We now do the casting down to the appropriate type.
382
346
      my_error(ER_WRONG_STRING_LENGTH, MYF(0),
383
347
               table_options->comment().c_str(),"Table COMMENT",
384
348
               (uint32_t) TABLE_COMMENT_MAXLEN);
385
 
      return true;
 
349
      return(1);
386
350
    }
387
351
  }
388
352
 
389
353
  if (create_info->default_table_charset)
390
354
  {
391
 
    table_options->set_collation_id(create_info->default_table_charset->number);
 
355
    table_options->set_collation_id(
 
356
                               create_info->default_table_charset->number);
392
357
    table_options->set_collation(create_info->default_table_charset->name);
393
358
  }
394
359
 
478
443
        my_error(ER_WRONG_STRING_LENGTH, MYF(0),
479
444
                 key_info[i].comment.str,"Index COMMENT",
480
445
                 (uint32_t) TABLE_COMMENT_MAXLEN);
481
 
        return true;
 
446
        return(1);
482
447
      }
483
448
 
484
449
      idx->set_comment(key_info[i].comment.str);
525
490
 
526
491
  if (not table_proto.IsInitialized())
527
492
  {
528
 
    my_error(ER_CORRUPT_TABLE_DEFINITION, MYF(0),
529
 
             table_proto.name().c_str(),
530
 
             table_proto.InitializationErrorString().c_str());
531
 
 
532
 
    return true;
 
493
    my_error(ER_CORRUPT_TABLE_DEFINITION, MYF(0), table_proto.InitializationErrorString().c_str());
 
494
    return 1;
533
495
  }
534
496
 
535
497
  /*
546
508
    catch (...)
547
509
    {
548
510
      my_error(ER_CORRUPT_TABLE_DEFINITION, MYF(0),
549
 
               table_proto.name().c_str(),
550
 
               table_proto.InitializationErrorString().c_str());
 
511
               table_proto.InitializationErrorString().empty() ? "": table_proto.InitializationErrorString().c_str());
551
512
 
552
 
      return true;
 
513
      return 1;
553
514
    }
554
515
  }
555
516
 
556
 
  return false;
 
517
  return 0;
557
518
}
558
519
 
559
520
/*
576
537
*/
577
538
 
578
539
bool rea_create_table(Session *session,
579
 
                      const identifier::Table &identifier,
 
540
                      TableIdentifier &identifier,
580
541
                      message::Table &table_proto,
581
542
                      HA_CREATE_INFO *create_info,
582
543
                      List<CreateField> &create_fields,
585
546
  assert(table_proto.has_name());
586
547
  if (fill_table_proto(table_proto, create_fields, create_info,
587
548
                       keys, key_info))
588
 
  {
589
549
    return false;
590
 
  }
591
550
 
592
551
  assert(table_proto.name() == identifier.getTableName());
593
552
 
594
 
  if (not plugin::StorageEngine::createTable(*session,
595
 
                                             identifier,
596
 
                                             table_proto))
 
553
  if (plugin::StorageEngine::createTable(*session,
 
554
                                         identifier,
 
555
                                         table_proto))
597
556
  {
598
557
    return false;
599
558
  }